compile
[kdegraphics.git] / kolourpaint / cursors / kpCursorLightCross.cpp
blob10f11e827d6c1c6a8571b21dea4d813d37e2f756
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #define DEBUG_KP_CURSOR_LIGHT_CROSS 0
31 #include <kpCursorLightCross.h>
33 #include <qbitmap.h>
34 #include <qcursor.h>
36 #include <kdebug.h>
39 enum PixelValue
41 White, Black, Transparent
44 static void setPixel (unsigned char *colorBitmap,
45 unsigned char *maskBitmap,
46 int width,
47 int y, int x, enum PixelValue pv)
49 const int ColorBlack = 1;
50 const int ColorWhite = 0;
52 const int MaskOpaque = 1;
53 const int MaskTransparent = 0;
55 int colorValue, maskValue;
57 switch (pv)
59 case White:
60 colorValue = ColorWhite;
61 maskValue = MaskOpaque;
62 break;
64 case Black:
65 colorValue = ColorBlack;
66 maskValue = MaskOpaque;
67 break;
69 case Transparent:
70 default:
71 colorValue = ColorWhite;
72 maskValue = MaskTransparent;
73 break;
76 if (colorValue)
77 colorBitmap [y * (width / 8) + (x / 8)] |= (1 << (x % 8));
79 if (maskValue)
80 maskBitmap [y * (width / 8) + (x / 8)] |= (1 << (x % 8));
84 const QCursor *kpCursorLightCrossCreate ()
86 #if DEBUG_KP_CURSOR_LIGHT_CROSS
87 kDebug () << "kpCursorLightCrossCreate() ";
88 #endif
90 const int side = 24;
91 const int byteSize = (side * side) / 8;
92 unsigned char *colorBitmap = new unsigned char [byteSize];
93 unsigned char *maskBitmap = new unsigned char [byteSize];
95 memset (colorBitmap, 0, byteSize);
96 memset (maskBitmap, 0, byteSize);
98 const int oddSide = side - 1;
99 const int strokeLen = oddSide * 3 / 8;
101 for (int i = 0; i < strokeLen; i++)
103 const enum PixelValue pv = (i % 2) ? Black : White;
105 #define X_(val) (val)
106 #define Y_(val) (val)
107 #define DRAW(y,x) setPixel (colorBitmap, maskBitmap, side, (y), (x), pv)
108 // horizontal
109 DRAW (Y_(side / 2), X_(1 + i));
110 DRAW (Y_(side / 2), X_(side - 1 - i));
112 // vertical
113 DRAW (Y_(1 + i), X_(side / 2));
114 DRAW (Y_(side - 1 - i), X_(side / 2));
115 #undef DRAW
116 #undef Y_
117 #undef X_
120 const QSize size (side, side);
121 QCursor *cursor = new QCursor (
122 QBitmap::fromData (size, colorBitmap, QImage::Format_MonoLSB),
123 QBitmap::fromData (size, maskBitmap, QImage::Format_MonoLSB));
125 delete [] maskBitmap;
126 delete [] colorBitmap;
128 return cursor;