Debian Codegraph @

inc/gdraw.h

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 #ifndef FONTFORGE_GDRAW_H
29 #define FONTFORGE_GDRAW_H
30
31 #include "gimage.h"
32 #include "gresource.h"
33
34 typedef struct font_instance FontInstance, GFont;
35 enum gic_style { gic_overspot=2, gic_root=1, gic_hidden=0, gic_orlesser=4, gic_type=3 };
36 typedef struct ginput_context GIC;
37
38 typedef struct ggc {
39 struct gwindow *w;
40 Color fg;
41 Color bg;
42 GRect clip;
43 unsigned int bitmap_col: 1; /* window is mapped for bitmap */
44 int16_t skip_len, dash_len;
45 int16_t line_width;
46 int16_t ts;
47 int32_t ts_xoff, ts_yoff;
48 int dash_offset;
49 GFont *fi;
50 } GGC;
51
52 typedef struct gtextbounds {
53 int16_t lbearing; /* of first character */
54 /* origin to left edge of first char's raster */
55 int32_t rbearing; /* origin to right edge of last char's raster */
56 int16_t as,ds; /* maximum ascent and maximum descent */
57 /* (both numbers will be positive for "g" */
58 /* so total height = as+ds */
59 int16_t fas, fds; /* font ascent and descent */
60 /* total width = rbearing-lbearing */
61 int32_t width; /* above are for the bounding rect, not the text */
62 /* "width" which may be totally different */
63 } GTextBounds;
64
65 enum selnames { sn_primary, sn_clipboard, sn_drag_and_drop, sn_user1, sn_user2, sn_max };
66 typedef struct gwindow *GWindow;
67 typedef struct gdisplay GDisplay;
68 typedef struct gtimer GTimer;
69
70 enum keystate_mask { ksm_shift=1, ksm_capslock=2, ksm_control=4, ksm_meta=8,
71 ksm_cmdsuse=0x8,
72 /* Suse X on a Mac maps command to meta. As of Mac 10.2, the command key is 0x10 */
73 /* In 10.0 the command key was 0x20 */
74 ksm_cmdmacosx=0x10, /* But not the command key under suse ppc linux*/
75 ksm_numlock=0x10, /* It's numlock on my 386 system */
76 ksm_super=0x40, /* RedHat mask for the key with the windows flag on it */
77 ksm_hyper=0x80,
78 /* Both Suse and Mac OS/X.2 now map option to 0x2000, but under 10.0 it was meta */
79 /* Under 10.4 it is the meta mask again */
80 /* Under 10.6 it is 0x2000 again. I wish they'd be consistent */
81 ksm_option=0x2000, /* sometimes */
82 ksm_menumask=(ksm_control|ksm_meta|ksm_cmdmacosx|0xf0),
83
84 ksm_button1=(1<<8), ksm_button2=(1<<9), ksm_button3=(1<<10),
85 ksm_button4=(1<<11), ksm_button5=(1<<12),
86 ksm_buttons=(ksm_button1|ksm_button2|ksm_button3|ksm_button4|ksm_button5)
87 };
88 enum mnemonic_focus { mf_normal, mf_tab, mf_mnemonic, mf_shortcut };
89
90 enum event_type { et_noevent = -1, et_char, et_charup, // is 1
91 et_mousemove, et_mousedown, et_mouseup,
92 et_crossing, /* these four are assumed to be consecutive */
93 et_focus, // is 7
94 et_expose, et_visibility, et_resize, et_timer,
95 et_close/*request by user*/, et_create,
96 et_map, et_destroy/*window being freed*/,
97 et_selclear,
98 et_drag, et_dragout, et_drop,
99 et_lastnativeevent=et_drop,
100 et_controlevent, et_user };
101
102 enum visibility_state { vs_unobscured, vs_partially, vs_obscured };
103
104 enum et_subtype { et_buttonpress, et_buttonactivate, et_radiochanged,
105 et_listselected, et_listdoubleclick,
106 et_scrollbarchange,
107 et_textchanged, et_textfocuschanged,
108 et_save, et_lastsubtype };
109
110 enum sb { et_sb_top, et_sb_uppage, et_sb_up, et_sb_left=et_sb_up,
111 et_sb_down, et_sb_right=et_sb_down, et_sb_downpage,
112 et_sb_bottom,
113 et_sb_thumb, et_sb_thumbrelease, et_sb_halfup, et_sb_halfdown };
114
115 struct sbevent {
116 enum sb type;
117 int32_t pos;
118 };
119
120 typedef struct gevent {
121 enum event_type type;
122 #define _GD_EVT_CHRLEN 10
123 GWindow w;
124 union {
125 struct {
126 char *device; /* for wacom devices */
127 uint32_t time;
128 uint16_t state;
129 int16_t x,y;
130 uint16_t keysym;
131 int16_t autorepeat;
132 unichar_t chars[_GD_EVT_CHRLEN];
133 } chr;
134 struct {
135 char *device; /* for wacom devices */
136 uint32_t time;
137 int16_t state;
138 int16_t x,y;
139 int16_t button;
140 int16_t clicks;
141 int32_t pressure, xtilt, ytilt, separation;
142 } mouse;
143 struct {
144 GRect rect;
145 } expose;
146 struct {
147 enum visibility_state state;
148 } visibility;
149 struct {
150 GRect size;
151 int16_t dx, dy, dwidth, dheight;
152 unsigned int moved: 1;
153 unsigned int sized: 1;
154 } resize;
155 struct {
156 char *device; /* for wacom devices */
157 uint32_t time;
158 int16_t state;
159 int16_t x,y;
160 unsigned int entered: 1;
161 } crossing;
162 struct {
163 unsigned int gained_focus: 1;
164 unsigned int mnemonic_focus: 2;
165 } focus;
166 struct {
167 unsigned int is_visible: 1;
168 } map;
169 struct {
170 enum selnames sel;
171 } selclear;
172 struct {
173 int32_t x,y;
174 } drag_drop;
175 struct {
176 GTimer *timer;
177 void *userdata;
178 } timer;
179 struct {
180 enum et_subtype subtype;
181 struct ggadget *g;
182 union {
183 struct sbevent sb;
184 struct {
185 int gained_focus;
186 } tf_focus;
187 struct {
188 int from_pulldown; /* -1 normally, else index into pulldown list */
189 } tf_changed;
190 struct {
191 int clicks;
192 int16_t button, state;
193 } button;
194 struct {
195 int from_mouse, changed_index;
196 } list;
197 } u;
198 } control;
199 struct {
200 long subtype;
201 void *userdata;
202 } user;
203 } u;
204 void *native_window;
205 } GEvent;
206
207 typedef enum cursor_types { ct_default, ct_pointer, ct_backpointer, ct_hand,
208 ct_question, ct_cross, ct_4way, ct_text, ct_watch, ct_draganddrop,
209 ct_invisible,
210 ct_user, ct_user2 /* and so on */ } GCursor;
211
212 enum window_attr_mask { wam_events=0x2, wam_bordwidth=0x4,
213 wam_bordcol=0x8, wam_backcol=0x10, wam_cursor=0x20, wam_wtitle=0x40,
214 wam_ititle=0x80, wam_icon=0x100, wam_nodecor=0x200,
215 wam_positioned=0x400, wam_centered=0x800, wam_undercursor=0x1000,
216 wam_noresize=0x2000, wam_restrict=0x4000, wam_redirect=0x8000,
217 wam_isdlg=0x10000, wam_notrestricted=0x20000,
218 wam_transient=0x40000,
219 wam_utf8_wtitle=0x80000, wam_utf8_ititle=0x100000,
220 wam_nocairo=0x200000, wam_verytransient=0x400000, wam_palette=0x800000 };
221
222 #ifdef __cplusplus
223 extern "C++" {
224 inline enum window_attr_mask operator|(enum window_attr_mask lhs, enum window_attr_mask rhs) {
225 return static_cast<enum window_attr_mask>(static_cast<int>(lhs) |
226 static_cast<int>(rhs));
227 }
228 }
229 #endif
230
231 typedef struct gwindow_attrs {
232 enum window_attr_mask mask;
233 uint32_t event_masks; /* (1<<et_char) | (1<<et_mouseup) etc */
234 int16_t border_width;
235 Color border_color; /* Color_UNKNOWN if unspecified */
236 Color background_color;
237 GCursor cursor;
238 /* Remainder is only for top level windows */
239 const unichar_t *window_title;
240 const unichar_t *icon_title;
241 struct gwindow *icon; /* A bitmap pixmap, or NULL */
242 unsigned int nodecoration: 1; /* no wm decoration */
243 unsigned int positioned: 1; /* position information is important */
244 unsigned int centered: 2; /* center the window on the screen. pos.width&pos.height are used */
245 unsigned int undercursor: 1; /* center the window under the cursor. */
246 unsigned int noresize: 1; /* set min and max sizes to current size */
247 unsigned int restrict_input_to_me: 1;/* for dialogs, no input outside of dlg */
248 unsigned int redirect_chars_to_me: 1;/* ditto, we get any input outside of us */
249 unsigned int is_dlg: 1; /* 1 for dlg, 0 for main window */
250 unsigned int not_restricted: 1; /* gets events if if a restricted (modal) dlg is up */
251 GWindow redirect_from; /* only redirect input from this window and its children */
252 GWindow transient; /* the Transient_FOR hint */
253 const char *utf8_window_title;
254 const char *utf8_icon_title;
255 } GWindowAttrs;
256
257 #define GWINDOWATTRS_EMPTY { 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
258
259 typedef struct gdeveventmask {
260 int event_mask;
261 char *device_name;
262 } GDevEventMask;
263
264 enum gzoom_flags { gzf_pos=1, gzf_size=2 };
265
266 typedef int (*GDrawEH)(GWindow,GEvent *);
267
268 extern Color _GDraw_res_fg, _GDraw_res_bg, _GDraw_res_warnfg;
269 extern int _GDraw_res_res, _GDraw_res_multiclicktime, _GDraw_res_multiclickwiggle;
270 extern int _GDraw_res_selnottime, _GDraw_res_twobuttonfixup, _GDraw_res_macosxcmd;
271 extern int _GDraw_res_synchronize;
272
273 extern unichar_t *GDrawKeysyms[];
274 extern GDisplay *screen_display;
275
276 extern void GDrawResourceFind(void);
277
278 extern void GDrawDestroyDisplays(void);
279 extern void GDrawCreateDisplays(char *displayname,char *programname);
280
281 extern int GDrawPointsToPixels(GWindow gw,int points);
282 extern int GDrawPixelsToPoints(GWindow gw,int pixels);
283
284 extern void GDrawSetDefaultIcon(GWindow icon);
285 extern GWindow GDrawCreateTopWindow(GDisplay *gdisp, GRect *pos, int (*eh)(GWindow,GEvent *), void *user_data, GWindowAttrs *wattrs);
286 extern GWindow GDrawCreateSubWindow(GWindow w, GRect *pos, int (*eh)(GWindow,GEvent *), void *user_data, GWindowAttrs *wattrs);
287 extern GWindow GDrawCreatePixmap(GDisplay *gdisp, GWindow similar, uint16_t width, uint16_t height);
288 extern GWindow GDrawCreateBitmap(GDisplay *gdisp, uint16_t width, uint16_t height, uint8_t *data);
289 extern GCursor GDrawCreateCursor(GWindow src,GWindow mask,Color fg,Color bg,
290 int16_t x, int16_t y );
291 extern void GDrawDestroyWindow(GWindow w);
292 extern int GDrawNativeWindowExists(GDisplay *gdisp, void *native);
293 extern void GDrawSetZoom(GWindow w, GRect *zoomsize, enum gzoom_flags);
294 extern void GDrawSetWindowBackground(GWindow w, Color color);
295
296 /**
297 * Set the window type to the given name.
298 *
299 * You should not free the 'name' string, it is assumed to exist for
300 * the lifetime of the fontforge run, for example, as a constant
301 * string. No copy of name is performed.
302 */
303 extern void GDrawSetWindowTypeName(GWindow w, char* name);
304 /**
305 * Get the window type string that was set with GDrawSetWindowTypeName()
306 * or NULL if no such string was set.
307 *
308 * No memory allocations are performed. You should not free the string
309 * that is returned.
310 */
311 extern char* GDrawGetWindowTypeName(GWindow w);
312 extern int GDrawSetDither(GDisplay *gdisp, int dither);
313 extern void GDrawSetVisible(GWindow w, int visible);
314 extern int GDrawIsVisible(GWindow w);
315 extern void GDrawTrueMove(GWindow w, int32_t x, int32_t y);
316 extern void GDrawMove(GWindow w, int32_t x, int32_t y);
317 extern void GDrawResize(GWindow w, int32_t width, int32_t height);
318 extern void GDrawMoveResize(GWindow w, int32_t x, int32_t y, int32_t width, int32_t height);
319 extern GWindow GDrawGetRoot(GDisplay *);
320 extern Color GDrawGetDefaultBackground(GDisplay *);
321 extern Color GDrawGetDefaultForeground(GDisplay *);
322 extern Color GDrawGetWarningForeground(GDisplay *);
323 extern GRect *GDrawGetSize(GWindow w, GRect *ret);
324 extern GDrawEH GDrawGetEH(GWindow w);
325 extern void GDrawSetEH(GWindow w,GDrawEH e_h);
326 extern void GDrawGetPointerPosition(GWindow w, GEvent *mouse);
327 extern GWindow GDrawGetPointerWindow(GWindow w);
328 extern void GDrawRaise(GWindow w);
329 extern void GDrawSetWindowTitles8(GWindow w, const char *title, const char *icontit);
330 extern char *GDrawGetWindowTitle8(GWindow w);
331 extern void GDrawSetTransientFor(GWindow transient,GWindow owner);
332 extern void GDrawSetCursor(GWindow w, GCursor ct);
333 extern GCursor GDrawGetCursor(GWindow w);
334 extern GWindow GDrawGetParentWindow(GWindow gw);
335 extern int GDrawWindowIsAncestor(GWindow ancester, GWindow descendent);
336 extern void GDrawSetUserData(GWindow gw, void *ud);
337 extern void *GDrawGetUserData(GWindow gw);
338 extern GDisplay *GDrawGetDisplayOfWindow(GWindow);
339 extern void GDrawTranslateCoordinates(GWindow from,GWindow to, GPoint *pt);
340 extern int32_t GDrawEventInWindow(GWindow inme,GEvent *event);
341 extern void GDrawBeep(GDisplay *gdisp);
342 extern void GDrawFlush(GDisplay *gdisp);
343
344 extern bool GDrawClipContains(const GWindow w, const GRect *other, bool rev);
345 extern bool GDrawClipOverlaps(const GWindow w, const GRect *other);
346 extern void GDrawGetClip(GWindow w, GRect *ret);
347 extern void GDrawPushClip(GWindow w, GRect *rct, GRect *old);
348 extern void GDrawPopClip(GWindow w, GRect *old);
349 extern void GDrawPushClipOnly(GWindow w);
350 extern void GDrawClipPreserve(GWindow w);
351 extern void GDrawSetDashedLine(GWindow w,int16_t dash_len, int16_t skip_len, int16_t off);
352 extern void GDrawSetStippled(GWindow w,int16_t ts, int32_t yoff,int32_t xoff);
353 extern void GDrawSetLineWidth(GWindow w,int16_t width);
354 extern int16_t GDrawGetLineWidth( GWindow w );
355
356 extern void GDrawSetBackground(GWindow w,Color col);
357
358 extern GFont *GDrawSetFont(GWindow gw, GFont *fi);
359 extern GFont *GDrawSetDefaultFont(GWindow gw);
360 extern GFont *GDrawInstanciateFont(GWindow gw, FontRequest *rq);
361 extern GFont *GDrawAttachFont(GWindow gw, FontRequest *rq);
362 extern FontRequest *GDrawDecomposeFont(GFont *fi, FontRequest *rq);
363 extern void GDrawWindowFontMetrics(GWindow gw,GFont *fi,int *as, int *ds, int *ld);
364 extern void GDrawDefaultFontMetrics(GWindow gw,int *as, int *ds, int *ld);
365
366 extern int32_t GDrawGetTextBounds(GWindow gw,const unichar_t *text, int32_t cnt, GTextBounds *size);
367 extern int32_t GDrawGetTextWidth(GWindow gw, const unichar_t *text, int32_t cnt);
368 extern int32_t GDrawDrawText(GWindow gw, int32_t x, int32_t y, const unichar_t *txt, int32_t cnt, Color col);
369 /* UTF8 routines */
370 extern int32_t GDrawGetText8Bounds(GWindow gw, const char *text, int32_t cnt, GTextBounds *size);
371 extern int32_t GDrawGetText8Width(GWindow gw, const char *text, int32_t cnt);
372 extern int32_t GDrawGetText8Height(GWindow gw, const char *text, int32_t cnt);
373 extern int32_t GDrawDrawText8(GWindow gw, int32_t x, int32_t y, const char *txt, int32_t cnt, Color col);
374
375 extern GIC *GDrawCreateInputContext(GWindow w,enum gic_style def_style);
376 extern void GDrawSetGIC(GWindow w,GIC *gic,int x, int y);
377 extern int GDrawKeyState(GWindow w, int keysym);
378
379 extern void GDrawDrawLine(GWindow w, int32_t x,int32_t y, int32_t xend,int32_t yend, Color col);
380 extern void GDrawDrawArrow(GWindow w, int32_t x,int32_t y, int32_t xend,int32_t yend, int arrows, Color col);
381 extern void GDrawDrawRect(GWindow w, GRect *rect, Color col);
382 extern void GDrawFillRect(GWindow w, GRect *rect, Color col);
383 extern void GDrawFillRoundRect(GWindow w, GRect *rect, int radius, Color col);
384 extern void GDrawDrawElipse(GWindow w, GRect *rect, Color col);
385 extern void GDrawFillElipse(GWindow w, GRect *rect, Color col);
386 extern void GDrawDrawArc(GWindow w, GRect *rect, int32_t sangle, int32_t tangle, Color col);
387 extern void GDrawDrawPoly(GWindow w, GPoint *pts, int16_t cnt, Color col);
388 extern void GDrawFillPoly(GWindow w, GPoint *pts, int16_t cnt, Color col);
389 extern void GDrawScroll(GWindow w, GRect *rect, int32_t hor, int32_t vert);
390 extern void GDrawDrawImage(GWindow w, GImage *img, GRect *src, int32_t x, int32_t y);
391 extern void GDrawDrawGlyph(GWindow w, GImage *img, GRect *src, int32_t x, int32_t y);
392 extern void GDrawDrawScaledImage(GWindow w, GImage *img, int32_t x, int32_t y);
393 extern void GDrawDrawImageMagnified(GWindow w, GImage *img, GRect *src, int32_t x, int32_t y,
394 int32_t width, int32_t height);
395 extern void GDrawDrawPixmap(GWindow w, GWindow pixmap, GRect *src, int32_t x, int32_t y);
396
397 extern void GDrawGrabSelection(GWindow w,enum selnames sel);
398 extern void GDrawAddSelectionType(GWindow w,enum selnames sel,char *type,
399 void *data,int32_t cnt,int32_t unitsize,void *(*gendata)(void *,int32_t *len),
400 void (*freedata)(void *));
401 extern void *GDrawRequestSelection(GWindow w,enum selnames sn, char *type_name, int32_t *len);
402 extern int GDrawSelectionHasType(GWindow w,enum selnames sn, char *type_name);
403 extern void GDrawBindSelection(GDisplay *disp,enum selnames sel, char *atomname);
404 extern int GDrawSelectionOwned(GDisplay *disp,enum selnames sel);
405
406 extern void GDrawPointerUngrab(GDisplay *disp);
407 extern void GDrawPointerGrab(GWindow w);
408 extern int GDrawEnableExposeRequests(GWindow w,int enabled);
409 extern void GDrawRequestExpose(GWindow w, GRect *rect, int doclear);
410 extern void GDrawSync(GDisplay *gdisp);
411 extern void GDrawForceUpdate(GWindow w);
412 extern void GDrawProcessOneEvent(GDisplay *disp);
413 extern void GDrawProcessPendingEvents(GDisplay *disp);
414 extern void GDrawSkipMouseMoveEvents(GWindow w,GEvent *last);
415 extern void GDrawEventLoop(GDisplay *disp);
416 extern void GDrawPostEvent(GEvent *e);
417 extern void GDrawPostDragEvent(GWindow gw,GEvent *e,enum event_type);
418
419 extern GTimer *GDrawRequestTimer(GWindow w,int32_t time_from_now,int32_t frequency,
420 void *userdata);
421 extern void GDrawCancelTimer(GTimer *timer);
422
423 extern int GDrawRequestDeviceEvents(GWindow w,int devcnt,struct gdeveventmask *de);
424 extern int GDrawShortcutKeyMatches(const GEvent *e, unichar_t ch);
425
426 extern void GDrawPathStartNew(GWindow w);
427 extern void GDrawPathStartSubNew(GWindow w);
428 extern int GDrawFillRuleSetWinding(GWindow w);
429 extern void GDrawPathClose(GWindow w);
430 extern void GDrawPathMoveTo(GWindow w,double x, double y);
431 extern void GDrawPathLineTo(GWindow w,double x, double y);
432 extern void GDrawPathCurveTo(GWindow w,
433 double cx1, double cy1,
434 double cx2, double cy2,
435 double x, double y);
436 extern void GDrawPathStroke(GWindow w,Color col);
437 extern void GDrawPathFill(GWindow w,Color col);
438 extern void GDrawPathFillAndStroke(GWindow w,Color fillcol, Color strokecol);
439
440 extern void GDrawLayoutInit(GWindow w, char *text, int cnt, GFont *fi);
441 extern void GDrawLayoutDraw(GWindow w, int32_t x, int32_t y, Color fg);
442 extern void GDrawLayoutIndexToPos(GWindow w, int index, GRect *pos);
443 extern int GDrawLayoutXYToIndex(GWindow w, int x, int y);
444 extern void GDrawLayoutExtents(GWindow w, GRect *size);
445 extern void GDrawLayoutSetWidth(GWindow w, int width);
446 extern int GDrawLayoutLineCount(GWindow w);
447 extern int GDrawLayoutLineStart(GWindow w,int line);
448
449 extern void GDrawFatalError(const char *fmt,...);
450 extern void GDrawIError(const char *fmt,...);
451 extern void GDrawError(const char *fmt,...);
452
453 extern int GImageGetScaledWidth(GWindow gw, GImage *img);
454 extern int GImageGetScaledHeight(GWindow gw, GImage *img);
455
456 #endif /* FONTFORGE_GDRAW_H */