4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
33 #include "UI_resources.h"
34 #include "RNA_types.h"
39 struct uiHandleButtonData;
41 struct wmOperatorType;
44 struct uiWidgetColors;
51 /* ****************** general defines ************** */
53 /* visual types for drawing */
54 /* for time being separated from functional types */
71 UI_WTYPE_POINTER_LINK,
76 UI_WTYPE_MENU_ICON_RADIO,
77 UI_WTYPE_MENU_POINTER_LINK,
97 #define UI_MAX_DRAW_STR 400
98 #define UI_MAX_NAME_STR 128
101 #define UI_PANEL_MINX 100
102 #define UI_PANEL_MINY 70
105 #define UI_SELECT 1 /* use when the button is pressed */
106 /*#define UI_MOUSE_OVER 2*/ /*UNUSED, free flag*/
108 #define UI_HAS_ICON 8
109 #define UI_TEXTINPUT 16
111 /* warn: rest of uiBut->flag in UI_interface.h */
113 /* internal panel drawing defines */
115 #define PNL_HEADER 20
119 #define PNL_CLOSEDX 2
120 #define PNL_CLOSEDY 4
122 /*#define PNL_TABBED 8*/ /*UNUSED*/
123 #define PNL_OVERLAP 16
125 /* Button text selection:
126 * extension direction, selextend, inside ui_do_but_TEX */
127 #define EXTEND_LEFT 1
128 #define EXTEND_RIGHT 2
130 /* for scope resize zone */
131 #define SCOPE_RESIZE_PAD 9
140 typedef struct uiLinkLine { /* only for draw/edit */
141 struct uiLinkLine *next, *prev;
145 struct uiBut *from, *to;
149 void **poin; /* pointer to original pointer */
150 void ***ppoin; /* pointer to original pointer-array */
151 short *totlink; /* if pointer-array, here is the total */
154 short fromcode, tocode;
160 struct uiBut *next, *prev;
161 short type, pointype, bit, bitnr, retval, strwidth, ofs, pos, selsta, selend;
166 char strdata[UI_MAX_NAME_STR];
167 char drawstr[UI_MAX_DRAW_STR];
169 float x1, y1, x2, y2;
172 float hardmin, hardmax, softmin, softmax;
177 uiButHandleFunc func;
182 uiButHandleNFunc funcN;
185 struct bContextStore *context;
187 /* not ysed yet, was used in 2.4x for ui_draw_pulldown_round & friends */
189 void (*embossfunc)(int , int , float, float, float, float, float, int);
190 void (*sliderfunc)(int , float, float, float, float, float, float, int);
193 uiButCompleteFunc autocomplete_func;
196 uiButSearchFunc search_func;
199 uiButHandleRenameFunc rename_func;
206 const char *tip, *lockstr;
211 char changed; /* could be made into a single flag */
212 unsigned char unit_type; /* so buttons can support unit systems which are not RNA */
217 uiIDPoinFuncFP idpoin_func;
221 uiBlockCreateFunc block_create_func;
223 /* PULLDOWN/MENU data */
224 uiMenuCreateFunc menu_create_func;
227 struct PointerRNA rnapoin;
228 struct PropertyRNA *rnaprop;
231 struct PointerRNA rnasearchpoin;
232 struct PropertyRNA *rnasearchprop;
235 struct wmOperatorType *optype;
236 struct IDProperty *opproperties;
237 struct PointerRNA *opptr;
239 unsigned char menu_key; /* 'a'-'z', always lower case */
241 /* Draggable data, type is WM_DRAG_... */
247 /* active button data */
248 struct uiHandleButtonData *active;
261 uiBlock *next, *prev;
268 struct uiLayout *curlayout;
272 char name[UI_MAX_NAME_STR];
276 float minx, miny, maxx, maxy;
281 uiButHandleFunc func;
285 uiButHandleNFunc funcN;
288 uiMenuHandleFunc butm_func;
291 uiBlockHandleFunc handle_func;
292 void *handle_func_arg;
294 /* custom extra handling */
295 int (*block_event_func)(const struct bContext *C, struct uiBlock *, struct wmEvent *);
297 /* extra draw function for custom blocks */
298 void (*drawextra)(const struct bContext *C, void *idv, void *arg1, void *arg2, rcti *rect);
299 void *drawextra_arg1;
300 void *drawextra_arg2;
305 double auto_open_last;
310 char active; // to keep blocks while drawing and free them afterwards
311 char tooltipdisabled; // to avoid tooltip after click
312 char endblock; // uiEndBlock done?
314 float xofs, yofs; // offset to parent button
315 int dobounds, mx, my; // for doing delayed
316 int bounds, minbounds; // for doing delayed
318 rctf safety; // pulldowns, to detect outside, can differ per case how it is created
319 ListBase saferct; // uiSafetyRct list
321 uiPopupBlockHandle *handle; // handle
323 int puphash; // popup menu hash for memory
325 void *evil_C; // XXX hack for dynamic operator enums
327 float _hsv[3]; // XXX, only access via ui_block_hsv_get()
328 char color_profile; // color profile for correcting linear colors for display
331 typedef struct uiSafetyRct {
332 struct uiSafetyRct *next, *prev;
339 extern void ui_delete_linkline(uiLinkLine *line, uiBut *but);
341 extern int ui_translate_buttons(void);
342 extern int ui_translate_menus(void);
343 extern int ui_translate_tooltips(void);
345 void ui_fontscale(short *points, float aspect);
347 extern void ui_block_to_window_fl(const struct ARegion *ar, uiBlock *block, float *x, float *y);
348 extern void ui_block_to_window(const struct ARegion *ar, uiBlock *block, int *x, int *y);
349 extern void ui_block_to_window_rct(const struct ARegion *ar, uiBlock *block, rctf *graph, rcti *winr);
350 extern void ui_window_to_block_fl(const struct ARegion *ar, uiBlock *block, float *x, float *y);
351 extern void ui_window_to_block(const struct ARegion *ar, uiBlock *block, int *x, int *y);
352 extern void ui_window_to_region(const ARegion *ar, int *x, int *y);
354 extern double ui_get_but_val(uiBut *but);
355 extern void ui_set_but_val(uiBut *but, double value);
356 extern void ui_set_but_hsv(uiBut *but);
357 extern void ui_get_but_vectorf(uiBut *but, float *vec);
358 extern void ui_set_but_vectorf(uiBut *but, float *vec);
360 extern void ui_hsvcircle_vals_from_pos(float *valrad, float *valdist, rcti *rect, float mx, float my);
362 extern void ui_get_but_string(uiBut *but, char *str, int maxlen);
363 extern void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen);
364 extern int ui_set_but_string(struct bContext *C, uiBut *but, const char *str);
365 extern int ui_get_but_string_max_length(uiBut *but);
367 extern void ui_set_but_default(struct bContext *C, uiBut *but);
369 extern void ui_set_but_soft_range(uiBut *but, double value);
371 extern void ui_check_but(uiBut *but);
372 extern int ui_is_but_float(uiBut *but);
373 extern int ui_is_but_unit(uiBut *but);
375 extern void ui_bounds_block(uiBlock *block);
376 extern void ui_block_translate(uiBlock *block, int x, int y);
377 extern void ui_block_do_align(uiBlock *block);
379 /* interface_regions.c */
381 struct uiPopupBlockHandle {
383 struct ARegion *region;
384 int towardsx, towardsy;
389 void (*popup_func)(struct bContext *C, void *arg, int event);
390 void (*cancel_func)(void *arg);
393 /* for operator popups */
394 struct wmOperatorType *optype;
406 uiBlock *ui_block_func_COL(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but);
407 void ui_block_func_ICONROW(struct bContext *C, uiLayout *layout, void *arg_but);
408 void ui_block_func_ICONTEXTROW(struct bContext *C, uiLayout *layout, void *arg_but);
410 struct ARegion *ui_tooltip_create(struct bContext *C, struct ARegion *butregion, uiBut *but);
411 void ui_tooltip_free(struct bContext *C, struct ARegion *ar);
413 uiBut *ui_popup_menu_memory(uiBlock *block, uiBut *but);
415 float *ui_block_hsv_get(uiBlock *block);
417 /* searchbox for string button */
418 ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, uiBut *but);
419 int ui_searchbox_inside(struct ARegion *ar, int x, int y);
420 void ui_searchbox_update(struct bContext *C, struct ARegion *ar, uiBut *but, int reset);
421 void ui_searchbox_autocomplete(struct bContext *C, struct ARegion *ar, uiBut *but, char *str);
422 void ui_searchbox_event(struct bContext *C, struct ARegion *ar, uiBut *but, struct wmEvent *event);
423 void ui_searchbox_apply(uiBut *but, struct ARegion *ar);
424 void ui_searchbox_free(struct bContext *C, struct ARegion *ar);
425 void ui_but_search_test(uiBut *but);
427 typedef uiBlock* (*uiBlockHandleCreateFunc)(struct bContext *C, struct uiPopupBlockHandle *handle, void *arg1);
429 uiPopupBlockHandle *ui_popup_block_create(struct bContext *C, struct ARegion *butregion, uiBut *but,
430 uiBlockCreateFunc create_func, uiBlockHandleCreateFunc handle_create_func, void *arg);
431 uiPopupBlockHandle *ui_popup_menu_create(struct bContext *C, struct ARegion *butregion, uiBut *but,
432 uiMenuCreateFunc create_func, void *arg, char *str);
434 void ui_popup_block_free(struct bContext *C, uiPopupBlockHandle *handle);
436 void ui_set_name_menu(uiBut *but, int value);
437 int ui_step_name_menu(uiBut *but, int step);
441 /* interface_panel.c */
442 extern int ui_handler_panel_region(struct bContext *C, struct wmEvent *event);
443 extern void ui_draw_aligned_panel(struct uiStyle *style, uiBlock *block, rcti *rect);
445 /* interface_draw.c */
446 extern void ui_dropshadow(rctf *rct, float radius, float aspect, int select);
448 void ui_draw_gradient(rcti *rect, float *hsv, int type, float alpha);
450 void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
451 void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
452 void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
453 void ui_draw_but_COLORBAND(uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
454 void ui_draw_but_NORMAL(uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
455 void ui_draw_but_CURVE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
456 void ui_draw_but_IMAGE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
458 /* interface_handlers.c */
459 extern void ui_button_activate_do(struct bContext *C, struct ARegion *ar, uiBut *but);
460 extern void ui_button_active_free(const struct bContext *C, uiBut *but);
461 extern int ui_button_is_active(struct ARegion *ar);
463 /* interface_widgets.c */
464 void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3);
465 void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect);
466 void ui_draw_search_back(struct uiStyle *style, uiBlock *block, rcti *rect);
467 int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol);
468 void ui_draw_link_bezier(rcti *rect);
470 extern void ui_draw_but(const struct bContext *C, ARegion *ar, struct uiStyle *style, uiBut *but, rcti *rect);
471 /* theme color init */
473 void ui_widget_color_init(struct ThemeUI *tui);
475 void ui_draw_menu_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state);
476 void ui_draw_preview_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state);
478 /* interface_style.c */
479 void uiStyleInit(void);
481 /* interface_icons.c */
482 int ui_id_icon_get(struct bContext *C, struct ID *id, int preview);
485 void init_userdef_do_versions(void);
486 void ui_theme_init_default(void);
487 void ui_resources_init(void);
488 void ui_resources_free(void);
490 /* interface_layout.c */
491 void ui_layout_add_but(uiLayout *layout, uiBut *but);
492 int ui_but_can_align(uiBut *but);
493 void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop);
495 /* interface_anim.c */
496 void ui_but_anim_flag(uiBut *but, float cfra);
497 void ui_but_anim_insert_keyframe(struct bContext *C);
498 void ui_but_anim_delete_keyframe(struct bContext *C);
499 void ui_but_anim_add_driver(struct bContext *C);
500 void ui_but_anim_remove_driver(struct bContext *C);
501 void ui_but_anim_copy_driver(struct bContext *C);
502 void ui_but_anim_paste_driver(struct bContext *C);
503 void ui_but_anim_add_keyingset(struct bContext *C);
504 void ui_but_anim_remove_keyingset(struct bContext *C);
505 int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen);
506 int ui_but_anim_expression_set(uiBut *but, const char *str);
507 void ui_but_anim_autokey(struct bContext *C, uiBut *but, struct Scene *scene, float cfra);