File indexing completed on 2024-05-05 04:21:03
0001 0002 /* 0003 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 0004 All rights reserved. 0005 0006 Redistribution and use in source and binary forms, with or without 0007 modification, are permitted provided that the following conditions 0008 are met: 0009 0010 1. Redistributions of source code must retain the above copyright 0011 notice, this list of conditions and the following disclaimer. 0012 2. Redistributions in binary form must reproduce the above copyright 0013 notice, this list of conditions and the following disclaimer in the 0014 documentation and/or other materials provided with the distribution. 0015 0016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0022 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 0028 #define DEBUG_KP_CURSOR_LIGHT_CROSS 0 0029 0030 0031 #include "kpCursorLightCross.h" 0032 0033 #include "kpLogCategories.h" 0034 0035 #include <QBitmap> 0036 #include <QCursor> 0037 0038 0039 enum PixelValue 0040 { 0041 White, Black, Transparent 0042 }; 0043 0044 static void setPixel (unsigned char *colorBitmap, 0045 unsigned char *maskBitmap, 0046 int width, 0047 int y, int x, enum PixelValue pv) 0048 { 0049 const int ColorBlack = 1; 0050 const int ColorWhite = 0; 0051 0052 const int MaskOpaque = 1; 0053 const int MaskTransparent = 0; 0054 0055 int colorValue, maskValue; 0056 0057 switch (pv) 0058 { 0059 case White: 0060 colorValue = ColorWhite; 0061 maskValue = MaskOpaque; 0062 break; 0063 0064 case Black: 0065 colorValue = ColorBlack; 0066 maskValue = MaskOpaque; 0067 break; 0068 0069 case Transparent: 0070 colorValue = ColorWhite; 0071 maskValue = MaskTransparent; 0072 break; 0073 } 0074 0075 if (colorValue) { 0076 colorBitmap [y * (width / 8) + (x / 8)] |= (1 << (x % 8)); 0077 } 0078 0079 if (maskValue) { 0080 maskBitmap [y * (width / 8) + (x / 8)] |= (1 << (x % 8)); 0081 } 0082 } 0083 0084 0085 const QCursor *kpCursorLightCrossCreate () 0086 { 0087 #if DEBUG_KP_CURSOR_LIGHT_CROSS 0088 qCDebug(kpLogMisc) << "kpCursorLightCrossCreate() "; 0089 #endif 0090 0091 const int side = 24; 0092 const int byteSize = (side * side) / 8; 0093 auto *colorBitmap = new unsigned char [byteSize]; 0094 auto *maskBitmap = new unsigned char [byteSize]; 0095 0096 memset (colorBitmap, 0, byteSize); 0097 memset (maskBitmap, 0, byteSize); 0098 0099 const int oddSide = side - 1; 0100 const int strokeLen = oddSide * 3 / 8; 0101 0102 for (int i = 0; i < strokeLen; i++) 0103 { 0104 const enum PixelValue pv = (i % 2) ? Black : White; 0105 0106 #define X_(val) (val) 0107 #define Y_(val) (val) 0108 #define DRAW(y,x) setPixel (colorBitmap, maskBitmap, side, (y), (x), pv) 0109 // horizontal 0110 DRAW (Y_(side / 2), X_(1 + i)); 0111 DRAW (Y_(side / 2), X_(side - 1 - i)); 0112 0113 // vertical 0114 DRAW (Y_(1 + i), X_(side / 2)); 0115 DRAW (Y_(side - 1 - i), X_(side / 2)); 0116 #undef DRAW 0117 #undef Y_ 0118 #undef X_ 0119 } 0120 0121 const QSize size (side, side); 0122 QCursor *cursor = new QCursor ( 0123 QBitmap::fromData (size, colorBitmap, QImage::Format_MonoLSB), 0124 QBitmap::fromData (size, maskBitmap, QImage::Format_MonoLSB)); 0125 0126 delete [] maskBitmap; 0127 delete [] colorBitmap; 0128 0129 return cursor; 0130 } 0131