added summerhack
[summerhack] / tools / curve_draw / cursors.cc
1 #include <SDL.h>
2 #include "cursors.h"
3
4 static SDL_Cursor *create_cursor(const char **image);
5
6 SDL_Cursor *cursor_std, *cursor_cross, *cursor_x;
7
8 static const char *cur_std[] = {
9   /* width height num_colors chars_per_pixel */
10   "    32    32        3            1",
11   /* colors */
12   "X c #000000",
13   ". c #ffffff",
14   "  c None",
15   /* pixels */
16   ".                               ",
17   "..                              ",
18   ".X.                             ",
19   ".XX.                            ",
20   ".XXX.                           ",
21   ".XXXX.                          ",
22   ".XXXXX.                         ",
23   ".XXXXXX.                        ",
24   ".XXXXXXX.                       ",
25   ".XXXXXXXX.                      ",
26   ".XXXXX.....                     ",
27   ".XX.XX.                         ",
28   ".X. .XX.                        ",
29   "..  .XX.                        ",
30   ".    .XX.                       ",
31   "     .XX.                       ",
32   "      .XX.                      ",
33   "      .XX.                      ",
34   "       ..                       ",
35   "                                ",
36   "                                ",
37   "                                ",
38   "                                ",
39   "                                ",
40   "                                ",
41   "                                ",
42   "                                ",
43   "                                ",
44   "                                ",
45   "                                ",
46   "                                ",
47   "                                ",
48   "0,0"
49 };
50
51 static const char *cur_cross[] = {
52   /* width height num_colors chars_per_pixel */
53   "    32    32        3            1",
54   /* colors */
55   "X c #000000",
56   ". c #ffffff",
57   "  c None",
58   /* pixels */
59   "               .                ",
60   "              .X.               ",
61   "              .X.               ",
62   "              .X.               ",
63   "              .X.               ",
64   "              .X.               ",
65   "              .X.               ",
66   "              .X.               ",
67   "              .X.               ",
68   "              .X.               ",
69   "              .X.               ",
70   "              .X.               ",
71   "              .X.               ",
72   "               .                ",
73   " ............     ............  ",
74   ".XXXXXXXXXXXX.   .XXXXXXXXXXXX. ",
75   " ............     ............  ",
76   "               .                ",
77   "              .X.               ",
78   "              .X.               ",
79   "              .X.               ",
80   "              .X.               ",
81   "              .X.               ",
82   "              .X.               ",
83   "              .X.               ",
84   "              .X.               ",
85   "              .X.               ",
86   "              .X.               ",
87   "              .X.               ",
88   "              .X.               ",
89   "               .                ",
90   "                                ",
91   "15,15"
92 };
93
94 static const char *cur_x[] = {
95   /* width height num_colors chars_per_pixel */
96   "    32    32        3            1",
97   /* colors */
98   "X c #000000",
99   ". c #ffffff",
100   "  c None",
101   /* pixels */
102   "                                ",
103   "                                ",
104   "  ..                       ..   ",
105   "  .X.                     .X.   ",
106   "   .X.                   .X.    ",
107   "    .X.                 .X.     ",
108   "     .X.               .X.      ",
109   "      .X.             .X.       ",
110   "       .X.           .X.        ",
111   "        .X.   ...   .X.         ",
112   "         .X. .XXX. .X.          ",
113   "          .X.X...X.X.           ",
114   "           .X.   .X.            ",
115   "          .X.     .X.           ",
116   "         .X.       .X.          ",
117   "         .X.       .X.          ",
118   "         .X.       .X.          ",
119   "          .X.     .X.           ",
120   "           .X.   .X.            ",
121   "          .X.X...X.X.           ",
122   "         .X. .XXX. .X.          ",
123   "        .X.   ...   .X.         ",
124   "       .X.           .X.        ",
125   "      .X.             .X.       ",
126   "     .X.               .X.      ",
127   "    .X.                 .X.     ",
128   "   .X.                   .X.    ",
129   "  .X.                     .X.   ",
130   "  ..                       ..   ",
131   "                                ",
132   "                                ",
133   "                                ",
134   "15,15"
135 };
136
137
138
139 void init_cursors() {
140         cursor_std = create_cursor(cur_std);
141         cursor_cross = create_cursor(cur_cross);
142         cursor_x = create_cursor(cur_x);
143 }
144
145 static SDL_Cursor *create_cursor(const char **image) {
146         int i, row, col;
147         Uint8 data[4*32];
148         Uint8 mask[4*32];
149         int hot_x, hot_y;
150
151         i = -1;
152         for(row=0; row<32; ++row) {
153                 for (col=0; col<32; ++col) {
154                         if(col % 8) {
155                                 data[i] <<= 1;
156                                 mask[i] <<= 1;
157                         } else {
158                                 ++i;
159                                 data[i] = mask[i] = 0;
160                         }
161                         switch(image[4+row][col]) {
162                         case 'X':
163                                 data[i] |= 0x01;
164                                 mask[i] |= 0x01;
165                                 break;
166                         case '.':
167                                 mask[i] |= 0x01;
168                                 break;
169                         case ' ':
170                                 break;
171                         }
172                 }
173         }
174         sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
175         return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
176 }