1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
//mdm:
// Painter : class_pixmap.h
// Creation date : Fri Mar 18 14:30:48 CEST 2005
// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
// Lucia Papini (^ashura^) English Translation.
// This file is part of the KVirc irc client distribution
// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
//
// This program is FREE software. You can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your opinion) any later version.
//
// This program is distributed in the HOPE that it will be USEFUL,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, write to the Free Software Foundation,
// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include "class_pixmap.h"
#include "kvi_debug.h"
#include "kvi_locale.h"
#include <tqfile.h>
/*
@doc: pixmap
@keyterms:
pixmap object class
@title:
pixmap class
@type:
class
@short:
This class provide a pixmap.
@inherits:
[class]object[/class]
[class]widget[/class]
@description:
The pixmap class is an off-screen, pixel-based paint device.
@functions:
!fn: $fill(<widget:object>,<x_offset:integer>,<y:offset>)
Fills the pixmap with the widget's background color or pixmap.[br]
Note that x_offset, y_offest are offsets in the widget.
!fn: $resize(<width:integer>,<height:integer>)
Resizes the pixmap to w width and h height. Set wh or hg to 0, to have a null pixmap.
!fn: $scale(<sx:real>,<sy:real>)
Scales the pixmap by sx horizontally and sy vertically.
!fn: $rotate(<a:real>)
Rotates the pixmap by a degrees.
!fn: $load(<file_name:string>)
Load a pixmap from the <file>.
!fn: <integer> $height()
Return the height of the pixmap.
!fn: <integer> $width()
Return the width of the pixmap.
*/
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_pixmap,"pixmap","object")
KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"fill",functionfill)
KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"resize",functionresize)
KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"load",functionload)
KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"height",functionheight)
KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"width",functionwidth)
KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"setOpacity",functionsetOpacity)
KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"scale",functionscale)
KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"rotate",functionrotate)
KVSO_END_REGISTERCLASS(KviKvsObject_pixmap)
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_pixmap,KviKvsObject)
m_pPixmap=new TQPixmap();
m_pImage=new TQImage();
bPixmapModified=false;
bImageModified=false;
KVSO_END_CONSTRUCTOR(KviKvsObject_pixmap)
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_pixmap)
emit aboutToDie();
delete m_pPixmap;
if (m_pImage) delete m_pImage;
KVSO_END_CONSTRUCTOR(KviKvsObject_pixmap)
bool KviKvsObject_pixmap::functionfill(KviKvsObjectFunctionCall *c)
{
KviKvsObject *ob;
kvs_int_t iXoffset,iYoffset;
kvs_hobject_t hObject;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject)
KVSO_PARAMETER("x_offset",KVS_PT_INT,0,iXoffset)
KVSO_PARAMETER("y_offset",KVS_PT_INT,0,iYoffset)
KVSO_PARAMETERS_END(c)
ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject);
if (!ob)
{
c->warning(__tr2qs("Widget parameter is not an object"));
return true;
}
if(!ob->object()->isWidgetType())
{
c->warning(__tr2qs("Widget object required"));
return true;
}
bPixmapModified=true;
m_pPixmap->fill(((TQWidget *)(ob->object())),iXoffset,iYoffset);
return true;
}
bool KviKvsObject_pixmap::functionscale(KviKvsObjectFunctionCall *c)
{
kvs_real_t uScaleX,uScaleY;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("sx",KVS_PT_REAL,0,uScaleX)
KVSO_PARAMETER("sy",KVS_PT_REAL,0,uScaleY)
KVSO_PARAMETERS_END(c)
TQWMatrix wm;
wm.scale(uScaleX, uScaleY);
*m_pPixmap = m_pPixmap->xForm(wm);
bPixmapModified=true;
return true;
}
bool KviKvsObject_pixmap::functionrotate(KviKvsObjectFunctionCall *c)
{
kvs_real_t uDegrees;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("a",KVS_PT_REAL,0,uDegrees)
KVSO_PARAMETERS_END(c)
TQWMatrix wm;
wm.rotate(uDegrees);
*m_pPixmap = m_pPixmap->xForm(wm);
bPixmapModified=true;
return true;
}
bool KviKvsObject_pixmap::functionresize(KviKvsObjectFunctionCall *c)
{
kvs_int_t uWidth,uHeight;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("width",KVS_PT_UNSIGNEDINTEGER,0,uWidth)
KVSO_PARAMETER("height",KVS_PT_UNSIGNEDINTEGER,0,uHeight)
KVSO_PARAMETERS_END(c)
m_pPixmap->resize(uWidth,uHeight);
bPixmapModified=true;
return true;
}
bool KviKvsObject_pixmap::functionload(KviKvsObjectFunctionCall *c)
{
TQString szFile;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile)
KVSO_PARAMETERS_END(c)
if(!TQFile::exists(szFile))
{
c->warning(__tr2qs("I can't find the specified file %Q."),&szFile);
return true;
}
m_pPixmap->load(szFile);
bPixmapModified=true;
return true;
}
bool KviKvsObject_pixmap::functionheight(KviKvsObjectFunctionCall *c)
{
c->returnValue()->setInteger(m_pPixmap->height());
return true;
}
bool KviKvsObject_pixmap::functionwidth(KviKvsObjectFunctionCall *c)
{
c->returnValue()->setInteger(m_pPixmap->width());
return true;
}
bool KviKvsObject_pixmap::functionsetOpacity(KviKvsObjectFunctionCall *c)
{
if(!m_pPixmap)return true;
kvs_real_t dOpacity;
kvs_uint_t uXoffset,uYoffset;
kvs_uint_t uWidth,uHeight;
KviKvsObject * pObDest;
kvs_hobject_t hObject;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("opacity_factor",KVS_PT_DOUBLE,0,dOpacity)
KVSO_PARAMETER("destination",KVS_PT_HOBJECT,0,hObject)
KVSO_PARAMETER("x_offset",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uXoffset)
KVSO_PARAMETER("y_offset",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uYoffset)
KVSO_PARAMETER("width",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uWidth)
KVSO_PARAMETER("height",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uHeight)
KVSO_PARAMETERS_END(c)
pObDest=KviKvsKernel::instance()->objectController()->lookupObject(hObject);
if (!pObDest)
{
c->warning(__tr2qs("Destination parameter is not an object"));
return true;
}
if(!pObDest->inherits("KviKvsObject_pixmap"))
{
c->warning(__tr2qs("Destination must be a pixmap object"));
return true;
}
TQImage *buffer=((KviKvsObject_pixmap *)pObDest)->getImage();
((KviKvsObject_pixmap *)pObDest)->imageChanged();
if (bPixmapModified) {
*m_pImage=m_pPixmap->convertToImage();
}
if (uWidth>buffer->width() || uHeight>buffer->height())
{
c->warning(__tr2qs("Area dimensions are out of destination size "));
return true;
}
if (!uWidth){
if(m_pImage->width()>buffer->width())
{
c->warning(__tr2qs("Pixmap dimensions are out of destination size "));
return true;
}
}
if (!uHeight)
{
if(m_pImage->height()>buffer->height())
{
c->warning(__tr2qs("Pixmap dimensions are out of destination size "));
return true;
}
}
if(uXoffset+uWidth>m_pImage->width())
{
c->warning(__tr2qs("Offset width area is out of pixmap size "));
return true;
}
if( uYoffset+uHeight>m_pImage->height())
{
c->warning(__tr2qs("Offset height area is out of pixmap size "));
return true;
}
buffer->setAlphaBuffer(true);
int iHedge=uHeight?uHeight:m_pImage->height();
int iWedge=uWidth?uWidth:m_pImage->width();
for(int y = uYoffset;y<iHedge;y++)
{
TQRgb * dst = (TQRgb *)buffer->scanLine(y);
TQRgb * src = (TQRgb *)m_pImage->scanLine(y);
src += uXoffset;
TQRgb * end;
end = src + iWedge;
while(src < end)
{
*dst = tqRgba(
(int)(tqRed(*src)),
(int)(tqGreen(*src)),
(int)(tqBlue(*src)),
(int)(tqAlpha(*src)*dOpacity)
);
src++;
dst++;
}
}
return true;
}
TQPixmap * KviKvsObject_pixmap::getPixmap()
{
if (bImageModified) {
m_pPixmap->convertFromImage(*m_pImage);
bImageModified=false;
}
return m_pPixmap;
}
TQImage * KviKvsObject_pixmap::getImage()
{
if (bPixmapModified) {
*m_pImage=m_pPixmap->convertToImage();
//tqDebug ("image info2 %d and %d",test.width(),test.height());
bPixmapModified=false;
}
return m_pImage;
}
#include "m_class_pixmap.moc"
|