Debian Codegraph @

fontforgeexe/cvpalettes.c

raw symbols SCIP
1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <fontforge-config.h>
29
30 #include "cvundoes.h"
31 #include "fontforgeui.h"
32 #include "gresedit.h"
33 #include "spiro.h"
34 #include "splinefill.h"
35 #include "splineorder2.h"
36 #include "splineutil.h"
37 #include "splineutil2.h"
38 #include "ustring.h"
39
40 #include "charview_private.h"
41 #include "gkeysym.h"
42 #include "hotkeys.h"
43 #include "splinefont.h"
44 #include "ustring.h"
45 #include "utype.h"
46
47 #include <math.h>
48
49 int palettes_docked=1;
50 int rectelipse=0, polystar=0, regular_star=1;
51 int center_out[2] = { false, true };
52 float rr_radius=0;
53 int ps_pointcnt=6;
54 float star_percent=1.7320508; /* Regular 6 pointed star */
55 extern int interpCPsOnMotion;
56 extern Color cvpalettefgcol;
57 extern Color cvpalettebgcol;
58 extern Color cvpaletteactborcol;
59 extern Color cvbutton3dedgelightcol;
60 extern Color cvbutton3dedgedarkcol;
61
62 static void CVLCheckLayerCount(CharView *cv, int resize);
63
64 extern void CVDebugFree(DebugView *dv);
65
66 extern GDevEventMask input_em[];
67 extern const int input_em_cnt;
68
69 int cvvisible[2] = { 1, 1}, bvvisible[3]= { 1,1,1 };
70 static GWindow cvlayers, cvtools, bvlayers, bvtools, bvshades;
71 static GWindow cvlayers2=NULL;
72
73 #define LSHOW_CUBIC 1
74 #define LSHOW_FG 2
75 #define LSHOW_PREVIEW 4
76 static int layerscols = LSHOW_CUBIC|LSHOW_FG|LSHOW_PREVIEW; /* which columns to show in layers1 palette */
77 static int layer_height = 0; /* height of each layer row in layers1 palette */
78 static int layer_header_height = 0; /* height of initial stuff in layers1 palette */
79 static int layer_footer_height = 0; /* height of +/- buttons at bottom of layers1 palette */
80 static int layers_max = 2; /* Maximum number of layers for which widgets have been allocated in layers1 palette */
81 struct l2 {
82 int active; /* index of the active layer */
83 int offtop; /* first layer to show at the top line in layers palette */
84 int visible_layers; /* number of layers apart from the guides layer to show before using a scrollbar */
85 int current_layers; /* number of layers for the current character, and the number used in l2.layers */
86 int max_layers; /* maximum number of layers for which layer controls and previews have been allocated */
87 BDFChar **layers; /* layer thumbnail previews */
88 int sb_start; /* x pixel position of the scrollbar */
89 int column_width; /* width of various indicator columns */
90 int header_height; /* height of the header in pixels before the first layer */
91 int mo_col, mo_layer; /* mouse over column and layer */
92 int rename_active; /* If >=2, layer number for which the edit box for layer names is active */
93 GClut *clut;
94 GFont *font; /* font to draw text in the palette with */
95 } layerinfo = { /* info about the current layers in the layers palette */
96 2, 0, 0, 0, 0, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL
97 };
98
99 struct l2 layer2 = { 2, 0, 0, 0, 0, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL };
100 static int layers2_active = -1;
101 static GPoint cvtoolsoff = { -9999, -9999 }, cvlayersoff = { -9999, -9999 }, bvlayersoff = { -9999, -9999 }, bvtoolsoff = { -9999, -9999 }, bvshadesoff = { -9999, -9999 };
102 int palettes_fixed=1;
103 static GCursor tools[cvt_max+1] = { ct_pointer }, spirotools[cvt_max+1];
104
105 enum cvtools cv_b1_tool = cvt_pointer, cv_cb1_tool = cvt_pointer,
106 cv_b2_tool = cvt_magnify, cv_cb2_tool = cvt_ruler;
107
108 GResFont toolspalette_font = GRESFONT_INIT("400 10px " SANS_UI_FAMILIES);
109 GResFont layerspalette_font = GRESFONT_INIT("400 10px " SANS_UI_FAMILIES);
110
111 #define CV_LAYERS_WIDTH 104
112 #define CV_LAYERS_HEIGHT 100
113 #define CV_LAYERS_INITIALCNT 6
114 #define CV_LAYERS_LINE_HEIGHT 25
115 #define CV_LAYERS2_WIDTH 185
116 #define CV_LAYERS2_HEIGHT 126
117 #define CV_LAYERS2_LINE_HEIGHT 25
118 #define CV_LAYERS2_HEADER_HEIGHT 20
119 #define BV_TOOLS_WIDTH 53
120 #define BV_TOOLS_HEIGHT 80
121 #define BV_LAYERS_HEIGHT 73
122 #define BV_LAYERS_WIDTH 73
123 #define BV_SHADES_HEIGHT (8+9*16)
124
125 /* These are control ids for the layers palette controls */
126 #define CID_VBase 1000
127 #define CID_VGrid (CID_VBase+ly_grid)
128 #define CID_VBack (CID_VBase+ly_back)
129 #define CID_VFore (CID_VBase+ly_fore)
130
131 #define CID_EBase 3000
132 #define CID_EGrid (CID_EBase+ly_grid)
133 #define CID_EBack (CID_EBase+ly_back)
134 #define CID_EFore (CID_EBase+ly_fore)
135
136 #define CID_QBase 5000
137 #define CID_QGrid (CID_QBase+ly_grid)
138 #define CID_QBack (CID_QBase+ly_back)
139 #define CID_QFore (CID_QBase+ly_fore)
140
141 #define CID_FBase 7000
142
143 #define CID_SB 8000
144 #define CID_Edit 8001
145
146 #define CID_AddLayer 9000
147 #define CID_RemoveLayer 9001
148 #define CID_RenameLayer 9002
149 #define CID_LayersMenu 9003
150 #define CID_LayerLabel 9004
151
152 static void SetPaletteVisible(GWindow parent, GWindow palette, bool visible) {
153 GDrawSetVisible(palette, visible);
154 if (!palettes_docked) {
155 GDrawSetTransientFor(palette, visible ? parent : NULL);
156 if (visible) {
157 GDrawRaise(palette);
158 }
159 }
160 }
161
162 /* Initialize a window that is to be used for a palette. Specific widgets and other functionality are added elsewhere. */
163 static GWindow CreatePalette(GWindow w, GRect *pos, int (*eh)(GWindow,GEvent *), void *user_data, GWindowAttrs *wattrs, GWindow v) {
164 GWindow gw;
165 GPoint pt, base;
166 GRect newpos;
167 GWindow root;
168 GRect ownerpos, screensize;
169
170 pt.x = pos->x; pt.y = pos->y;
171 if ( !palettes_fixed ) {
172 root = GDrawGetRoot(NULL);
173 GDrawGetSize(w,&ownerpos);
174 GDrawGetSize(root,&screensize);
175 GDrawTranslateCoordinates(w,root,&pt);
176 base.x = base.y = 0;
177 GDrawTranslateCoordinates(w,root,&base);
178 if ( pt.x<0 ) {
179 if ( base.x+ownerpos.width+20+pos->width+20 > screensize.width )
180 pt.x=0;
181 else
182 pt.x = base.x+ownerpos.width+20;
183 }
184 if ( pt.y<0 ) pt.y=0;
185 if ( pt.x+pos->width>screensize.width )
186 pt.x = screensize.width-pos->width;
187 if ( pt.y+pos->height>screensize.height )
188 pt.y = screensize.height-pos->height;
189 }
190 wattrs->mask |= wam_bordcol|wam_bordwidth;
191 wattrs->border_width = 1;
192 wattrs->border_color = cvpalettefgcol;
193
194 newpos.x = pt.x; newpos.y = pt.y; newpos.width = pos->width; newpos.height = pos->height;
195 wattrs->mask|= wam_positioned;
196 wattrs->positioned = true;
197 if (palettes_docked) {
198 pos->x = 0;
199 gw = GDrawCreateSubWindow(v, pos, eh, user_data, wattrs);
200 } else {
201 wattrs->mask |= wam_palette;
202 gw = GDrawCreateTopWindow(NULL,&newpos,eh,user_data,wattrs);
203 }
204
205 return( gw );
206 }
207
208
209
210 /* Return screen coordinates of the palette in off, relative to the root window origin. */
211 static void SaveOffsets(GWindow main, GWindow palette, GPoint *off) {
212 if ( !palettes_docked && !palettes_fixed && GDrawIsVisible(palette)) {
213 GRect mr, pr;
214 GWindow root, temp;
215 root = GDrawGetRoot(NULL);
216 while ( (temp=GDrawGetParentWindow(main))!=root )
217 main = temp;
218 GDrawGetSize(main,&mr);
219 GDrawGetSize(palette,&pr);
220 off->x = pr.x-mr.x;
221 off->y = pr.y-mr.y;
222 if ( off->x<0 ) off->x = 0;
223 if ( off->y<0 ) off->y = 0;
224 }
225 }
226
227 /* Set the palette window position to off, a point in the root window space. */
228 static void RestoreOffsets(GWindow main, GWindow palette, GPoint *off) {
229 GPoint pt;
230 GWindow root,temp;
231 GRect screensize, pos;
232
233 if ( palettes_fixed )
234 return;
235 pt = *off;
236 root = GDrawGetRoot(NULL);
237 GDrawGetSize(root,&screensize);
238 GDrawGetSize(palette,&pos);
239 while ( (temp=GDrawGetParentWindow(main))!=root )
240 main = temp;
241 GDrawTranslateCoordinates(main,root,&pt);
242 if ( pt.x<0 ) pt.x=0;
243 if ( pt.y<0 ) pt.y=0;
244 if ( pt.x+pos.width>screensize.width )
245 pt.x = screensize.width-pos.width;
246 if ( pt.y+pos.height>screensize.height )
247 pt.y = screensize.height-pos.height;
248 GDrawTrueMove(palette,pt.x,pt.y);
249 GDrawRaise(palette);
250 }
251
252 static void CVMenuTool(GWindow gw,struct gmenuitem *mi,GEvent *e) {
253 CharView *cv = (CharView *) GDrawGetUserData(gw);
254 cv->b1_tool = mi->mid;
255 if ( cvtools!=NULL )
256 GDrawRequestExpose(cvtools,NULL,false);
257 CVToolsSetCursor(cv,0,NULL);
258 }
259
260 static void CVChangeSpiroMode(CharView *cv);
261 static void CVMenuSpiroSet(GWindow gw,struct gmenuitem *mi,GEvent *e) {
262 CharView *cv = (CharView *) GDrawGetUserData(gw);
263 CVChangeSpiroMode(cv);
264 }
265
266 void cvtoollist_check(GWindow gw,struct gmenuitem *mi,GEvent *e) {
267 CharView *cv = (CharView *) GDrawGetUserData(gw);
268 int order2 = cv->b.layerheads[cv->b.drawmode]->order2;
269
270 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
271 mi->ti.checked = mi->mid==cv->b1_tool;
272 switch ( mi->mid ) {
273 case cvt_freehand:
274 mi->ti.disabled = order2;
275 break;
276 case cvt_spiro:
277 mi->ti.disabled = !hasspiro();
278 break;
279 }
280 }
281 }
282
283 /* Note: If you change this ordering, change enum cvtools */
284 static char *popupsres[] = {
285 N_("Pointer"), N_("Magnify (Minify with alt)"),
286 N_("Draw a freehand curve"), N_("Scroll by hand"),
287 N_("Cut splines in two"), N_("Measure distance, angle between points"),
288 N_("Add a point, then drag out its control points"), N_("Change whether spiro is active or not"),
289 N_("Add a curve point"), N_("Add a curve point always either horizontal or vertical"),
290 N_("Add a corner point"), N_("Add a tangent point"),
291 N_("Scale the selection"), N_("Rotate the selection"),
292 N_("Flip the selection"), N_("Skew the selection"),
293 N_("Rotate the selection in 3D and project back to plane"), N_("Perform a perspective transformation on the selection"),
294 N_("Rectangle or Ellipse"), N_("Polygon or Star"),
295 N_("Rectangle or Ellipse"), N_("Polygon or Star")};
296 GMenuItem2 cvtoollist[] = {
297 { { (unichar_t *) N_("_Pointer"), (GImage *) "toolspointer.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Pointer|No Shortcut"), NULL, NULL, CVMenuTool, cvt_pointer },
298 { { (unichar_t *) N_("_Magnify"), (GImage *) "toolsmagnify.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Magnify|No Shortcut"), NULL, NULL, CVMenuTool, cvt_magnify },
299 { { (unichar_t *) N_("_Freehand"), (GImage *) "toolsfreehand.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Freehand|No Shortcut"), NULL, NULL, CVMenuTool, cvt_freehand },
300 { { (unichar_t *) N_("_Scroll"), (GImage *) "toolsscroll.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Scroll|No Shortcut"), NULL, NULL, CVMenuTool, cvt_hand },
301 { { (unichar_t *) N_("_Knife"), (GImage *) "toolsknife.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Knife|No Shortcut"), NULL, NULL, CVMenuTool, cvt_knife },
302 { { (unichar_t *) N_("_Ruler"), (GImage *) "toolsruler.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Ruler|No Shortcut"), NULL, NULL, CVMenuTool, cvt_ruler },
303 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
304 { { (unichar_t *) N_("P_en"), (GImage *) "toolspen.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Pen|No Shortcut"), NULL, NULL, CVMenuTool, cvt_pen },
305 { { (unichar_t *) N_("_Activate Spiro"), (GImage *) "toolsspiro.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Activate Spiro|No Shortcut"), NULL, NULL, CVMenuSpiroSet, cvt_spiro },
306 { { (unichar_t *) N_("_Curve"), (GImage *) "pointscurve.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Curve|No Shortcut"), NULL, NULL, CVMenuTool, cvt_curve },
307 { { (unichar_t *) N_("_HVCurve"), (GImage *) "pointshvcurve.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("HVCurve|No Shortcut"), NULL, NULL, CVMenuTool, cvt_hvcurve },
308 { { (unichar_t *) N_("C_orner"), (GImage *) "pointscorner.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("Corner|No Shortcut"), NULL, NULL, CVMenuTool, cvt_corner },
309 { { (unichar_t *) N_("_Tangent"), (GImage *) "pointstangent.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Tangent|No Shortcut"), NULL, NULL, CVMenuTool, cvt_tangent },
310 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
311 { { (unichar_t *) N_("Sca_le"), (GImage *) "toolsscale.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Scale|No Shortcut"), NULL, NULL, CVMenuTool, cvt_scale },
312 { { (unichar_t *) N_("Rotate"), (GImage *) "toolsrotate.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Rotate|No Shortcut"), NULL, NULL, CVMenuTool, cvt_rotate },
313 { { (unichar_t *) N_("Flip"), (GImage *) "toolsflip.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Flip|No Shortcut"), NULL, NULL, CVMenuTool, cvt_flip },
314 { { (unichar_t *) N_("Ske_w"), (GImage *) "toolsskew.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Skew|No Shortcut"), NULL, NULL, CVMenuTool, cvt_skew },
315 { { (unichar_t *) N_("_3D Rotate"), (GImage *) "tools3drotate.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("3D Rotate|No Shortcut"), NULL, NULL, CVMenuTool, cvt_3d_rotate },
316 { { (unichar_t *) N_("Perspecti_ve"), (GImage *) "toolsperspective.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Perspective|No Shortcut"), NULL, NULL, CVMenuTool, cvt_perspective },
317 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
318 { { (unichar_t *) N_("Rectan_gle"), (GImage *) "toolsrect.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Rectangle|No Shortcut"), NULL, NULL, CVMenuTool, cvt_rect },
319 { { (unichar_t *) N_("Pol_ygon"), (GImage *) "toolspolygon.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Polygon|No Shortcut"), NULL, NULL, CVMenuTool, cvt_poly },
320 { { (unichar_t *) N_("Ellipse"), (GImage *) "toolselipse.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Ellipse|No Shortcut"), NULL, NULL, CVMenuTool, cvt_elipse },
321 { { (unichar_t *) N_("Star"), (GImage *) "toolsstar.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Star|No Shortcut"), NULL, NULL, CVMenuTool, cvt_star },
322 GMENUITEM2_EMPTY
323 };
324 GMenuItem2 cvspirotoollist[] = {
325 { { (unichar_t *) N_("_Pointer"), (GImage *) "toolspointer.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Pointer|No Shortcut"), NULL, NULL, CVMenuTool, cvt_pointer },
326 { { (unichar_t *) N_("_Magnify"), (GImage *) "toolsmagnify.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Magnify|No Shortcut"), NULL, NULL, CVMenuTool, cvt_magnify },
327 { { (unichar_t *) N_("_Freehand"), (GImage *) "toolsfreehand.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Freehand|No Shortcut"), NULL, NULL, CVMenuTool, cvt_freehand },
328 { { (unichar_t *) N_("_Scroll"), (GImage *) "toolsscroll.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("Scroll|No Shortcut"), NULL, NULL, CVMenuTool, cvt_hand },
329 { { (unichar_t *) N_("_Knife"), (GImage *) "toolsknife.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Knife|No Shortcut"), NULL, NULL, CVMenuTool, cvt_knife },
330 { { (unichar_t *) N_("_Ruler"), (GImage *) "toolsruler.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Ruler|No Shortcut"), NULL, NULL, CVMenuTool, cvt_ruler },
331 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
332 { { (unichar_t *) N_("_Knife"), (GImage *) "toolsknife.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Knife|No Shortcut"), NULL, NULL, CVMenuTool, cvt_knife },
333 { { (unichar_t *) N_("_Ruler"), (GImage *) "toolsruler.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Ruler|No Shortcut"), NULL, NULL, CVMenuTool, cvt_ruler },
334 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
335 { { (unichar_t *) N_("De_activate Spiro"), (GImage *) "toolsspiro.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Activate Spiro|No Shortcut"), NULL, NULL, CVMenuSpiroSet, cvt_spiro },
336 { { (unichar_t *) N_("C_orner"), (GImage *) "pointscorner.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("Corner|No Shortcut"), NULL, NULL, CVMenuTool, cvt_spirocorner },
337 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
338 { { (unichar_t *) N_("G_4"), (GImage *) "pointscurve.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'C' }, H_("G4|No Shortcut"), NULL, NULL, CVMenuTool, cvt_spirog4 },
339 { { (unichar_t *) N_("G_2"), (GImage *) "pointsG2curve.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'o' }, H_("G2|No Shortcut"), NULL, NULL, CVMenuTool, cvt_spirog2 },
340 { { (unichar_t *) N_("Lef_t"), (GImage *) "pointsspiroprev.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Left|No Shortcut"), NULL, NULL, CVMenuTool, cvt_spiroleft },
341 { { (unichar_t *) N_("Rig_ht"), (GImage *) "pointsspironext.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Right|No Shortcut"), NULL, NULL, CVMenuTool, cvt_spiroright },
342 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
343 { { (unichar_t *) N_("Sca_le"), (GImage *) "toolsscale.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Scale|No Shortcut"), NULL, NULL, CVMenuTool, cvt_scale },
344 { { (unichar_t *) N_("Rotate"), (GImage *) "toolsrotate.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Rotate|No Shortcut"), NULL, NULL, CVMenuTool, cvt_rotate },
345 { { (unichar_t *) N_("Flip"), (GImage *) "toolsflip.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Flip|No Shortcut"), NULL, NULL, CVMenuTool, cvt_flip },
346 { { (unichar_t *) N_("Ske_w"), (GImage *) "toolsskew.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Skew|No Shortcut"), NULL, NULL, CVMenuTool, cvt_skew },
347 { { (unichar_t *) N_("_3D Rotate"), (GImage *) "tools3drotate.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("3D Rotate|No Shortcut"), NULL, NULL, CVMenuTool, cvt_3d_rotate },
348 { { (unichar_t *) N_("Perspecti_ve"), (GImage *) "toolsperspective.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Perspective|No Shortcut"), NULL, NULL, CVMenuTool, cvt_perspective },
349 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
350 { { (unichar_t *) N_("Rectan_gle"), (GImage *) "toolsrect.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Rectangle|No Shortcut"), NULL, NULL, CVMenuTool, cvt_rect },
351 { { (unichar_t *) N_("Pol_ygon"), (GImage *) "toolspolygon.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Polygon|No Shortcut"), NULL, NULL, CVMenuTool, cvt_poly },
352 { { (unichar_t *) N_("Ellipse"), (GImage *) "toolselipse.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Ellipse|No Shortcut"), NULL, NULL, CVMenuTool, cvt_elipse },
353 { { (unichar_t *) N_("Star"), (GImage *) "toolsstar.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Star|No Shortcut"), NULL, NULL, CVMenuTool, cvt_star },
354 GMENUITEM2_EMPTY
355 };
356
357 static char *editablelayers[] = {
358 /* GT: Foreground, make it short */
359 N_("F_ore"),
360 /* GT: Background, make it short */
361 N_("_Back"),
362 /* GT: Guide layer, make it short */
363 N_("_Guide")
364 };
365 static real raddiam_x = 20, raddiam_y = 20, rotate_by=0;
366
367 real CVRoundRectRadius(void) {
368 return( rr_radius );
369 }
370
371 int CVRectElipseCenter(void) {
372 return( center_out[rectelipse] );
373 }
374
375 int CVPolyStarPoints(void) {
376 return( ps_pointcnt );
377 }
378
379 real CVStarRatio(void) {
380 if ( regular_star )
381 return( sin(FF_PI/ps_pointcnt)*tan(2*FF_PI/ps_pointcnt)+cos(FF_PI/ps_pointcnt) );
382
383 return( star_percent );
384 }
385
386 struct ask_info {
387 GWindow gw;
388 int done;
389 int ret;
390 float *val;
391 int *co;
392 GGadget *rb1;
393 GGadget *reg;
394 GGadget *pts;
395 int ispolystar;
396 int haspos;
397 char *lab;
398 CharView *cv;
399 };
400 #define CID_ValText 1001
401 #define CID_PointPercent 1002
402 #define CID_CentCornLab 1003
403 #define CID_CentCornX 1004
404 #define CID_CentCornY 1005
405 #define CID_RadDiamLab 1006
406 #define CID_RadDiamX 1007
407 #define CID_RadDiamY 1008
408 #define CID_Angle 1009
409
410 static void FakeShapeEvents(CharView *cv) {
411 GEvent event;
412 real trans[6];
413
414 cv->active_tool = rectelipse ? cvt_elipse : cvt_rect;
415 if ( cv->b.sc->inspiro && hasspiro() ) {
416 GDrawSetCursor(cv->v,spirotools[cv->active_tool]);
417 GDrawSetCursor(cvtools,spirotools[cv->active_tool]);
418 } else {
419 GDrawSetCursor(cv->v,tools[cv->active_tool]);
420 GDrawSetCursor(cvtools,tools[cv->active_tool]);
421 }
422 cv->showing_tool = cv->active_tool;
423
424 memset(&event,0,sizeof(event));
425 event.type = et_mousedown;
426 CVMouseDownShape(cv,&event);
427 cv->info.x += raddiam_x;
428 cv->info.y += raddiam_y;
429 CVMouseMoveShape(cv);
430 CVMouseUpShape(cv);
431 if ( raddiam_x!=0 && raddiam_y!=0 && rotate_by!=0 ) {
432 trans[0] = trans[3] = cos ( rotate_by*FF_PI/180. );
433 trans[1] = sin( rotate_by*FF_PI/180. );
434 trans[2] = -trans[1];
435 trans[4] = -cv->p.x*trans[0] - cv->p.y*trans[2] + cv->p.x;
436 trans[5] = -cv->p.x*trans[1] - cv->p.y*trans[3] + cv->p.y;
437 SplinePointListTransform(cv->b.layerheads[cv->b.drawmode]->splines,trans,
438 interpCPsOnMotion?tpt_OnlySelectedInterpCPs:tpt_OnlySelected);
439 SCUpdateAll(cv->b.sc);
440 }
441 cv->active_tool = cvt_none;
442 }
443
444 static int TA_OK(GGadget *g, GEvent *e) {
445 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
446 struct ask_info *d = GDrawGetUserData(GGadgetGetWindow(g));
447 real val, val2=0;
448 int err=0;
449 int re = !GGadgetIsChecked(d->rb1);
450 if ( d->ispolystar ) {
451 val = GetInt8(d->gw,CID_ValText,d->lab,&err);
452 if ( !(regular_star = GGadgetIsChecked(d->reg)))
453 val2 = GetReal8(d->gw,CID_PointPercent,_("Size of Points"),&err);
454 } else {
455 val = GetReal8(d->gw,CID_ValText,d->lab,&err);
456 d->co[re] = !GGadgetIsChecked(d->reg);
457 }
458 if ( err )
459 return( true );
460 if ( d->haspos ) {
461 real x,y, radx,rady, ang;
462 x = GetInt8(d->gw,CID_CentCornX,_("_X"),&err);
463 y = GetInt8(d->gw,CID_CentCornY,_("_Y"),&err);
464 radx = GetInt8(d->gw,CID_RadDiamX,_("Radius: "),&err);
465 rady = GetInt8(d->gw,CID_RadDiamY,_("Radius: "),&err);
466 ang = GetInt8(d->gw,CID_Angle,_("Angle:"),&err);
467 if ( err )
468 return( true );
469 d->cv->p.x = d->cv->info.x = x;
470 d->cv->p.y = d->cv->info.y = y;
471 raddiam_x = radx; raddiam_y = rady;
472 rotate_by = ang;
473 rectelipse = re;
474 *d->val = val;
475 FakeShapeEvents(d->cv);
476 }
477 *d->val = val;
478 d->ret = re;
479 d->done = true;
480 if ( !regular_star && d->ispolystar )
481 star_percent = val2/100;
482 SavePrefs(true);
483 }
484 return( true );
485 }
486
487 static int TA_Cancel(GGadget *g, GEvent *e) {
488 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
489 struct ask_info *d = GDrawGetUserData(GGadgetGetWindow(g));
490 d->done = true;
491 }
492 return( true );
493 }
494
495 static int TA_CenRadChange(GGadget *g, GEvent *e) {
496 if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) {
497 struct ask_info *d = GDrawGetUserData(GGadgetGetWindow(g));
498 int is_bb = GGadgetIsChecked(d->reg);
499 GGadgetSetTitle8(GWidgetGetControl(d->gw,CID_CentCornLab),
500 is_bb ? _("Corner") : _("C_enter"));
501 GGadgetSetTitle8(GWidgetGetControl(d->gw,CID_RadDiamLab),
502 is_bb ? _("Diameter:") : _("Radius: "));
503 }
504 return( true );
505 }
506
507 static int TA_RadChange(GGadget *g, GEvent *e) {
508 if ( e->type==et_controlevent && e->u.control.subtype == et_radiochanged ) {
509 struct ask_info *d = GDrawGetUserData(GGadgetGetWindow(g));
510 int is_ellipse = !GGadgetIsChecked(d->rb1);
511 GGadgetSetEnabled(GWidgetGetControl(d->gw,CID_ValText), !is_ellipse );
512 GGadgetSetChecked(d->reg,!center_out[is_ellipse]);
513 GGadgetSetChecked(d->pts,center_out[is_ellipse]);
514 if ( d->haspos )
515 TA_CenRadChange(g,e);
516 }
517 return( true );
518 }
519
520 static int toolask_e_h(GWindow gw, GEvent *event) {
521 if ( event->type==et_close ) {
522 struct ask_info *d = GDrawGetUserData(gw);
523 d->done = true;
524 } else if ( event->type == et_map ) {
525 /* Above palettes */
526 GDrawRaise(gw);
527 }
528 return( event->type!=et_char );
529 }
530
531 static int Ask(char *rb1, char *rb2, int rb, char *lab, float *val, int *co,
532 int ispolystar, CharView *cv ) {
533 struct ask_info d;
534 char buffer[20], buf[20];
535 char cenx[20], ceny[20], radx[20], rady[20], angle[20];
536 GRect pos;
537 GWindowAttrs wattrs;
538 GGadgetCreateData gcd[19];
539 GTextInfo label[19];
540 int off = ((ispolystar&1)?15:0) + ((ispolystar&2)?84:0);
541 int haspos = (ispolystar&2)?1:0;
542
543 ispolystar &= 1;
544
545 d.done = false;
546 d.ret = rb;
547 d.val = val;
548 d.co = co;
549 d.ispolystar = ispolystar;
550 d.haspos = haspos;
551 d.lab = lab;
552 d.cv = cv;
553
554 memset(&wattrs,0,sizeof(wattrs));
555 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
556 wattrs.event_masks = ~(1<<et_charup);
557 wattrs.restrict_input_to_me = 1;
558 wattrs.undercursor = 1;
559 wattrs.cursor = ct_pointer;
560 wattrs.utf8_window_title = _("Shape Type");
561 wattrs.is_dlg = true;
562 pos.x = pos.y = 0;
563 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,190));
564 pos.height = GDrawPointsToPixels(NULL,120+off);
565 d.gw = GDrawCreateTopWindow(NULL,&pos,toolask_e_h,&d,&wattrs);
566
567 memset(&label,0,sizeof(label));
568 memset(&gcd,0,sizeof(gcd));
569
570 label[0].text = (unichar_t *) rb1;
571 label[0].text_is_1byte = true;
572 gcd[0].gd.label = &label[0];
573 gcd[0].gd.pos.x = 5; gcd[0].gd.pos.y = 5;
574 gcd[0].gd.flags = gg_enabled|gg_visible | (rb==0?gg_cb_on:0);
575 gcd[0].creator = GRadioCreate;
576
577 label[1].text = (unichar_t *) rb2;
578 label[1].text_is_1byte = true;
579 gcd[1].gd.label = &label[1];
580 gcd[1].gd.pos.x = ispolystar?65:75; gcd[1].gd.pos.y = 5;
581 gcd[1].gd.flags = gg_enabled|gg_visible | (rb==1?gg_cb_on:0);
582 gcd[1].creator = GRadioCreate;
583
584 label[2].text = (unichar_t *) lab;
585 label[2].text_is_1byte = true;
586 gcd[2].gd.label = &label[2];
587 gcd[2].gd.pos.x = 5; gcd[2].gd.pos.y = 25;
588 gcd[2].gd.flags = gg_enabled|gg_visible ;
589 gcd[2].creator = GLabelCreate;
590
591 sprintf( buffer, "%g", *val );
592 label[3].text = (unichar_t *) buffer;
593 label[3].text_is_1byte = true;
594 gcd[3].gd.label = &label[3];
595 gcd[3].gd.pos.x = 5; gcd[3].gd.pos.y = 40;
596 gcd[3].gd.flags = gg_enabled|gg_visible ;
597 gcd[3].gd.cid = CID_ValText;
598 gcd[3].creator = GTextFieldCreate;
599
600 gcd[4].gd.pos.x = 20-3; gcd[4].gd.pos.y = 85+off;
601 gcd[4].gd.pos.width = -1; gcd[4].gd.pos.height = 0;
602 gcd[4].gd.flags = gg_visible | gg_enabled | gg_but_default;
603 label[4].text = (unichar_t *) _("_OK");
604 label[4].text_is_1byte = true;
605 label[4].text_in_resource = true;
606 gcd[4].gd.mnemonic = 'O';
607 gcd[4].gd.label = &label[4];
608 gcd[4].gd.handle_controlevent = TA_OK;
609 gcd[4].creator = GButtonCreate;
610
611 gcd[5].gd.pos.x = -20; gcd[5].gd.pos.y = 85+3+off;
612 gcd[5].gd.pos.width = -1; gcd[5].gd.pos.height = 0;
613 gcd[5].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
614 label[5].text = (unichar_t *) _("_Cancel");
615 label[5].text_is_1byte = true;
616 label[5].text_in_resource = true;
617 gcd[5].gd.label = &label[5];
618 gcd[5].gd.mnemonic = 'C';
619 gcd[5].gd.handle_controlevent = TA_Cancel;
620 gcd[5].creator = GButtonCreate;
621
622 if ( ispolystar ) {
623 label[6].text = (unichar_t *) _("Regular");
624 label[6].text_is_1byte = true;
625 gcd[6].gd.label = &label[6];
626 gcd[6].gd.pos.x = 5; gcd[6].gd.pos.y = 70;
627 gcd[6].gd.flags = gg_enabled|gg_visible | (rb==0?gg_cb_on:0);
628 gcd[6].creator = GRadioCreate;
629
630 label[7].text = (unichar_t *) _("Points:");
631 label[7].text_is_1byte = true;
632 gcd[7].gd.label = &label[7];
633 gcd[7].gd.pos.x = 65; gcd[7].gd.pos.y = 70;
634 gcd[7].gd.flags = gg_enabled|gg_visible | (rb==1?gg_cb_on:0);
635 gcd[7].creator = GRadioCreate;
636
637 sprintf( buf, "%4g", star_percent*100 );
638 label[8].text = (unichar_t *) buf;
639 label[8].text_is_1byte = true;
640 gcd[8].gd.label = &label[8];
641 gcd[8].gd.pos.x = 125; gcd[8].gd.pos.y = 70; gcd[8].gd.pos.width=50;
642 gcd[8].gd.flags = gg_enabled|gg_visible ;
643 gcd[8].gd.cid = CID_PointPercent;
644 gcd[8].creator = GTextFieldCreate;
645
646 label[9].text = (unichar_t *) "%";
647 label[9].text_is_1byte = true;
648 gcd[9].gd.label = &label[9];
649 gcd[9].gd.pos.x = 180; gcd[9].gd.pos.y = 70;
650 gcd[9].gd.flags = gg_enabled|gg_visible ;
651 gcd[9].creator = GLabelCreate;
652 } else {
653 label[6].text = (unichar_t *) _("Bounding Box");
654 label[6].text_is_1byte = true;
655 gcd[6].gd.label = &label[6];
656 gcd[6].gd.pos.x = 5; gcd[6].gd.pos.y = 65;
657 gcd[6].gd.flags = gg_enabled|gg_visible | (co[rb]==0?gg_cb_on:0);
658 gcd[6].creator = GRadioCreate;
659
660 label[7].text = (unichar_t *) _("Center Out");
661 label[7].text_is_1byte = true;
662 gcd[7].gd.label = &label[7];
663 gcd[7].gd.pos.x = 90; gcd[7].gd.pos.y = 65;
664 gcd[7].gd.flags = gg_enabled|gg_visible | (co[rb]==1?gg_cb_on:0);
665 gcd[7].creator = GRadioCreate;
666
667 if ( rb )
668 gcd[3].gd.flags = gg_visible;
669 gcd[0].gd.handle_controlevent = TA_RadChange;
670 gcd[1].gd.handle_controlevent = TA_RadChange;
671
672 if ( haspos ) {
673 gcd[6].gd.handle_controlevent = TA_CenRadChange;
674 gcd[7].gd.handle_controlevent = TA_CenRadChange;
675
676 label[8].text = (unichar_t *) _("_X");
677 label[8].text_is_1byte = true;
678 label[8].text_in_resource = true;
679 gcd[8].gd.label = &label[8];
680 gcd[8].gd.pos.x = 70; gcd[8].gd.pos.y = gcd[7].gd.pos.y+15;
681 gcd[8].gd.flags = gg_enabled|gg_visible;
682 gcd[8].creator = GLabelCreate;
683
684 label[9].text = (unichar_t *) _("_Y");
685 label[9].text_is_1byte = true;
686 label[9].text_in_resource = true;
687 gcd[9].gd.label = &label[9];
688 gcd[9].gd.pos.x = 120; gcd[9].gd.pos.y = gcd[8].gd.pos.y;
689 gcd[9].gd.flags = gg_enabled|gg_visible;
690 gcd[9].creator = GLabelCreate;
691
692 label[10].text = (unichar_t *) (co[rb] ? _("C_enter") : _("C_orner") );
693 label[10].text_is_1byte = true;
694 label[10].text_in_resource = true;
695 gcd[10].gd.label = &label[10];
696 gcd[10].gd.pos.x = 5; gcd[10].gd.pos.y = gcd[8].gd.pos.y+17;
697 gcd[10].gd.flags = gg_enabled|gg_visible;
698 gcd[10].gd.cid = CID_CentCornLab;
699 gcd[10].creator = GLabelCreate;
700
701 sprintf( cenx, "%g", (double) cv->info.x );
702 label[11].text = (unichar_t *) cenx;
703 label[11].text_is_1byte = true;
704 gcd[11].gd.label = &label[11];
705 gcd[11].gd.pos.x = 60; gcd[11].gd.pos.y = gcd[10].gd.pos.y-4;
706 gcd[11].gd.pos.width = 40;
707 gcd[11].gd.flags = gg_enabled|gg_visible;
708 gcd[11].gd.cid = CID_CentCornX;
709 gcd[11].creator = GTextFieldCreate;
710
711 sprintf( ceny, "%g", (double) cv->info.y );
712 label[12].text = (unichar_t *) ceny;
713 label[12].text_is_1byte = true;
714 gcd[12].gd.label = &label[12];
715 gcd[12].gd.pos.x = 110; gcd[12].gd.pos.y = gcd[11].gd.pos.y;
716 gcd[12].gd.pos.width = gcd[11].gd.pos.width;
717 gcd[12].gd.flags = gg_enabled|gg_visible;
718 gcd[12].gd.cid = CID_CentCornY;
719 gcd[12].creator = GTextFieldCreate;
720
721 label[13].text = (unichar_t *) (co[rb] ? _("Radius: ") : _("Diameter:") );
722 label[13].text_is_1byte = true;
723 gcd[13].gd.label = &label[13];
724 gcd[13].gd.pos.x = 5; gcd[13].gd.pos.y = gcd[10].gd.pos.y+24;
725 gcd[13].gd.flags = gg_enabled|gg_visible;
726 gcd[13].gd.cid = CID_RadDiamLab;
727 gcd[13].creator = GLabelCreate;
728
729 sprintf( radx, "%g", (double) raddiam_x );
730 label[14].text = (unichar_t *) radx;
731 label[14].text_is_1byte = true;
732 gcd[14].gd.label = &label[14];
733 gcd[14].gd.pos.x = gcd[11].gd.pos.x; gcd[14].gd.pos.y = gcd[13].gd.pos.y-4;
734 gcd[14].gd.pos.width = gcd[11].gd.pos.width;
735 gcd[14].gd.flags = gg_enabled|gg_visible;
736 gcd[14].gd.cid = CID_RadDiamX;
737 gcd[14].creator = GTextFieldCreate;
738
739 sprintf( rady, "%g", (double) raddiam_y );
740 label[15].text = (unichar_t *) rady;
741 label[15].text_is_1byte = true;
742 gcd[15].gd.label = &label[15];
743 gcd[15].gd.pos.x = gcd[12].gd.pos.x; gcd[15].gd.pos.y = gcd[14].gd.pos.y;
744 gcd[15].gd.pos.width = gcd[11].gd.pos.width;
745 gcd[15].gd.flags = gg_enabled|gg_visible;
746 gcd[15].gd.cid = CID_RadDiamY;
747 gcd[15].creator = GTextFieldCreate;
748
749 label[16].text = (unichar_t *) _("Angle:");
750 label[16].text_is_1byte = true;
751 gcd[16].gd.label = &label[16];
752 gcd[16].gd.pos.x = 5; gcd[16].gd.pos.y = gcd[13].gd.pos.y+24;
753 gcd[16].gd.flags = gg_enabled|gg_visible;
754 gcd[16].creator = GLabelCreate;
755
756 sprintf( angle, "%g", (double) rotate_by );
757 label[17].text = (unichar_t *) angle;
758 label[17].text_is_1byte = true;
759 gcd[17].gd.label = &label[17];
760 gcd[17].gd.pos.x = 60; gcd[17].gd.pos.y = gcd[16].gd.pos.y-4;
761 gcd[17].gd.pos.width = gcd[11].gd.pos.width;
762 gcd[17].gd.flags = gg_enabled|gg_visible;
763 gcd[17].gd.cid = CID_Angle;
764 gcd[17].creator = GTextFieldCreate;
765 }
766 }
767 GGadgetsCreate(d.gw,gcd);
768 d.rb1 = gcd[0].ret;
769 d.reg = gcd[6].ret;
770 d.pts = gcd[7].ret;
771
772 GDrawSetVisible(d.gw,true);
773 while ( !d.done )
774 GDrawProcessOneEvent(NULL);
775 GDrawDestroyWindow(d.gw);
776 return( d.ret );
777 }
778
779 static void CVRectElipse(CharView *cv) {
780 rectelipse = Ask(_("Rectangle"),_("Ellipse"),rectelipse,
781 _("Round Rectangle Radius"),&rr_radius,center_out,false, cv);
782 GDrawRequestExpose(cvtools,NULL,false);
783 }
784
785 void CVRectEllipsePosDlg(CharView *cv) {
786 rectelipse = Ask(_("Rectangle"),_("Ellipse"),rectelipse,
787 _("Round Rectangle Radius"),&rr_radius,center_out,2, cv);
788 GDrawRequestExpose(cvtools,NULL,false);
789 }
790
791 static void CVPolyStar(CharView *cv) {
792 float temp = ps_pointcnt;
793 int foo[2];
794 polystar = Ask(_("Polygon"),_("Star"),polystar,
795 _("Number of star points/Polygon vertices"),&temp,foo,true, cv);
796 ps_pointcnt = temp;
797 }
798
799 /* Note: If you change this ordering, change enum cvtools */
800 // index0 is non selected / selected image
801 // index1 is the row in the toolbar
802 // index2 is the column in the toolbar
803 //
804 // This is two null terminated collections. The second collection
805 // contains the alternate icons for circle and star at the bottom of
806 // the toolbar.
807 static GImage *normbuttons[2][14][2] = {
808 {
809 { &GIcon_pointer, &GIcon_magnify },
810 { &GIcon_freehand, &GIcon_hand },
811 { &GIcon_knife, &GIcon_ruler },
812 { &GIcon_pen, &GIcon_spirodisabled },
813 { &GIcon_curve, &GIcon_hvcurve },
814 { &GIcon_corner, &GIcon_tangent},
815 { &GIcon_scale, &GIcon_rotate },
816 { &GIcon_flip, &GIcon_skew },
817 { &GIcon_3drotate, &GIcon_perspective },
818 { &GIcon_rect, &GIcon_poly},
819 { 0, 0 },
820 { &GIcon_elipse, &GIcon_star},
821 { 0, 0 },
822 { 0, 0 }
823 }
824 , {
825 { &GIcon_pointer_selected, &GIcon_magnify_selected },
826 { &GIcon_freehand_selected, &GIcon_hand_selected },
827 { &GIcon_knife_selected, &GIcon_ruler_selected },
828 { &GIcon_pen_selected, &GIcon_spiroup_selected },
829 { &GIcon_curve_selected, &GIcon_hvcurve_selected },
830 { &GIcon_corner_selected, &GIcon_tangent_selected},
831 { &GIcon_scale_selected, &GIcon_rotate_selected },
832 { &GIcon_flip_selected, &GIcon_skew_selected },
833 { &GIcon_3drotate_selected, &GIcon_perspective_selected },
834 { &GIcon_rect_selected, &GIcon_poly_selected},
835 { 0, 0 },
836 { &GIcon_elipse_selected, &GIcon_star_selected},
837 { 0, 0 },
838 { 0, 0 }
839 }};
840 static GImage *spirobuttons[2][14][2] = {
841 {
842 { &GIcon_pointer, &GIcon_magnify },
843 { &GIcon_freehand, &GIcon_hand },
844 { &GIcon_knife, &GIcon_ruler },
845 { &GIcon_spiroright, &GIcon_spirodown },
846 { &GIcon_spirocurve, &GIcon_spirog2curve },
847 { &GIcon_spirocorner, &GIcon_spiroleft },
848 { &GIcon_scale, &GIcon_rotate },
849 { &GIcon_flip, &GIcon_skew },
850 { &GIcon_3drotate, &GIcon_perspective },
851 { &GIcon_rect, &GIcon_poly},
852 { 0, 0 },
853 { &GIcon_elipse, &GIcon_star},
854 { 0, 0 },
855 { 0, 0 }
856 }
857 , {
858 { &GIcon_pointer_selected, &GIcon_magnify_selected },
859 { &GIcon_freehand_selected, &GIcon_hand_selected },
860 { &GIcon_knife_selected, &GIcon_ruler_selected },
861 { &GIcon_spiroright_selected, &GIcon_spirodown_selected },
862 { &GIcon_spirocurve_selected, &GIcon_spirog2curve_selected },
863 { &GIcon_spirocorner_selected, &GIcon_spiroleft_selected },
864 { &GIcon_scale_selected, &GIcon_rotate_selected },
865 { &GIcon_flip_selected, &GIcon_skew_selected },
866 { &GIcon_3drotate_selected, &GIcon_perspective_selected },
867 { &GIcon_rect_selected, &GIcon_poly_selected},
868 { 0, 0 },
869 { &GIcon_elipse_selected, &GIcon_star_selected},
870 { 0, 0 },
871 { 0, 0 }
872 }};
873 static GImage *normsmalls[] = { &GIcon_smallpointer, &GIcon_smallmag,
874 &GIcon_smallpencil, &GIcon_smallhand,
875 &GIcon_smallknife, &GIcon_smallruler,
876 &GIcon_smallpen, NULL,
877 &GIcon_smallcurve, &GIcon_smallhvcurve,
878 &GIcon_smallcorner, &GIcon_smalltangent,
879 &GIcon_smallscale, &GIcon_smallrotate,
880 &GIcon_smallflip, &GIcon_smallskew,
881 &GIcon_small3drotate, &GIcon_smallperspective,
882 &GIcon_smallrect, &GIcon_smallpoly,
883 &GIcon_smallelipse, &GIcon_smallstar };
884 static GImage *spirosmalls[] = { &GIcon_smallpointer, &GIcon_smallmag,
885 &GIcon_smallpencil, &GIcon_smallhand,
886 &GIcon_smallknife, &GIcon_smallruler,
887 &GIcon_smallspiroright, NULL,
888 &GIcon_smallspirocurve, &GIcon_smallspirog2curve,
889 &GIcon_smallspirocorner, &GIcon_smallspiroleft,
890 &GIcon_smallscale, &GIcon_smallrotate,
891 &GIcon_smallflip, &GIcon_smallskew,
892 &GIcon_small3drotate, &GIcon_smallperspective,
893 &GIcon_smallrect, &GIcon_smallpoly,
894 &GIcon_smallelipse, &GIcon_smallstar };
895
896 static int getSmallIconsHeight()
897 {
898 return GIcon_smallpointer.u.image->height;
899 }
900
901 static int getToolbarWidth( CharView *cv )
902 {
903 int cache = 0;
904 if( !cache ) {
905 GImage* (*buttons)[14][2] = (CVInSpiro(cv) ? spirobuttons : normbuttons);
906 int i = 0;
907
908 for ( i=0; buttons[0][i][0]; ++i ) {
909 cache = MAX( cache, buttons[0][i][0]->u.image->width + buttons[0][i][1]->u.image->width );
910 }
911 }
912 return cache;
913 }
914
915 static int getToolbarHeight( CharView *cv )
916 {
917 int cache = 0;
918 if( !cache ) {
919 GImage* (*buttons)[14][2] = (CVInSpiro(cv) ? spirobuttons : normbuttons);
920 int i = 0;
921
922 for ( i=0; buttons[0][i][0]; ++i ) {
923 cache += MAX( buttons[0][i][0]->u.image->height, buttons[0][i][1]->u.image->height );
924 }
925 }
926 cache += getSmallIconsHeight() * 4;
927 cache += 6;
928 return cache;
929 }
930
931
932 typedef struct _IJ
933 {
934 int i;
935 int j;
936 } IJ;
937
938 typedef void (*visitButtonsVisitor) ( CharView *cv, // CharView passed to visitButtons()
939 GImage* gimage, int mi, // button we are visiting and adjusted 'i'
940 int i, int j, // i and j position of button (j is across 0,1) (i is down 0...11)
941 int iconx, int icony, // pixel where this button starts
942 int selected, // is this button the active tool
943 void* udata ); // user data
944
945
946 /**
947 * Visit every button in the toolbar calling the function 'v' with a
948 * collection of interesting state data.
949 */
950 static void visitButtons( CharView* cv, visitButtonsVisitor v, void* udata )
951 {
952 GImage* (*buttons)[14][2] = (CVInSpiro(cv) ? spirobuttons : normbuttons);
953 int i,j,sel, mi;
954 int tool = cv->cntrldown?cv->cb1_tool:cv->b1_tool;
955 int icony = 1;
956 for ( i=0; buttons[0][i][0]; ++i ) {
957 int iconx = 1;
958 for ( j=0; j<2 && buttons[0][i][j]; ++j ) {
959
960 mi = i;
961 sel = (tool == mi*2+j );
962 if( (buttons[0][mi][j] == &GIcon_rect && rectelipse)
963 || (buttons[0][mi][j] == &GIcon_poly && polystar) )
964 {
965 sel = (tool == (mi+1)*2+j );
966 mi+=2;
967 }
968
969 v( cv, buttons[sel][mi][j], mi, i, j, iconx, icony, sel, udata );
970 iconx += buttons[sel][mi][j]->u.image->width;
971 }
972 icony += MAX( buttons[0][i][0]->u.image->width, buttons[0][i][1]->u.image->width );
973 }
974 }
975
976 typedef struct _getIJFromMouseVisitorData
977 {
978 int mx, my;
979 IJ ret;
980 } getIJFromMouseVisitorData;
981
982 static void getIJFromMouseVisitor( CharView *cv, GImage* gimage,
983 int mi, int i, int j,
984 int iconx, int icony, int selected, void* udata )
985 {
986 getIJFromMouseVisitorData* d = (getIJFromMouseVisitorData*)udata;
987 if( IS_IN_ORDER3( iconx, d->mx, iconx + gimage->u.image->width )
988 && IS_IN_ORDER3( icony, d->my, icony + gimage->u.image->height ))
989 {
990 d->ret.i = i;
991 d->ret.j = j;
992 }
993 }
994
995 /**
996 * Get the i,j coordinates of the toolbar button that is under the
997 * mouse at mx,my or return -1,-1 if nothing is under the mouse.
998 */
999 static IJ getIJFromMouse( CharView* cv, int mx, int my )
1000 {
1001 getIJFromMouseVisitorData d;
1002 d.mx = mx;
1003 d.my = my;
1004 d.ret.i = -1;
1005 d.ret.j = -1;
1006 visitButtons( cv, getIJFromMouseVisitor, &d );
1007 return d.ret;
1008 }
1009
1010 /*
1011 * This draws the three-dimensional relief on a button. It gets the dimensions from the button image.
1012 */
1013
1014 void cvp_draw_relief(GWindow pixmap, GImage *iconimg, int iconx, int icony, int selected) {
1015 int iconw = iconimg->u.image->width;
1016 int iconh = iconimg->u.image->height;
1017 int norm = !selected;
1018 // Note: The original code placed the right and bottom fake relief
1019 // outside of the button image area (offset by 25 instead of 24),
1020 // but we are staying just inside the image area now.
1021 GDrawDrawLine(pixmap,iconx,icony,iconx+iconw,icony,norm?cvbutton3dedgelightcol:cvbutton3dedgedarkcol);
1022 GDrawDrawLine(pixmap,iconx,icony,iconx,icony+iconh,norm?cvbutton3dedgelightcol:cvbutton3dedgedarkcol);
1023 GDrawDrawLine(pixmap,iconx,icony+iconh,iconx+iconw,icony+iconh,norm?cvbutton3dedgedarkcol:cvbutton3dedgelightcol);
1024 GDrawDrawLine(pixmap,iconx+iconw,icony,iconx+iconw,icony+iconh,norm?cvbutton3dedgedarkcol:cvbutton3dedgelightcol);
1025 }
1026
1027
1028 /**
1029 * This visitor draws the actual image for each toolbar button
1030 * The drawing is done to d->pixmap.
1031 * icony is the max
1032 */
1033 typedef struct _ToolsExposeVisitorData
1034 {
1035 GWindow pixmap;
1036 int maxicony; //< largest icony that the visitor saw
1037 int lastIconHeight; //< height of the last icon visited
1038 } ToolsExposeVisitorData;
1039 static void ToolsExposeVisitor( CharView *cv, GImage* gimage,
1040 int mi, int i, int j,
1041 int iconx, int icony, int selected, void* udata )
1042 {
1043 extern int cvbutton3d; // This comes from elsewhere.
1044 ToolsExposeVisitorData* d = (ToolsExposeVisitorData*)udata;
1045 GImage* (*buttons)[14][2] = (CVInSpiro(cv) ? spirobuttons : normbuttons);
1046
1047 // We draw the button image onto the toolbar image.
1048 GDrawDrawImage(d->pixmap,buttons[selected][mi][j],NULL,iconx,icony);
1049
1050 // We may need to draw relief, too.
1051 if (cvbutton3d > 0) cvp_draw_relief(d->pixmap, buttons[0][mi][j], iconx, icony, selected);
1052
1053 d->maxicony = MAX( d->maxicony, icony );
1054 d->lastIconHeight = buttons[selected][mi][j]->u.image->height;
1055 }
1056
1057
1058 static void ToolsExpose(GWindow pixmap, CharView *cv, GRect *r) {
1059 GRect old;
1060 static const unichar_t _Mouse[][9] = {
1061 { 'M', 's', 'e', '1', '\0' },
1062 { '^', 'M', 's', 'e', '1', '\0' },
1063 { 'M', 's', 'e', '2', '\0' },
1064 { '^', 'M', 's', 'e', '2', '\0' }};
1065 int j;
1066 int dither = GDrawSetDither(NULL,false);
1067 GRect temp;
1068 int canspiro = hasspiro(), inspiro = canspiro && cv->b.sc->inspiro;
1069 GImage **smalls = inspiro ? spirosmalls : normsmalls;
1070
1071 normbuttons[0][3][1] = canspiro ? &GIcon_spiroup : &GIcon_spirodisabled;
1072
1073 GDrawPushClip(pixmap,r,&old);
1074 GDrawFillRect(pixmap,r,cvpalettebgcol);
1075 GDrawSetLineWidth(pixmap,0);
1076
1077 ToolsExposeVisitorData d;
1078 d.pixmap = pixmap;
1079 d.maxicony = 0;
1080 visitButtons( cv, ToolsExposeVisitor, &d );
1081 int bottomOfMainIconsY = d.maxicony + d.lastIconHeight;
1082
1083
1084 GDrawSetFont(pixmap,toolspalette_font.fi);
1085 temp.x = 52-16;
1086 temp.y = bottomOfMainIconsY;
1087 temp.width = 16;
1088 temp.height = 4*12;
1089 GDrawFillRect(pixmap,&temp,cvpalettebgcol);
1090 for ( j=0; j<4; ++j ) {
1091 GDrawDrawText(pixmap,2,bottomOfMainIconsY+j*getSmallIconsHeight()+10,
1092 (unichar_t *) _Mouse[j],-1,cvpalettefgcol);
1093 if ( (&cv->b1_tool)[j]!=cvt_none && smalls[(&cv->b1_tool)[j]])
1094 GDrawDrawImage(pixmap,smalls[(&cv->b1_tool)[j]],NULL,52-16,bottomOfMainIconsY+j*getSmallIconsHeight());
1095 }
1096 GDrawPopClip(pixmap,&old);
1097 GDrawSetDither(NULL,dither);
1098 }
1099
1100 int TrueCharState(GEvent *event) {
1101 int bit = 0;
1102 /* X doesn't set the state until after the event. I want the state to */
1103 /* reflect whatever key just got depressed/released */
1104 int keysym = event->u.chr.keysym;
1105
1106 if ( keysym == GK_Caps_Lock || keysym == GK_Shift_Lock ) {
1107 static int set_on_last_down = false;
1108 /* caps lock is sticky and doesn't work like the other modifiers */
1109 /* but it is even worse. the bit seems to be set on key down, but */
1110 /* unset on key up. In other words on key up, the bit will always */
1111 /* set and we have no idea which way it will go. So we guess, and */
1112 /* if they haven't messed with the key outside ff we should be right */
1113 if ( event->type == et_char ) {
1114 set_on_last_down = (event->u.chr.state ^ ksm_capslock)& ksm_capslock;
1115 return( event->u.chr.state ^ ksm_capslock );
1116 } else if ( !(event->u.chr.state & ksm_capslock) || set_on_last_down )
1117 return( event->u.chr.state );
1118 else
1119 return( event->u.chr.state & ~ksm_capslock );
1120 }
1121
1122 if ( keysym == GK_Meta_L || keysym == GK_Meta_R ||
1123 keysym == GK_Alt_L || keysym == GK_Alt_R )
1124 bit = ksm_meta;
1125 else if ( keysym == GK_Shift_L || keysym == GK_Shift_R )
1126 bit = ksm_shift;
1127 else if ( keysym == GK_Control_L || keysym == GK_Control_R )
1128 bit = ksm_control;
1129 else if ( keysym == GK_Super_L || keysym == GK_Super_R )
1130 bit = ksm_super;
1131 else if ( keysym == GK_Hyper_L || keysym == GK_Hyper_R )
1132 bit = ksm_hyper;
1133 else
1134 return( event->u.chr.state );
1135
1136 if ( event->type == et_char )
1137 return( event->u.chr.state | bit );
1138 else
1139 return( event->u.chr.state & ~bit );
1140 }
1141
1142 void CVToolsSetCursor(CharView *cv, int state, char *device) {
1143 int shouldshow;
1144 int cntrl;
1145 int old_showing_tool = cv->showing_tool;
1146
1147 if ( tools[0] == ct_pointer ) {
1148 tools[cvt_pointer] = ct_mypointer;
1149 tools[cvt_magnify] = ct_magplus;
1150 tools[cvt_freehand] = ct_pencil;
1151 tools[cvt_hand] = ct_myhand;
1152 tools[cvt_curve] = ct_circle;
1153 tools[cvt_hvcurve] = ct_hvcircle;
1154 tools[cvt_corner] = ct_square;
1155 tools[cvt_tangent] = ct_triangle;
1156 tools[cvt_pen] = ct_pen;
1157 tools[cvt_knife] = ct_knife;
1158 tools[cvt_ruler] = ct_ruler;
1159 tools[cvt_scale] = ct_scale;
1160 tools[cvt_flip] = ct_flip;
1161 tools[cvt_rotate] = ct_rotate;
1162 tools[cvt_skew] = ct_skew;
1163 tools[cvt_3d_rotate] = ct_3drotate;
1164 tools[cvt_perspective] = ct_perspective;
1165 tools[cvt_rect] = ct_rect;
1166 tools[cvt_poly] = ct_poly;
1167 tools[cvt_elipse] = ct_elipse;
1168 tools[cvt_star] = ct_star;
1169 tools[cvt_minify] = ct_magminus;
1170 memcpy(spirotools,tools,sizeof(tools));
1171 spirotools[cvt_spirog2] = ct_g2circle;
1172 spirotools[cvt_spiroleft] = ct_spiroleft;
1173 spirotools[cvt_spiroright] = ct_spiroright;
1174 }
1175
1176 shouldshow = cvt_none;
1177 if ( cv->active_tool!=cvt_none )
1178 shouldshow = cv->active_tool;
1179 else if ( cv->pressed_display!=cvt_none )
1180 shouldshow = cv->pressed_display;
1181 else if ( device==NULL || strcmp(device,"Mouse1")==0 ) {
1182 if ( (state&(ksm_shift|ksm_control)) && (state&ksm_button4))
1183 shouldshow = cvt_magnify;
1184 else if ( (state&(ksm_shift|ksm_control)) && (state&ksm_button5))
1185 shouldshow = cvt_minify;
1186 else if ( (state&ksm_control) && (state&(ksm_button2|ksm_super)) )
1187 shouldshow = cv->cb2_tool;
1188 else if ( (state&(ksm_button2|ksm_super)) )
1189 shouldshow = cv->b2_tool;
1190 else if ( (state&ksm_control) )
1191 shouldshow = cv->cb1_tool;
1192 else
1193 shouldshow = cv->b1_tool;
1194 } else if ( strcmp(device,"eraser")==0 )
1195 shouldshow = cv->er_tool;
1196 else if ( strcmp(device,"stylus")==0 ) {
1197 if ( (state&(ksm_button2|ksm_control|ksm_super)) )
1198 shouldshow = cv->s2_tool;
1199 else
1200 shouldshow = cv->s1_tool;
1201 }
1202 if ( shouldshow==cvt_magnify && (state&ksm_meta))
1203 shouldshow = cvt_minify;
1204 if ( shouldshow!=cv->showing_tool ) {
1205 CPEndInfo(cv);
1206 if ( cv->b.sc->inspiro && hasspiro()) {
1207 GDrawSetCursor(cv->v,spirotools[shouldshow]);
1208 if ( cvtools!=NULL ) /* Might happen if window owning docked palette destroyed */
1209 GDrawSetCursor(cvtools,spirotools[shouldshow]);
1210 } else {
1211 GDrawSetCursor(cv->v,tools[shouldshow]);
1212 if ( cvtools!=NULL ) /* Might happen if window owning docked palette destroyed */
1213 GDrawSetCursor(cvtools,tools[shouldshow]);
1214 }
1215 cv->showing_tool = shouldshow;
1216 if ( old_showing_tool==cvt_scale || shouldshow==cvt_scale )
1217 GDrawRequestExpose(cv->v,NULL,false);
1218 }
1219
1220 if ( device==NULL || strcmp(device,"stylus")==0 ) {
1221 cntrl = (state&ksm_control)?1:0;
1222 if ( device!=NULL && (state&ksm_button2))
1223 cntrl = true;
1224 if ( cntrl != cv->cntrldown ) {
1225 cv->cntrldown = cntrl;
1226 GDrawRequestExpose(cvtools,NULL,false);
1227 }
1228 }
1229 }
1230
1231 static int CVCurrentTool(CharView *cv, GEvent *event) {
1232 if ( event->u.mouse.device!=NULL && strcmp(event->u.mouse.device,"eraser")==0 )
1233 return( cv->er_tool );
1234 else if ( event->u.mouse.device!=NULL && strcmp(event->u.mouse.device,"stylus")==0 ) {
1235 if ( event->u.mouse.button==2 )
1236 /* Only thing that matters is touch which maps to button 1 */;
1237 else if ( cv->had_control )
1238 return( cv->s2_tool );
1239 else
1240 return( cv->s1_tool );
1241 }
1242 if ( cv->had_control && event->u.mouse.button==2 )
1243 return( cv->cb2_tool );
1244 else if ( event->u.mouse.button==2 )
1245 return( cv->b2_tool );
1246 else if ( cv->had_control ) {
1247 return( cv->cb1_tool );
1248 } else {
1249 return( cv->b1_tool );
1250 }
1251 }
1252
1253 static void SCCheckForSSToOptimize(SplineChar *sc, SplineSet *ss,int order2) {
1254
1255 for ( ; ss!=NULL ; ss = ss->next ) {
1256 if ( ss->beziers_need_optimizer ) {
1257 SplineSetAddExtrema(sc,ss,ae_only_good,sc->parent->ascent+sc->parent->descent);
1258 ss->beziers_need_optimizer = false;
1259 }
1260 if ( order2 && ss->first->next!=NULL && !ss->first->next->order2 ) {
1261 SplineSet *temp = SSttfApprox(ss), foo;
1262 foo = *ss;
1263 ss->first = temp->first; ss->last = temp->last;
1264 temp->first = foo.first; temp->last = foo.last;
1265 SplinePointListFree(temp);
1266 }
1267 }
1268 }
1269
1270 static void CVChangeSpiroMode(CharView *cv) {
1271 if ( hasspiro() ) {
1272 cv->b.sc->inspiro = !cv->b.sc->inspiro;
1273 cv->showing_tool = cvt_none;
1274 CVClearSel(cv);
1275 if ( !cv->b.sc->inspiro )
1276 SCCheckForSSToOptimize(cv->b.sc,cv->b.layerheads[cv->b.drawmode]->splines,
1277 cv->b.layerheads[cv->b.drawmode]->order2);
1278 GDrawRequestExpose(cvtools,NULL,false);
1279 SCUpdateAll(cv->b.sc);
1280 } else
1281 #ifdef _NO_LIBSPIRO
1282 ff_post_error(_("You may not use spiros"),_("This version of fontforge was not linked with the spiro library, so you may not use them."));
1283 #else
1284 ff_post_error(_("You may not use spiros"),_("FontForge was unable to load libspiro, spiros are not available for use."));
1285 #endif
1286 }
1287
1288 char* HKTextInfoToUntranslatedTextFromTextInfo( GTextInfo* ti ); // From ../gdraw/gmenu.c.
1289
1290
1291 static void ToolsMouse(CharView *cv, GEvent *event) {
1292 IJ ij = getIJFromMouse( cv, event->u.mouse.x, event->u.mouse.y );
1293 int i = ij.i;
1294 int j = ij.j;
1295 int mi = i;
1296 int pos;
1297 int isstylus = event->u.mouse.device!=NULL && strcmp(event->u.mouse.device,"stylus")==0;
1298 int styluscntl = isstylus && (event->u.mouse.state&0x200);
1299 static int settings[2];
1300
1301 if( j==-1 || i==-1 )
1302 return;
1303
1304 if(j >= 2)
1305 return; /* If the wm gave me a window the wrong size */
1306
1307
1308 if ( i==(cvt_rect)/2 ) {
1309 int current = CVCurrentTool(cv,event);
1310 int changed = false;
1311 if ( event->type == et_mousedown && event->u.mouse.clicks>=2 ) {
1312 rectelipse = settings[0];
1313 polystar = settings[1];
1314 } else if ( event->type == et_mousedown ) {
1315 settings[0] = rectelipse; settings[1] = polystar;
1316 /* A double click will change the type twice, which leaves it where it was, which is desired */
1317 if ( j==0 && ((!rectelipse && current==cvt_rect) || (rectelipse && current==cvt_elipse)) ) {
1318 rectelipse = !rectelipse;
1319 changed = true;
1320 } else if (j==1 && ((!polystar && current==cvt_poly) || (polystar && current==cvt_star)) ) {
1321 polystar = !polystar;
1322 changed = true;
1323 }
1324 if ( changed ) {
1325 SavePrefs(true);
1326 GDrawRequestExpose(cvtools,NULL,false);
1327 }
1328 }
1329 if ( (j==0 && rectelipse) || (j==1 && polystar) )
1330 ++mi;
1331 }
1332 pos = mi*2 + j;
1333 GGadgetEndPopup();
1334 /* we have two fewer buttons than commands as two buttons each control two commands */
1335 if ( pos<0 || pos>=cvt_max )
1336 pos = cvt_none;
1337 if ( event->type == et_mousedown ) {
1338 if ( isstylus && event->u.mouse.button==2 )
1339 /* Not a real button press, only touch counts. This is a modifier */;
1340 else if ( pos==cvt_spiro ) {
1341 CVChangeSpiroMode(cv);
1342 /* This is just a button that indicates a state */
1343 } else {
1344 cv->pressed_tool = cv->pressed_display = pos;
1345 cv->had_control = ((event->u.mouse.state&ksm_control) || styluscntl)?1:0;
1346 event->u.mouse.state |= (1<<(7+event->u.mouse.button));
1347 }
1348 if ( event->u.mouse.clicks>=2 &&
1349 (pos/2 == cvt_scale/2 || pos/2 == cvt_rotate/2 || pos == cvt_3d_rotate ))
1350 CVDoTransform(cv,pos);
1351 } else if ( event->type == et_mousemove ) {
1352 if ( cv->pressed_tool==cvt_none && pos!=cvt_none ) {
1353 /* Not pressed */
1354 char *msg = _(popupsres[pos]);
1355 if ( cv->b.sc->inspiro && hasspiro()) {
1356 if ( pos==cvt_spirog2 )
1357 msg = _("Add a g2 curve point");
1358 else if ( pos==cvt_spiroleft )
1359 msg = _("Add a prev constraint point (sometimes like a tangent)");
1360 else if ( pos==cvt_spiroright )
1361 msg = _("Add a next constraint point (sometimes like a tangent)");
1362 }
1363 // We want to display the hotkey for the key in question if possible.
1364 char * mininame = HKTextInfoToUntranslatedTextFromTextInfo(&cvtoollist[pos].ti);
1365 char * menuname = NULL;
1366 Hotkey* toolhotkey = NULL;
1367 if (mininame != NULL) {
1368 if ( (menuname = smprintf("%s%s", "Point.Tools.", mininame)) != NULL) {
1369 toolhotkey = hotkeyFindByMenuPath(cv->gw, menuname);
1370 free(menuname); menuname = NULL;
1371 }
1372 free(mininame); mininame = NULL;
1373 }
1374 char * finalmsg = NULL;
1375 if (toolhotkey != NULL && (finalmsg = smprintf("%s (%s)", msg, toolhotkey->text)) != NULL) {
1376 GGadgetPreparePopup8(cvtools, finalmsg);
1377 free(finalmsg); finalmsg = NULL;
1378 } else GGadgetPreparePopup8(cvtools, msg); // That's what we were doing before. Much simpler.
1379 } else if ( pos!=cv->pressed_tool || cv->had_control != (((event->u.mouse.state&ksm_control) || styluscntl)?1:0) )
1380 cv->pressed_display = cvt_none;
1381 else
1382 cv->pressed_display = cv->pressed_tool;
1383 } else if ( event->type == et_mouseup ) {
1384 int old_b1_tool = cv->b1_tool;
1385 if ( pos==cvt_freehand && event->u.mouse.clicks==2 ) {
1386 FreeHandStrokeDlg(CVFreeHandInfo());
1387 } else if ( pos==cvt_pointer && event->u.mouse.clicks==2 ) {
1388 PointerDlg(cv);
1389 } else if ( pos==cvt_ruler && event->u.mouse.clicks==2 ) {
1390 RulerDlg(cv);
1391 } else if ( i==cvt_rect/2 && event->u.mouse.clicks==2 ) {
1392 ((j==0)?CVRectElipse:CVPolyStar)(cv);
1393 mi = i;
1394 if ( (j==0 && rectelipse) || (j==1 && polystar) )
1395 ++mi;
1396 pos = mi*2 + j;
1397 cv->pressed_tool = cv->pressed_display = pos;
1398 }
1399 if ( pos!=cv->pressed_tool || cv->had_control != (((event->u.mouse.state&ksm_control)||styluscntl)?1:0) )
1400 cv->pressed_tool = cv->pressed_display = cvt_none;
1401 else {
1402 if ( event->u.mouse.device!=NULL && strcmp(event->u.mouse.device,"eraser")==0 )
1403 cv->er_tool = pos;
1404 else if ( isstylus ) {
1405 if ( event->u.mouse.button==2 )
1406 /* Only thing that matters is touch which maps to button 1 */;
1407 else if ( cv->had_control )
1408 cv->s2_tool = pos;
1409 else
1410 cv->s1_tool = pos;
1411 } else if ( cv->had_control && event->u.mouse.button==2 )
1412 cv->cb2_tool = cv_cb2_tool = pos;
1413 else if ( event->u.mouse.button==2 )
1414 cv->b2_tool = cv_b2_tool = pos;
1415 else if ( cv->had_control ) {
1416 cv->cb1_tool = cv_cb1_tool = pos;
1417 } else {
1418 cv->b1_tool = cv_b1_tool = pos;
1419 }
1420 SavePrefs(true);
1421 cv->pressed_tool = cv->pressed_display = cvt_none;
1422 }
1423 GDrawRequestExpose(cvtools,NULL,false);
1424 if ( old_b1_tool!=cv->b1_tool && (old_b1_tool==cvt_scale || cv->b1_tool==cvt_scale) )
1425 GDrawRequestExpose(cv->v,NULL,false);
1426 event->u.chr.state &= ~(1<<(7+event->u.mouse.button));
1427 }
1428 CVToolsSetCursor(cv,event->u.mouse.state,event->u.mouse.device);
1429 }
1430
1431 static void PostCharToWindow(GWindow to, GEvent *e) {
1432 GPoint p;
1433
1434 p.x = e->u.chr.x; p.y = e->u.chr.y;
1435 GDrawTranslateCoordinates(e->w,to,&p);
1436 e->u.chr.x = p.x; e->u.chr.y = p.y;
1437 e->w = to;
1438 GDrawPostEvent(e);
1439 }
1440
1441 static int cvtools_e_h(GWindow gw, GEvent *event) {
1442 CharView *cv = (CharView *) GDrawGetUserData(gw);
1443
1444 if ( event->type==et_destroy && cvtools == gw ) {
1445 cvtools = NULL;
1446 return( true );
1447 }
1448
1449 if ( cv==NULL )
1450 return( true );
1451
1452 GGadgetPopupExternalEvent(event);
1453 switch ( event->type ) {
1454 case et_expose:
1455 ToolsExpose(gw,cv,&event->u.expose.rect);
1456 break;
1457 case et_mousedown:
1458 ToolsMouse(cv,event);
1459 break;
1460 case et_mousemove:
1461 ToolsMouse(cv,event);
1462 break;
1463 case et_mouseup:
1464 ToolsMouse(cv,event);
1465 break;
1466 case et_crossing:
1467 cv->pressed_display = cvt_none;
1468 CVToolsSetCursor(cv,event->u.mouse.state,NULL);
1469 break;
1470 case et_char: case et_charup:
1471 if ( cv->had_control != ((event->u.chr.state&ksm_control)?1:0) )
1472 cv->pressed_display = cvt_none;
1473 PostCharToWindow(cv->gw,event);
1474 break;
1475 case et_close:
1476 SetPaletteVisible(NULL, gw, false);
1477 break;
1478 default: break;
1479 }
1480 return( true );
1481 }
1482
1483 GWindow CVMakeTools(CharView *cv) {
1484 GRect r;
1485 GWindowAttrs wattrs;
1486
1487 if ( cvtools!=NULL )
1488 return( cvtools );
1489
1490 memset(&wattrs,0,sizeof(wattrs));
1491 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_positioned|wam_isdlg;
1492 wattrs.event_masks = -1;
1493 wattrs.cursor = ct_mypointer;
1494 wattrs.positioned = true;
1495 wattrs.is_dlg = true;
1496 wattrs.utf8_window_title = _("Tools");
1497
1498 r.width = getToolbarWidth(cv); r.height = getToolbarHeight(cv);
1499 if ( cvtoolsoff.x==-9999 ) {
1500 cvtoolsoff.x = -r.width-6; cvtoolsoff.y = cv->mbh+20;
1501 }
1502 r.x = cvtoolsoff.x; r.y = cvtoolsoff.y;
1503 if ( palettes_docked )
1504 r.x = r.y = 0;
1505 cvtools = CreatePalette( cv->gw, &r, cvtools_e_h, NULL, &wattrs, cv->v );
1506
1507 if ( GDrawRequestDeviceEvents(cvtools,input_em_cnt,input_em)>0 ) {
1508 /* Success! They've got a wacom tablet */
1509 }
1510
1511 if ( cvvisible[1])
1512 SetPaletteVisible(cv->gw, cvtools,true);
1513 return( cvtools );
1514 }
1515
1516
1517 /* ********************************************************* */
1518 /* ****************** Layers Palette ********************* */
1519 /* ********************************************************* */
1520
1521
1522
1523 /* Create a layer thumbnail */
1524 static BDFChar *BDFCharFromLayer(SplineChar *sc,int layer) {
1525 SplineChar dummy;
1526 memset(&dummy,0,sizeof(dummy));
1527 dummy.layer_cnt = 2;
1528 dummy.layers = sc->layers+layer-1;
1529 dummy.parent = sc->parent;
1530 return( SplineCharAntiAlias(&dummy,ly_fore,24,4));
1531 }
1532
1533 /**
1534 * \brief Recalculate the number of visible layers,
1535 * reposition the visibility checkboxes, and
1536 * if requested, reposition/resize the scrollbar.
1537 *
1538 * \param [in] cv The charview
1539 */
1540 static void CVLayers2Reflow(CharView *cv, bool resize) {
1541 extern int _GScrollBar_Width;
1542 GGadget *scrollbar;
1543 GRect cvl2size;
1544
1545 GDrawGetSize(cvlayers2, &cvl2size);
1546 // Minus 2 because we always have the 'Guide' and 'Back' entries
1547 layer2.visible_layers = (cvl2size.height - layer2.header_height - 2 * CV_LAYERS2_LINE_HEIGHT) / CV_LAYERS2_LINE_HEIGHT;
1548 if (layer2.visible_layers < 0) {
1549 layer2.visible_layers = 0;
1550 }
1551
1552 // Reposition the visibility checkboxes
1553 int num_potentially_visible = 2 + layer2.visible_layers + 1;
1554 if (num_potentially_visible > layer2.current_layers){
1555 num_potentially_visible = layer2.current_layers;
1556 }
1557 for (int i = 2, first_visible = 2 + layer2.offtop; i < layer2.current_layers; i++) {
1558 GGadget *vis = GWidgetGetControl(cvlayers2, CID_VBase + i - 1);
1559 if (vis == NULL) {
1560 break;
1561 }
1562 if (i >= first_visible && (i - layer2.offtop) < num_potentially_visible) {
1563 GGadgetMove(vis, 5, layer2.header_height + (i - layer2.offtop) * CV_LAYERS2_LINE_HEIGHT);
1564 GGadgetSetVisible(vis, true);
1565 } else {
1566 GGadgetSetVisible(vis, false);
1567 }
1568 }
1569
1570 if (!resize) {
1571 return;
1572 }
1573
1574 scrollbar = GWidgetGetControl(cvlayers2, CID_SB);
1575 // Check if we need the scrollbar or not.
1576 if (layer2.current_layers - 2 <= layer2.visible_layers || layer2.visible_layers <= 0) {
1577 GGadgetSetVisible(scrollbar, false);
1578 layer2.sb_start = cvl2size.width;
1579 layer2.offtop = 0;
1580 } else {
1581 layer2.sb_start = cvl2size.width - GDrawPointsToPixels(cv->gw, _GScrollBar_Width);
1582 GGadgetMove(scrollbar, layer2.sb_start, 0);
1583 GGadgetResize(scrollbar, GDrawPointsToPixels(cv->gw, _GScrollBar_Width), cvl2size.height);
1584 GGadgetSetVisible(scrollbar, true);
1585
1586 GScrollBarSetBounds(scrollbar, 0, layer2.current_layers - 2, layer2.visible_layers);
1587 GScrollBarSetPos(scrollbar, layer2.offtop);
1588 }
1589
1590 GDrawRequestExpose(cvlayers2, NULL, false);
1591 }
1592
1593 /* Update the type3 layers palette to the given character view */
1594 static void CVLayers2Set(CharView *cv) {
1595 int i, top;
1596
1597 GGadgetSetChecked(GWidgetGetControl(cvlayers2,CID_VFore),cv->showfore);
1598 GGadgetSetChecked(GWidgetGetControl(cvlayers2,CID_VBack),cv->showback[0]&1);
1599 GGadgetSetChecked(GWidgetGetControl(cvlayers2,CID_VGrid),cv->showgrids);
1600
1601 int ly = 0;
1602 // We want to look at the unhandled layers.
1603 if (ly <= ly_back) ly = ly_back + 1;
1604 if (ly <= ly_fore) ly = ly_fore + 1;
1605 if (ly <= ly_grid) ly = ly_grid + 1;
1606 while (ly < cv->b.sc->parent->layer_cnt) {
1607 GGadget *tmpgadget = GWidgetGetControl(cvlayers2, CID_VBase + ly);
1608 if (tmpgadget != NULL) {
1609 // We set a low cap on the number of layers provisioned with check boxes for safety.
1610 // So it is important to check that this exists.
1611 GGadgetSetChecked(tmpgadget, cv->showback[ly>>5]&(1<<(ly&31)));
1612 }
1613 ly ++;
1614 }
1615
1616 /* set old to NULL */
1617 layer2.offtop = 0;
1618 for ( i=2; i<layer2.current_layers; ++i ) {
1619 BDFCharFree(layer2.layers[i]);
1620 layer2.layers[i]=NULL;
1621 }
1622
1623 /* reallocate enough space if necessary */
1624 if ( cv->b.sc->layer_cnt+1>=layer2.max_layers ) {
1625 top = cv->b.sc->layer_cnt+10;
1626 if ( layer2.layers==NULL )
1627 layer2.layers = calloc(top,sizeof(BDFChar *));
1628 else {
1629 layer2.layers = realloc(layer2.layers,top*sizeof(BDFChar *));
1630 for ( i=layer2.current_layers; i<top; ++i )
1631 layer2.layers[i] = NULL;
1632 }
1633 layer2.max_layers = top;
1634 }
1635 layer2.current_layers = cv->b.sc->layer_cnt+1;
1636 for ( i=ly_fore; i<cv->b.sc->layer_cnt; ++i )
1637 layer2.layers[i+1] = BDFCharFromLayer(cv->b.sc,i);
1638 layer2.active = CVLayer(&cv->b)+1;
1639
1640 CVLayers2Reflow(cv, true);
1641 }
1642
1643 static void Layers2Expose(CharView *cv,GWindow pixmap,GEvent *event) {
1644 int i, ll;
1645 const char *str;
1646 GRect r, oldclip;
1647 struct _GImage base;
1648 GImage gi;
1649 int leftOffset, layerCount;
1650
1651 if ( event->u.expose.rect.y+event->u.expose.rect.height<layer2.header_height )
1652 return;
1653
1654 // Calculate the left offset (from the checkboxes)
1655 GGadgetGetSize(GWidgetGetControl(cvlayers2, CID_VGrid), &r);
1656 leftOffset = r.x + r.width;
1657 // Compute the drawable area and clip to it.
1658 GDrawGetSize(cvlayers2, &r);
1659 r.x = leftOffset;
1660 r.width = layer2.sb_start - r.x;
1661 r.y = layer2.header_height;
1662 r.height = r.height - layer2.header_height;
1663 GDrawPushClip(pixmap, &r, &oldclip);
1664 GDrawFillRect(pixmap,&r,cvpalettebgcol);
1665
1666 GDrawSetDither(NULL, false); /* on 8 bit displays we don't want any dithering */
1667
1668 memset(&gi,0,sizeof(gi));
1669 memset(&base,0,sizeof(base));
1670 gi.u.image = &base;
1671 base.image_type = it_index;
1672 base.clut = layer2.clut;
1673 base.trans = -1;
1674 GDrawSetFont(pixmap,layer2.font);
1675
1676 // +2 for the defaults, +1 to show one extra (could be partially visible)
1677 layerCount = layer2.visible_layers + 2 + 1;
1678 if (layerCount > layer2.current_layers) {
1679 layerCount = layer2.current_layers;
1680 }
1681 for (i = 0; i < layerCount; ++i) {
1682 ll = i<2 ? i : i+layer2.offtop;
1683 if ( ll==layer2.active ) {
1684 r.x = leftOffset;
1685 r.width = layer2.sb_start - r.x;
1686 r.y = layer2.header_height + i * CV_LAYERS2_LINE_HEIGHT;
1687 r.height = CV_LAYERS2_LINE_HEIGHT;
1688 GDrawFillRect(pixmap,&r,cvpalettefgcol);
1689 }
1690 GDrawDrawLine(pixmap, r.x, layer2.header_height + i * CV_LAYERS2_LINE_HEIGHT,
1691 r.x + r.width, layer2.header_height + i * CV_LAYERS2_LINE_HEIGHT,
1692 0x808080);
1693 if ( i==0 || i==1 ) {
1694 str = i==0?_("Guide") : _("Back");
1695 GDrawDrawText8(pixmap, r.x + 2, layer2.header_height + i * CV_LAYERS2_LINE_HEIGHT + (CV_LAYERS2_LINE_HEIGHT - 12) / 2 + 12,
1696 (char *) str,-1,ll==layer2.active?cvpalettebgcol:cvpalettefgcol);
1697 } else if ( layer2.offtop+i>=layer2.current_layers ) {
1698 break;
1699 } else if ( layer2.layers[layer2.offtop+i]!=NULL ) {
1700 #if 0
1701 // This is currently broken, and we do not have time to fix it.
1702 BDFChar *bdfc = layer2.layers[layer2.offtop+i];
1703 base.data = bdfc->bitmap;
1704 base.bytes_per_line = bdfc->bytes_per_line;
1705 base.width = bdfc->xmax-bdfc->xmin+1;
1706 base.height = bdfc->ymax-bdfc->ymin+1;
1707 GDrawDrawImage(pixmap,&gi,NULL,
1708 r.x+2+bdfc->xmin,
1709 layer2.header_height + i * CV_LAYERS2_LINE_HEIGHT + as - bdfc->ymax);
1710 #else
1711 // This logic comes from CVInfoDrawText.
1712 const int layernamesz = 100;
1713 char layername[layernamesz+1];
1714 strncpy(layername,_("Guide"),layernamesz);
1715 int idx = layer2.offtop+i-1;
1716 if(idx >= 0 && idx < cv->b.sc->parent->layer_cnt) {
1717 strncpy(layername,cv->b.sc->parent->layers[idx].name,layernamesz);
1718 } else {
1719 fprintf(stderr, "Invalid layer!\n");
1720 }
1721 // And this comes from above.
1722 GDrawDrawText8(pixmap, r.x + 2, layer2.header_height + i * CV_LAYERS2_LINE_HEIGHT + (CV_LAYERS2_LINE_HEIGHT - 12) / 2 + 12,
1723 (char *) layername,-1,ll==layer2.active?cvpalettebgcol:cvpalettefgcol);
1724 #endif // 0
1725 }
1726 }
1727 GDrawPopClip(pixmap, &oldclip);
1728 }
1729
1730 // Frank changed the prefix from MID to MIDL in order to avert conflicts with values set in charview_private.h.
1731 #define MIDL_LayerInfo 1
1732 #define MIDL_NewLayer 2
1733 #define MIDL_DelLayer 3
1734 #define MIDL_First 4
1735 #define MIDL_Earlier 5
1736 #define MIDL_Later 6
1737 #define MIDL_Last 7
1738 #define MIDL_MakeLine 100
1739 #define MIDL_MakeArc 200
1740 #define MIDL_InsertPtOnSplineAt 2309
1741 #define MIDL_NamePoint 2318
1742 #define MIDL_NameContour 2319
1743
1744 static void CVLayer2Invoked(GWindow v, GMenuItem *mi, GEvent *e) {
1745 CharView *cv = (CharView *) GDrawGetUserData(v);
1746 Layer temp;
1747 int layer = CVLayer(&cv->b);
1748 SplineChar *sc = cv->b.sc;
1749 int i;
1750 char *buts[3];
1751 buts[0] = _("_Yes"); buts[1]=_("_No"); buts[2] = NULL;
1752
1753 switch ( mi->mid ) {
1754 case MIDL_LayerInfo:
1755 if ( !LayerDialog(cv->b.layerheads[cv->b.drawmode],cv->b.sc->parent))
1756 return;
1757 break;
1758 case MIDL_NewLayer:
1759 LayerDefault(&temp);
1760 if ( !LayerDialog(&temp,cv->b.sc->parent))
1761 return;
1762 sc->layers = realloc(sc->layers,(sc->layer_cnt+1)*sizeof(Layer));
1763 sc->layers[sc->layer_cnt] = temp;
1764 cv->b.layerheads[dm_fore] = &sc->layers[sc->layer_cnt];
1765 cv->b.layerheads[dm_back] = &sc->layers[ly_back];
1766 ++sc->layer_cnt;
1767 break;
1768 case MIDL_DelLayer:
1769 if ( sc->layer_cnt==2 ) /* May not delete the last foreground layer */
1770 return;
1771 if ( gwwv_ask(_("Cannot Be Undone"),(const char **) buts,0,1,_("This operation cannot be undone, do it anyway?"))==1 )
1772 return;
1773 SplinePointListsFree(sc->layers[layer].splines);
1774 RefCharsFree(sc->layers[layer].refs);
1775 ImageListsFree(sc->layers[layer].images);
1776 UndoesFree(sc->layers[layer].undoes);
1777 UndoesFree(sc->layers[layer].redoes);
1778 for ( i=layer+1; i<sc->layer_cnt; ++i )
1779 sc->layers[i-1] = sc->layers[i];
1780 --sc->layer_cnt;
1781 if ( layer==sc->layer_cnt )
1782 cv->b.layerheads[dm_fore] = &sc->layers[layer-1];
1783 break;
1784 case MIDL_First:
1785 if ( layer==ly_fore )
1786 return;
1787 temp = sc->layers[layer];
1788 for ( i=layer-1; i>=ly_fore; --i )
1789 sc->layers[i+1] = sc->layers[i];
1790 sc->layers[i+1] = temp;
1791 cv->b.layerheads[dm_fore] = &sc->layers[ly_fore];
1792 break;
1793 case MIDL_Earlier:
1794 if ( layer==ly_fore )
1795 return;
1796 temp = sc->layers[layer];
1797 sc->layers[layer] = sc->layers[layer-1];
1798 sc->layers[layer-1] = temp;
1799 cv->b.layerheads[dm_fore] = &sc->layers[layer-1];
1800 break;
1801 case MIDL_Later:
1802 if ( layer==sc->layer_cnt-1 )
1803 return;
1804 temp = sc->layers[layer];
1805 sc->layers[layer] = sc->layers[layer+1];
1806 sc->layers[layer+1] = temp;
1807 cv->b.layerheads[dm_fore] = &sc->layers[layer+1];
1808 break;
1809 case MIDL_Last:
1810 if ( layer==sc->layer_cnt-1 )
1811 return;
1812 temp = sc->layers[layer];
1813 for ( i=layer+1; i<sc->layer_cnt; ++i )
1814 sc->layers[i-1] = sc->layers[i];
1815 sc->layers[i-1] = temp;
1816 cv->b.layerheads[dm_fore] = &sc->layers[i-1];
1817 break;
1818 }
1819 CVLayers2Set(cv);
1820 CVCharChangedUpdate(&cv->b);
1821 }
1822
1823 static void Layer2Menu(CharView *cv,GEvent *event, int nolayer) {
1824 GMenuItem mi[20];
1825 int i;
1826 static char *names[] = { N_("Layer Info..."), N_("New Layer..."), N_("Del Layer"), (char *) -1,
1827 N_("_First"), N_("_Earlier"), N_("L_ater"), N_("_Last"), NULL };
1828 static int mids[] = { MIDL_LayerInfo, MIDL_NewLayer, MIDL_DelLayer, -1,
1829 MIDL_First, MIDL_Earlier, MIDL_Later, MIDL_Last, 0 };
1830 int layer = CVLayer(&cv->b);
1831
1832 memset(mi,'\0',sizeof(mi));
1833 for ( i=0; names[i]!=0; ++i ) {
1834 if ( names[i]!=(char *) -1 ) {
1835 mi[i].ti.text = (unichar_t *) _(names[i]);
1836 mi[i].ti.text_is_1byte = true;
1837 } else
1838 mi[i].ti.line = true;
1839 mi[i].ti.fg = COLOR_DEFAULT;
1840 mi[i].ti.bg = COLOR_DEFAULT;
1841 mi[i].mid = mids[i];
1842 mi[i].invoke = CVLayer2Invoked;
1843 if ( mids[i]!=MIDL_NewLayer && nolayer )
1844 mi[i].ti.disabled = true;
1845 if (( mids[i]==MIDL_First || mids[i]==MIDL_Earlier ) && layer==ly_fore )
1846 mi[i].ti.disabled = true;
1847 if (( mids[i]==MIDL_Last || mids[i]==MIDL_Later ) && layer==cv->b.sc->layer_cnt-1 )
1848 mi[i].ti.disabled = true;
1849 if ( mids[i]==MIDL_DelLayer && cv->b.sc->layer_cnt==2 )
1850 mi[i].ti.disabled = true;
1851 }
1852 GMenuCreatePopupMenu(cvlayers2,event, mi);
1853 }
1854
1855 static void Layer2Scroll(CharView *cv, GEvent *event) {
1856 int off = 0;
1857 enum sb sbt = event->u.control.u.sb.type;
1858
1859 if ( sbt==et_sb_top )
1860 off = 0;
1861 else if ( sbt==et_sb_bottom )
1862 off = cv->b.sc->layer_cnt-1-layer2.visible_layers;
1863 else if ( sbt==et_sb_up ) {
1864 off = layer2.offtop-1;
1865 } else if ( sbt==et_sb_down ) {
1866 off = layer2.offtop+1;
1867 } else if ( sbt==et_sb_uppage ) {
1868 off = layer2.offtop-layer2.visible_layers+1;
1869 } else if ( sbt==et_sb_downpage ) {
1870 off = layer2.offtop+layer2.visible_layers-1;
1871 } else /* if ( sbt==et_sb_thumb || sbt==et_sb_thumbrelease ) */ {
1872 off = event->u.control.u.sb.pos;
1873 }
1874 if ( off>cv->b.sc->layer_cnt-1-layer2.visible_layers )
1875 off = cv->b.sc->layer_cnt-1-layer2.visible_layers;
1876 if ( off<0 ) off=0;
1877 if ( off==layer2.offtop )
1878 return;
1879 layer2.offtop = off;
1880 GScrollBarSetPos(GWidgetGetControl(cvlayers2,CID_SB),off);
1881 CVLayers2Reflow(cv, false);
1882 GDrawRequestExpose(cvlayers2,NULL,false);
1883 }
1884
1885 static int cvlayers2_e_h(GWindow gw, GEvent *event) {
1886 CharView *cv = (CharView *) GDrawGetUserData(gw);
1887
1888 if ( event->type==et_destroy && cvlayers2 == gw ) {
1889 cvlayers2 = NULL;
1890 return( true );
1891 }
1892
1893 if ( cv==NULL )
1894 return( true );
1895
1896 switch ( event->type ) {
1897 case et_close:
1898 SetPaletteVisible(NULL, gw, false);
1899 break;
1900 case et_char: case et_charup:
1901 PostCharToWindow(cv->gw,event);
1902 break;
1903 case et_resize:
1904 CVLayers2Reflow(cv, true);
1905 break;
1906 case et_expose:
1907 Layers2Expose(cv,gw,event);
1908 break;
1909 case et_mousedown: {
1910 if ( event->u.mouse.y>CV_LAYERS2_HEADER_HEIGHT ) {
1911 if (event->u.mouse.button >= 4) {
1912 // Scroll the list
1913 event->u.control.u.sb.type = (event->u.mouse.button == 4 || event->u.mouse.button == 6) ? et_sb_up : et_sb_down;
1914 Layer2Scroll(cv, event);
1915 return true;
1916 }
1917 int layer = (event->u.mouse.y-CV_LAYERS2_HEADER_HEIGHT)/CV_LAYERS2_LINE_HEIGHT;
1918 if ( layer<2 ) {
1919 cv->b.drawmode = layer==0 ? dm_grid : dm_back;
1920 layer2.active = layer;
1921 } else if ( layer-1+layer2.offtop >= cv->b.sc->layer_cnt ) {
1922 if ( event->u.mouse.button==3 )
1923 Layer2Menu(cv,event,true);
1924 else
1925 GDrawBeep(NULL);
1926 return(true);
1927 } else {
1928 layer2.active = layer+layer2.offtop;
1929 cv->b.drawmode = dm_fore;
1930 cv->b.layerheads[dm_fore] = &cv->b.sc->layers[layer-1+layer2.offtop];
1931 }
1932 GDrawRequestExpose(cvlayers2,NULL,false);
1933 GDrawRequestExpose(cv->v,NULL,false);
1934 GDrawRequestExpose(cv->gw,NULL,false); /* the logo (where the scrollbars join) shows what layer we are in */
1935 if ( event->u.mouse.button==3 )
1936 Layer2Menu(cv,event,cv->b.drawmode!=dm_fore);
1937 else if ( event->u.mouse.clicks==2 && cv->b.drawmode==dm_fore ) {
1938 if ( LayerDialog(cv->b.layerheads[cv->b.drawmode],cv->b.sc->parent))
1939 CVCharChangedUpdate(&cv->b);
1940 }
1941 }
1942 } break;
1943 case et_controlevent:
1944 if ( event->u.control.subtype == et_radiochanged ) {
1945 enum drawmode dm = cv->b.drawmode;
1946 int tmpcid = -1;
1947 int tmplayer = -1;
1948 switch(GGadgetGetCid(event->u.control.g)) {
1949 case CID_VFore:
1950 CVShows.showfore = cv->showfore = GGadgetIsChecked(event->u.control.g);
1951 if ( CVShows.showback )
1952 cv->showback[0] |= 2;
1953 else
1954 cv->showback[0] &= ~2;
1955 break;
1956 case CID_VBack:
1957 CVShows.showback = GGadgetIsChecked(event->u.control.g);
1958 if ( CVShows.showback )
1959 cv->showback[0] |= 1;
1960 else
1961 cv->showback[0] &= ~1;
1962 break;
1963 case CID_VGrid:
1964 CVShows.showgrids = cv->showgrids = GGadgetIsChecked(event->u.control.g);
1965 break;
1966 default:
1967 tmpcid = GGadgetGetCid(event->u.control.g);
1968 tmplayer = tmpcid - CID_VBase;
1969 if (tmpcid < 0 || tmplayer < 0) break;
1970 // We check that the layer is valid (since the code does not presently, as far as Frank knows, handle layer deletion).
1971 // We also check that the CID is within the allocated range (although this may not be necessary since the checkbox would not exist otherwise).
1972 if (tmplayer > 0 && tmplayer < 999 && tmplayer < cv->b.sc->parent->layer_cnt) {
1973 if (GGadgetIsChecked(event->u.control.g)) {
1974 cv->showback[tmplayer>>5]|=(1<<(tmplayer&31));
1975 } else {
1976 cv->showback[tmplayer>>5]&=~(1<<(tmplayer&31));
1977 }
1978 }
1979 break;
1980 }
1981 GDrawRequestExpose(cv->v,NULL,false);
1982 if ( dm!=cv->b.drawmode )
1983 GDrawRequestExpose(cv->gw,NULL,false); /* the logo (where the scrollbars join) shows what layer we are in */
1984 } else
1985 Layer2Scroll(cv,event);
1986 break;
1987 default: break;
1988 }
1989 return( true );
1990 }
1991
1992 /* This is used for Type 3 fonts. CVMakeLayers is used for other fonts. */
1993 static void CVMakeLayers2(CharView *cv) {
1994 GRect r;
1995 GWindowAttrs wattrs;
1996 GGadgetCreateData gcd[25];
1997 GTextInfo label[25];
1998 static GBox radio_box = { bt_none, bs_rect, 0, 0, 0, 0, 0, 0, 0, 0, COLOR_DEFAULT, COLOR_DEFAULT, 0, 0, 0, 0, 0, 0, 0 };
1999 int i;
2000 extern int _GScrollBar_Width;
2001
2002 if ( layer2.clut==NULL )
2003 layer2.clut = _BDFClut(4);
2004 if ( cvlayers2!=NULL )
2005 return;
2006 memset(&wattrs,0,sizeof(wattrs));
2007 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_positioned|wam_isdlg;
2008 wattrs.event_masks = -1;
2009 wattrs.cursor = ct_mypointer;
2010 wattrs.positioned = true;
2011 wattrs.is_dlg = true;
2012 wattrs.utf8_window_title = _("Layers");
2013
2014 r.width = GGadgetScale(CV_LAYERS2_WIDTH); r.height = CV_LAYERS2_HEIGHT;
2015 if ( cvlayersoff.x==-9999 ) {
2016 cvlayersoff.x = -r.width-6;
2017 cvlayersoff.y = cv->mbh+getToolbarHeight(cv)+45/*25*/; /* 45 is right if there's decor, 25 when none. twm gives none, kde gives decor */
2018 }
2019 r.x = cvlayersoff.x; r.y = cvlayersoff.y;
2020 if ( palettes_docked ) { r.x = 0; r.y=getToolbarHeight(cv)+2; }
2021 cvlayers2 = CreatePalette( cv->gw, &r, cvlayers2_e_h, NULL, &wattrs, cv->v );
2022
2023 memset(&label,0,sizeof(label));
2024 memset(&gcd,0,sizeof(gcd));
2025
2026 for ( i=0; i<sizeof(label)/sizeof(label[0]); ++i )
2027 label[i].font = layerspalette_font.fi;
2028 layer2.font = layerspalette_font.fi;
2029
2030 gcd[0].gd.pos.width = GDrawPointsToPixels(cv->gw,_GScrollBar_Width);
2031 gcd[0].gd.pos.x = CV_LAYERS2_WIDTH-gcd[0].gd.pos.width;
2032 gcd[0].gd.pos.y = CV_LAYERS2_HEADER_HEIGHT+2*CV_LAYERS2_LINE_HEIGHT;
2033 gcd[0].gd.pos.height = CV_LAYERS2_HEIGHT-gcd[0].gd.pos.y;
2034 gcd[0].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels|gg_sb_vert;
2035 gcd[0].gd.cid = CID_SB;
2036 gcd[0].creator = GScrollBarCreate;
2037 layer2.sb_start = gcd[0].gd.pos.x;
2038
2039 /* GT: Abbreviation for "Visible" */
2040 label[1].text = (unichar_t *) _("V");
2041 label[1].text_is_1byte = true;
2042 gcd[1].gd.label = &label[1];
2043 gcd[1].gd.pos.x = 7; gcd[1].gd.pos.y = 5;
2044 gcd[1].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels;
2045 gcd[1].gd.popup_msg = _("Is Layer Visible?");
2046 gcd[1].creator = GLabelCreate;
2047
2048 label[2].text = (unichar_t *) _("Layer");
2049 label[2].text_is_1byte = true;
2050 gcd[2].gd.label = &label[2];
2051 gcd[2].gd.pos.x = 30; gcd[2].gd.pos.y = 5;
2052 gcd[2].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels;
2053 gcd[2].gd.cid = CID_LayerLabel;
2054 gcd[2].gd.popup_msg = _("Is Layer Editable?");
2055 gcd[2].creator = GLabelCreate;
2056
2057 gcd[3].gd.pos.x = 5; gcd[3].gd.pos.y = CV_LAYERS2_HEADER_HEIGHT+(CV_LAYERS2_LINE_HEIGHT-12)/2;
2058 gcd[3].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
2059 gcd[3].gd.cid = CID_VGrid;
2060 gcd[3].gd.popup_msg = _("Is Layer Visible?");
2061 gcd[3].gd.box = &radio_box;
2062 gcd[3].creator = GCheckBoxCreate;
2063
2064 gcd[4].gd.pos.x = 5; gcd[4].gd.pos.y = gcd[3].gd.pos.y+CV_LAYERS2_LINE_HEIGHT;
2065 gcd[4].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
2066 gcd[4].gd.cid = CID_VBack;
2067 gcd[4].gd.popup_msg = _("Is Layer Visible?");
2068 gcd[4].gd.box = &radio_box;
2069 gcd[4].creator = GCheckBoxCreate;
2070
2071 gcd[5].gd.pos.x = 5; gcd[5].gd.pos.y = gcd[4].gd.pos.y+CV_LAYERS2_LINE_HEIGHT;
2072 gcd[5].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
2073 gcd[5].gd.cid = CID_VFore;
2074 gcd[5].gd.popup_msg = _("Is Layer Visible?");
2075 gcd[5].gd.box = &radio_box;
2076 gcd[5].creator = GCheckBoxCreate;
2077
2078 int wi = 6; // Widget index.
2079 int ly = 0;
2080 // We want to look at the unhandled layers.
2081 if (ly <= ly_back) ly = ly_back + 1;
2082 if (ly <= ly_fore) ly = ly_fore + 1;
2083 if (ly <= ly_grid) ly = ly_grid + 1;
2084 while (ly < cv->b.sc->parent->layer_cnt && wi < 24) {
2085 gcd[wi].gd.pos.x = 5; gcd[wi].gd.pos.y = gcd[wi-1].gd.pos.y+CV_LAYERS2_LINE_HEIGHT;
2086 gcd[wi].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
2087 gcd[wi].gd.cid = CID_VBase + ly; // There are plenty of CID values available for these above CID_VBase.
2088 gcd[wi].gd.popup_msg = _("Is Layer Visible?");
2089 gcd[wi].gd.box = &radio_box;
2090 gcd[wi].creator = GCheckBoxCreate;
2091 ly++;
2092 wi++;
2093 }
2094
2095 if ( cv->showgrids ) gcd[3].gd.flags |= gg_cb_on;
2096 if ( cv->showback[0]&1 ) gcd[4].gd.flags |= gg_cb_on;
2097 if ( cv->showfore ) gcd[5].gd.flags |= gg_cb_on;
2098
2099 GGadgetsCreate(cvlayers2, gcd);
2100 // Calculate the header height. The '-1' is magic! Needed to obtain symmetry
2101 layer2.header_height = GGadgetGetY(GWidgetGetControl(cvlayers2, CID_VGrid)) - 1;
2102 // Move the "Layer" label into the correct position based on the width of the checkbox
2103 GGadgetGetSize(GWidgetGetControl(cvlayers2, CID_VGrid), &r);
2104 GGadgetMove(GWidgetGetControl(cvlayers2, CID_LayerLabel), r.x + r.width, 5);
2105 if ( cvvisible[0] )
2106 SetPaletteVisible(cv->gw, cvlayers2, true);
2107 }
2108
2109 static void LayersSwitch(CharView *cv) {
2110 }
2111
2112 void SC_MoreLayers(SplineChar *sc, Layer *old) { /* We've added more layers */
2113 CharView *curcv, *cv;
2114 if ( sc->parent==NULL || !sc->parent->multilayer )
2115 return;
2116 for ( cv=(CharView *) (sc->views); cv!=NULL ; cv=(CharView *) (cv->b.next) ) {
2117 cv->b.layerheads[dm_fore] = &cv->b.sc->layers[cv->b.layerheads[dm_fore]-old];
2118 cv->b.layerheads[dm_back] = &cv->b.sc->layers[ly_back];
2119 }
2120 if ( cvtools==NULL )
2121 return;
2122 curcv = GDrawGetUserData(cvtools);
2123 if ( curcv==NULL || curcv->b.sc!=sc )
2124 return;
2125 CVLayers2Set(curcv);
2126 }
2127
2128 void SCLayersChange(SplineChar *sc) { /* many of the foreground layers need to be redrawn */
2129 CharView *curcv;
2130 if ( cvtools==NULL || !sc->parent->multilayer )
2131 return;
2132 curcv = GDrawGetUserData(cvtools);
2133 if ( curcv==NULL || curcv->b.sc!=sc )
2134 return;
2135 CVLayers2Set(curcv);
2136 }
2137
2138 void CVLayerChange(CharView *cv) { /* Current layer needs to be redrawn */
2139 CharView *curcv;
2140 int layer;
2141
2142 if ( cvtools==NULL || !cv->b.sc->parent->multilayer )
2143 return;
2144 curcv = GDrawGetUserData(cvtools);
2145 if ( curcv!=cv )
2146 return;
2147 if ( cv->b.drawmode==dm_grid || cv->b.drawmode==dm_back )
2148 return;
2149 layer = CVLayer(&cv->b);
2150 BDFCharFree(layer2.layers[layer+1]);
2151 layer2.layers[layer+1] = BDFCharFromLayer(cv->b.sc,layer);
2152 GDrawRequestExpose(cvlayers2,NULL,false);
2153 }
2154
2155 /* Update the state of the controls of the non-type3 layers palette to the given character view */
2156 /* New widgets are not allocated here. For that, see CVLCheckLayerCount(). */
2157 static void CVLayers1Set(CharView *cv) {
2158 int i, top;
2159
2160 GGadgetSetChecked(GWidgetGetControl(cvlayers,CID_VFore),cv->showfore);
2161 GGadgetSetChecked(GWidgetGetControl(cvlayers,CID_VBack),cv->showback[0]&1);
2162 GGadgetSetChecked(GWidgetGetControl(cvlayers,CID_VGrid),cv->showgrids);
2163
2164 /* clear old layer previews */
2165 layerinfo.offtop = 0;
2166 for ( i=2; i<layerinfo.current_layers; ++i ) {
2167 BDFCharFree(layerinfo.layers[i]);
2168 layerinfo.layers[i]=NULL;
2169 }
2170
2171 /* reallocate enough space if necessary */
2172 if ( cv->b.sc->layer_cnt+1>=layerinfo.max_layers ) {
2173 top = cv->b.sc->layer_cnt+10;
2174 if ( layerinfo.layers==NULL )
2175 layerinfo.layers = calloc(top,sizeof(BDFChar *));
2176 else {
2177 layerinfo.layers = realloc(layerinfo.layers,top*sizeof(BDFChar *));
2178 for ( i=layerinfo.current_layers; i<top; ++i )
2179 layerinfo.layers[i] = NULL;
2180 }
2181 layerinfo.max_layers = top;
2182 }
2183 layerinfo.current_layers = cv->b.sc->layer_cnt+1;
2184 for ( i=ly_fore; i<cv->b.sc->layer_cnt; ++i )
2185 layerinfo.layers[i+1] = BDFCharFromLayer(cv->b.sc,i);
2186 layerinfo.active = CVLayer(&cv->b)+1;
2187
2188 if ( layerinfo.visible_layers==0 ) {
2189 GRect size;
2190 GDrawGetSize(cvlayers,&size);
2191 layerinfo.visible_layers=(size.height-layer_header_height)/layer_height;
2192 }
2193 GScrollBarSetBounds(GWidgetGetControl(cvlayers,CID_SB),0,cv->b.sc->layer_cnt+1-2, layerinfo.visible_layers);
2194 if ( layerinfo.offtop>cv->b.sc->layer_cnt-1-layerinfo.visible_layers )
2195 layerinfo.offtop = cv->b.sc->layer_cnt-1-layerinfo.visible_layers;
2196 if ( layerinfo.offtop<0 ) layerinfo.offtop = 0;
2197 GScrollBarSetPos(GWidgetGetControl(cvlayers,CID_SB),layerinfo.offtop);
2198
2199 for ( i=0; i<cv->b.sc->layer_cnt; i++ ) {
2200 GGadgetSetChecked(GWidgetGetControl(cvlayers,CID_VBase+i),cv->showback[i>>5]&(1<<(i&31)));
2201 }
2202
2203 layerinfo.active = CVLayer(&cv->b); /* the index of the active layer */
2204 GDrawRequestExpose(cvlayers,NULL,false);
2205 }
2206
2207 /* Update the layers palette to reflect the given character view. No new gadgets
2208 * are created or hid here, only the state of existing gadgets is changed.
2209 * New layer gadgets are created in CVLCheckLayerCount(). */
2210 void CVLayersSet(CharView *cv) {
2211 if ( cv->b.sc->parent->multilayer ) {
2212 CVLayers2Set(cv);
2213 return;
2214 }
2215 /* This is for the non-type3 layers palette: */
2216 CVLayers1Set(cv);
2217 }
2218
2219 /**
2220 * Get the offset at the right hand size of the eyeball to show/hide
2221 * a layer. This is the x offset where the Q/C indicators might be drawn.
2222 */
2223 static int32_t Layers_getOffsetAtRightOfViewLayer(CharView *cv)
2224 {
2225 int32_t ret = 64;
2226 GGadget *v = GWidgetGetControl(cvlayers,CID_VBack);
2227 if( v )
2228 {
2229 GRect size;
2230 GGadgetGetSize(v,&size);
2231 ret = 7 + size.width;
2232 }
2233 return ret;
2234 }
2235
2236
2237 /* Draw the fg/bg, cubic/quadratic columns, plus layer preview and label name */
2238 static void LayersExpose(CharView *cv,GWindow pixmap,GEvent *event) {
2239 int i, ll, y;
2240 const char *str;
2241 GRect r;
2242 struct _GImage base;
2243 GImage gi;
2244 int ww;
2245
2246 int yt = .7*layer_height; /* vertical spacer to add when drawing text in the row */
2247 int column_width;
2248 int quadcol, fgcol, editcol;
2249
2250 if ( event->u.expose.rect.y+event->u.expose.rect.height<layer_header_height )
2251 return;
2252
2253 int offsetAtRightOfViewLayer = Layers_getOffsetAtRightOfViewLayer(cv);
2254 column_width = layerinfo.column_width;
2255
2256 GDrawSetDither(NULL, false); /* on 8 bit displays we don't want any dithering */
2257 ww=layerinfo.sb_start;
2258
2259 memset(&gi,0,sizeof(gi));
2260 memset(&base,0,sizeof(base));
2261 gi.u.image = &base;
2262 base.image_type = it_index;
2263 base.clut = layer2.clut;
2264 base.trans = -1;
2265 GDrawSetFont(pixmap,layerinfo.font);
2266
2267 quadcol=fgcol=offsetAtRightOfViewLayer;
2268 if ( layerscols & LSHOW_CUBIC )
2269 {
2270 /* show quad col */
2271 quadcol = offsetAtRightOfViewLayer;
2272 fgcol = offsetAtRightOfViewLayer+column_width;
2273 }
2274 if ( layerscols & LSHOW_FG )
2275 {
2276 /* show fg col */
2277 fgcol = quadcol+column_width;
2278 }
2279 // editcol is the X offset where the layer name label should be drawn
2280 editcol = fgcol+column_width;
2281 int bottomOfLast = 0;
2282
2283 /* loop once per layer, where 0==guides, 1=back, 2=fore, etc */
2284 for ( i=(event->u.expose.rect.y-layer_header_height)/layer_height;
2285 i<(event->u.expose.rect.y+event->u.expose.rect.height+layer_height-layer_header_height)/layer_height;
2286 ++i ) {
2287 ll = i-1+layerinfo.offtop;
2288 if ( ll>=cv->b.sc->layer_cnt || ll<-1 ) continue;
2289
2290 y = layer_header_height + i*layer_height;
2291 bottomOfLast = y + layer_height;
2292 if ( y<layer_header_height ) continue;
2293
2294 /* draw quadratic/cubic toggle */
2295 if ( layerscols & LSHOW_CUBIC ) {
2296 if ( layerinfo.mo_layer==ll && layerinfo.mo_col==CID_QBase ) {
2297 r.x = quadcol; r.width = column_width;
2298 r.y = y;
2299 r.height = layer_height;
2300 GDrawFillRect(pixmap,&r,cvpaletteactborcol);
2301 }
2302 str = ( ll>=0 && ll<cv->b.sc->layer_cnt ? (cv->b.sc->layers[ll].order2? "Q" : "C") : " ");
2303 GDrawDrawText8(pixmap, quadcol, y + yt,
2304 (char *) str,-1,cvpalettefgcol);
2305 }
2306
2307 /* draw fg/bg toggle */
2308 if ( layerscols & LSHOW_FG ) {
2309 if ( layerinfo.mo_layer==ll && layerinfo.mo_col==CID_FBase ) {
2310 r.x = fgcol; r.width = column_width;
2311 r.y = y;
2312 r.height = layer_height;
2313 GDrawFillRect(pixmap,&r,cvpaletteactborcol);
2314 }
2315 str = ( ll>=0 && ll<cv->b.sc->layer_cnt ? (cv->b.sc->layers[ll].background? "B" : "F") : "#");
2316 GDrawDrawText8(pixmap, fgcol, y + yt,
2317 (char *) str,-1,cvpalettefgcol);
2318 }
2319
2320 /* draw layer thumbnail and label */
2321 if ( ll==layerinfo.active ) {
2322 r.x = editcol; r.width = ww-r.x;
2323 r.y = y;
2324 r.height = layer_height;
2325 GDrawFillRect(pixmap,&r,cvpalettefgcol);
2326 } else if ( layerinfo.mo_layer==ll && layerinfo.mo_col==CID_EBase ) {
2327 r.x = editcol; r.width = ww-r.x;
2328 r.y = y;
2329 r.height = layer_height;
2330 GDrawFillRect(pixmap,&r,cvpaletteactborcol);
2331 }
2332 r.x=editcol;
2333 if ( ll==-1 || ll==0 || ll==1) {
2334 str = ll==-1 ? _("Guide") : (ll==0 ?_("Back") : _("Fore")) ;
2335 GDrawDrawText8(pixmap,r.x+2,y + yt,
2336 (char *) str,-1,ll==layerinfo.active?cvpalettebgcol:cvpalettefgcol);
2337 } else if ( ll>=layerinfo.current_layers ) {
2338 break; /* no more layers to draw! */
2339 } else if ( ll>=0 && layerinfo.layers[ll]!=NULL ) {
2340 BDFChar *bdfc = layerinfo.layers[ll];
2341 base.data = bdfc->bitmap;
2342 base.bytes_per_line = bdfc->bytes_per_line;
2343 base.width = bdfc->xmax-bdfc->xmin+1;
2344 base.height = bdfc->ymax-bdfc->ymin+1;
2345 // GDrawDrawImage(pixmap,&gi,NULL,
2346 // r.x+2+bdfc->xmin,
2347 // y+as-bdfc->ymax);
2348 str = cv->b.sc->parent->layers[ll].name;
2349 if ( !str || !*str ) str="-";
2350 GDrawDrawText8(pixmap, r.x+2, y + yt,
2351 (char *) str,-1,ll==layerinfo.active?cvpalettebgcol:cvpalettefgcol);
2352 }
2353 }
2354
2355 if( bottomOfLast )
2356 {
2357 GGadgetSetY(GWidgetGetControl(cvlayers,CID_AddLayer), bottomOfLast + 2 );
2358 GGadgetSetY(GWidgetGetControl(cvlayers,CID_RemoveLayer), bottomOfLast + 2 );
2359 GGadgetSetY(GWidgetGetControl(cvlayers,CID_LayersMenu), bottomOfLast + 2 );
2360 }
2361
2362 }
2363
2364 /* Remove the layer rename edit box. If save!=0, then record the text as the new layer name. */
2365 static void CVLRemoveEdit(CharView *cv, int save) {
2366 if ( layerinfo.rename_active ) {
2367 GGadget *g = GWidgetGetControl(cvlayers,CID_Edit);
2368 const unichar_t *str = GGadgetGetTitle(g);
2369 int l = layerinfo.active;
2370
2371 if ( save
2372 && layerinfo.active>=0 && str!=NULL && str[0]!='\0'
2373 && uc_strcmp( str,cv->b.sc->parent->layers[l].name) ) {
2374 free( cv->b.sc->parent->layers[l].name );
2375 cv->b.sc->parent->layers[l].name = cu_copy( str );
2376
2377 CVLCheckLayerCount(cv,true);
2378 CVLayersSet(cv);
2379 }
2380 GGadgetSetVisible(g,false);
2381 GDrawRequestExpose(cvlayers,NULL,false);
2382
2383 layerinfo.rename_active = 0;
2384 GDrawRequestExpose(cv->gw, NULL, false);
2385 }
2386 }
2387
2388 /* Make sure we've got the right number of gadgets in the layers palette, and that
2389 * they are positioned properly. Their state are updated in CVLayers1Set().
2390 * If resize, then make the palette fit the layers up to a max number of layers. */
2391 static void CVLCheckLayerCount(CharView *cv, int resize) {
2392
2393 SplineChar *sc = cv->b.sc;
2394 int i;
2395 GGadgetCreateData gcd[4];
2396 GTextInfo label[3];
2397 GRect size;
2398 int width;
2399 int maxwidth=0;
2400 int togsize=0;
2401 int x, y;
2402 int column_width = layerinfo.column_width;
2403 char namebuf[40];
2404 int viscol=0, quadcol, fgcol, editcol;
2405 extern int _GScrollBar_Width;
2406 int offsetAtRightOfViewLayer = Layers_getOffsetAtRightOfViewLayer(cv);
2407
2408 if (layerinfo.rename_active) CVLRemoveEdit(cv,true);
2409
2410 quadcol=fgcol=offsetAtRightOfViewLayer;
2411 if ( layerscols & LSHOW_CUBIC )
2412 {
2413 quadcol = offsetAtRightOfViewLayer;
2414 fgcol = offsetAtRightOfViewLayer+column_width;
2415 }
2416 if ( layerscols & LSHOW_FG )
2417 {
2418 fgcol = quadcol+column_width;
2419 }
2420 // editcol is the X offset where the layer name label should be drawn
2421 editcol = fgcol+column_width;
2422
2423 /* First figure out if we need to create any new widgets. If we have more */
2424 /* widgets than we need, we just set them to be invisible. */
2425 if ( sc->layer_cnt > layers_max ) {
2426 memset(&label,0,sizeof(label));
2427 memset(&gcd,0,sizeof(gcd));
2428 for ( i=layers_max; i<sc->layer_cnt; ++i ) {
2429 /* for each new layer, create new widgets */
2430
2431 /* Visibility toggle */
2432 gcd[0].gd.flags = gg_enabled;
2433 gcd[0].gd.cid = CID_VBase+i;
2434 gcd[0].gd.popup_msg = _("Is Layer Visible?");
2435 gcd[0].creator = GVisibilityBoxCreate;
2436
2437 GGadgetsCreate(cvlayers,gcd);
2438 GVisibilityBoxSetToMinWH(GWidgetGetControl(cvlayers,CID_VBase+i));
2439 }
2440 layers_max = sc->layer_cnt;
2441 }
2442
2443 /* Then position everything, and name it properly */
2444
2445 GDrawSetFont(cvlayers,layerinfo.font); /* for width finding code, need this */
2446
2447 /* First need to position the add, remove, and layers gadgets */
2448 GGadgetGetSize(GWidgetGetControl(cvlayers,CID_RemoveLayer),&size);
2449 x = 7+size.width;
2450 y = layer_header_height;
2451 GGadgetMove(GWidgetGetControl(cvlayers,CID_AddLayer), x, 5);
2452 GGadgetSetSize(GWidgetGetControl(cvlayers,CID_AddLayer),&size);
2453 GGadgetGetSize(GWidgetGetControl(cvlayers,CID_AddLayer),&size);
2454 x += size.width;
2455 GGadgetGetSize(GWidgetGetControl(cvlayers,CID_LayersMenu),&size);
2456 GGadgetMove(GWidgetGetControl(cvlayers,CID_LayersMenu), x+5, 5+(y-8-size.height)/2);
2457 maxwidth=x+5+size.width;
2458
2459 if ( !resize )
2460 {
2461 /* adjust the number of layers that can be visible in the palette */
2462 GDrawGetSize(cvlayers,&size);
2463 layerinfo.visible_layers=(size.height-layer_header_height)/layer_height;
2464 if ( layerinfo.offtop+layerinfo.visible_layers>=sc->layer_cnt )
2465 layerinfo.offtop = sc->layer_cnt-layerinfo.visible_layers;
2466 if ( layerinfo.offtop<0 ) layerinfo.offtop=0;
2467 }
2468 if ( layerinfo.visible_layers<2 ) layerinfo.visible_layers=2;
2469
2470 /* Now position each layer row */
2471 for ( i=-1; i<layers_max; ++i ) {
2472 GGadget *v = GWidgetGetControl(cvlayers,CID_VBase+i);
2473
2474 width=0;
2475 togsize = editcol;
2476
2477 if ( i>=0 && i<sc->layer_cnt ) {
2478 char *hasmn = strchr(sc->parent->layers[i].name,'_');
2479 if ( hasmn==NULL && i>=2 && i<9 && strlen(sc->parent->layers[i].name)<30 ) {
2480 /* For the first 10 or so layers, add a mnemonic like "(_3)" to the name label */
2481 /* if it does not already have a mnemonic. */
2482 /* sprintf(namebuf, "%s (_%d)", sc->parent->layers[i].name, i+1); */
2483 sprintf(namebuf, "%s", sc->parent->layers[i].name);
2484 } else if ( hasmn==NULL ) {
2485 sprintf(namebuf,"%s", i==-1 ? _("Guide") : (i==0 ?_("Back") : _("Fore")) );
2486 }
2487 width = GDrawGetText8Width(cvlayers, namebuf, -1);
2488 width += 10; // padding takes up some space.
2489 if ( width+togsize>maxwidth ) maxwidth = width + togsize;
2490 } else if ( i==-1 ) {
2491 if ( width+togsize>maxwidth ) maxwidth = width + togsize;
2492 }
2493
2494 if ( i+1<layerinfo.offtop || i>=layerinfo.offtop+layerinfo.visible_layers ||
2495 (sc->layer_cnt<=layerinfo.visible_layers && i>=sc->layer_cnt)) {
2496 /* layer is currently scrolled out of palette */
2497 GGadgetSetVisible(v,false);
2498 } else {
2499 GGadgetMove(v,viscol ,y);
2500 GGadgetSetVisible(v,true);
2501 y += layer_height;
2502 }
2503 }
2504
2505 /* Update the scroll bar */
2506 if ( sc->layer_cnt+1<=layerinfo.visible_layers ) {
2507 /* don't need the scroll bar, so turn it off */
2508 GGadgetSetVisible(GWidgetGetControl(cvlayers,CID_SB),false);
2509 } else {
2510 if( !resize )
2511 {
2512 GGadget *sb = GWidgetGetControl(cvlayers,CID_SB);
2513 maxwidth += 2 + GDrawPointsToPixels(cv->gw,_GScrollBar_Width);
2514 GScrollBarSetBounds(sb,0,sc->layer_cnt,layerinfo.visible_layers);
2515 GScrollBarSetPos(sb,cv->layers_off_top);
2516 GGadgetSetVisible(sb,true);
2517 }
2518 }
2519
2520 /* Resize the palette to fit */
2521 if ( resize )
2522 {
2523 y += GDrawPointsToPixels(NULL,3);
2524 GDrawGetSize(cvlayers,&size);
2525 GDrawResize(cvlayers,maxwidth,y+layer_footer_height);
2526 }
2527
2528 GDrawGetSize(cvlayers,&size);
2529 layerinfo.sb_start = size.width
2530 - (sc->layer_cnt+1<=layerinfo.visible_layers ? 0 : GDrawPointsToPixels(cv->gw,_GScrollBar_Width));
2531 GGadget *sb = GWidgetGetControl(cvlayers,CID_SB);
2532 GGadgetResize(sb, GDrawPointsToPixels(cv->gw,_GScrollBar_Width), size.height-layer_header_height);
2533 GGadgetMove(sb,layerinfo.sb_start,layer_header_height);
2534
2535 GDrawRequestExpose(cvlayers,NULL,false);
2536 }
2537
2538 /* Respond to scroll events from cvlayers scrollbar. */
2539 static void LayerScroll(CharView *cv, GEvent *event) {
2540 int off = 0;
2541 enum sb sbt = event->u.control.u.sb.type;
2542
2543 if ( sbt==et_sb_top )
2544 off = 0;
2545 else if ( sbt==et_sb_bottom )
2546 off = cv->b.sc->layer_cnt-layerinfo.visible_layers;
2547 else if ( sbt==et_sb_up ) {
2548 off = cv->layers_off_top-1;
2549 } else if ( sbt==et_sb_down ) {
2550 off = cv->layers_off_top+1;
2551 } else if ( sbt==et_sb_uppage ) {
2552 off = cv->layers_off_top-layerinfo.visible_layers+1;
2553 } else if ( sbt==et_sb_downpage ) {
2554 off = cv->layers_off_top+layerinfo.visible_layers-1;
2555 } else /* if ( sbt==et_sb_thumb || sbt==et_sb_thumbrelease ) */ {
2556 off = event->u.control.u.sb.pos;
2557 }
2558 if ( off>cv->b.sc->layer_cnt-layerinfo.visible_layers )
2559 off = cv->b.sc->layer_cnt-layerinfo.visible_layers;
2560 if ( off<0 ) off=0;
2561 if ( off==cv->layers_off_top )
2562 return;
2563 cv->layers_off_top = off;
2564 layerinfo.offtop = off;
2565 CVLCheckLayerCount(cv, false);
2566 GScrollBarSetPos(GWidgetGetControl(cvlayers,CID_SB),off);
2567 GDrawRequestExpose(cvlayers,NULL,false);
2568 }
2569
2570 /* Layers palette menu ids */
2571 #define LMID_LayerInfo 1
2572 #define LMID_NewLayer 2
2573 #define LMID_DelLayer 3
2574 #define LMID_Fill 4
2575 #define LMID_First 5
2576 #define LMID_Up 6
2577 #define LMID_Down 7
2578 #define LMID_Last 8
2579 #define LMID_Foreground 9
2580 #define LMID_Background 10
2581 #define LMID_Cubic 11
2582 #define LMID_Quadratic 12
2583 #define LMID_ShowCubic 13
2584 #define LMID_ShowFore 14
2585
2586 /* Return a unique layer name based on base.
2587 * This just appends a number to base until the name is not found. */
2588 static char *UniqueLayerName(SplineChar *sc, const char *base)
2589 {
2590 static char buffer[100];
2591 const char *basestr=base;
2592 int i=1, c;
2593
2594 if ( basestr==NULL || basestr[0]=='\0' ) basestr=_("Layer");
2595
2596 while (1) {
2597 if (i==1) sprintf( buffer,"%s",basestr );
2598 else sprintf( buffer,"%s %d",basestr, i );
2599
2600 for (c=0; c<sc->layer_cnt; c++) {
2601 if (!strcmp(sc->parent->layers[c].name,buffer)) break;
2602 }
2603
2604 if ( c==sc->layer_cnt ) break;
2605 i++;
2606 }
2607
2608 return buffer;
2609 }
2610
2611 /* Layers palette menu selection */
2612 static void CVLayerInvoked(GWindow v, GMenuItem *mi, GEvent *e) {
2613 CharView *cv = (CharView *) GDrawGetUserData(v);
2614 int layer = CVLayer(&cv->b);
2615 SplineChar *sc = cv->b.sc;
2616 Layer temp;
2617 int i;
2618 char *buts[3];
2619 buts[0] = _("_Yes"); buts[1]=_("_No"); buts[2] = NULL;
2620
2621 switch ( mi->mid ) {
2622 case LMID_Fill:
2623 cv->showfilled = !cv->showfilled;
2624 GDrawRequestExpose(cv->v,NULL,false);
2625 break;
2626
2627 case LMID_ShowCubic:
2628 layerscols=(layerscols&~LSHOW_CUBIC)|((layerscols&LSHOW_CUBIC)?0:1);
2629 CVLCheckLayerCount(cv, true);
2630 break;
2631
2632 case LMID_ShowFore:
2633 layerscols=(layerscols&~LSHOW_FG)|((layerscols&LSHOW_FG)?0:2);
2634 CVLCheckLayerCount(cv, true);
2635 break;
2636
2637 case LMID_Foreground:
2638 if ( layer>ly_fore && cv->b.sc->parent->layers[layer].background==1) {
2639 SFLayerSetBackground(cv->b.sc->parent,layer,0);
2640 GDrawRequestExpose(cvlayers,NULL,false);
2641 }
2642 break;
2643
2644 case LMID_Background:
2645 if ( layer>=ly_fore && cv->b.sc->parent->layers[layer].background==0) {
2646 SFLayerSetBackground(cv->b.sc->parent,layer,1);
2647 GDrawRequestExpose(cvlayers,NULL,false);
2648 }
2649 break;
2650
2651 case LMID_Cubic:
2652 if ( layer!=ly_grid && cv->b.sc->layers[layer].order2 ) {
2653 SFConvertLayerToOrder3(cv->b.sc->parent, layer);
2654 GDrawRequestExpose(cvlayers,NULL,false);
2655 }
2656 break;
2657
2658 case LMID_Quadratic:
2659 if ( layer!=ly_grid && !cv->b.sc->layers[layer].order2 ) {
2660 SFConvertLayerToOrder2(cv->b.sc->parent, layer);
2661 GDrawRequestExpose(cvlayers,NULL,false);
2662 }
2663 break;
2664
2665 case LMID_NewLayer:
2666 SFAddLayer(cv->b.sc->parent, /* font of the glyph in the charview */
2667 UniqueLayerName(sc,_("Back")), /* Name */
2668 0, /* 0=cubic, 1=quad */
2669 1); /* 1=back, 0=fore */
2670
2671 layer=cv->b.sc->parent->layer_cnt-1;
2672
2673 cv->showback[layer>>5] |= (1<<(layer&31)); /* make it visible */
2674 CVLCheckLayerCount(cv, true); /* update widget existence */
2675 CVLayersSet(cv); /* update widget state */
2676 break;
2677 case LMID_DelLayer:
2678 layer = CVLayer((CharViewBase *) cv); /* the index of the active layer */
2679 if (layer==ly_fore || layer==ly_back || layer==ly_grid)
2680 return;
2681 if ( gwwv_ask(_("Cannot Be Undone"),(const char **) buts,0,1,_("This operation cannot be undone, do it anyway?"))==1 )
2682 return;
2683 SFRemoveLayer(cv->b.sc->parent, layer);
2684 CVLCheckLayerCount(cv, true); /* update widget existence */
2685 CVLayersSet(cv); /* update widget state */
2686 break;
2687
2688 case LMID_First: /* move layer contents to top */
2689 if ( layer==ly_fore )
2690 return;
2691 temp = sc->layers[layer];
2692 for ( i=layer-1; i>=ly_fore; --i )
2693 sc->layers[i+1] = sc->layers[i];
2694 sc->layers[i+1] = temp;
2695 cv->b.layerheads[dm_fore] = &sc->layers[ly_fore];
2696 break;
2697 case LMID_Up: /* move layer contents one up */
2698 if ( layer==ly_fore )
2699 return;
2700 temp = sc->layers[layer];
2701 sc->layers[layer] = sc->layers[layer-1];
2702 sc->layers[layer-1] = temp;
2703 cv->b.layerheads[dm_fore] = &sc->layers[layer-1];
2704 break;
2705 case LMID_Down: /* move layer contents one down */
2706 if ( layer==sc->layer_cnt-1 )
2707 return;
2708 temp = sc->layers[layer];
2709 sc->layers[layer] = sc->layers[layer+1];
2710 sc->layers[layer+1] = temp;
2711 cv->b.layerheads[dm_fore] = &sc->layers[layer+1];
2712 break;
2713 case LMID_Last:
2714 if ( layer==sc->layer_cnt-1 )
2715 return;
2716 temp = sc->layers[layer]; /* move layer contents to bottom */
2717 for ( i=layer+1; i<sc->layer_cnt; ++i )
2718 sc->layers[i-1] = sc->layers[i];
2719 sc->layers[i-1] = temp;
2720 cv->b.layerheads[dm_fore] = &sc->layers[i-1];
2721 break;
2722 }
2723 CVLayersSet(cv);
2724 CVCharChangedUpdate(&cv->b);
2725 }
2726
2727 /* Pop up the layers palette context menu */
2728 static void LayerMenu(CharView *cv,GEvent *event, int nolayer) {
2729 GMenuItem mi[20];
2730 int i;
2731 static char *names[] = {
2732 /*N_("Rename Layer..."),*/
2733 N_("New Layer"),
2734 N_("Del Layer"),
2735 (char *) -1,
2736 N_("Shift Contents To _First"),
2737 N_("Shift Contents _Up"),
2738 N_("Shift Contents _Down"),
2739 N_("Shift Contents To _Last"),
2740 (char *) -1,
2741 N_("Make Foreground"),/* or N_("Make Background"), */
2742 N_("Make Cubic"), /* or N_("Make Quadratic"), */
2743 (char *) -1,
2744 N_("Fill"),
2745 (char *) -1,
2746 N_("Show Cubic Column"),
2747 N_("Show Fore/Back Column"),
2748 NULL,
2749 };
2750 static int mids[] = {
2751 /*LMID_RenameLayer,*/
2752 LMID_NewLayer,
2753 LMID_DelLayer,
2754 -1,
2755 LMID_First,
2756 LMID_Up,
2757 LMID_Down,
2758 LMID_Last,
2759 -1,
2760 LMID_Foreground, /* or LMID_Background, */
2761 LMID_Cubic, /* or LMID_Quadratic, */
2762 -1,
2763 LMID_Fill,
2764 -1,
2765 LMID_ShowCubic,
2766 LMID_ShowFore,
2767 0
2768 };
2769 int layer = CVLayer(&cv->b);
2770
2771 memset(mi,'\0',sizeof(mi));
2772 for ( i=0; names[i]!=0; ++i ) {
2773 if ( names[i]!=(char *) -1 ) {
2774 mi[i].ti.text = (unichar_t *) _(names[i]);
2775 mi[i].ti.text_is_1byte = true;
2776 mi[i].ti.text_in_resource = true;
2777 } else
2778 mi[i].ti.line = true;
2779
2780 mi[i].ti.fg = COLOR_DEFAULT;
2781 mi[i].ti.bg = COLOR_DEFAULT;
2782 mi[i].mid = mids[i];
2783 mi[i].invoke = CVLayerInvoked;
2784
2785 /*if ( mids[i]!=LMID_NewLayer && nolayer )
2786 mi[i].ti.disabled = true;*/
2787
2788 if ( ( mids[i]==LMID_First || mids[i]==LMID_Up ) && ( layer==-1 || layer==0) )
2789 mi[i].ti.disabled = true;
2790
2791 else if ( ( mids[i]==LMID_Last || mids[i]==LMID_Down ) && (layer==ly_grid || layer==cv->b.sc->layer_cnt-1) )
2792 mi[i].ti.disabled = true;
2793
2794 else if ( mids[i]==LMID_DelLayer && ( layer<2 || cv->b.sc->layer_cnt==2) )
2795 mi[i].ti.disabled = true;
2796
2797 else if ( mids[i]==LMID_Fill ) {
2798 mi[i].ti.checkable = 1;
2799 mi[i].ti.checked = cv->showfilled;
2800
2801 } else if ( mids[i]==LMID_Foreground ) {
2802 if ( layer>=0 ) {
2803 if ( ! cv->b.sc->layers[layer].background ) {
2804 mi[i].mid = LMID_Background;
2805 mi[i].ti.text = (unichar_t *) _("Make Background");
2806 }
2807 } else {
2808 mi[i].ti.disabled = true;
2809 }
2810 } else if ( mids[i]==LMID_Cubic ) {
2811 if ( ! cv->b.sc->layers[layer].order2 ) {
2812 mi[i].mid = LMID_Quadratic;
2813 mi[i].ti.text = (unichar_t *) _("Make Quadratic");
2814 }
2815
2816 } else if ( mids[i]==LMID_ShowCubic ) {
2817 mi[i].ti.checkable = 1;
2818 mi[i].ti.checked = (layerscols & LSHOW_CUBIC)?1:0;
2819
2820 } else if ( mids[i]==LMID_ShowFore ) {
2821 mi[i].ti.checkable = 1;
2822 mi[i].ti.checked = (layerscols & LSHOW_FG)?1:0;
2823 }
2824 }
2825 GMenuCreatePopupMenu(cvlayers, event, mi);
2826 }
2827
2828 /* Scan for which layer and column one clicks on in the layers 1 palette */
2829 /* -1 is the guides layer, 0 is default back, 1 default fore, etc. */
2830 /* col will be set to either -1 for none, CID_VBase, CID_QBase, CID_FBase, or CID_EBase */
2831 static int CVLScanForItem(int x, int y, int *col) {
2832 int l=(y-layer_header_height)/layer_height + layerinfo.offtop - 1;
2833 int viscol=0, quadcol, fgcol, editcol;
2834 int cw=layerinfo.column_width;
2835
2836 quadcol=fgcol=viscol;
2837 if ( layerscols & LSHOW_CUBIC ) { quadcol = viscol+cw; fgcol=viscol+cw; }
2838 if ( layerscols & LSHOW_FG ) { fgcol = quadcol+cw; }
2839 editcol=fgcol+cw;
2840
2841 *col=-1;
2842 if ( x>0 && x<viscol+cw ) *col=CID_VBase;
2843 /**
2844 * The two below options, CID_QBase and CID_FBase allow the curve
2845 * type and foreground/background to be changed simply by clicking
2846 * on them. The cubic/quadratic and background/foreground
2847 * attributes should NOT be buttons that can change these
2848 * attributes, they should only SHOW the attribute. Changing the
2849 * attributes can be done in Font Info, Layers, and is done
2850 * infrequently and has a lot of implications so shouldn't be
2851 * easily done by mistake.
2852 */
2853 // else if ( (layerscols & LSHOW_CUBIC) && x>=quadcol && x<quadcol+cw ) *col=CID_QBase;
2854 // else if ( (layerscols & LSHOW_FG) && x>=fgcol && x<fgcol+cw ) *col=CID_FBase;
2855 else if ( x>=editcol ) *col=CID_EBase;
2856
2857 return l;
2858 }
2859
2860 /* Called in response to some event where we want to change the current layer. */
2861 void CVLSelectLayer(CharView *cv, int layer) {
2862 if ( layer<-1 || layer>=cv->b.sc->layer_cnt )
2863 return;
2864
2865 if ( layer==-1 ) {
2866 cv->b.drawmode = dm_grid;
2867 cv->lastselpt = NULL;
2868 } else {
2869 if ( layer==1 ) {
2870 cv->b.drawmode = dm_fore;
2871 cv->lastselpt = NULL;
2872 } else {
2873 cv->b.drawmode = dm_back;
2874 cv->b.layerheads[dm_back] = &cv->b.sc->layers[layer];
2875 cv->lastselpt = NULL;
2876 }
2877
2878 CVDebugFree(cv->dv);
2879 SplinePointListsFree(cv->b.gridfit); cv->b.gridfit = NULL;
2880 FreeType_FreeRaster(cv->oldraster); cv->oldraster = NULL;
2881 FreeType_FreeRaster(cv->raster); cv->raster = NULL;
2882 cv->show_ft_results = false;
2883 }
2884 layerinfo.active = CVLayer(&cv->b); /* the index of the active layer */
2885
2886 GDrawRequestExpose(cv->v,NULL,false);
2887 if (cvlayers2) GDrawRequestExpose(cvlayers2,NULL,false);
2888 if (cvlayers) GDrawRequestExpose(cvlayers,NULL,false);
2889 GDrawRequestExpose(cv->gw,NULL,false);
2890 }
2891
2892 static int cvlayers_e_h(GWindow gw, GEvent *event) {
2893 CharView *cv = (CharView *) GDrawGetUserData(gw);
2894 char *buts[3];
2895 buts[0] = _("_Yes"); buts[1]=_("_No"); buts[2] = NULL;
2896
2897 if ( event->type==et_destroy && cvlayers == gw )
2898 {
2899 cvlayers = NULL;
2900 return( true );
2901 }
2902
2903 if ( cv==NULL )
2904 return( true );
2905
2906 switch ( event->type ) {
2907 case et_close:
2908 SetPaletteVisible(NULL, gw, false);
2909 break;
2910 case et_char: case et_charup:
2911 if ( event->u.chr.keysym == GK_Return) {
2912 CVLRemoveEdit(cv, true);
2913 } else if ( event->u.chr.keysym == GK_Escape) {
2914 CVLRemoveEdit(cv, false);
2915 } else PostCharToWindow(cv->gw,event);
2916 break;
2917 case et_mousemove: {
2918 int l, col;
2919
2920 l = CVLScanForItem(event->u.mouse.x,event->u.mouse.y, &col);
2921 if ( l!=layerinfo.mo_layer || col!=layerinfo.mo_col ) {
2922 layerinfo.mo_layer = l;
2923 layerinfo.mo_col = col;
2924 GDrawRequestExpose(cvlayers,NULL,false);
2925 }
2926
2927 return( true );
2928
2929 } break;
2930 case et_mousedown: {
2931 if ( layerinfo.rename_active ) CVLRemoveEdit(cv, true);
2932 } break;
2933 case et_mouseup: {
2934 int l, x, cid, h;
2935 GGadget *g;
2936 l = CVLScanForItem(event->u.mouse.x,event->u.mouse.y, &cid);
2937
2938 if ( cid==CID_EBase && l>=-1 && l<cv->b.sc->layer_cnt )
2939 {
2940 /* Need to check for this BEFORE checking for right click! */
2941 if ( event->u.mouse.button==1 && event->u.mouse.clicks==2 )
2942 {
2943 /* bring up edit box for layer name */
2944
2945 if ( l<2 )
2946 return ( true );
2947
2948 x = 7+(1+((layerscols&LSHOW_CUBIC)?1:0)+((layerscols&LSHOW_FG)?1:0))*layerinfo.column_width;
2949 g = GWidgetGetControl(cvlayers,CID_Edit);
2950 h = 1.5*layer_height;
2951
2952 GGadgetResize(g, layerinfo.sb_start-x, h);
2953 GGadgetMove(g, x,layer_header_height+(l+1.5+layerinfo.offtop)*layer_height-h/2);
2954 GGadgetSetVisible(g,true);
2955 /* GGadgetSetTitle8((GTextField*)g, cv->b.sc->parent->layers[l].name); */
2956 GGadgetSetTitle8(g, cv->b.sc->parent->layers[l].name);
2957
2958 layerinfo.active=l;
2959 layerinfo.rename_active=1;
2960 return ( true );
2961 }
2962
2963 CVLSelectLayer(cv, l);
2964 }
2965
2966 /* right click to pop up menu */
2967 if ( event->u.mouse.button==3 ) {
2968 LayerMenu(cv,event,true);
2969 return(true);
2970 }
2971
2972 /* otherwise, deal with clicking up on the various controls */
2973 if ( l<-1 || l>=cv->b.sc->layer_cnt)
2974 return (true);
2975
2976 if ( cid==CID_QBase) {
2977 if (l>=0) { /* don't try to adjust if calling for guides layer */
2978 if (cv->b.sc->layers[l].order2)
2979 SFConvertLayerToOrder3(cv->b.sc->parent, l);
2980 else
2981 SFConvertLayerToOrder2(cv->b.sc->parent, l);
2982 GDrawRequestExpose(cvlayers,NULL,false);
2983 GDrawRequestExpose(cv->v,NULL,false);
2984 }
2985 } else if ( cid==CID_FBase) {
2986 if (l>1) { /* don't try to adjust if calling guides, default fore or back layer */
2987 if (cv->b.sc->layers[l].background)
2988 SFLayerSetBackground(cv->b.sc->parent,l,0);
2989 else
2990 SFLayerSetBackground(cv->b.sc->parent,l,1);
2991 GDrawRequestExpose(cvlayers,NULL,false);
2992 GDrawRequestExpose(cv->v,NULL,false);
2993 }
2994 }
2995 } break; /* case et_mouseup */
2996 case et_expose:
2997 LayersExpose(cv,gw,event);
2998 break;
2999 case et_resize:
3000 if ( event->u.resize.sized ) {
3001 CVLCheckLayerCount(cv,false); /* update widget existence, but do not resize */
3002 }
3003 break;
3004 case et_controlevent:
3005 if ( event->u.control.subtype == et_buttonactivate ) {
3006 int cid = GGadgetGetCid(event->u.control.g);
3007 int layer;
3008
3009 switch( cid ) {
3010 case CID_AddLayer: {
3011 SplineChar *sc = cv->b.sc;
3012
3013 /* This adds a new layer to the end of the current layers list.
3014 * Somehow it is created as an invisible layer. */
3015 SFAddLayer(cv->b.sc->parent, /* font of the glyph in the charview */
3016 UniqueLayerName(sc,_("Back")), /* Name */
3017 0, /* 0=cubic, 1=quad */
3018 1); /* 1=back, 0=fore */
3019
3020 layer=cv->b.sc->parent->layer_cnt-1;
3021
3022 cv->showback[layer>>5] |= (1<<(layer&31)); /* make it visible */
3023 CVLCheckLayerCount(cv,true); /* update widget existence */
3024 CVLayersSet(cv); /* update widget state */
3025 } break;
3026 case CID_RemoveLayer:
3027 layer = CVLayer((CharViewBase *) cv); /* the index of the active layer */
3028 if (layer==ly_fore || layer==ly_back || layer==ly_grid)
3029 return ( true );
3030 if ( gwwv_ask(_("Cannot Be Undone"),(const char **) buts,0,1,_("This operation cannot be undone, do it anyway?"))==1 )
3031 return ( true );
3032 SFRemoveLayer(cv->b.sc->parent, layer);
3033 CVLCheckLayerCount(cv,true); /* update widget existence */
3034 CVLayersSet(cv); /* update widget state */
3035 break;
3036 case CID_RenameLayer: {
3037 /* *** */
3038 int x = 7+(1+((layerscols&LSHOW_CUBIC)?1:0)+((layerscols&LSHOW_FG)?1:0))*layerinfo.column_width;
3039 GGadget *g = GWidgetGetControl(cvlayers,CID_Edit);
3040 layer = CVLayer((CharViewBase *) cv); /* the index of the active layer */
3041 /* layer = layerinfo.active */ /* the index of the active layer */
3042
3043 GGadgetResize(g, layerinfo.sb_start-x,1.5*layer_height);
3044 GGadgetMove(g, x,layer_header_height+(layer+1+layerinfo.offtop)*layer_height);
3045 GGadgetSetVisible(g,true);
3046 GGadgetSetTitle8(g, cv->b.sc->parent->layers[layer].name);
3047
3048 layerinfo.rename_active=1;
3049
3050 CVLCheckLayerCount(cv,true); /* update widget existence */
3051 CVLayersSet(cv); /* update widget state */
3052 GDrawRequestExpose(cvtools,NULL,false);
3053
3054 } break;
3055 }
3056 } else if ( event->u.control.subtype == et_radiochanged ) {
3057 enum drawmode dm = cv->b.drawmode;
3058 int cid = GGadgetGetCid(event->u.control.g);
3059
3060 switch( cid ) {
3061 case CID_VFore:
3062 CVShows.showfore = cv->showfore = GGadgetIsChecked(event->u.control.g);
3063 GDrawRequestExpose(cv->v,NULL,false);
3064 break;
3065 case CID_VBack:
3066 CVShows.showback = GGadgetIsChecked(event->u.control.g);
3067 if ( CVShows.showback )
3068 cv->showback[0] |= 1;
3069 else
3070 cv->showback[0] &= ~1;
3071 GDrawRequestExpose(cv->v,NULL,false);
3072 break;
3073 case CID_VGrid:
3074 CVShows.showgrids = cv->showgrids = GGadgetIsChecked(event->u.control.g);
3075 GDrawRequestExpose(cv->v,NULL,false);
3076 break;
3077 case CID_EFore:
3078 cv->b.drawmode = dm_fore;
3079 cv->lastselpt = NULL;
3080
3081 CVDebugFree(cv->dv);
3082 SplinePointListsFree(cv->b.gridfit); cv->b.gridfit = NULL;
3083 FreeType_FreeRaster(cv->oldraster); cv->oldraster = NULL;
3084 FreeType_FreeRaster(cv->raster); cv->raster = NULL;
3085 cv->show_ft_results = false;
3086 break;
3087 case CID_EBack:
3088 cv->b.drawmode = dm_back;
3089 cv->b.layerheads[dm_back] = &cv->b.sc->layers[ly_back];
3090 cv->lastselpt = NULL;
3091
3092 CVDebugFree(cv->dv);
3093 SplinePointListsFree(cv->b.gridfit); cv->b.gridfit = NULL;
3094 FreeType_FreeRaster(cv->oldraster); cv->oldraster = NULL;
3095 FreeType_FreeRaster(cv->raster); cv->raster = NULL;
3096 cv->show_ft_results = false;
3097 break;
3098 case CID_EGrid:
3099 cv->b.drawmode = dm_grid;
3100 cv->lastselpt = NULL;
3101 break;
3102 default:
3103 if ( cid>=CID_VBase-1 && cid<CID_VBase+999) {
3104 cid -= CID_VBase;
3105 if ( GGadgetIsChecked(event->u.control.g))
3106 cv->showback[cid>>5] |= (1<<(cid&31));
3107 else
3108 cv->showback[cid>>5] &= ~(1<<(cid&31));
3109
3110 GDrawRequestExpose(cv->v,NULL,false);
3111 if ( dm!=cv->b.drawmode )
3112 GDrawRequestExpose(cv->gw,NULL,false); /* the logo (where the scrollbars join) shows what layer we are in */
3113 }
3114 }
3115
3116 } else if ( event->u.control.subtype == et_scrollbarchange ) {
3117 LayerScroll(cv,event);
3118
3119 }
3120 break; /* case et_controlevent */
3121 default: {
3122 } break;
3123 } /* switch ( event->type ) */
3124 return( true );
3125 }
3126
3127 /* Set to true the editable field for the current layer, and false for the other layers. */
3128 void CVSetLayer(CharView *cv,int layer) {
3129
3130 /* Update the drawmode of cv */
3131 if ( layer == ly_grid )
3132 cv->b.drawmode = dm_grid;
3133 else if (layer == ly_fore )
3134 cv->b.drawmode = dm_fore;
3135 else {
3136 cv->b.drawmode = dm_back;
3137 cv->b.layerheads[dm_back] = &cv->b.sc->layers[layer];
3138 }
3139 if ( cvlayers!=NULL && GDrawGetUserData(cvlayers)==cv )
3140 GDrawRequestExpose(cvlayers,NULL,false);
3141 }
3142
3143 /* Check if a key press corresponds to a mnemonic the palette knows about. */
3144 int CVPaletteMnemonicCheck(GEvent *event) {
3145 static struct strmatch { char *str; int cid; } strmatch[] = {
3146 /* GT: Foreground, make it short */
3147 { N_("F_ore"), CID_EFore },
3148 /* GT: Background, make it short */
3149 { N_("_Back"), CID_EBack },
3150 /* GT: Guide layer, make it short */
3151 { N_("_Guide"), CID_EGrid },
3152 { NULL, 0 }
3153 };
3154 unichar_t mn, mnc;
3155 int j, i, ch;
3156 char *foo;
3157 GEvent fake;
3158 CharView *cv;
3159 SplineFont *parent;
3160 int curlayer;
3161
3162 if ( cvtools==NULL )
3163 return( false );
3164 cv = GDrawGetUserData(cvtools);
3165 parent = cv->b.sc->parent;
3166 curlayer = CVLayer(&cv->b); /* the index of the active layer */
3167
3168 if ( isdigit(event->u.chr.keysym) ) {
3169 int off = event->u.chr.keysym - '0';
3170
3171 if ( off-1<parent->layer_cnt && off!=curlayer ) {
3172 CVLSelectLayer(cv, off);
3173 if ( cv->b.sc->parent->multilayer )
3174 GDrawRequestExpose(cvlayers2,NULL,false);
3175 else
3176 return( true );
3177 }
3178 }
3179
3180 /* mnemonic is encoded in the layer name */
3181 for ( j=0; j<2; ++j ) {
3182 for ( i=0; j==0 ? i<parent->layer_cnt : strmatch[i].str!=NULL; ++i ) {
3183 for ( foo = j==0 ? parent->layers[i].name : _(strmatch[i].str);
3184 (ch=utf8_ildb((const char **) &foo))!=0; )
3185 if ( ch=='_' )
3186 break;
3187 if ( ch=='_' )
3188 mnc = utf8_ildb((const char **) &foo);
3189 else
3190 mnc = 0;
3191 mn = mnc;
3192 if ( islower(mn)) mnc = toupper(mn);
3193 else if ( isupper(mn)) mnc = tolower(mn);
3194 if ( event->u.chr.chars[0]==mn || event->u.chr.chars[0]==mnc ) {
3195 if ( cv->b.sc->parent->multilayer ) {
3196 fake.type = et_mousedown;
3197 fake.w = cvlayers;
3198 fake.u.mouse.x = 40;
3199 if ( strmatch[i].cid==CID_EGrid ) {
3200 fake.u.mouse.y = layer2.header_height+12;
3201 } else if ( strmatch[i].cid==CID_EBack ) {
3202 fake.u.mouse.y = layer2.header_height+12+CV_LAYERS2_LINE_HEIGHT;
3203 } else {
3204 fake.u.mouse.y = layer2.header_height+12+2*CV_LAYERS2_LINE_HEIGHT;
3205 }
3206 cvlayers2_e_h(cvlayers2,&fake);
3207 } else {
3208 CVLSelectLayer(cv, i);
3209 GDrawRequestExpose(cvlayers,NULL,false);
3210 }
3211 return( true );
3212 }
3213 }
3214 }
3215 return( false );
3216 }
3217
3218 /* This is used for fonts other than Type 3 fonts. CVMakeLayers2() is used for Type 3.
3219 * Only the basics of the palette are set up here, with the widgets for the default fore, back,
3220 * and guides layers. The palette is updated to actual character views in CVLCheckLayerCount(). */
3221 GWindow CVMakeLayers(CharView *cv) {
3222 GRect r,size;
3223 GWindowAttrs wattrs;
3224 GGadgetCreateData gcd[25];
3225 GTextInfo label[25];
3226 GGadget *gadget;
3227 extern int _GScrollBar_Width;
3228 int i=0;
3229 int viscol=0;
3230
3231 if ( cvlayers!=NULL )
3232 return( cvlayers );
3233
3234 /* Initialize layerinfo */
3235 if ( layerinfo.clut==NULL )
3236 layerinfo.clut = _BDFClut(4);
3237
3238 layerinfo.font = layerspalette_font.fi;
3239
3240 /* Initialize palette window */
3241 memset(&wattrs,0,sizeof(wattrs));
3242 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_positioned|wam_isdlg;
3243 wattrs.event_masks = -1;
3244 wattrs.cursor = ct_mypointer;
3245 wattrs.positioned = true;
3246 wattrs.is_dlg = true;
3247 wattrs.utf8_window_title = _("Layers");
3248
3249 r.width = GGadgetScale(104); r.height = CV_LAYERS_HEIGHT;
3250 if ( cvlayersoff.x==-9999 ) {
3251 /* Offset of window on screen, by default make it sit just below the tools palette */
3252 cvlayersoff.x = -r.width-6;
3253 cvlayersoff.y = cv->mbh+getToolbarHeight(cv)+45/*25*/; /* 45 is right if there's decor, 25 when none. twm gives none, kde gives decor */
3254 }
3255 r.x = cvlayersoff.x; r.y = cvlayersoff.y;
3256 if ( palettes_docked ) { r.x = 0; r.y=getToolbarHeight(cv)+2; }
3257 cvlayers = CreatePalette( cv->gw, &r, cvlayers_e_h, NULL, &wattrs, cv->v );
3258
3259 memset(&label,0,sizeof(label));
3260 memset(&gcd,0,sizeof(gcd));
3261
3262 int32_t plusw = GDrawGetText8Width(cv->gw, _("+"), -1);
3263 int32_t plush = GDrawGetText8Height(cv->gw, _("+"), -1);
3264 plusw = GDrawPointsToPixels(NULL,plusw+4);
3265 plush = GDrawPointsToPixels(NULL,plush+4);
3266 plush = MAX( plush, plusw ); // make it square.
3267
3268 /* Remove Layer button */
3269 label[0].text = (unichar_t *) _("-");
3270 label[0].text_is_1byte = true;
3271 gcd[i].gd.label = &label[0];
3272 gcd[i].gd.pos.x = 7; gcd[i].gd.pos.y = 5;
3273 gcd[i].gd.pos.width = plusw; gcd[i].gd.pos.height = plush;
3274 gcd[i].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels;
3275 gcd[i].gd.cid = CID_RemoveLayer;
3276 gcd[i].gd.popup_msg = _("Delete the current layer");
3277 gcd[i].creator = GButtonCreate;
3278 ++i;
3279
3280 /* Add Layer button */
3281 label[1].text = (unichar_t *) _("+");
3282 label[1].text_is_1byte = true;
3283 gcd[i].gd.label = &label[1];
3284 gcd[i].gd.pos.x = 30; gcd[i].gd.pos.y = 5;
3285 gcd[i].gd.pos.width = plusw; gcd[i].gd.pos.height = plush;
3286 gcd[i].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels;
3287 gcd[i].gd.cid = CID_AddLayer;
3288 gcd[i].gd.popup_msg = _("Add a new layer");
3289 gcd[i].creator = GButtonCreate;
3290 ++i;
3291
3292 /* "Layers" label next to the add and remove buttons */
3293 label[2].text = (unichar_t *) "";
3294 label[2].text_is_1byte = true;
3295 gcd[i].gd.label = &label[2];
3296 gcd[i].gd.pos.x = 47; gcd[i].gd.pos.y = 5;
3297 gcd[i].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels;
3298 gcd[i].gd.cid = CID_LayersMenu;
3299 /* gcd[i].gd.popup_msg = _("Rename the current layer"); */
3300 gcd[i].creator = GLabelCreate;
3301 ++i;
3302
3303 /* Default visibility toggles for Fore, Back, and Guides */
3304 gcd[i].gd.pos.x = viscol; gcd[i].gd.pos.y = 38;
3305 gcd[i].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
3306 if ( cv->showgrids ) gcd[i].gd.flags |= gg_cb_on;
3307 gcd[i].gd.cid = CID_VGrid;
3308 gcd[i].gd.popup_msg = _("Is Layer Visible?");
3309 gcd[i].creator = GVisibilityBoxCreate;
3310 ++i;
3311
3312 gcd[i].gd.pos.x = viscol; gcd[i].gd.pos.y = 38;
3313 gcd[i].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
3314 if ( cv->showback[0]&1 ) gcd[i].gd.flags |= gg_cb_on;
3315 gcd[i].gd.cid = CID_VBack;
3316 gcd[i].gd.popup_msg = _("Is Layer Visible?");
3317 gcd[i].creator = GVisibilityBoxCreate;
3318 ++i;
3319
3320 gcd[i].gd.pos.x = viscol; gcd[i].gd.pos.y = 21;
3321 gcd[i].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
3322 if ( cv->showfore ) gcd[i].gd.flags |= gg_cb_on;
3323 gcd[i].gd.cid = CID_VFore;
3324 gcd[i].gd.popup_msg = _("Is Layer Visible?");
3325 gcd[i].creator = GVisibilityBoxCreate;
3326 ++i;
3327
3328
3329 /* Scroll bar */
3330 gcd[i].gd.pos.width = GDrawPointsToPixels(cv->gw,_GScrollBar_Width);
3331 gcd[i].gd.pos.x = 0; /* <- these get updated to real values later */
3332 gcd[i].gd.pos.y = 0;
3333 gcd[i].gd.pos.height = 50;
3334 gcd[i].gd.flags = gg_enabled|gg_pos_in_pixels|gg_sb_vert;
3335 gcd[i].gd.cid = CID_SB;
3336 gcd[i].creator = GScrollBarCreate;
3337 layerinfo.sb_start = gcd[i].gd.pos.x;
3338 ++i;
3339
3340 /* Edit box for in place layer rename */
3341 gcd[i].gd.pos.width=gcd[i].gd.pos.height=1;
3342 gcd[i].gd.flags = gg_enabled|gg_pos_in_pixels;
3343 gcd[i].gd.cid = CID_Edit;
3344 gcd[i].gd.popup_msg = _("Type in new layer name");
3345 gcd[i].creator = GTextFieldCreate;
3346 ++i;
3347
3348 GGadgetsCreate(cvlayers,gcd);
3349 if ( cvvisible[0] )
3350 SetPaletteVisible(cv->gw, cvlayers, true);
3351 layers_max=2;
3352
3353 gadget=GWidgetGetControl(cvlayers,CID_AddLayer);
3354 GGadgetGetSize(gadget,&size);
3355 layer_header_height = 0;
3356 layer_footer_height = size.y + size.height;
3357
3358 GGadgetGetSize(GWidgetGetControl(cvlayers,CID_VGrid),&size);
3359 layer_height = size.height;
3360 int32_t w = GDrawGetText8Width(cvlayers, "W", -1);
3361 layerinfo.column_width = w+6;
3362
3363 layerinfo.active = CVLayer(&cv->b); /* the index of the active layer */
3364 layerinfo.mo_col = -2; /* -2 forces this variable to be updated. afterwords it will be -1 for nothing, or >=0 */
3365 layerinfo.mo_layer = -2;
3366 layerinfo.offtop = 0;
3367 layerinfo.rename_active = 0;
3368
3369 GVisibilityBoxSetToMinWH(GWidgetGetControl(cvlayers,CID_VGrid));
3370 GVisibilityBoxSetToMinWH(GWidgetGetControl(cvlayers,CID_VBack));
3371 GVisibilityBoxSetToMinWH(GWidgetGetControl(cvlayers,CID_VFore));
3372
3373 return( cvlayers );
3374 }
3375
3376
3377 /* ***************** CVTools and other common palette functions follow ************ */
3378
3379 static void CVPopupInvoked(GWindow v, GMenuItem *mi, GEvent *e) {
3380 CharView *cv = (CharView *) GDrawGetUserData(v);
3381 int pos;
3382
3383 pos = mi->mid;
3384 if ( pos==cvt_spiro ) {
3385 CVChangeSpiroMode(cv);
3386 } else if ( cv->had_control ) {
3387 if ( cv->cb1_tool!=pos ) {
3388 cv->cb1_tool = cv_cb1_tool = pos;
3389 GDrawRequestExpose(cvtools,NULL,false);
3390 }
3391 } else {
3392 if ( cv->b1_tool!=pos ) {
3393 cv->b1_tool = cv_b1_tool = pos;
3394 GDrawRequestExpose(cvtools,NULL,false);
3395 }
3396 }
3397 CVToolsSetCursor(cv,cv->had_control?ksm_control:0,NULL);
3398 }
3399
3400 static void CVPopupLayerInvoked(GWindow v, GMenuItem *mi, GEvent *e) {
3401 CharView *cv = (CharView *) GDrawGetUserData(v);
3402 int layer = mi->mid==0 ? 1 : mi->mid==1 ? 0 : -1;
3403
3404 if ( layerinfo.active!=layer )
3405 CVLSelectLayer(cv, layer);
3406 }
3407
3408 static void CVPopupSelectInvoked(GWindow v, GMenuItem *mi, GEvent *e) {
3409 CharView *cv = (CharView *) GDrawGetUserData(v);
3410
3411 switch ( mi->mid ) {
3412 case 0:
3413 CVPGetInfo(cv);
3414 break;
3415 case 1:
3416 if ( cv->p.ref!=NULL )
3417 CharViewCreate(cv->p.ref->sc,(FontView *) (cv->b.fv),-1);
3418 break;
3419 case 2:
3420 CVAddAnchor(cv);
3421 break;
3422 case 3:
3423 CVMakeClipPath(cv);
3424 break;
3425 case MIDL_MakeLine: {
3426 _CVMenuMakeLine((CharViewBase *) cv,mi->mid==MIDL_MakeArc, e!=NULL && (e->u.mouse.state&ksm_meta));
3427 break;
3428 }
3429 case MIDL_MakeArc: {
3430 _CVMenuMakeLine((CharViewBase *) cv,mi->mid==MIDL_MakeArc, e!=NULL && (e->u.mouse.state&ksm_meta));
3431 break;
3432 }
3433 case MIDL_InsertPtOnSplineAt: {
3434 _CVMenuInsertPt( cv );
3435 break;
3436 }
3437 case MIDL_NamePoint: {
3438 if ( cv->p.sp )
3439 _CVMenuNamePoint( cv, cv->p.sp );
3440 break;
3441 }
3442 case MIDL_NameContour: {
3443 _CVMenuNameContour( cv );
3444 break;
3445 }
3446
3447 }
3448 }
3449
3450 void CVToolsPopup(CharView *cv, GEvent *event) {
3451 GMenuItem mi[125];
3452 int i=0;
3453 int j=0;
3454 int anysel=0;
3455 static char *selectables[] = { N_("Get Info..."), N_("Open Reference"), N_("Add Anchor"), NULL };
3456
3457 memset(mi,'\0',sizeof(mi));
3458 anysel = CVTestSelectFromEvent(cv,event);
3459
3460 if( anysel )
3461 {
3462 if ( cv->b.sc->inspiro && hasspiro()) {
3463 mi[i].ti.text = (unichar_t *) _("G4 Curve");
3464 mi[i].ti.text_is_1byte = true;
3465 mi[i].ti.fg = COLOR_DEFAULT;
3466 mi[i].ti.bg = COLOR_DEFAULT;
3467 mi[i].mid = MID_SpiroG4;
3468 mi[i].invoke = CVMenuPointType;
3469 i++;
3470 mi[i].ti.text = (unichar_t *) _("G2 Curve");
3471 mi[i].ti.text_is_1byte = true;
3472 mi[i].ti.fg = COLOR_DEFAULT;
3473 mi[i].ti.bg = COLOR_DEFAULT;
3474 mi[i].mid = MID_SpiroG2;
3475 mi[i].invoke = CVMenuPointType;
3476 i++;
3477 mi[i].ti.text = (unichar_t *) _("Corner");
3478 mi[i].ti.text_is_1byte = true;
3479 mi[i].ti.fg = COLOR_DEFAULT;
3480 mi[i].ti.bg = COLOR_DEFAULT;
3481 mi[i].mid = MID_SpiroCorner;
3482 mi[i].invoke = CVMenuPointType;
3483 i++;
3484 mi[i].ti.text = (unichar_t *) _("Left Constraint");
3485 mi[i].ti.text_is_1byte = true;
3486 mi[i].ti.fg = COLOR_DEFAULT;
3487 mi[i].ti.bg = COLOR_DEFAULT;
3488 mi[i].mid = MID_SpiroLeft;
3489 mi[i].invoke = CVMenuPointType;
3490 i++;
3491 mi[i].ti.text = (unichar_t *) _("Right Constraint");
3492 mi[i].ti.text_is_1byte = true;
3493 mi[i].ti.fg = COLOR_DEFAULT;
3494 mi[i].ti.bg = COLOR_DEFAULT;
3495 mi[i].mid = MID_SpiroRight;
3496 mi[i].invoke = CVMenuPointType;
3497 i++;
3498 } else {
3499 mi[i].ti.text = (unichar_t *) _("Curve");
3500 mi[i].ti.text_is_1byte = true;
3501 mi[i].ti.fg = COLOR_DEFAULT;
3502 mi[i].ti.bg = COLOR_DEFAULT;
3503 mi[i].mid = MID_Curve;
3504 mi[i].invoke = CVMenuPointType;
3505 i++;
3506 mi[i].ti.text = (unichar_t *) _("HVCurve");
3507 mi[i].ti.text_is_1byte = true;
3508 mi[i].ti.fg = COLOR_DEFAULT;
3509 mi[i].ti.bg = COLOR_DEFAULT;
3510 mi[i].mid = MID_HVCurve;
3511 mi[i].invoke = CVMenuPointType;
3512 i++;
3513 mi[i].ti.text = (unichar_t *) _("Corner");
3514 mi[i].ti.text_is_1byte = true;
3515 mi[i].ti.fg = COLOR_DEFAULT;
3516 mi[i].ti.bg = COLOR_DEFAULT;
3517 mi[i].mid = MID_Corner;
3518 mi[i].invoke = CVMenuPointType;
3519 i++;
3520 mi[i].ti.text = (unichar_t *) _("Tangent");
3521 mi[i].ti.text_is_1byte = true;
3522 mi[i].ti.fg = COLOR_DEFAULT;
3523 mi[i].ti.bg = COLOR_DEFAULT;
3524 mi[i].mid = MID_Tangent;
3525 mi[i].invoke = CVMenuPointType;
3526 i++;
3527 }
3528
3529 mi[i].ti.line = true;
3530 mi[i].ti.fg = COLOR_DEFAULT;
3531 mi[i].ti.bg = COLOR_DEFAULT;
3532 i++;
3533
3534 mi[i].ti.text = (unichar_t *) _("Merge");
3535 mi[i].ti.text_is_1byte = true;
3536 mi[i].ti.fg = COLOR_DEFAULT;
3537 mi[i].ti.bg = COLOR_DEFAULT;
3538 mi[i].mid = MID_Merge;
3539 mi[i].invoke = CVMerge;
3540 i++;
3541 mi[i].ti.text = (unichar_t *) _("Merge to Line");
3542 mi[i].ti.text_is_1byte = true;
3543 mi[i].ti.fg = COLOR_DEFAULT;
3544 mi[i].ti.bg = COLOR_DEFAULT;
3545 mi[i].mid = MID_MergeToLine;
3546 mi[i].invoke = CVMergeToLine;
3547 i++;
3548
3549 mi[i].ti.text = (unichar_t *) _("Align Points");
3550 mi[i].ti.text_is_1byte = true;
3551 mi[i].ti.fg = COLOR_DEFAULT;
3552 mi[i].ti.bg = COLOR_DEFAULT;
3553 mi[i].mid = MID_Average;
3554 mi[i].invoke = CVMenuConstrain;
3555 i++;
3556
3557 }
3558
3559
3560 if( !anysel )
3561 {
3562 for ( i=0;i<=cvt_skew; ++i ) {
3563 char *msg = _(popupsres[i]);
3564 if ( cv->b.sc->inspiro && hasspiro()) {
3565 if ( i==cvt_spirog2 )
3566 msg = _("Add a g2 curve point");
3567 else if ( i==cvt_spiroleft )
3568 msg = _("Add a left \"tangent\" point");
3569 else if ( i==cvt_spiroright )
3570 msg = _("Add a right \"tangent\" point");
3571 }
3572 mi[i].ti.text = (unichar_t *) msg;
3573 mi[i].ti.text_is_1byte = true;
3574 mi[i].ti.fg = COLOR_DEFAULT;
3575 mi[i].ti.bg = COLOR_DEFAULT;
3576 mi[i].mid = i;
3577 mi[i].invoke = CVPopupInvoked;
3578 }
3579 }
3580
3581 if( !anysel )
3582 {
3583 if ( cvlayers!=NULL && !cv->b.sc->parent->multilayer ) {
3584 mi[i].ti.line = true;
3585 mi[i].ti.fg = COLOR_DEFAULT;
3586 mi[i++].ti.bg = COLOR_DEFAULT;
3587 for ( j=0;j<3; ++j, ++i ) {
3588 mi[i].ti.text = (unichar_t *) _(editablelayers[j]);
3589 mi[i].ti.text_in_resource = true;
3590 mi[i].ti.text_is_1byte = true;
3591 mi[i].ti.fg = COLOR_DEFAULT;
3592 mi[i].ti.bg = COLOR_DEFAULT;
3593 mi[i].mid = j;
3594 mi[i].invoke = CVPopupLayerInvoked;
3595 }
3596 }
3597 }
3598
3599 if( i > 0 ) {
3600 mi[i].ti.line = true;
3601 mi[i].ti.fg = COLOR_DEFAULT;
3602 mi[i++].ti.bg = COLOR_DEFAULT;
3603 }
3604
3605 for ( j=0; selectables[j]!=0; ++j )
3606 {
3607 if ( (!anysel && j!=2 ) ||
3608 ( j==0 && cv->p.spline ) ||
3609 ( j==1 && !cv->p.ref ))
3610 {
3611 // don't show them a disabled item
3612 continue;
3613
3614 // or, if the above "continue;" is commented then keep the entry
3615 // but don't let them select it
3616 mi[i].ti.disabled = true;
3617 }
3618 mi[i].ti.text = (unichar_t *) _(selectables[j]);
3619 mi[i].ti.text_is_1byte = true;
3620 mi[i].ti.fg = COLOR_DEFAULT;
3621 mi[i].ti.bg = COLOR_DEFAULT;
3622 mi[i].mid = j;
3623 mi[i].invoke = CVPopupSelectInvoked;
3624 i++;
3625 }
3626
3627 if ( anysel ) {
3628 mi[i].ti.text = (unichar_t *)_("Name Point...");
3629 mi[i].ti.text_is_1byte = true;
3630 mi[i].ti.fg = COLOR_DEFAULT;
3631 mi[i].ti.bg = COLOR_DEFAULT;
3632 mi[i].mid = MIDL_NamePoint;
3633 mi[i].invoke = CVPopupSelectInvoked;
3634 i++;
3635 }
3636
3637 if ( cv->b.sc->parent->multilayer ) {
3638 mi[i].ti.text = (unichar_t *) _("Make Clip Path");
3639 mi[i].ti.text_is_1byte = true;
3640 mi[i].ti.fg = COLOR_DEFAULT;
3641 mi[i].ti.bg = COLOR_DEFAULT;
3642 mi[i].mid = j;
3643 mi[i].invoke = CVPopupSelectInvoked;
3644 i++;
3645 }
3646
3647 int cnt = CVCountSelectedPoints(cv);
3648 // printf(".... count:%d\n", cnt );
3649 if( cnt > 1 ) {
3650 mi[i].ti.text = (unichar_t *) _("Make Line");
3651 mi[i].ti.text_is_1byte = true;
3652 mi[i].ti.fg = COLOR_DEFAULT;
3653 mi[i].ti.bg = COLOR_DEFAULT;
3654 mi[i].mid = MIDL_MakeLine;
3655 mi[i].invoke = CVPopupSelectInvoked;
3656 i++;
3657
3658 mi[i].ti.text = (unichar_t *) _("Make Arc");
3659 mi[i].ti.text_is_1byte = true;
3660 mi[i].ti.fg = COLOR_DEFAULT;
3661 mi[i].ti.bg = COLOR_DEFAULT;
3662 mi[i].mid = MIDL_MakeArc;
3663 mi[i].invoke = CVPopupSelectInvoked;
3664 i++;
3665
3666 mi[i].ti.text = (unichar_t *) _("Insert Point On Spline At...");
3667 mi[i].ti.text_is_1byte = true;
3668 mi[i].ti.fg = COLOR_DEFAULT;
3669 mi[i].ti.bg = COLOR_DEFAULT;
3670 mi[i].mid = MIDL_InsertPtOnSplineAt;
3671 mi[i].invoke = CVPopupSelectInvoked;
3672 i++;
3673
3674 mi[i].ti.text = (unichar_t *) _("Name Point");
3675 mi[i].ti.text_is_1byte = true;
3676 mi[i].ti.fg = COLOR_DEFAULT;
3677 mi[i].ti.bg = COLOR_DEFAULT;
3678 mi[i].mid = MIDL_NamePoint;
3679 mi[i].invoke = CVPopupSelectInvoked;
3680 i++;
3681
3682 mi[i].ti.text = (unichar_t *) _("Name Contour");
3683 mi[i].ti.text_is_1byte = true;
3684 mi[i].ti.fg = COLOR_DEFAULT;
3685 mi[i].ti.bg = COLOR_DEFAULT;
3686 mi[i].mid = MIDL_NameContour;
3687 mi[i].invoke = CVPopupSelectInvoked;
3688 i++;
3689 }
3690
3691 cv->had_control = (event->u.mouse.state&ksm_control)?1:0;
3692 GMenuCreatePopupMenuWithName(cv->v,event, "Popup", mi);
3693 }
3694
3695 static void CVPaletteCheck(CharView *cv) {
3696 if ( cvtools==NULL ) {
3697 if ( palettes_fixed ) {
3698 cvtoolsoff.x = 0; cvtoolsoff.y = 0;
3699 }
3700 CVMakeTools(cv);
3701 }
3702 if ( cv->b.sc->parent->multilayer && cvlayers2==NULL ) {
3703 if ( palettes_fixed ) {
3704 cvlayersoff.x = 0; cvlayersoff.y = getToolbarHeight(cv)+45/*25*/; /* 45 is right if there's decor, 25 when none. twm gives none, kde gives decor */
3705 }
3706 CVMakeLayers2(cv);
3707 } else if ( !cv->b.sc->parent->multilayer && cvlayers==NULL ) {
3708 if ( palettes_fixed ) {
3709 cvlayersoff.x = 0; cvlayersoff.y = getToolbarHeight(cv)+45/*25*/; /* 45 is right if there's decor, 25 when none. twm gives none, kde gives decor */
3710 }
3711 CVMakeLayers(cv);
3712 }
3713 }
3714
3715 int CVPaletteIsVisible(CharView *cv,int which) {
3716 CVPaletteCheck(cv);
3717 if ( which==1 )
3718 return( cvtools!=NULL && GDrawIsVisible(cvtools) );
3719
3720 if ( cv->b.sc->parent->multilayer )
3721 return( cvlayers2!=NULL && GDrawIsVisible(cvlayers2));
3722
3723 return( cvlayers!=NULL && GDrawIsVisible(cvlayers) );
3724 }
3725
3726 void CVPaletteSetVisible(CharView *cv,int which,int visible) {
3727 CVPaletteCheck(cv);
3728 if ( which==1 && cvtools!=NULL)
3729 SetPaletteVisible(cv->gw, cvtools, visible);
3730 else if ( which==0 && cv->b.sc->parent->multilayer && cvlayers2!=NULL )
3731 SetPaletteVisible(cv->gw, cvlayers2, visible );
3732 else if ( which==0 && cvlayers!=NULL )
3733 SetPaletteVisible(cv->gw, cvlayers, visible );
3734 cvvisible[which] = visible;
3735 SavePrefs(true);
3736 }
3737
3738 void CVPalettesRaise(CharView *cv) {
3739 if ( cvtools!=NULL && GDrawIsVisible(cvtools))
3740 GDrawRaise(cvtools);
3741 if ( cvlayers!=NULL && GDrawIsVisible(cvlayers))
3742 GDrawRaise(cvlayers);
3743 if ( cvlayers2!=NULL && GDrawIsVisible(cvlayers2))
3744 GDrawRaise(cvlayers2);
3745 }
3746
3747 void _CVPaletteActivate(CharView *cv, int force, int docking_changed) {
3748 CharView *old;
3749
3750 CVPaletteCheck(cv);
3751 if ( layers2_active!=-1 && layers2_active!=cv->b.sc->parent->multilayer ) {
3752 if ( !cvvisible[0] ) {
3753 if ( cvlayers2!=NULL ) SetPaletteVisible(NULL, cvlayers2, false);
3754 if ( cvlayers !=NULL ) SetPaletteVisible(NULL, cvlayers, false);
3755 } else if ( layers2_active && cvlayers!=NULL ) {
3756 if ( cvlayers2!=NULL ) SetPaletteVisible(NULL, cvlayers2, false);
3757 SetPaletteVisible(cv->gw, cvlayers, true);
3758 } else if ( !layers2_active && cvlayers2!=NULL ) {
3759 if ( cvlayers !=NULL ) SetPaletteVisible(NULL, cvlayers, false);
3760 SetPaletteVisible(cv->gw, cvlayers2, true);
3761 }
3762 }
3763 layers2_active = cv->b.sc->parent->multilayer;
3764 if ( (old = GDrawGetUserData(cvtools))!=cv || force) {
3765 if ( old!=NULL ) {
3766 SaveOffsets(old->gw,cvtools,&cvtoolsoff);
3767 if ( old->b.sc->parent->multilayer )
3768 SaveOffsets(old->gw,cvlayers2,&cvlayersoff);
3769 else
3770 SaveOffsets(old->gw,cvlayers,&cvlayersoff);
3771 }
3772
3773 if ((palettes_docked && old != cv) || docking_changed) {
3774 // When docked, we need to recreate the palettes
3775 // Because they were created as a child of the old charview
3776 GDrawDestroyWindow(cvtools);
3777
3778 if (cvlayers != NULL)
3779 GDrawDestroyWindow(cvlayers);
3780 if (cvlayers2 != NULL)
3781 GDrawDestroyWindow(cvlayers2);
3782
3783 cvtools = cvlayers = cvlayers2 = NULL;
3784 CVPaletteCheck(cv);
3785 }
3786
3787 GDrawSetUserData(cvtools,cv);
3788
3789 if ( cv->b.sc->parent->multilayer ) {
3790 LayersSwitch(cv);
3791 GDrawSetUserData(cvlayers2,cv);
3792 } else {
3793 GDrawSetUserData(cvlayers,cv);
3794 CVLCheckLayerCount(cv,true);
3795 }
3796 if (palettes_docked) {
3797 if (cvvisible[1])
3798 GDrawRequestExpose(cvtools, NULL, false);
3799 if (cvvisible[0]) {
3800 if (cv->b.sc->parent->multilayer)
3801 GDrawRequestExpose(cvlayers2, NULL, false);
3802 else
3803 GDrawRequestExpose(cvlayers, NULL, false);
3804 }
3805 } else {
3806 if ( cvvisible[0]) {
3807 if ( cv->b.sc->parent->multilayer )
3808 RestoreOffsets(cv->gw,cvlayers2,&cvlayersoff);
3809 else
3810 RestoreOffsets(cv->gw,cvlayers,&cvlayersoff);
3811 }
3812 if ( cvvisible[1])
3813 RestoreOffsets(cv->gw,cvtools,&cvtoolsoff);
3814 }
3815 SetPaletteVisible(cv->gw, cvtools, cvvisible[1]);
3816 if ( cv->b.sc->parent->multilayer )
3817 SetPaletteVisible(cv->gw, cvlayers2, cvvisible[0]);
3818 else
3819 SetPaletteVisible(cv->gw, cvlayers, cvvisible[0]);
3820 if ( cvvisible[1]) {
3821 cv->showing_tool = cvt_none;
3822 CVToolsSetCursor(cv,0,NULL);
3823 GDrawRequestExpose(cvtools,NULL,false);
3824 }
3825 if ( cvvisible[0])
3826 CVLayersSet(cv);
3827 }
3828 if ( bvtools!=NULL ) {
3829 BitmapView *bv = GDrawGetUserData(bvtools);
3830 if ( bv!=NULL ) {
3831 SaveOffsets(bv->gw,bvtools,&bvtoolsoff);
3832 SaveOffsets(bv->gw,bvlayers,&bvlayersoff);
3833 if ( !bv->shades_hidden )
3834 SaveOffsets(bv->gw,bvshades,&bvshadesoff);
3835 GDrawSetUserData(bvtools,NULL);
3836 GDrawSetUserData(bvlayers,NULL);
3837 GDrawSetUserData(bvshades,NULL);
3838 }
3839 SetPaletteVisible(NULL, bvtools, false);
3840 SetPaletteVisible(NULL, bvlayers, false);
3841 SetPaletteVisible(NULL, bvshades, false);
3842 }
3843 }
3844
3845 void CVPaletteActivate(CharView *cv) {
3846 _CVPaletteActivate(cv,false,false);
3847 }
3848
3849 void CV_LayerPaletteCheck(SplineFont *sf) {
3850 CharView *old;
3851
3852 if ( cvlayers!=NULL ) {
3853 if ( (old = GDrawGetUserData(cvlayers))!=NULL ) {
3854 if ( old->b.sc->parent==sf )
3855 _CVPaletteActivate(old,true,false);
3856 }
3857 }
3858 }
3859
3860 /* make the charview point to the correct layer heads for the specified glyph */
3861 void SFLayerChange(SplineFont *sf) {
3862 CharView *old, *cv;
3863 int i;
3864
3865 for ( i=0; i<sf->glyphcnt; ++i ) if ( sf->glyphs[i]!=NULL ) {
3866 SplineChar *sc = sf->glyphs[i];
3867 for ( cv=(CharView *) (sc->views); cv!=NULL; cv=(CharView *) (cv->b.next) ) {
3868 cv->b.layerheads[dm_back] = &sc->layers[ly_back];
3869 cv->b.layerheads[dm_fore] = &sc->layers[ly_fore];
3870 cv->b.layerheads[dm_grid] = &sf->grid;
3871 }
3872 }
3873
3874 if ( cvtools==NULL )
3875 return; /* No charviews open */
3876 old = GDrawGetUserData(cvtools);
3877 if ( old==NULL || old->b.sc->parent!=sf ) /* Irrelevant */
3878 return;
3879 _CVPaletteActivate(old,true,false);
3880 }
3881
3882 void CVPalettesHideIfMine(CharView *cv) {
3883 if ( cvtools==NULL )
3884 return;
3885 if ( GDrawGetUserData(cvtools)==cv ) {
3886 SaveOffsets(cv->gw,cvtools,&cvtoolsoff);
3887 SetPaletteVisible(NULL, cvtools, false);
3888 GDrawSetUserData(cvtools,NULL);
3889 if ( cv->b.sc->parent->multilayer && cvlayers2!=NULL ) {
3890 SaveOffsets(cv->gw,cvlayers2,&cvlayersoff);
3891 SetPaletteVisible(NULL, cvlayers2, false);
3892 GDrawSetUserData(cvlayers2,NULL);
3893 } else {
3894 SaveOffsets(cv->gw,cvlayers,&cvlayersoff);
3895 SetPaletteVisible(NULL, cvlayers, false);
3896 GDrawSetUserData(cvlayers,NULL);
3897 }
3898 }
3899 }
3900
3901 int CVPalettesWidth(void) {
3902 return( GGadgetScale(CV_LAYERS2_WIDTH));
3903 }
3904
3905 /* ************************************************************************** */
3906 /* **************************** Bitmap Palettes ***************************** */
3907 /* ************************************************************************** */
3908
3909 static void BVLayersSet(BitmapView *bv) {
3910 GGadgetSetChecked(GWidgetGetControl(bvlayers,CID_VFore),bv->showfore);
3911 GGadgetSetChecked(GWidgetGetControl(bvlayers,CID_VBack),bv->showoutline);
3912 GGadgetSetChecked(GWidgetGetControl(bvlayers,CID_VGrid),bv->showgrid);
3913 }
3914
3915 static int bvlayers_e_h(GWindow gw, GEvent *event) {
3916 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
3917
3918 if ( event->type==et_destroy && bvlayers == gw ) {
3919 bvlayers = NULL;
3920 return( true );
3921 }
3922
3923 if ( bv==NULL )
3924 return( true );
3925
3926 switch ( event->type ) {
3927 case et_close:
3928 SetPaletteVisible(NULL, gw, false);
3929 break;
3930 case et_char: case et_charup:
3931 PostCharToWindow(bv->gw,event);
3932 break;
3933 case et_controlevent:
3934 if ( event->u.control.subtype == et_radiochanged ) {
3935 switch(GGadgetGetCid(event->u.control.g)) {
3936 case CID_VFore:
3937 BVShows.showfore = bv->showfore = GGadgetIsChecked(event->u.control.g);
3938 break;
3939 case CID_VBack:
3940 BVShows.showoutline = bv->showoutline = GGadgetIsChecked(event->u.control.g);
3941 break;
3942 case CID_VGrid:
3943 BVShows.showgrid = bv->showgrid = GGadgetIsChecked(event->u.control.g);
3944 break;
3945 }
3946 GDrawRequestExpose(bv->v,NULL,false);
3947 }
3948 break;
3949 default: break;
3950 }
3951 return( true );
3952 }
3953
3954 GWindow BVMakeLayers(BitmapView *bv) {
3955 GRect r;
3956 GWindowAttrs wattrs;
3957 GGadgetCreateData gcd[8], boxes[2], *hvarray[5][3];
3958 GTextInfo label[8];
3959 static GBox radio_box = { bt_none, bs_rect, 0, 0, 0, 0, 0, 0, 0, 0, COLOR_DEFAULT, COLOR_DEFAULT, 0, 0, 0, 0, 0, 0, 0 };
3960 int i;
3961
3962 if ( bvlayers!=NULL )
3963 return(bvlayers);
3964 memset(&wattrs,0,sizeof(wattrs));
3965 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_positioned|wam_isdlg;
3966 wattrs.event_masks = -1;
3967 wattrs.cursor = ct_mypointer;
3968 wattrs.positioned = true;
3969 wattrs.is_dlg = true;
3970 wattrs.utf8_window_title = _("Layers");
3971
3972 r.width = GGadgetScale(BV_LAYERS_WIDTH); r.height = BV_LAYERS_HEIGHT;
3973 r.x = -r.width-6; r.y = bv->mbh+BV_TOOLS_HEIGHT+45/*25*/; /* 45 is right if there's decor, is in kde, not in twm. Sigh */
3974 if ( palettes_docked ) {
3975 r.x = 0; r.y = BV_TOOLS_HEIGHT+4;
3976 } else if ( palettes_fixed ) {
3977 r.x = 0; r.y = BV_TOOLS_HEIGHT+45;
3978 }
3979 bvlayers = CreatePalette( bv->gw, &r, bvlayers_e_h, bv, &wattrs, bv->v );
3980
3981 memset(&label,0,sizeof(label));
3982 memset(&gcd,0,sizeof(gcd));
3983 memset(&boxes,0,sizeof(boxes));
3984
3985 for ( i=0; i<sizeof(label)/sizeof(label[0]); ++i )
3986 label[i].font = layerspalette_font.fi;
3987
3988 /* GT: Abbreviation for "Visible" */
3989 label[0].text = (unichar_t *) _("V");
3990 label[0].text_is_1byte = true;
3991 gcd[0].gd.label = &label[0];
3992 gcd[0].gd.pos.x = 7; gcd[0].gd.pos.y = 5;
3993 gcd[0].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels;
3994 gcd[0].gd.popup_msg = _("Is Layer Visible?");
3995 gcd[0].creator = GLabelCreate;
3996
3997 label[1].text = (unichar_t *) "Layer";
3998 label[1].text_is_1byte = true;
3999 gcd[1].gd.label = &label[1];
4000 gcd[1].gd.pos.x = 23; gcd[1].gd.pos.y = 5;
4001 gcd[1].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels;
4002 gcd[1].gd.popup_msg = _("Is Layer Visible?");
4003 gcd[1].creator = GLabelCreate;
4004 hvarray[0][0] = &gcd[0]; hvarray[0][1] = &gcd[1]; hvarray[0][2] = NULL;
4005
4006 gcd[2].gd.pos.x = 5; gcd[2].gd.pos.y = 21;
4007 gcd[2].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
4008 gcd[2].gd.cid = CID_VFore;
4009 gcd[2].gd.popup_msg = _("Is Layer Visible?");
4010 gcd[2].gd.box = &radio_box;
4011 gcd[2].creator = GCheckBoxCreate;
4012 label[2].text = (unichar_t *) _("Bitmap");
4013 label[2].text_is_1byte = true;
4014 gcd[2].gd.label = &label[2];
4015 hvarray[1][0] = &gcd[2]; hvarray[1][1] = GCD_ColSpan; hvarray[1][2] = NULL;
4016
4017 gcd[3].gd.pos.x = 5; gcd[3].gd.pos.y = 37;
4018 gcd[3].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
4019 gcd[3].gd.cid = CID_VBack;
4020 gcd[3].gd.popup_msg = _("Is Layer Visible?");
4021 gcd[3].gd.box = &radio_box;
4022 gcd[3].creator = GCheckBoxCreate;
4023 label[3].text = (unichar_t *) _("Outline");
4024 label[3].text_is_1byte = true;
4025 gcd[3].gd.label = &label[3];
4026 hvarray[2][0] = &gcd[3]; hvarray[2][1] = GCD_ColSpan; hvarray[2][2] = NULL;
4027
4028 gcd[4].gd.pos.x = 5; gcd[4].gd.pos.y = 53;
4029 gcd[4].gd.flags = gg_enabled|gg_visible|gg_dontcopybox|gg_pos_in_pixels;
4030 gcd[4].gd.cid = CID_VGrid;
4031 gcd[4].gd.popup_msg = _("Is Layer Visible?");
4032 gcd[4].gd.box = &radio_box;
4033 gcd[4].creator = GCheckBoxCreate;
4034 label[4].text = (unichar_t *) _("_Guide");
4035 label[4].text_is_1byte = true;
4036 label[4].text_in_resource = true;
4037 gcd[4].gd.label = &label[4];
4038 hvarray[3][0] = &gcd[4]; hvarray[3][1] = GCD_ColSpan; hvarray[3][2] = NULL;
4039 hvarray[4][0] = NULL;
4040
4041 if ( bv->showfore ) gcd[2].gd.flags |= gg_cb_on;
4042 if ( bv->showoutline ) gcd[3].gd.flags |= gg_cb_on;
4043 if ( bv->showgrid ) gcd[4].gd.flags |= gg_cb_on;
4044
4045 boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2;
4046 boxes[0].gd.flags = gg_enabled|gg_visible;
4047 boxes[0].gd.u.boxelements = hvarray[0];
4048 boxes[0].creator = GHVGroupCreate;
4049
4050 GGadgetsCreate(bvlayers,boxes);
4051 GHVBoxFitWindow(boxes[0].ret);
4052
4053 if ( bvvisible[0] )
4054 SetPaletteVisible(bv->gw, bvlayers, true);
4055 return( bvlayers );
4056 }
4057
4058 struct shades_layout {
4059 int depth;
4060 int div;
4061 int cnt; /* linear number of squares */
4062 int size;
4063 };
4064
4065 static void BVShadesDecompose(BitmapView *bv, struct shades_layout *lay) {
4066 GRect r;
4067 int temp;
4068
4069 GDrawGetSize(bvshades,&r);
4070 lay->depth = BDFDepth(bv->bdf);
4071 lay->div = 255/((1<<lay->depth)-1);
4072 lay->cnt = lay->depth==8 ? 16 : lay->depth;
4073 temp = r.width>r.height ? r.height : r.width;
4074 lay->size = (temp-8+1)/lay->cnt - 1;
4075 }
4076
4077 static void BVShadesExpose(GWindow pixmap, BitmapView *bv, GRect *r) {
4078 struct shades_layout lay;
4079 GRect old;
4080 int i,j,index;
4081 GRect block;
4082 Color bg = default_background;
4083 int greybg = (3*COLOR_RED(bg)+6*COLOR_GREEN(bg)+COLOR_BLUE(bg))/10;
4084
4085 GDrawSetLineWidth(pixmap,0);
4086 BVShadesDecompose(bv,&lay);
4087 GDrawPushClip(pixmap,r,&old);
4088 for ( i=0; i<=lay.cnt; ++i ) {
4089 int p = 3+i*(lay.size+1);
4090 int m = 8+lay.cnt*(lay.size+1);
4091 GDrawDrawLine(pixmap,p,0,p,m,bg);
4092 GDrawDrawLine(pixmap,0,p,m,p,bg);
4093 }
4094 block.width = block.height = lay.size;
4095 for ( i=0; i<lay.cnt; ++i ) {
4096 block.y = 4 + i*(lay.size+1);
4097 for ( j=0; j<lay.cnt; ++j ) {
4098 block.x = 4 + j*(lay.size+1);
4099 index = (i*lay.cnt+j)*lay.div;
4100 if (( bv->color >= index - lay.div/2 &&
4101 bv->color <= index + lay.div/2 ) ||
4102 ( bv->color_under_cursor >= index - lay.div/2 &&
4103 bv->color_under_cursor <= index + lay.div/2 )) {
4104 GRect outline;
4105 outline.x = block.x-1; outline.y = block.y-1;
4106 outline.width = block.width+1; outline.height = block.height+1;
4107 GDrawDrawRect(pixmap,&outline,
4108 ( bv->color >= index - lay.div/2 &&
4109 bv->color <= index + lay.div/2 )?0x00ff00:0xffffff);
4110 }
4111 index = (255-index) * greybg / 255;
4112 GDrawFillRect(pixmap,&block,0x010101*index);
4113 }
4114 }
4115 }
4116
4117 static void BVShadesMouse(BitmapView *bv, GEvent *event) {
4118 struct shades_layout lay;
4119 int i, j;
4120
4121 GGadgetEndPopup();
4122 if ( event->type == et_mousemove && !bv->shades_down )
4123 return;
4124 BVShadesDecompose(bv,&lay);
4125 if ( event->u.mouse.x<4 || event->u.mouse.y<4 ||
4126 event->u.mouse.x>=4+lay.cnt*(lay.size+1) ||
4127 event->u.mouse.y>=4+lay.cnt*(lay.size+1) )
4128 return;
4129 i = (event->u.mouse.y-4)/(lay.size+1);
4130 j = (event->u.mouse.x-4)/(lay.size+1);
4131 if ( bv->color != (i*lay.cnt + j)*lay.div ) {
4132 bv->color = (i*lay.cnt + j)*lay.div;
4133 GDrawRequestExpose(bvshades,NULL,false);
4134 }
4135 if ( event->type == et_mousedown ) bv->shades_down = true;
4136 else if ( event->type == et_mouseup ) bv->shades_down = false;
4137 if ( event->type == et_mouseup )
4138 GDrawRequestExpose(bv->gw,NULL,false);
4139 }
4140
4141 static int bvshades_e_h(GWindow gw, GEvent *event) {
4142 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
4143
4144 if ( event->type==et_destroy && bvshades == gw ) {
4145 bvshades = NULL;
4146 return( true );
4147 }
4148
4149 if ( bv==NULL )
4150 return( true );
4151
4152 switch ( event->type ) {
4153 case et_expose:
4154 BVShadesExpose(gw,bv,&event->u.expose.rect);
4155 break;
4156 case et_mousemove:
4157 case et_mouseup:
4158 case et_mousedown:
4159 BVShadesMouse(bv,event);
4160 break;
4161 case et_char: case et_charup:
4162 PostCharToWindow(bv->gw,event);
4163 break;
4164 case et_destroy:
4165 break;
4166 case et_close:
4167 SetPaletteVisible(NULL, gw, false);
4168 break;
4169 default: break;
4170 }
4171 return( true );
4172 }
4173
4174 static GWindow BVMakeShades(BitmapView *bv) {
4175 GRect r;
4176 GWindowAttrs wattrs;
4177
4178 if ( bvshades!=NULL )
4179 return( bvshades );
4180 memset(&wattrs,0,sizeof(wattrs));
4181 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_positioned|wam_isdlg/*|wam_backcol*/;
4182 wattrs.event_masks = -1;
4183 wattrs.cursor = ct_eyedropper;
4184 wattrs.positioned = true;
4185 wattrs.is_dlg = true;
4186 wattrs.background_color = 0xffffff;
4187 wattrs.utf8_window_title = _("Shades");
4188
4189 r.width = BV_SHADES_HEIGHT; r.height = r.width;
4190 r.x = -r.width-6; r.y = bv->mbh+225;
4191 if ( palettes_docked ) {
4192 r.x = 0; r.y = BV_TOOLS_HEIGHT+BV_LAYERS_HEIGHT+4;
4193 } else if ( palettes_fixed ) {
4194 r.x = 0; r.y = BV_TOOLS_HEIGHT+BV_LAYERS_HEIGHT+90;
4195 }
4196 bvshades = CreatePalette( bv->gw, &r, bvshades_e_h, bv, &wattrs, bv->v );
4197 bv->shades_hidden = BDFDepth(bv->bdf)==1;
4198 if ( bvvisible[2] && !bv->shades_hidden )
4199 SetPaletteVisible(bv->gw, bvshades, true);
4200 return( bvshades );
4201 }
4202
4203 static char *bvpopups[] = { N_("Pointer"), N_("Magnify (Minify with alt)"),
4204 N_("Set/Clear Pixels"), N_("Draw a Line"),
4205 N_("Shift Entire Bitmap"), N_("Scroll Bitmap") };
4206
4207 static void BVToolsExpose(GWindow pixmap, BitmapView *bv, GRect *r) {
4208 GRect old;
4209 /* Note: If you change this ordering, change enum bvtools */
4210 static GImage *buttons[][2] = { { &GIcon_pointer, &GIcon_magnify },
4211 { &GIcon_pencil, &GIcon_line },
4212 { &GIcon_shift, &GIcon_hand }};
4213 int i,j,norm;
4214 int tool = bv->cntrldown?bv->cb1_tool:bv->b1_tool;
4215 int dither = GDrawSetDither(NULL,false);
4216
4217 GDrawPushClip(pixmap,r,&old);
4218 GDrawFillRect(pixmap,r,cvpalettebgcol);
4219 GDrawSetLineWidth(pixmap,0);
4220 for ( i=0; i<sizeof(buttons)/sizeof(buttons[0]); ++i ) for ( j=0; j<2; ++j ) {
4221 GDrawDrawImage(pixmap,buttons[i][j],NULL,j*27+1,i*27+1);
4222 norm = (i*2+j!=tool);
4223 GDrawDrawLine(pixmap,j*27,i*27,j*27+25,i*27,norm?0xe0e0e0:0x707070);
4224 GDrawDrawLine(pixmap,j*27,i*27,j*27,i*27+25,norm?0xe0e0e0:0x707070);
4225 GDrawDrawLine(pixmap,j*27,i*27+25,j*27+25,i*27+25,norm?0x707070:0xe0e0e0);
4226 GDrawDrawLine(pixmap,j*27+25,i*27,j*27+25,i*27+25,norm?0x707070:0xe0e0e0);
4227 }
4228 GDrawPopClip(pixmap,&old);
4229 GDrawSetDither(NULL,dither);
4230 }
4231
4232 void BVToolsSetCursor(BitmapView *bv, int state,char *device) {
4233 int shouldshow;
4234 static enum bvtools tools[bvt_max2+1] = { bvt_none };
4235 int cntrl;
4236
4237 if ( tools[0] == bvt_none ) {
4238 tools[bvt_pointer] = ct_mypointer;
4239 tools[bvt_magnify] = ct_magplus;
4240 tools[bvt_pencil] = ct_pencil;
4241 tools[bvt_line] = ct_line;
4242 tools[bvt_shift] = ct_shift;
4243 tools[bvt_hand] = ct_myhand;
4244 tools[bvt_minify] = ct_magminus;
4245 tools[bvt_eyedropper] = ct_eyedropper;
4246 tools[bvt_setwidth] = ct_setwidth;
4247 tools[bvt_setvwidth] = ct_updown;
4248 tools[bvt_rect] = ct_rect;
4249 tools[bvt_filledrect] = ct_filledrect;
4250 tools[bvt_elipse] = ct_elipse;
4251 tools[bvt_filledelipse] = ct_filledelipse;
4252 }
4253
4254 shouldshow = bvt_none;
4255 if ( bv->active_tool!=bvt_none )
4256 shouldshow = bv->active_tool;
4257 else if ( bv->pressed_display!=bvt_none )
4258 shouldshow = bv->pressed_display;
4259 else if ( device==NULL || strcmp(device,"Mouse1")==0 ) {
4260 if ( (state&(ksm_shift|ksm_control)) && (state&ksm_button4))
4261 shouldshow = bvt_magnify;
4262 else if ( (state&(ksm_shift|ksm_control)) && (state&ksm_button5))
4263 shouldshow = bvt_minify;
4264 else if ( (state&ksm_control) && (state&(ksm_button2|ksm_super)) )
4265 shouldshow = bv->cb2_tool;
4266 else if ( (state&(ksm_button2|ksm_super)) )
4267 shouldshow = bv->b2_tool;
4268 else if ( (state&ksm_control) )
4269 shouldshow = bv->cb1_tool;
4270 else
4271 shouldshow = bv->b1_tool;
4272 } else if ( strcmp(device,"eraser")==0 )
4273 shouldshow = bv->er_tool;
4274 else if ( strcmp(device,"stylus")==0 ) {
4275 if ( (state&(ksm_button2|ksm_control|ksm_super)) )
4276 shouldshow = bv->s2_tool;
4277 else
4278 shouldshow = bv->s1_tool;
4279 }
4280
4281 if ( shouldshow==bvt_magnify && (state&ksm_meta))
4282 shouldshow = bvt_minify;
4283 if ( (shouldshow==bvt_pencil || shouldshow==bvt_line) && (state&ksm_meta) && bv->bdf->clut!=NULL )
4284 shouldshow = bvt_eyedropper;
4285 if ( shouldshow!=bvt_none && shouldshow!=bv->showing_tool ) {
4286 GDrawSetCursor(bv->v,tools[shouldshow]);
4287 if ( bvtools != NULL )
4288 GDrawSetCursor(bvtools,tools[shouldshow]);
4289 bv->showing_tool = shouldshow;
4290 }
4291
4292 if ( device==NULL || strcmp(device,"stylus")==0 ) {
4293 cntrl = (state&ksm_control)?1:0;
4294 if ( device!=NULL && (state&ksm_button2))
4295 cntrl = true;
4296 if ( cntrl != bv->cntrldown ) {
4297 bv->cntrldown = cntrl;
4298 GDrawRequestExpose(bvtools,NULL,false);
4299 }
4300 }
4301 }
4302
4303 static void BVToolsMouse(BitmapView *bv, GEvent *event) {
4304 int i = (event->u.mouse.y/27), j = (event->u.mouse.x/27);
4305 int pos;
4306 int isstylus = event->u.mouse.device!=NULL && strcmp(event->u.mouse.device,"stylus")==0;
4307 int styluscntl = isstylus && (event->u.mouse.state&0x200);
4308
4309 if(j >= 2)
4310 return; /* If the wm gave me a window the wrong size */
4311
4312 pos = i*2 + j;
4313 GGadgetEndPopup();
4314 if ( pos<0 || pos>=bvt_max )
4315 pos = bvt_none;
4316 if ( event->type == et_mousedown ) {
4317 if ( isstylus && event->u.mouse.button==2 )
4318 /* Not a real button press, only touch counts. This is a modifier */;
4319 else {
4320 bv->pressed_tool = bv->pressed_display = pos;
4321 bv->had_control = ((event->u.mouse.state&ksm_control) || styluscntl)?1:0;
4322 event->u.chr.state |= (1<<(7+event->u.mouse.button));
4323 }
4324 } else if ( event->type == et_mousemove ) {
4325 if ( bv->pressed_tool==bvt_none && pos!=bvt_none ) {
4326 /* Not pressed */
4327 if ( !bv->shades_hidden && strcmp(bvpopups[pos],"Set/Clear Pixels")==0 )
4328 GGadgetPreparePopup8(bvtools,_("Set/Clear Pixels\n(Eyedropper with alt)"));
4329 else
4330 GGadgetPreparePopup8(bvtools,_(bvpopups[pos]));
4331 } else if ( pos!=bv->pressed_tool || bv->had_control != (((event->u.mouse.state&ksm_control)||styluscntl)?1:0) )
4332 bv->pressed_display = bvt_none;
4333 else
4334 bv->pressed_display = bv->pressed_tool;
4335 } else if ( event->type == et_mouseup ) {
4336 if ( pos!=bv->pressed_tool || bv->had_control != (((event->u.mouse.state&ksm_control)||styluscntl)?1:0) )
4337 bv->pressed_tool = bv->pressed_display = bvt_none;
4338 else {
4339 if ( event->u.mouse.device!=NULL && strcmp(event->u.mouse.device,"eraser")==0 )
4340 bv->er_tool = pos;
4341 else if ( isstylus ) {
4342 if ( event->u.mouse.button==2 )
4343 /* Only thing that matters is touch which maps to button 1 */;
4344 else if ( bv->had_control )
4345 bv->s2_tool = pos;
4346 else
4347 bv->s1_tool = pos;
4348 } else if ( bv->had_control && event->u.mouse.button==2 )
4349 bv->cb2_tool = pos;
4350 else if ( event->u.mouse.button==2 )
4351 bv->b2_tool = pos;
4352 else if ( bv->had_control ) {
4353 if ( bv->cb1_tool!=pos ) {
4354 bv->cb1_tool = pos;
4355 GDrawRequestExpose(bvtools,NULL,false);
4356 }
4357 } else {
4358 if ( bv->b1_tool!=pos ) {
4359 bv->b1_tool = pos;
4360 GDrawRequestExpose(bvtools,NULL,false);
4361 }
4362 }
4363 bv->pressed_tool = bv->pressed_display = bvt_none;
4364 }
4365 event->u.mouse.state &= ~(1<<(7+event->u.mouse.button));
4366 }
4367 BVToolsSetCursor(bv,event->u.mouse.state,event->u.mouse.device);
4368 }
4369
4370 static int bvtools_e_h(GWindow gw, GEvent *event) {
4371 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
4372
4373 if ( event->type==et_destroy && bvtools == gw ) {
4374 bvtools = NULL;
4375 return( true );
4376 }
4377
4378 if ( bv==NULL )
4379 return( true );
4380
4381 switch ( event->type ) {
4382 case et_expose:
4383 BVToolsExpose(gw,bv,&event->u.expose.rect);
4384 break;
4385 case et_mousedown:
4386 BVToolsMouse(bv,event);
4387 break;
4388 case et_mousemove:
4389 BVToolsMouse(bv,event);
4390 break;
4391 case et_mouseup:
4392 BVToolsMouse(bv,event);
4393 break;
4394 case et_crossing:
4395 bv->pressed_display = bvt_none;
4396 BVToolsSetCursor(bv,event->u.mouse.state,event->u.mouse.device);
4397 break;
4398 case et_char: case et_charup:
4399 if ( bv->had_control != ((event->u.chr.state&ksm_control)?1:0) )
4400 bv->pressed_display = bvt_none;
4401 PostCharToWindow(bv->gw,event);
4402 break;
4403 case et_close:
4404 SetPaletteVisible(NULL, gw, false);
4405 break;
4406 default: break;
4407 }
4408 return( true );
4409 }
4410
4411 GWindow BVMakeTools(BitmapView *bv) {
4412 GRect r;
4413 GWindowAttrs wattrs;
4414
4415 if ( bvtools!=NULL )
4416 return( bvtools );
4417 memset(&wattrs,0,sizeof(wattrs));
4418 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_positioned|wam_isdlg;
4419 wattrs.event_masks = -1;
4420 wattrs.cursor = ct_mypointer;
4421 wattrs.positioned = true;
4422 wattrs.is_dlg = true;
4423 wattrs.utf8_window_title = _("Tools");
4424
4425 r.width = BV_TOOLS_WIDTH; r.height = BV_TOOLS_HEIGHT;
4426 r.x = -r.width-6; r.y = bv->mbh+20;
4427 if ( palettes_fixed || palettes_docked ) {
4428 r.x = 0; r.y = 0;
4429 }
4430 bvtools = CreatePalette( bv->gw, &r, bvtools_e_h, bv, &wattrs, bv->v );
4431 if ( bvvisible[1] )
4432 SetPaletteVisible(bv->gw, bvtools, true);
4433 return( bvtools );
4434 }
4435
4436 static void BVPopupInvoked(GWindow v, GMenuItem *mi,GEvent *e) {
4437 BitmapView *bv = (BitmapView *) GDrawGetUserData(v);
4438 int pos;
4439
4440 pos = mi->mid;
4441 if ( bv->had_control ) {
4442 if ( bv->cb1_tool!=pos ) {
4443 bv->cb1_tool = pos;
4444 GDrawRequestExpose(bvtools,NULL,false);
4445 }
4446 } else {
4447 if ( bv->b1_tool!=pos ) {
4448 bv->b1_tool = pos;
4449 GDrawRequestExpose(bvtools,NULL,false);
4450 }
4451 }
4452 BVToolsSetCursor(bv,bv->had_control?ksm_control:0,NULL);
4453 }
4454
4455 void BVToolsPopup(BitmapView *bv, GEvent *event) {
4456 GMenuItem mi[21];
4457 int i, j;
4458
4459 memset(mi,'\0',sizeof(mi));
4460 for ( i=0;i<6; ++i ) {
4461 mi[i].ti.text = (unichar_t *) _(bvpopups[i]);
4462 mi[i].ti.text_is_1byte = true;
4463 mi[i].ti.fg = COLOR_DEFAULT;
4464 mi[i].ti.bg = COLOR_DEFAULT;
4465 mi[i].mid = i;
4466 mi[i].invoke = BVPopupInvoked;
4467 }
4468
4469 mi[i].ti.text = (unichar_t *) _("Rectangle");
4470 mi[i].ti.text_is_1byte = true;
4471 mi[i].ti.fg = COLOR_DEFAULT;
4472 mi[i].ti.bg = COLOR_DEFAULT;
4473 mi[i].mid = bvt_rect;
4474 mi[i++].invoke = BVPopupInvoked;
4475 mi[i].ti.text = (unichar_t *) _("Filled Rectangle"); mi[i].ti.text_is_1byte = true;
4476 mi[i].ti.fg = COLOR_DEFAULT;
4477 mi[i].ti.bg = COLOR_DEFAULT;
4478 mi[i].mid = bvt_filledrect;
4479 mi[i++].invoke = BVPopupInvoked;
4480 mi[i].ti.text = (unichar_t *) _("Ellipse"); mi[i].ti.text_is_1byte = true;
4481 mi[i].ti.fg = COLOR_DEFAULT;
4482 mi[i].ti.bg = COLOR_DEFAULT;
4483 mi[i].mid = bvt_elipse;
4484 mi[i++].invoke = BVPopupInvoked;
4485 mi[i].ti.text = (unichar_t *) _("Filled Ellipse"); mi[i].ti.text_is_1byte = true;
4486 mi[i].ti.fg = COLOR_DEFAULT;
4487 mi[i].ti.bg = COLOR_DEFAULT;
4488 mi[i].mid = bvt_filledelipse;
4489 mi[i++].invoke = BVPopupInvoked;
4490
4491 mi[i].ti.fg = COLOR_DEFAULT;
4492 mi[i].ti.bg = COLOR_DEFAULT;
4493 mi[i++].ti.line = true;
4494 for ( j=0; j<6; ++j, ++i ) {
4495 mi[i].ti.text = (unichar_t *) BVFlipNames[j];
4496 mi[i].ti.text_is_1byte = true;
4497 mi[i].ti.fg = COLOR_DEFAULT;
4498 mi[i].ti.bg = COLOR_DEFAULT;
4499 mi[i].mid = j;
4500 mi[i].invoke = BVMenuRotateInvoked;
4501 }
4502 if ( bv->fv->b.sf->onlybitmaps ) {
4503 mi[i].ti.fg = COLOR_DEFAULT;
4504 mi[i].ti.bg = COLOR_DEFAULT;
4505 mi[i++].ti.line = true;
4506 mi[i].ti.text = (unichar_t *) _("Set _Width...");
4507 mi[i].ti.text_is_1byte = true;
4508 mi[i].ti.text_in_resource = true;
4509 mi[i].ti.fg = COLOR_DEFAULT;
4510 mi[i].ti.bg = COLOR_DEFAULT;
4511 mi[i].mid = bvt_setwidth;
4512 mi[i].invoke = BVPopupInvoked;
4513 }
4514 bv->had_control = (event->u.mouse.state&ksm_control)?1:0;
4515 GMenuCreatePopupMenu(bv->v,event, mi);
4516 }
4517
4518 static void BVPaletteCheck(BitmapView *bv) {
4519 if ( bvtools==NULL ) {
4520 BVMakeTools(bv);
4521 BVMakeLayers(bv);
4522 BVMakeShades(bv);
4523 }
4524 }
4525
4526 int BVPaletteIsVisible(BitmapView *bv,int which) {
4527 BVPaletteCheck(bv);
4528 if ( which==1 )
4529 return( bvtools!=NULL && GDrawIsVisible(bvtools) );
4530 if ( which==2 )
4531 return( bvshades!=NULL && GDrawIsVisible(bvshades) );
4532
4533 return( bvlayers!=NULL && GDrawIsVisible(bvlayers) );
4534 }
4535
4536 void BVPaletteSetVisible(BitmapView *bv,int which,int visible) {
4537 BVPaletteCheck(bv);
4538 if ( which==1 && bvtools!=NULL)
4539 SetPaletteVisible(bv->gw, bvtools, visible );
4540 else if ( which==2 && bvshades!=NULL)
4541 SetPaletteVisible(bv->gw, bvshades, visible );
4542 else if ( which==0 && bvlayers!=NULL )
4543 SetPaletteVisible(bv->gw, bvlayers, visible );
4544 bvvisible[which] = visible;
4545 SavePrefs(true);
4546 }
4547
4548 static void _BVPaletteActivate(BitmapView *bv, int force, int docking_changed) {
4549 BitmapView *old;
4550
4551 BVPaletteCheck(bv);
4552 if ( ((old = GDrawGetUserData(bvtools)) != bv) || force ) {
4553 if ( old!=NULL ) {
4554 SaveOffsets(old->gw,bvtools,&bvtoolsoff);
4555 SaveOffsets(old->gw,bvlayers,&bvlayersoff);
4556 SaveOffsets(old->gw,bvshades,&bvshadesoff);
4557 }
4558
4559 if ((palettes_docked && old != bv) || docking_changed) {
4560 // Recreate the bvtools if docked, similar to cvtools
4561 GDrawDestroyWindow(bvtools);
4562 GDrawDestroyWindow(bvlayers);
4563 GDrawDestroyWindow(bvshades);
4564 bvtools = bvlayers = bvshades = NULL;
4565 BVPaletteCheck(bv);
4566 }
4567
4568 GDrawSetUserData(bvtools,bv);
4569 GDrawSetUserData(bvlayers,bv);
4570 GDrawSetUserData(bvshades,bv);
4571
4572 if (palettes_docked) {
4573 if (bvvisible[0])
4574 GDrawRequestExpose(bvlayers, NULL, false);
4575 if (bvvisible[1])
4576 GDrawRequestExpose(bvtools, NULL, false);
4577 if (bvvisible[2])
4578 GDrawRequestExpose(bvshades, NULL, false);
4579 } else {
4580 if ( bvvisible[0])
4581 RestoreOffsets(bv->gw,bvlayers,&bvlayersoff);
4582 if ( bvvisible[1])
4583 RestoreOffsets(bv->gw,bvtools,&bvtoolsoff);
4584 if ( bvvisible[2] && !bv->shades_hidden )
4585 RestoreOffsets(bv->gw,bvshades,&bvshadesoff);
4586 }
4587 SetPaletteVisible(bv->gw, bvtools, bvvisible[1]);
4588 SetPaletteVisible(bv->gw, bvlayers, bvvisible[0]);
4589 SetPaletteVisible(bv->gw, bvshades, bvvisible[2] && bv->bdf->clut!=NULL);
4590 if ( bvvisible[1]) {
4591 bv->showing_tool = bvt_none;
4592 BVToolsSetCursor(bv,0,NULL);
4593 GDrawRequestExpose(bvtools,NULL,false);
4594 }
4595 if ( bvvisible[0])
4596 BVLayersSet(bv);
4597 if ( bvvisible[2] && !bv->shades_hidden )
4598 GDrawRequestExpose(bvtools,NULL,false);
4599 }
4600 if ( cvtools!=NULL ) {
4601 CharView *cv = GDrawGetUserData(cvtools);
4602 if ( cv!=NULL ) {
4603 SaveOffsets(cv->gw,cvtools,&cvtoolsoff);
4604 SaveOffsets(cv->gw,cvlayers,&cvlayersoff);
4605 GDrawSetUserData(cvtools,NULL);
4606 if ( cvlayers!=NULL )
4607 GDrawSetUserData(cvlayers,NULL);
4608 if ( cvlayers2!=NULL )
4609 GDrawSetUserData(cvlayers2,NULL);
4610 }
4611 SetPaletteVisible(NULL, cvtools, false);
4612 if ( cvlayers!=NULL )
4613 SetPaletteVisible(NULL, cvlayers, false);
4614 if ( cvlayers2!=NULL )
4615 SetPaletteVisible(NULL, cvlayers2, false);
4616 }
4617 }
4618
4619 void BVPaletteActivate(BitmapView *bv) {
4620 _BVPaletteActivate(bv, false, false);
4621 }
4622
4623 void BVPalettesHideIfMine(BitmapView *bv) {
4624 if ( bvtools==NULL )
4625 return;
4626 if ( GDrawGetUserData(bvtools)==bv ) {
4627 SaveOffsets(bv->gw,bvtools,&bvtoolsoff);
4628 SaveOffsets(bv->gw,bvlayers,&bvlayersoff);
4629 SaveOffsets(bv->gw,bvshades,&bvshadesoff);
4630 SetPaletteVisible(NULL, bvtools, false);
4631 SetPaletteVisible(NULL, bvlayers, false);
4632 SetPaletteVisible(NULL, bvshades, false);
4633 GDrawSetUserData(bvtools,NULL);
4634 GDrawSetUserData(bvlayers,NULL);
4635 GDrawSetUserData(bvshades,NULL);
4636 }
4637 }
4638
4639 void CVPaletteDeactivate(void) {
4640 if ( cvtools!=NULL ) {
4641 CharView *cv = GDrawGetUserData(cvtools);
4642 if ( cv!=NULL ) {
4643 SaveOffsets(cv->gw,cvtools,&cvtoolsoff);
4644 GDrawSetUserData(cvtools,NULL);
4645 if ( cv->b.sc->parent->multilayer && cvlayers2!=NULL ) {
4646 SaveOffsets(cv->gw,cvlayers2,&cvlayersoff);
4647 GDrawSetUserData(cvlayers2,NULL);
4648 } else if ( cvlayers!=NULL ) {
4649 SaveOffsets(cv->gw,cvlayers,&cvlayersoff);
4650 GDrawSetUserData(cvlayers,NULL);
4651 }
4652 }
4653 SetPaletteVisible(NULL, cvtools, false);
4654 if ( cvlayers!=NULL )
4655 SetPaletteVisible(NULL, cvlayers, false);
4656 if ( cvlayers2!=NULL )
4657 SetPaletteVisible(NULL, cvlayers2, false);
4658 }
4659 if ( bvtools!=NULL ) {
4660 BitmapView *bv = GDrawGetUserData(bvtools);
4661 if ( bv!=NULL ) {
4662 SaveOffsets(bv->gw,bvtools,&bvtoolsoff);
4663 SaveOffsets(bv->gw,bvlayers,&bvlayersoff);
4664 SaveOffsets(bv->gw,bvshades,&bvshadesoff);
4665 GDrawSetUserData(bvtools,NULL);
4666 GDrawSetUserData(bvlayers,NULL);
4667 GDrawSetUserData(bvshades,NULL);
4668 }
4669 SetPaletteVisible(NULL, bvtools, false);
4670 SetPaletteVisible(NULL, bvlayers, false);
4671 SetPaletteVisible(NULL, bvshades, false);
4672 }
4673 }
4674
4675 void BVPaletteColorChange(BitmapView *bv) {
4676 if ( bvshades!=NULL )
4677 GDrawRequestExpose(bvshades,NULL,false);
4678 GDrawRequestExpose(bv->gw,NULL,false);
4679 }
4680
4681 void BVPaletteColorUnderChange(BitmapView *bv,int color_under) {
4682 if ( bvshades!=NULL && color_under!=bv->color_under_cursor ) {
4683 bv->color_under_cursor = color_under;
4684 GDrawRequestExpose(bvshades,NULL,false);
4685 }
4686 }
4687
4688 void BVPaletteChangedChar(BitmapView *bv) {
4689 if ( bvshades!=NULL && bvvisible[2]) {
4690 int hidden = bv->bdf->clut==NULL;
4691 if ( hidden!=bv->shades_hidden ) {
4692 SetPaletteVisible(bv->gw, bvshades, !hidden);
4693 bv->shades_hidden = hidden;
4694 GDrawRequestExpose(bv->gw,NULL,false);
4695 } else
4696 GDrawRequestExpose(bvshades,NULL,false);
4697 }
4698 }
4699
4700 void PalettesChangeDocking() {
4701 palettes_docked = !palettes_docked;
4702
4703 if (cvtools != NULL)
4704 _CVPaletteActivate((CharView*)GDrawGetUserData(cvtools), true, true);
4705 if (bvtools != NULL)
4706 _BVPaletteActivate((BitmapView*)GDrawGetUserData(bvtools), true, true);
4707
4708 SavePrefs(true);
4709 }
4710
4711 int BVPalettesWidth(void) {
4712 return( GGadgetScale(BV_LAYERS_WIDTH));
4713 }