1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 * 16 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 17 * All rights reserved. 18 */ 19 20 /** \file 21 * \ingroup edinterface 22 */ 23 24 #pragma once 25 26 #include "BLI_compiler_attrs.h" 27 #include "BLI_rect.h" 28 29 #include "DNA_listBase.h" 30 #include "RNA_types.h" 31 #include "UI_interface.h" 32 #include "UI_resources.h" 33 34 struct ARegion; 35 struct AnimationEvalContext; 36 struct CurveMapping; 37 struct CurveProfile; 38 struct ID; 39 struct ImBuf; 40 struct Scene; 41 struct bContext; 42 struct bContextStore; 43 struct uiHandleButtonData; 44 struct uiLayout; 45 struct uiStyle; 46 struct uiUndoStack_Text; 47 struct uiWidgetColors; 48 struct wmEvent; 49 struct wmKeyConfig; 50 struct wmOperatorType; 51 struct wmTimer; 52 53 /* ****************** general defines ************** */ 54 55 #define RNA_NO_INDEX -1 56 #define RNA_ENUM_VALUE -2 57 58 #define UI_MENU_PADDING (int)(0.2f * UI_UNIT_Y) 59 60 #define UI_MENU_WIDTH_MIN (UI_UNIT_Y * 9) 61 /* some extra padding added to menus containing submenu icons */ 62 #define UI_MENU_SUBMENU_PADDING (6 * UI_DPI_FAC) 63 64 /* menu scrolling */ 65 #define UI_MENU_SCROLL_ARROW 12 66 #define UI_MENU_SCROLL_MOUSE (UI_MENU_SCROLL_ARROW + 2) 67 #define UI_MENU_SCROLL_PAD 4 68 69 /* panel limits */ 70 #define UI_PANEL_MINX 100 71 #define UI_PANEL_MINY 70 72 73 /* popover width (multiplied by 'U.widget_unit') */ 74 #define UI_POPOVER_WIDTH_UNITS 10 75 76 /* uiBut->flag */ 77 enum { 78 UI_SELECT = (1 << 0), /* use when the button is pressed */ 79 UI_SCROLLED = (1 << 1), /* temp hidden, scrolled away */ 80 UI_ACTIVE = (1 << 2), 81 UI_HAS_ICON = (1 << 3), 82 UI_HIDDEN = (1 << 4), 83 UI_SELECT_DRAW = (1 << 5), /* Display selected, doesn't impact interaction. */ 84 /** Property search filter is active and the button does not match. */ 85 UI_SEARCH_FILTER_NO_MATCH = (1 << 12), 86 /* warn: rest of uiBut->flag in UI_interface.h */ 87 }; 88 89 /* uiBut->dragflag */ 90 enum { 91 UI_BUT_DRAGPOIN_FREE = (1 << 0), 92 }; 93 94 /* but->pie_dir */ 95 typedef enum RadialDirection { 96 UI_RADIAL_NONE = -1, 97 UI_RADIAL_N = 0, 98 UI_RADIAL_NE = 1, 99 UI_RADIAL_E = 2, 100 UI_RADIAL_SE = 3, 101 UI_RADIAL_S = 4, 102 UI_RADIAL_SW = 5, 103 UI_RADIAL_W = 6, 104 UI_RADIAL_NW = 7, 105 } RadialDirection; 106 107 extern const char ui_radial_dir_order[8]; 108 extern const char ui_radial_dir_to_numpad[8]; 109 extern const short ui_radial_dir_to_angle[8]; 110 111 /* internal panel drawing defines */ 112 #define PNL_HEADER (UI_UNIT_Y * 1.2) /* 24 default */ 113 114 /* bit button defines */ 115 /* Bit operations */ 116 #define UI_BITBUT_TEST(a, b) (((a) & (1 << (b))) != 0) 117 #define UI_BITBUT_VALUE_TOGGLED(a, b) ((a) ^ (1 << (b))) 118 #define UI_BITBUT_VALUE_ENABLED(a, b) ((a) | (1 << (b))) 119 #define UI_BITBUT_VALUE_DISABLED(a, b) ((a) & ~(1 << (b))) 120 121 /* bit-row */ 122 #define UI_BITBUT_ROW(min, max) \ 123 (((max) >= 31 ? 0xFFFFFFFF : (1 << ((max) + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0)) 124 125 /* split numbuts by ':' and align l/r */ 126 #define USE_NUMBUTS_LR_ALIGN 127 128 /* Use new 'align' computation code. */ 129 #define USE_UIBUT_SPATIAL_ALIGN 130 131 /* PieMenuData->flags */ 132 enum { 133 /** pie menu item collision is detected at 90 degrees */ 134 UI_PIE_DEGREES_RANGE_LARGE = (1 << 0), 135 /** use initial center of pie menu to calculate direction */ 136 UI_PIE_INITIAL_DIRECTION = (1 << 1), 137 /** pie menu is drag style */ 138 UI_PIE_DRAG_STYLE = (1 << 2), 139 /** mouse not far enough from center position */ 140 UI_PIE_INVALID_DIR = (1 << 3), 141 /** pie menu changed to click style, click to confirm */ 142 UI_PIE_CLICK_STYLE = (1 << 4), 143 /** pie animation finished, do not calculate any more motion */ 144 UI_PIE_ANIMATION_FINISHED = (1 << 5), 145 /** pie gesture selection has been done, now wait for mouse motion to end */ 146 UI_PIE_GESTURE_END_WAIT = (1 << 6), 147 }; 148 149 #define PIE_CLICK_THRESHOLD_SQ 50.0f 150 151 /* max amount of items a radial menu (pie menu) can contain */ 152 #define PIE_MAX_ITEMS 8 153 154 struct uiBut { 155 struct uiBut *next, *prev; 156 157 /* Pointer back to the layout item holding this button. */ 158 uiLayout *layout; 159 int flag, drawflag; 160 eButType type; 161 eButPointerType pointype; 162 short bit, bitnr, retval, strwidth, alignnr; 163 short ofs, pos, selsta, selend; 164 165 char *str; 166 char strdata[UI_MAX_NAME_STR]; 167 char drawstr[UI_MAX_DRAW_STR]; 168 169 rctf rect; /* block relative coords */ 170 171 char *poin; 172 float hardmin, hardmax, softmin, softmax; 173 174 /* both these values use depends on the button type 175 * (polymorphic struct or union would be nicer for this stuff) */ 176 177 /** 178 * For #uiBut.type: 179 * - UI_BTYPE_LABEL: Use `(a1 == 1.0f)` to use a2 as a blending factor (imaginative!). 180 * - UI_BTYPE_SCROLL: Use as scroll size. 181 * - UI_BTYPE_SEARCH_MENU: Use as number or rows. 182 */ 183 float a1; 184 185 /** 186 * For #uiBut.type: 187 * - UI_BTYPE_HSVCIRCLE: Use to store the luminosity. 188 * - UI_BTYPE_LABEL: If `(a1 == 1.0f)` use a2 as a blending factor. 189 * - UI_BTYPE_SEARCH_MENU: Use as number or columns. 190 */ 191 float a2; 192 193 uchar col[4]; 194 195 uiButHandleFunc func; 196 void *func_arg1; 197 void *func_arg2; 198 199 uiButHandleNFunc funcN; 200 void *func_argN; 201 202 struct bContextStore *context; 203 204 uiButCompleteFunc autocomplete_func; 205 void *autofunc_arg; 206 207 uiButHandleRenameFunc rename_func; 208 void *rename_arg1; 209 void *rename_orig; 210 211 /** Run an action when holding the button down. */ 212 uiButHandleHoldFunc hold_func; 213 void *hold_argN; 214 215 const char *tip; 216 uiButToolTipFunc tip_func; 217 void *tip_argN; 218 219 /** info on why button is disabled, displayed in tooltip */ 220 const char *disabled_info; 221 222 BIFIconID icon; 223 /** emboss: UI_EMBOSS, UI_EMBOSS_NONE ... etc, copied from the #uiBlock.emboss */ 224 char emboss; 225 /** direction in a pie menu, used for collision detection (RadialDirection) */ 226 signed char pie_dir; 227 /** could be made into a single flag */ 228 bool changed; 229 /** so buttons can support unit systems which are not RNA */ 230 uchar unit_type; 231 short modifier_key; 232 short iconadd; 233 234 /* UI_BTYPE_BLOCK data */ 235 uiBlockCreateFunc block_create_func; 236 237 /* UI_BTYPE_PULLDOWN/UI_BTYPE_MENU data */ 238 uiMenuCreateFunc menu_create_func; 239 240 uiMenuStepFunc menu_step_func; 241 242 /* RNA data */ 243 struct PointerRNA rnapoin; 244 struct PropertyRNA *rnaprop; 245 int rnaindex; 246 247 /* Operator data */ 248 struct wmOperatorType *optype; 249 struct PointerRNA *opptr; 250 short opcontext; 251 uchar menu_key; /* 'a'-'z', always lower case */ 252 253 ListBase extra_op_icons; /* uiButExtraOpIcon */ 254 255 /* Draggable data, type is WM_DRAG_... */ 256 char dragtype; 257 short dragflag; 258 void *dragpoin; 259 struct ImBuf *imb; 260 float imb_scale; 261 262 /* active button data */ 263 struct uiHandleButtonData *active; 264 265 /* Custom button data. */ 266 void *custom_data; 267 268 char *editstr; 269 double *editval; 270 float *editvec; 271 272 uiButPushedStateFunc pushed_state_func; 273 void *pushed_state_arg; 274 275 /* pointer back */ 276 uiBlock *block; 277 }; 278 279 /** Derived struct for #UI_BTYPE_NUM */ 280 typedef struct uiButNumber { 281 uiBut but; 282 283 float step_size; 284 float precision; 285 } uiButNumber; 286 287 /** Derived struct for #UI_BTYPE_COLOR */ 288 typedef struct uiButColor { 289 uiBut but; 290 291 bool is_pallete_color; 292 int palette_color_index; 293 } uiButColor; 294 295 /** Derived struct for #UI_BTYPE_TAB */ 296 typedef struct uiButTab { 297 uiBut but; 298 struct MenuType *menu; 299 } uiButTab; 300 301 /** Derived struct for #UI_BTYPE_SEARCH_MENU */ 302 typedef struct uiButSearch { 303 uiBut but; 304 305 uiButSearchCreateFn popup_create_fn; 306 uiButSearchUpdateFn items_update_fn; 307 void *item_active; 308 309 void *arg; 310 uiButSearchArgFreeFn arg_free_fn; 311 312 uiButSearchContextMenuFn item_context_menu_fn; 313 uiButSearchTooltipFn item_tooltip_fn; 314 315 const char *item_sep_string; 316 317 struct PointerRNA rnasearchpoin; 318 struct PropertyRNA *rnasearchprop; 319 } uiButSearch; 320 321 /** Derived struct for #UI_BTYPE_DECORATOR */ 322 typedef struct uiButDecorator { 323 uiBut but; 324 325 struct PointerRNA rnapoin; 326 struct PropertyRNA *rnaprop; 327 int rnaindex; 328 } uiButDecorator; 329 330 /** Derived struct for #UI_BTYPE_PROGRESS_BAR. */ 331 typedef struct uiButProgressbar { 332 uiBut but; 333 334 /* 0..1 range */ 335 float progress; 336 } uiButProgressbar; 337 338 /** Derived struct for #UI_BTYPE_HSVCUBE. */ 339 typedef struct uiButHSVCube { 340 uiBut but; 341 342 eButGradientType gradient_type; 343 } uiButHSVCube; 344 345 /** Derived struct for #UI_BTYPE_COLORBAND. */ 346 typedef struct uiButColorBand { 347 uiBut but; 348 349 struct ColorBand *edit_coba; 350 } uiButColorBand; 351 352 /** Derived struct for #UI_BTYPE_CURVEPROFILE. */ 353 typedef struct uiButCurveProfile { 354 uiBut but; 355 356 struct CurveProfile *edit_profile; 357 } uiButCurveProfile; 358 359 /** Derived struct for #UI_BTYPE_CURVE. */ 360 typedef struct uiButCurveMapping { 361 uiBut but; 362 363 struct CurveMapping *edit_cumap; 364 eButGradientType gradient_type; 365 } uiButCurveMapping; 366 367 /** 368 * Additional, superimposed icon for a button, invoking an operator. 369 */ 370 typedef struct uiButExtraOpIcon { 371 struct uiButExtraOpIcon *next, *prev; 372 373 BIFIconID icon; 374 struct wmOperatorCallParams *optype_params; 375 376 bool highlighted; 377 } uiButExtraOpIcon; 378 379 typedef struct ColorPicker { 380 struct ColorPicker *next, *prev; 381 /** Color data, may be HSV or HSL. */ 382 float color_data[3]; 383 /** Initial color data (detect changes). */ 384 float color_data_init[3]; 385 bool is_init; 386 /** Cubic saturation for the color wheel. */ 387 bool use_color_cubic; 388 bool use_color_lock; 389 bool use_luminosity_lock; 390 float luminosity_lock_value; 391 } ColorPicker; 392 393 typedef struct ColorPickerData { 394 ListBase list; 395 } ColorPickerData; 396 397 struct PieMenuData { 398 /** store title and icon to allow access when pie levels are created */ 399 const char *title; 400 int icon; 401 402 float pie_dir[2]; 403 float pie_center_init[2]; 404 float pie_center_spawned[2]; 405 float last_pos[2]; 406 double duration_gesture; 407 int flags; 408 /** initial event used to fire the pie menu, store here so we can query for release */ 409 int event; 410 float alphafac; 411 }; 412 413 /* uiBlock.content_hints */ 414 enum eBlockContentHints { 415 /** In a menu block, if there is a single sub-menu button, we add some 416 * padding to the right to put nicely aligned triangle icons there. */ 417 UI_BLOCK_CONTAINS_SUBMENU_BUT = (1 << 0), 418 }; 419 420 /** 421 * A group of button references, used by property search to keep track of sets of buttons that 422 * should be searched together. For example, in property split layouts number buttons and their 423 * labels (and even their decorators) are separate buttons, but they must be searched and 424 * highlighted together. 425 */ 426 typedef struct uiButtonGroup { 427 void *next, *prev; 428 ListBase buttons; /* #LinkData with #uiBut data field. */ 429 short flag; 430 } uiButtonGroup; 431 432 /* #uiButtonGroup.flag. */ 433 typedef enum uiButtonGroupFlag { 434 /** While this flag is set, don't create new button groups for layout item calls. */ 435 UI_BUTTON_GROUP_LOCK = (1 << 0), 436 /** The buttons in this group are inside a panel header. */ 437 UI_BUTTON_GROUP_PANEL_HEADER = (1 << 1), 438 } uiButtonGroupFlag; 439 440 struct uiBlock { 441 uiBlock *next, *prev; 442 443 ListBase buttons; 444 struct Panel *panel; 445 uiBlock *oldblock; 446 447 ListBase butstore; /* UI_butstore_* runtime function */ 448 449 ListBase button_groups; /* #uiButtonGroup. */ 450 451 ListBase layouts; 452 struct uiLayout *curlayout; 453 454 ListBase contexts; 455 456 char name[UI_MAX_NAME_STR]; 457 458 float winmat[4][4]; 459 460 rctf rect; 461 float aspect; 462 463 uint puphash; /* popup menu hash for memory */ 464 465 uiButHandleFunc func; 466 void *func_arg1; 467 void *func_arg2; 468 469 uiButHandleNFunc funcN; 470 void *func_argN; 471 472 uiMenuHandleFunc butm_func; 473 void *butm_func_arg; 474 475 uiBlockHandleFunc handle_func; 476 void *handle_func_arg; 477 478 /* custom extra handling */ 479 int (*block_event_func)(const struct bContext *C, struct uiBlock *, const struct wmEvent *); 480 481 /* extra draw function for custom blocks */ 482 void (*drawextra)(const struct bContext *C, void *idv, void *arg1, void *arg2, rcti *rect); 483 void *drawextra_arg1; 484 void *drawextra_arg2; 485 486 int flag; 487 short alignnr; 488 /** Hints about the buttons of this block. Used to avoid iterating over 489 * buttons to find out if some criteria is met by any. Instead, check this 490 * criteria when adding the button and set a flag here if it's met. */ 491 short content_hints; /* eBlockContentHints */ 492 493 char direction; 494 /** UI_BLOCK_THEME_STYLE_* */ 495 char theme_style; 496 /** UI_EMBOSS, UI_EMBOSS_NONE ... etc, copied to #uiBut.emboss */ 497 char emboss; 498 bool auto_open; 499 char _pad[5]; 500 double auto_open_last; 501 502 const char *lockstr; 503 504 char lock; 505 /** to keep blocks while drawing and free them afterwards */ 506 char active; 507 /** to avoid tooltip after click */ 508 char tooltipdisabled; 509 /** UI_block_end done? */ 510 char endblock; 511 512 /** for doing delayed */ 513 eBlockBoundsCalc bounds_type; 514 /** Offset to use when calculating bounds (in pixels). */ 515 int bounds_offset[2]; 516 /** for doing delayed */ 517 int bounds, minbounds; 518 519 /** pulldowns, to detect outside, can differ per case how it is created */ 520 rctf safety; 521 /** uiSafetyRct list */ 522 ListBase saferct; 523 524 uiPopupBlockHandle *handle; /* handle */ 525 526 /** use so presets can find the operator, 527 * across menus and from nested popups which fail for operator context. */ 528 struct wmOperator *ui_operator; 529 530 /** XXX hack for dynamic operator enums */ 531 void *evil_C; 532 533 /** unit system, used a lot for numeric buttons so include here 534 * rather than fetching through the scene every time. */ 535 struct UnitSettings *unit; 536 /** \note only accessed by color picker templates. */ 537 ColorPickerData color_pickers; 538 539 bool is_color_gamma_picker; /* Block for color picker with gamma baked in. */ 540 541 /** display device name used to display this block, 542 * used by color widgets to transform colors from/to scene linear 543 */ 544 char display_device[64]; 545 546 struct PieMenuData pie_data; 547 }; 548 549 typedef struct uiSafetyRct { 550 struct uiSafetyRct *next, *prev; 551 rctf parent; 552 rctf safety; 553 } uiSafetyRct; 554 555 /* interface.c */ 556 557 void ui_fontscale(short *points, float aspect); 558 559 extern void ui_block_to_window_fl(const struct ARegion *region, 560 uiBlock *block, 561 float *x, 562 float *y); 563 extern void ui_block_to_window(const struct ARegion *region, uiBlock *block, int *x, int *y); 564 extern void ui_block_to_window_rctf(const struct ARegion *region, 565 uiBlock *block, 566 rctf *rct_dst, 567 const rctf *rct_src); 568 extern float ui_block_to_window_scale(const struct ARegion *region, uiBlock *block); 569 extern void ui_window_to_block_fl(const struct ARegion *region, 570 uiBlock *block, 571 float *x, 572 float *y); 573 extern void ui_window_to_block(const struct ARegion *region, uiBlock *block, int *x, int *y); 574 extern void ui_window_to_block_rctf(const struct ARegion *region, 575 uiBlock *block, 576 rctf *rct_dst, 577 const rctf *rct_src); 578 extern void ui_window_to_region(const struct ARegion *region, int *x, int *y); 579 extern void ui_window_to_region_rcti(const struct ARegion *region, 580 rcti *rect_dst, 581 const rcti *rct_src); 582 extern void ui_region_to_window(const struct ARegion *region, int *x, int *y); 583 extern void ui_region_winrct_get_no_margin(const struct ARegion *region, struct rcti *r_rect); 584 585 uiBut *ui_but_change_type(uiBut *but, eButType new_type); 586 587 extern double ui_but_value_get(uiBut *but); 588 extern void ui_but_value_set(uiBut *but, double value); 589 extern void ui_but_hsv_set(uiBut *but); 590 extern void ui_but_v3_get(uiBut *but, float vec[3]); 591 extern void ui_but_v3_set(uiBut *but, const float vec[3]); 592 593 extern void ui_hsvcircle_vals_from_pos( 594 const rcti *rect, const float mx, const float my, float *r_val_rad, float *r_val_dist); 595 extern void ui_hsvcircle_pos_from_vals( 596 const ColorPicker *cpicker, const rcti *rect, const float *hsv, float *xpos, float *ypos); 597 extern void ui_hsvcube_pos_from_vals( 598 const struct uiButHSVCube *hsv_but, const rcti *rect, const float *hsv, float *xp, float *yp); 599 600 extern void ui_but_string_get_ex(uiBut *but, 601 char *str, 602 const size_t maxlen, 603 const int float_precision, 604 const bool use_exp_float, 605 bool *r_use_exp_float) ATTR_NONNULL(1, 2); 606 extern void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) ATTR_NONNULL(); 607 extern char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size); 608 extern void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen) ATTR_NONNULL(); 609 extern bool ui_but_string_set(struct bContext *C, uiBut *but, const char *str) ATTR_NONNULL(); 610 extern bool ui_but_string_eval_number(struct bContext *C, 611 const uiBut *but, 612 const char *str, 613 double *value) ATTR_NONNULL(); 614 extern int ui_but_string_get_max_length(uiBut *but); 615 /* Clear & exit the active button's string. */ 616 extern void ui_but_active_string_clear_and_exit(struct bContext *C, uiBut *but) ATTR_NONNULL(); 617 extern uiBut *ui_but_drag_multi_edit_get(uiBut *but); 618 619 void ui_def_but_icon(uiBut *but, const int icon, const int flag); 620 void ui_def_but_icon_clear(uiBut *but); 621 622 void ui_but_extra_operator_icons_free(uiBut *but); 623 624 extern void ui_but_rna_menu_convert_to_panel_type(struct uiBut *but, const char *panel_type); 625 extern void ui_but_rna_menu_convert_to_menu_type(struct uiBut *but, const char *menu_type); 626 extern bool ui_but_menu_draw_as_popover(const uiBut *but); 627 628 void ui_but_range_set_hard(uiBut *but); 629 void ui_but_range_set_soft(uiBut *but); 630 631 extern void ui_but_update(uiBut *but); 632 extern void ui_but_update_edited(uiBut *but); 633 extern bool ui_but_is_float(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 634 extern bool ui_but_is_bool(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 635 extern bool ui_but_is_unit(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 636 extern bool ui_but_is_compatible(const uiBut *but_a, const uiBut *but_b) ATTR_WARN_UNUSED_RESULT; 637 extern bool ui_but_is_rna_valid(uiBut *but) ATTR_WARN_UNUSED_RESULT; 638 extern bool ui_but_supports_cycling(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 639 640 extern int ui_but_is_pushed_ex(uiBut *but, double *value) ATTR_WARN_UNUSED_RESULT; 641 extern int ui_but_is_pushed(uiBut *but) ATTR_WARN_UNUSED_RESULT; 642 643 void ui_but_override_flag(struct Main *bmain, uiBut *but); 644 645 extern void ui_block_bounds_calc(uiBlock *block); 646 647 extern struct ColorManagedDisplay *ui_block_cm_display_get(uiBlock *block); 648 void ui_block_cm_to_display_space_v3(uiBlock *block, float pixel[3]); 649 650 /* interface_regions.c */ 651 652 struct uiKeyNavLock { 653 /* set when we're using keyinput */ 654 bool is_keynav; 655 /* only used to check if we've moved the cursor */ 656 int event_xy[2]; 657 }; 658 659 typedef uiBlock *(*uiBlockHandleCreateFunc)(struct bContext *C, 660 struct uiPopupBlockHandle *handle, 661 void *arg1); 662 663 struct uiPopupBlockCreate { 664 uiBlockCreateFunc create_func; 665 uiBlockHandleCreateFunc handle_create_func; 666 void *arg; 667 void (*arg_free)(void *arg); 668 669 int event_xy[2]; 670 671 /* when popup is initialized from a button */ 672 struct ARegion *butregion; 673 uiBut *but; 674 }; 675 676 struct uiPopupBlockHandle { 677 /* internal */ 678 struct ARegion *region; 679 680 /* use only for 'UI_BLOCK_MOVEMOUSE_QUIT' popups */ 681 float towards_xy[2]; 682 double towardstime; 683 bool dotowards; 684 685 bool popup; 686 void (*popup_func)(struct bContext *C, void *arg, int event); 687 void (*cancel_func)(struct bContext *C, void *arg); 688 void *popup_arg; 689 690 /* store data for refreshing popups */ 691 struct uiPopupBlockCreate popup_create_vars; 692 /* true if we can re-create the popup using 'popup_create_vars' */ 693 bool can_refresh; 694 bool refresh; 695 696 struct wmTimer *scrolltimer; 697 float scrolloffset; 698 699 struct uiKeyNavLock keynav_state; 700 701 /* for operator popups */ 702 struct wmOperator *popup_op; 703 struct ScrArea *ctx_area; 704 struct ARegion *ctx_region; 705 706 /* return values */ 707 int butretval; 708 int menuretval; 709 int retvalue; 710 float retvec[4]; 711 712 /* menu direction */ 713 int direction; 714 715 /* Previous values so we don't resize or reposition on refresh. */ 716 rctf prev_block_rect; 717 rctf prev_butrct; 718 short prev_dir1, prev_dir2; 719 int prev_bounds_offset[2]; 720 721 /* Maximum estimated size to avoid having to reposition on refresh. */ 722 float max_size_x, max_size_y; 723 724 /* #ifdef USE_DRAG_POPUP */ 725 bool is_grab; 726 int grab_xy_prev[2]; 727 /* #endif */ 728 }; 729 730 /* -------------------------------------------------------------------- */ 731 /* interface_region_*.c */ 732 733 /* interface_region_tooltip.c */ 734 /* exposed as public API in UI_interface.h */ 735 736 /* interface_region_color_picker.c */ 737 void ui_rgb_to_color_picker_compat_v(const float rgb[3], float r_cp[3]); 738 void ui_rgb_to_color_picker_v(const float rgb[3], float r_cp[3]); 739 void ui_color_picker_to_rgb_v(const float r_cp[3], float rgb[3]); 740 void ui_color_picker_to_rgb(float r_cp0, float r_cp1, float r_cp2, float *r, float *g, float *b); 741 742 bool ui_but_is_color_gamma(uiBut *but); 743 744 void ui_scene_linear_to_color_picker_space(uiBut *but, float rgb[3]); 745 void ui_color_picker_to_scene_linear_space(uiBut *but, float rgb[3]); 746 747 uiBlock *ui_block_func_COLOR(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but); 748 ColorPicker *ui_block_colorpicker_create(struct uiBlock *block); 749 750 /* interface_region_search.c */ 751 /* Searchbox for string button */ 752 struct ARegion *ui_searchbox_create_generic(struct bContext *C, 753 struct ARegion *butregion, 754 uiButSearch *search_but); 755 struct ARegion *ui_searchbox_create_operator(struct bContext *C, 756 struct ARegion *butregion, 757 uiButSearch *search_but); 758 struct ARegion *ui_searchbox_create_menu(struct bContext *C, 759 struct ARegion *butregion, 760 uiButSearch *search_but); 761 762 bool ui_searchbox_inside(struct ARegion *region, int x, int y); 763 int ui_searchbox_find_index(struct ARegion *region, const char *name); 764 void ui_searchbox_update(struct bContext *C, struct ARegion *region, uiBut *but, const bool reset); 765 int ui_searchbox_autocomplete(struct bContext *C, struct ARegion *region, uiBut *but, char *str); 766 bool ui_searchbox_event(struct bContext *C, 767 struct ARegion *region, 768 uiBut *but, 769 struct ARegion *butregion, 770 const struct wmEvent *event); 771 bool ui_searchbox_apply(uiBut *but, struct ARegion *region); 772 void ui_searchbox_free(struct bContext *C, struct ARegion *region); 773 void ui_but_search_refresh(uiButSearch *but); 774 775 /* interface_region_menu_popup.c */ 776 int ui_but_menu_step(uiBut *but, int direction); 777 bool ui_but_menu_step_poll(const uiBut *but); 778 uiBut *ui_popup_menu_memory_get(struct uiBlock *block); 779 void ui_popup_menu_memory_set(uiBlock *block, struct uiBut *but); 780 781 uiBlock *ui_popup_block_refresh(struct bContext *C, 782 uiPopupBlockHandle *handle, 783 struct ARegion *butregion, 784 uiBut *but); 785 786 uiPopupBlockHandle *ui_popup_block_create(struct bContext *C, 787 struct ARegion *butregion, 788 uiBut *but, 789 uiBlockCreateFunc create_func, 790 uiBlockHandleCreateFunc handle_create_func, 791 void *arg, 792 void (*arg_free)(void *arg)); 793 uiPopupBlockHandle *ui_popup_menu_create(struct bContext *C, 794 struct ARegion *butregion, 795 uiBut *but, 796 uiMenuCreateFunc menu_func, 797 void *arg); 798 799 /* interface_region_popover.c */ 800 uiPopupBlockHandle *ui_popover_panel_create(struct bContext *C, 801 struct ARegion *butregion, 802 uiBut *but, 803 uiMenuCreateFunc menu_func, 804 void *arg); 805 806 /* interface_region_menu_pie.c */ 807 void ui_pie_menu_level_create(uiBlock *block, 808 struct wmOperatorType *ot, 809 const char *propname, 810 struct IDProperty *properties, 811 const EnumPropertyItem *items, 812 int totitem, 813 int context, 814 int flag); 815 816 /* interface_region_popup.c */ 817 void ui_popup_translate(struct ARegion *region, const int mdiff[2]); 818 void ui_popup_block_free(struct bContext *C, uiPopupBlockHandle *handle); 819 void ui_popup_block_scrolltest(struct uiBlock *block); 820 821 /* end interface_region_*.c */ 822 823 /* interface_panel.c */ 824 extern int ui_handler_panel_region(struct bContext *C, 825 const struct wmEvent *event, 826 struct ARegion *region, 827 const uiBut *active_but); 828 extern void ui_draw_aligned_panel(const struct uiStyle *style, 829 const uiBlock *block, 830 const rcti *rect, 831 const bool show_pin, 832 const bool show_background, 833 const bool region_search_filter_active); 834 void ui_panel_tag_search_filter_match(struct Panel *panel); 835 836 /* interface_draw.c */ 837 extern void ui_draw_dropshadow( 838 const rctf *rct, float radius, float aspect, float alpha, int select); 839 840 void ui_draw_gradient(const rcti *rect, 841 const float hsv[3], 842 const eButGradientType type, 843 const float alpha); 844 845 void ui_draw_but_TAB_outline(const rcti *rect, 846 float rad, 847 uchar highlight[3], 848 uchar highlight_fade[3]); 849 void ui_draw_but_HISTOGRAM(struct ARegion *region, 850 uiBut *but, 851 const struct uiWidgetColors *wcol, 852 const rcti *rect); 853 void ui_draw_but_WAVEFORM(struct ARegion *region, 854 uiBut *but, 855 const struct uiWidgetColors *wcol, 856 const rcti *rect); 857 void ui_draw_but_VECTORSCOPE(struct ARegion *region, 858 uiBut *but, 859 const struct uiWidgetColors *wcol, 860 const rcti *rect); 861 void ui_draw_but_COLORBAND(uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); 862 void ui_draw_but_UNITVEC(uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); 863 void ui_draw_but_CURVE(struct ARegion *region, 864 uiBut *but, 865 const struct uiWidgetColors *wcol, 866 const rcti *rect); 867 void ui_draw_but_CURVEPROFILE(struct ARegion *region, 868 uiBut *but, 869 const struct uiWidgetColors *wcol, 870 const rcti *rect); 871 void ui_draw_but_IMAGE(struct ARegion *region, 872 uiBut *but, 873 const struct uiWidgetColors *wcol, 874 const rcti *rect); 875 void ui_draw_but_TRACKPREVIEW(struct ARegion *region, 876 uiBut *but, 877 const struct uiWidgetColors *wcol, 878 const rcti *rect); 879 880 /* interface_undo.c */ 881 struct uiUndoStack_Text *ui_textedit_undo_stack_create(void); 882 void ui_textedit_undo_stack_destroy(struct uiUndoStack_Text *undo_stack); 883 void ui_textedit_undo_push(struct uiUndoStack_Text *undo_stack, 884 const char *text, 885 int cursor_index); 886 const char *ui_textedit_undo(struct uiUndoStack_Text *undo_stack, 887 int direction, 888 int *r_cursor_index); 889 890 /* interface_handlers.c */ 891 PointerRNA *ui_handle_afterfunc_add_operator(struct wmOperatorType *ot, 892 int opcontext, 893 bool create_props); 894 extern void ui_pan_to_scroll(const struct wmEvent *event, int *type, int *val); 895 extern void ui_but_activate_event(struct bContext *C, struct ARegion *region, uiBut *but); 896 extern void ui_but_activate_over(struct bContext *C, struct ARegion *region, uiBut *but); 897 extern void ui_but_execute_begin(struct bContext *C, 898 struct ARegion *region, 899 uiBut *but, 900 void **active_back); 901 extern void ui_but_execute_end(struct bContext *C, 902 struct ARegion *region, 903 uiBut *but, 904 void *active_back); 905 extern void ui_but_active_free(const struct bContext *C, uiBut *but); 906 extern int ui_but_menu_direction(uiBut *but); 907 extern void ui_but_text_password_hide(char password_str[UI_MAX_DRAW_STR], 908 uiBut *but, 909 const bool restore); 910 extern uiBut *ui_but_find_select_in_enum(uiBut *but, int direction); 911 bool ui_but_is_editing(const uiBut *but); 912 float ui_block_calc_pie_segment(struct uiBlock *block, const float event_xy[2]); 913 914 void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_strip); 915 void ui_but_clipboard_free(void); 916 bool ui_but_rna_equals(const uiBut *a, const uiBut *b); 917 bool ui_but_rna_equals_ex(const uiBut *but, 918 const PointerRNA *ptr, 919 const PropertyRNA *prop, 920 int index); 921 uiBut *ui_but_find_old(uiBlock *block_old, const uiBut *but_new); 922 uiBut *ui_but_find_new(uiBlock *block_new, const uiBut *but_old); 923 924 #ifdef WITH_INPUT_IME 925 void ui_but_ime_reposition(uiBut *but, int x, int y, bool complete); 926 struct wmIMEData *ui_but_ime_data_get(uiBut *but); 927 #endif 928 929 /* interface_widgets.c */ 930 931 /* Widget shader parameters, must match the shader layout. */ 932 typedef struct uiWidgetBaseParameters { 933 rctf recti, rect; 934 float radi, rad; 935 float facxi, facyi; 936 float round_corners[4]; 937 float color_inner1[4], color_inner2[4]; 938 float color_outline[4], color_emboss[4]; 939 float color_tria[4]; 940 float tria1_center[2], tria2_center[2]; 941 float tria1_size, tria2_size; 942 float shade_dir; 943 /* We pack alpha check and discard factor in alpha_discard. 944 * If the value is negative then we do alpha check. 945 * The absolute value itself is the discard factor. 946 * Initialize value to 1.0.f if you don't want discard */ 947 float alpha_discard; 948 float tria_type; 949 float _pad[3]; 950 } uiWidgetBaseParameters; 951 952 enum { 953 ROUNDBOX_TRIA_NONE = 0, 954 ROUNDBOX_TRIA_ARROWS, 955 ROUNDBOX_TRIA_SCROLL, 956 ROUNDBOX_TRIA_MENU, 957 ROUNDBOX_TRIA_CHECK, 958 ROUNDBOX_TRIA_HOLD_ACTION_ARROW, 959 960 ROUNDBOX_TRIA_MAX, /* don't use */ 961 }; 962 963 struct GPUBatch *ui_batch_roundbox_widget_get(void); 964 struct GPUBatch *ui_batch_roundbox_shadow_get(void); 965 966 void ui_draw_anti_tria_rect(const rctf *rect, char dir, const float color[4]); 967 void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect); 968 void ui_draw_box_opaque(rcti *rect, int roundboxalign); 969 void ui_draw_popover_back(struct ARegion *region, 970 struct uiStyle *style, 971 uiBlock *block, 972 rcti *rect); 973 void ui_draw_pie_center(uiBlock *block); 974 const struct uiWidgetColors *ui_tooltip_get_theme(void); 975 976 void ui_draw_widget_menu_back_color(const rcti *rect, bool use_shadow, const float color[4]); 977 void ui_draw_widget_menu_back(const rcti *rect, bool use_shadow); 978 void ui_draw_tooltip_background(const struct uiStyle *UNUSED(style), uiBlock *block, rcti *rect); 979 980 extern void ui_draw_but(const struct bContext *C, 981 struct ARegion *region, 982 struct uiStyle *style, 983 uiBut *but, 984 rcti *rect); 985 986 void ui_draw_menu_item(const struct uiFontStyle *fstyle, 987 rcti *rect, 988 const char *name, 989 int iconid, 990 int state, 991 bool use_sep, 992 int *r_xmax); 993 void ui_draw_preview_item( 994 const struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state); 995 996 #define UI_TEXT_MARGIN_X 0.4f 997 #define UI_POPUP_MARGIN (UI_DPI_FAC * 12) 998 /* margin at top of screen for popups */ 999 #define UI_POPUP_MENU_TOP (int)(8 * UI_DPI_FAC) 1000 1001 #define UI_PIXEL_AA_JITTER 8 1002 extern const float ui_pixel_jitter[UI_PIXEL_AA_JITTER][2]; 1003 1004 /* interface_style.c */ 1005 void uiStyleInit(void); 1006 1007 /* interface_icons.c */ 1008 void ui_icon_ensure_deferred(const struct bContext *C, const int icon_id, const bool big); 1009 int ui_id_icon_get(const struct bContext *C, struct ID *id, const bool big); 1010 1011 /* interface_icons_event.c */ 1012 void icon_draw_rect_input( 1013 float x, float y, int w, int h, float alpha, short event_type, short event_value); 1014 1015 /* resources.c */ 1016 void ui_resources_init(void); 1017 void ui_resources_free(void); 1018 1019 /* interface_layout.c */ 1020 void ui_layout_add_but(uiLayout *layout, uiBut *but); 1021 bool ui_layout_replace_but_ptr(uiLayout *layout, const void *old_but_ptr, uiBut *new_but); 1022 uiBut *ui_but_add_search(uiBut *but, 1023 PointerRNA *ptr, 1024 PropertyRNA *prop, 1025 PointerRNA *searchptr, 1026 PropertyRNA *searchprop); 1027 void ui_layout_list_set_labels_active(uiLayout *layout); 1028 /* menu callback */ 1029 void ui_item_menutype_func(struct bContext *C, struct uiLayout *layout, void *arg_mt); 1030 void ui_item_paneltype_func(struct bContext *C, struct uiLayout *layout, void *arg_pt); 1031 1032 /* interface_button_group.c */ 1033 void ui_block_new_button_group(uiBlock *block, short flag); 1034 void ui_button_group_add_but(uiBlock *block, uiBut *but); 1035 void ui_button_group_replace_but_ptr(uiBlock *block, const void *old_but_ptr, uiBut *new_but); 1036 void ui_block_free_button_groups(uiBlock *block); 1037 1038 /* interface_align.c */ 1039 bool ui_but_can_align(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 1040 int ui_but_align_opposite_to_area_align_get(const struct ARegion *region) ATTR_WARN_UNUSED_RESULT; 1041 void ui_block_align_calc(uiBlock *block, const struct ARegion *region); 1042 1043 /* interface_anim.c */ 1044 void ui_but_anim_flag(uiBut *but, const struct AnimationEvalContext *anim_eval_context); 1045 void ui_but_anim_copy_driver(struct bContext *C); 1046 void ui_but_anim_paste_driver(struct bContext *C); 1047 bool ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen); 1048 bool ui_but_anim_expression_set(uiBut *but, const char *str); 1049 bool ui_but_anim_expression_create(uiBut *but, const char *str); 1050 void ui_but_anim_autokey(struct bContext *C, uiBut *but, struct Scene *scene, float cfra); 1051 1052 void ui_but_anim_decorate_cb(struct bContext *C, void *arg_but, void *arg_dummy); 1053 void ui_but_anim_decorate_update_from_flag(uiButDecorator *but); 1054 1055 /* interface_query.c */ 1056 bool ui_but_is_editable(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 1057 bool ui_but_is_editable_as_text(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 1058 bool ui_but_is_toggle(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 1059 bool ui_but_is_interactive(const uiBut *but, const bool labeledit) ATTR_WARN_UNUSED_RESULT; 1060 bool ui_but_is_popover_once_compat(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 1061 bool ui_but_has_array_value(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 1062 int ui_but_icon(const uiBut *but); 1063 void ui_but_pie_dir(RadialDirection dir, float vec[2]); 1064 1065 bool ui_but_is_cursor_warp(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 1066 1067 bool ui_but_contains_pt(const uiBut *but, float mx, float my) ATTR_WARN_UNUSED_RESULT; 1068 bool ui_but_contains_rect(const uiBut *but, const rctf *rect); 1069 bool ui_but_contains_point_px_icon(const uiBut *but, 1070 struct ARegion *region, 1071 const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT; 1072 bool ui_but_contains_point_px(const uiBut *but, const struct ARegion *region, int x, int y) 1073 ATTR_WARN_UNUSED_RESULT; 1074 1075 uiBut *ui_list_find_mouse_over(struct ARegion *region, 1076 const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT; 1077 1078 uiBut *ui_but_find_mouse_over_ex(struct ARegion *region, 1079 const int x, 1080 const int y, 1081 const bool labeledit) ATTR_WARN_UNUSED_RESULT; 1082 uiBut *ui_but_find_mouse_over(struct ARegion *region, 1083 const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT; 1084 uiBut *ui_but_find_rect_over(const struct ARegion *region, 1085 const rcti *rect_px) ATTR_WARN_UNUSED_RESULT; 1086 1087 uiBut *ui_list_find_mouse_over_ex(struct ARegion *region, int x, int y) ATTR_WARN_UNUSED_RESULT; 1088 1089 bool ui_but_contains_password(const uiBut *but) ATTR_WARN_UNUSED_RESULT; 1090 1091 size_t ui_but_drawstr_len_without_sep_char(const uiBut *but); 1092 size_t ui_but_tip_len_only_first_line(const uiBut *but); 1093 1094 uiBut *ui_but_prev(uiBut *but) ATTR_WARN_UNUSED_RESULT; 1095 uiBut *ui_but_next(uiBut *but) ATTR_WARN_UNUSED_RESULT; 1096 uiBut *ui_but_first(uiBlock *block) ATTR_WARN_UNUSED_RESULT; 1097 uiBut *ui_but_last(uiBlock *block) ATTR_WARN_UNUSED_RESULT; 1098 1099 bool ui_block_is_menu(const uiBlock *block) ATTR_WARN_UNUSED_RESULT; 1100 bool ui_block_is_popover(const uiBlock *block) ATTR_WARN_UNUSED_RESULT; 1101 bool ui_block_is_pie_menu(const uiBlock *block) ATTR_WARN_UNUSED_RESULT; 1102 bool ui_block_is_popup_any(const uiBlock *block) ATTR_WARN_UNUSED_RESULT; 1103 1104 uiBlock *ui_block_find_mouse_over_ex(const struct ARegion *region, 1105 const int x, 1106 const int y, 1107 bool only_clip); 1108 uiBlock *ui_block_find_mouse_over(const struct ARegion *region, 1109 const struct wmEvent *event, 1110 bool only_clip); 1111 1112 uiBut *ui_region_find_first_but_test_flag(struct ARegion *region, 1113 int flag_include, 1114 int flag_exclude); 1115 uiBut *ui_region_find_active_but(struct ARegion *region) ATTR_WARN_UNUSED_RESULT; 1116 bool ui_region_contains_point_px(const struct ARegion *region, 1117 int x, 1118 int y) ATTR_WARN_UNUSED_RESULT; 1119 bool ui_region_contains_rect_px(const struct ARegion *region, const rcti *rect_px); 1120 1121 struct ARegion *ui_screen_region_find_mouse_over_ex(struct bScreen *screen, int x, int y); 1122 struct ARegion *ui_screen_region_find_mouse_over(struct bScreen *screen, 1123 const struct wmEvent *event); 1124 1125 /* interface_context_menu.c */ 1126 bool ui_popup_context_menu_for_button(struct bContext *C, uiBut *but); 1127 void ui_popup_context_menu_for_panel(struct bContext *C, 1128 struct ARegion *region, 1129 struct Panel *panel); 1130 1131 /* interface_eyedropper.c */ 1132 struct wmKeyMap *eyedropper_modal_keymap(struct wmKeyConfig *keyconf); 1133 struct wmKeyMap *eyedropper_colorband_modal_keymap(struct wmKeyConfig *keyconf); 1134 1135 /* interface_eyedropper_color.c */ 1136 void UI_OT_eyedropper_color(struct wmOperatorType *ot); 1137 1138 /* interface_eyedropper_colorband.c */ 1139 void UI_OT_eyedropper_colorramp(struct wmOperatorType *ot); 1140 void UI_OT_eyedropper_colorramp_point(struct wmOperatorType *ot); 1141 1142 /* interface_eyedropper_datablock.c */ 1143 void UI_OT_eyedropper_id(struct wmOperatorType *ot); 1144 1145 /* interface_eyedropper_depth.c */ 1146 void UI_OT_eyedropper_depth(struct wmOperatorType *ot); 1147 1148 /* interface_eyedropper_driver.c */ 1149 void UI_OT_eyedropper_driver(struct wmOperatorType *ot); 1150 1151 /* interface_eyedropper_gpencil_color.c */ 1152 void UI_OT_eyedropper_gpencil_color(struct wmOperatorType *ot); 1153 1154 /** 1155 * For use with #ui_rna_collection_search_update_fn. 1156 */ 1157 typedef struct uiRNACollectionSearch { 1158 PointerRNA target_ptr; 1159 PropertyRNA *target_prop; 1160 1161 PointerRNA search_ptr; 1162 PropertyRNA *search_prop; 1163 1164 uiBut *search_but; 1165 /* Let UI_butstore_ API update search_but pointer above over redraws. */ 1166 uiButStore *butstore; 1167 /* Block has to be stored for freeing butstore (uiBut.block doesn't work with undo). */ 1168 uiBlock *butstore_block; 1169 } uiRNACollectionSearch; 1170 void ui_rna_collection_search_update_fn(const struct bContext *C, 1171 void *arg, 1172 const char *str, 1173 uiSearchItems *items); 1174 1175 /* interface_ops.c */ 1176 bool ui_jump_to_target_button_poll(struct bContext *C); 1177 1178 /* interface_queries.c */ 1179 void ui_interface_tag_script_reload_queries(void); 1180