chalk

kis_cursor.cpp
1/*
2 * kis_cursor.cpp - part of KImageShop
3 *
4 * Copyright (c) 1999 Matthias Elter <elter@kde.org>
5 * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#include <tqbitmap.h>
23#include <tqcursor.h>
24#include <tqimage.h>
25#include <tqpainter.h>
26
27#include <kcursor.h>
28#include <kiconloader.h>
29#include <kstandarddirs.h>
30
31#include "kis_cursor.h"
32#include "kis_factory.h"
33
34KisCursor::KisCursor() {}
35
36/*
37 * Predefined TQt cursors
38 */
39TQCursor KisCursor::arrowCursor()
40{
41 return TQt::arrowCursor;
42}
43
44TQCursor KisCursor::upArrowCursor()
45{
46 return TQt::upArrowCursor;
47}
48
49TQCursor KisCursor::crossCursor()
50{
51 return TQt::crossCursor;
52}
53
54TQCursor KisCursor::waitCursor()
55{
56 return TQt::waitCursor;
57}
58
59TQCursor KisCursor::ibeamCursor()
60{
61 return TQt::ibeamCursor;
62}
63
64TQCursor KisCursor::sizeVerCursor()
65{
66 return TQt::sizeVerCursor;
67}
68
69TQCursor KisCursor::sizeHorCursor()
70{
71 return TQt::sizeHorCursor;
72}
73
74TQCursor KisCursor::sizeBDiagCursor()
75{
76 return TQt::sizeBDiagCursor;
77}
78
79TQCursor KisCursor::sizeFDiagCursor()
80{
81 return TQt::sizeFDiagCursor;
82}
83
84TQCursor KisCursor::sizeAllCursor()
85{
86 return TQt::sizeAllCursor;
87}
88
89TQCursor KisCursor::blankCursor()
90{
91 return TQt::blankCursor;
92}
93
94TQCursor KisCursor::splitVCursor()
95{
96 return TQt::splitVCursor;
97}
98
99TQCursor KisCursor::splitHCursor()
100{
101 return TQt::splitHCursor;
102}
103
104TQCursor KisCursor::pointingHandCursor()
105{
106 return TQt::pointingHandCursor;
107}
108
109
110/*
111 * Existing custom KimageShop cursors. Use the 'load' function for all new cursors.
112 */
113
114TQCursor KisCursor::pickerCursor()
115{
116 static unsigned char picker_bits[] = {
117 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a,
118 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f,
119 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02,
120 0x00, 0x72, 0x01, 0x00, 0x39, 0x00, 0x80, 0x1c, 0x00, 0x40, 0x0e, 0x00,
121 0x20, 0x07, 0x00, 0x90, 0x03, 0x00, 0xc8, 0x01, 0x00, 0xe4, 0x00, 0x00,
122 0x74, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00};
123
124 TQBitmap picker_bitmap(24, 24, picker_bits, true);
125 TQBitmap picker_mask = picker_bitmap.createHeuristicMask( false );
126
127 return TQCursor( picker_bitmap, picker_mask, 1, 22 );
128}
129
130
131TQCursor KisCursor::pickerPlusCursor()
132{
133 static unsigned char pickerplus_bits[] = {
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a,
135 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f,
136 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02,
137 0x00, 0x72, 0x01, 0x00, 0x39, 0x0c, 0x80, 0x1c, 0x0c, 0x40, 0x0e, 0x0c,
138 0x20, 0x07, 0x0c, 0x90, 0x83, 0x7f, 0xc8, 0x81, 0x7f, 0xe4, 0x00, 0x0c,
139 0x74, 0x00, 0x0c, 0x32, 0x00, 0x0c, 0x0a, 0x00, 0x0c, 0x00, 0x00, 0x00};
140
141 TQBitmap picker_bitmap(24, 24, pickerplus_bits, true);
142 TQBitmap picker_mask = picker_bitmap.createHeuristicMask( false );
143
144 return TQCursor( picker_bitmap, picker_mask, 1, 22 );
145}
146
147
148TQCursor KisCursor::pickerMinusCursor()
149{
150 static unsigned char pickerminus_bits[] = {
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a,
152 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f,
153 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02,
154 0x00, 0x72, 0x01, 0x00, 0x39, 0x00, 0x80, 0x1c, 0x00, 0x40, 0x0e, 0x00,
155 0x20, 0x07, 0x00, 0x90, 0xc3, 0x7f, 0xc8, 0xc1, 0x7f, 0xe4, 0x00, 0x00,
156 0x74, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00};
157
158 TQBitmap picker_bitmap(24, 24, pickerminus_bits, true);
159 TQBitmap picker_mask = picker_bitmap.createHeuristicMask( false );
160
161 return TQCursor( picker_bitmap, picker_mask, 1, 22 );
162}
163
164
165
166TQCursor KisCursor::penCursor()
167{
168 static unsigned char pen_bits[] = {
169 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x7d,
170 0x00, 0x80, 0x7e, 0x00, 0x40, 0x7f, 0x00, 0xa0, 0x3f, 0x00, 0xd0, 0x1f,
171 0x00, 0xe8, 0x0f, 0x00, 0xf4, 0x07, 0x00, 0xfa, 0x03, 0x00, 0xfd, 0x01,
172 0x80, 0xfe, 0x00, 0x40, 0x7f, 0x00, 0xa0, 0x3f, 0x00, 0xf0, 0x1f, 0x00,
173 0xd0, 0x0f, 0x00, 0x88, 0x07, 0x00, 0x88, 0x03, 0x00, 0xe4, 0x01, 0x00,
174 0x7c, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00};
175
176 TQBitmap pen_bitmap( 24, 24, pen_bits, true );
177 TQBitmap pen_mask = pen_bitmap.createHeuristicMask( false );
178
179 return TQCursor( pen_bitmap, pen_mask, 1, 22 );
180}
181
182TQCursor KisCursor::brushCursor()
183{
184 static unsigned char brush_bits[] = {
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x68, 0x00,
186 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0xfd, 0x00,
187 0x00, 0x80, 0x7e, 0x00, 0x00, 0x40, 0x3f, 0x00, 0x00, 0xa0, 0x1f, 0x00,
188 0x00, 0xd0, 0x0f, 0x00, 0x00, 0xe8, 0x07, 0x00, 0x00, 0xf4, 0x03, 0x00,
189 0x00, 0xe4, 0x01, 0x00, 0x00, 0xc2, 0x00, 0x00, 0x80, 0x41, 0x00, 0x00,
190 0x40, 0x32, 0x00, 0x00, 0xa0, 0x0f, 0x00, 0x00, 0xd0, 0x0f, 0x00, 0x00,
191 0xd0, 0x0f, 0x00, 0x00, 0xe8, 0x07, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00,
192 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
193
194 TQBitmap brush_bitmap( 25, 23, brush_bits, true );
195 TQBitmap brush_mask = brush_bitmap.createHeuristicMask( false );
196
197 return TQCursor( brush_bitmap, brush_mask, 1, 21 );
198}
199
200TQCursor KisCursor::airbrushCursor()
201{
202 static unsigned char airbrush_bits[] = {
203 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x68, 0x00, 0x00, 0x74,
204 0x00, 0x00, 0x7a, 0xf0, 0x00, 0x3d, 0x08, 0x81, 0x1e, 0xe8, 0x41, 0x0f,
205 0xe8, 0xa1, 0x07, 0xe8, 0xd1, 0x03, 0xe8, 0xe9, 0x01, 0xe8, 0xf5, 0x00,
206 0xe8, 0x7b, 0x00, 0xf0, 0x33, 0x00, 0xf0, 0x23, 0x1f, 0xa0, 0x9f, 0x3f,
207 0xd0, 0xff, 0x31, 0xe8, 0xf7, 0x30, 0xf4, 0x03, 0x18, 0xfc, 0x01, 0x0c,
208 0xf8, 0x00, 0x06, 0x76, 0x00, 0x03, 0x36, 0x00, 0x03, 0x00, 0x00, 0x00};
209
210 TQBitmap airbrush_bitmap( 24, 24, airbrush_bits, true );
211 TQBitmap airbrush_mask = airbrush_bitmap.createHeuristicMask( false );
212
213 return TQCursor( airbrush_bitmap, airbrush_mask, 1, 22 );
214}
215
216TQCursor KisCursor::eraserCursor()
217{
218 static unsigned char eraser_bits[] = {
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1d, 0x00,
220 0x00, 0x80, 0x3e, 0x00, 0x00, 0x40, 0x7f, 0x00, 0x00, 0xa0, 0xff, 0x00,
221 0x00, 0xd0, 0xff, 0x00, 0x00, 0xe8, 0x7f, 0x00, 0x00, 0xf4, 0x3f, 0x00,
222 0x00, 0xfe, 0x1f, 0x00, 0x00, 0xf9, 0x0f, 0x00, 0x80, 0xf2, 0x07, 0x00,
223 0x40, 0xe7, 0x03, 0x00, 0xa0, 0xcf, 0x01, 0x00, 0xd0, 0x9f, 0x00, 0x00,
224 0xe8, 0x7f, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0xf2, 0x1f, 0x00, 0x00,
225 0xe2, 0x0f, 0x00, 0x00, 0xc4, 0x07, 0x00, 0x00, 0x88, 0x03, 0x00, 0x00,
226 0x10, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
227
228 TQBitmap eraser_bitmap( 25, 24, eraser_bits, true );
229 TQBitmap eraser_mask = eraser_bitmap.createHeuristicMask( false );
230
231 return TQCursor( eraser_bitmap, eraser_mask, 7, 22 );
232}
233
234TQCursor KisCursor::fillerCursor()
235{
236 static unsigned char filler_bits[] = {
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x28, 0x00,
238 0x00, 0x54, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x85, 0x00, 0x80, 0x0a, 0x01,
239 0x40, 0x11, 0x01, 0xe0, 0x00, 0x02, 0x58, 0x01, 0x04, 0x2c, 0x02, 0x04,
240 0x44, 0x04, 0x08, 0x0c, 0x08, 0x18, 0x3c, 0x00, 0x14, 0x5c, 0x00, 0x0a,
241 0x9c, 0x01, 0x05, 0x1c, 0x82, 0x02, 0x18, 0x4c, 0x01, 0x18, 0xb0, 0x00,
242 0x08, 0x60, 0x00, 0x00, 0x00, 0x00};
243
244 TQBitmap filler_bitmap( 22, 22, filler_bits, true );
245 TQBitmap filler_mask = filler_bitmap.createHeuristicMask( false );
246
247 return TQCursor( filler_bitmap, filler_mask, 3, 20 );
248}
249
250TQCursor KisCursor::colorChangerCursor()
251{
252 static unsigned char colorChanger_bits[] = {
253 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x10, 0x01, 0x0e, 0x08, 0x02, 0x11,
254 0x04, 0x82, 0x20, 0x64, 0x84, 0x20, 0x92, 0x44, 0x46, 0x12, 0x49, 0x5f,
255 0x12, 0x31, 0x5f, 0x22, 0x01, 0x5f, 0xc2, 0x00, 0x4e, 0x02, 0x00, 0x40,
256 0xc2, 0x00, 0x46, 0xe2, 0x01, 0x4f, 0xe4, 0x19, 0x2f, 0xe4, 0x3d, 0x2f,
257 0xe8, 0x3d, 0x17, 0xd0, 0x3c, 0x10, 0x20, 0x38, 0x08, 0x40, 0x00, 0x06,
258 0x80, 0x81, 0x01, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00};
259
260 TQBitmap colorChanger_bitmap( 24, 23, colorChanger_bits, true );
261 TQBitmap colorChanger_mask = colorChanger_bitmap.createHeuristicMask( false );
262
263 return TQCursor( colorChanger_bitmap, colorChanger_mask, 12, 10 );
264}
265
266TQCursor KisCursor::zoomCursor()
267{
268 static unsigned char zoom_bits[] = {
269 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0xf0, 0x3f, 0x00, 0x38, 0x70, 0x00,
270 0x8c, 0xcf, 0x00, 0x0c, 0xdf, 0x00, 0x36, 0xbf, 0x01, 0xb6, 0xbf, 0x01,
271 0xf6, 0xbf, 0x01, 0xf6, 0xbf, 0x01, 0xe6, 0x9f, 0x00, 0xcc, 0xcf, 0x00,
272 0x9c, 0xe7, 0x01, 0x38, 0x70, 0x03, 0xf0, 0xbf, 0x05, 0xc0, 0xef, 0x0b,
273 0x00, 0xc0, 0x17, 0x00, 0x80, 0x2f, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x7e,
274 0x00, 0x00, 0x7c, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00};
275
276 TQBitmap zoom_bitmap( 24, 23, zoom_bits, true );
277 TQBitmap zoom_mask = zoom_bitmap.createHeuristicMask( false );
278
279 return TQCursor( zoom_bitmap, zoom_mask, 9, 8 );
280}
281
282TQCursor KisCursor::moveCursor()
283{
284 static unsigned char move_bits[] = {
285 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x7e, 0x00,
286 0x00, 0xff, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00,
287 0x10, 0x18, 0x08, 0x18, 0x18, 0x18, 0x1c, 0x18, 0x38, 0xfe, 0xff, 0x7f,
288 0xfe, 0xff, 0x7f, 0x1c, 0x18, 0x38, 0x18, 0x18, 0x18, 0x10, 0x18, 0x08,
289 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0xff, 0x00,
290 0x00, 0x7e, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00};
291
292 TQBitmap move_bitmap( 24, 24, move_bits, true );
293 TQBitmap move_mask = move_bitmap.createHeuristicMask( false );
294
295 return TQCursor( move_bitmap, move_mask, 12, 11 );
296}
297
298TQCursor KisCursor::handCursor()
299{
300 return KCursor::handCursor();
301}
302
303TQCursor KisCursor::selectCursor()
304{
305 static unsigned char select_bits[] = {
306 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
307 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
308 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0xff, 0xff, 0x7f,
309 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
310 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
311 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00};
312
313 TQBitmap select_bitmap(23, 23, select_bits, true);
314 TQBitmap select_mask = select_bitmap.createHeuristicMask( false );
315
316 return TQCursor( select_bitmap, select_mask, 11, 11 );
317}
318
319TQCursor KisCursor::openHandCursor()
320{
321 return load("openhand_cursor.xpm");
322}
323
324TQCursor KisCursor::closedHandCursor()
325{
326 return load("closedhand_cursor.xpm");
327}
328
329TQCursor KisCursor::rotateCursor()
330{
331 return load("rotate_cursor.xpm");
332}
333
334TQCursor KisCursor::load(const TQString & iconName, int hotspotX, int hotspotY)
335{
336 TQString filename = KisFactory::instance()->dirs()->findResource("kis_pics", iconName);
337 TQImage cursorImage;
338
339 cursorImage.load(filename);
340 Q_ASSERT(!cursorImage.isNull());
341 Q_ASSERT(cursorImage.hasAlphaBuffer());
342
343 TQBitmap bitmap(cursorImage.width(), cursorImage.height());
344 TQBitmap mask(cursorImage.width(), cursorImage.height());
345
346 TQPainter bitmapPainter(&bitmap);
347 TQPainter maskPainter(&mask);
348
349 for (TQ_INT32 x = 0; x < cursorImage.width(); ++x) {
350 for (TQ_INT32 y = 0; y < cursorImage.height(); ++y) {
351
352 TQRgb pixel = cursorImage.pixel(x, y);
353
354 if (tqAlpha(pixel) < 128) {
355 bitmapPainter.setPen(TQt::color0);
356 maskPainter.setPen(TQt::color0);
357 } else {
358 maskPainter.setPen(TQt::color1);
359
360 if (tqGray(pixel) < 128) {
361 bitmapPainter.setPen(TQt::color1);
362 } else {
363 bitmapPainter.setPen(TQt::color0);
364 }
365 }
366
367 bitmapPainter.drawPoint(x, y);
368 maskPainter.drawPoint(x, y);
369 }
370 }
371
372 return TQCursor(bitmap, mask, hotspotX, hotspotY);
373}
374