| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup edinterface | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | /* a full doc with API notes can be found in
 | 
					
						
							|  |  |  |  * bf-blender/trunk/blender/doc/guides/interface_API.txt */ | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include <ctype.h>
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | #include <math.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "PIL_time.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-16 17:32:01 +10:00
										 |  |  | #include "BLT_translation.h"
 | 
					
						
							| 
									
										
										
										
											2011-11-09 14:13:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | #include "DNA_screen_types.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | #include "DNA_userdef_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | #include "BLF_api.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "UI_interface.h"
 | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | #include "UI_interface_icons.h"
 | 
					
						
							| 
									
										
										
										
											2011-11-19 20:57:53 +00:00
										 |  |  | #include "UI_resources.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "UI_view2d.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 16:31:22 +02:00
										 |  |  | #include "GPU_batch_presets.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-10 01:33:56 -04:00
										 |  |  | #include "GPU_immediate.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-06 16:31:22 +02:00
										 |  |  | #include "GPU_matrix.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-27 19:07:23 -06:00
										 |  |  | #include "GPU_state.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-10 01:33:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | #include "interface_intern.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Defines & Structs
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define ANIMATION_TIME 0.30
 | 
					
						
							|  |  |  | #define ANIMATION_INTERVAL 0.02
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  | typedef enum uiPanelRuntimeFlag { | 
					
						
							|  |  |  |   PANEL_LAST_ADDED = (1 << 0), | 
					
						
							|  |  |  |   PANEL_ACTIVE = (1 << 2), | 
					
						
							|  |  |  |   PANEL_WAS_ACTIVE = (1 << 3), | 
					
						
							|  |  |  |   PANEL_ANIM_ALIGN = (1 << 4), | 
					
						
							|  |  |  |   PANEL_NEW_ADDED = (1 << 5), | 
					
						
							|  |  |  |   PANEL_SEARCH_FILTER_MATCH = (1 << 7), | 
					
						
							|  |  |  | } uiPanelRuntimeFlag; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* The state of the mouse position relative to the panel. */ | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | typedef enum uiPanelMouseState { | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   PANEL_MOUSE_OUTSIDE,        /** Mouse is not in the panel. */ | 
					
						
							|  |  |  |   PANEL_MOUSE_INSIDE_CONTENT, /** Mouse is in the actual panel content. */ | 
					
						
							|  |  |  |   PANEL_MOUSE_INSIDE_HEADER,  /** Mouse is in the panel header. */ | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | } uiPanelMouseState; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | typedef enum uiHandlePanelState { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PANEL_STATE_DRAG, | 
					
						
							|  |  |  |   PANEL_STATE_DRAG_SCALE, | 
					
						
							|  |  |  |   PANEL_STATE_WAIT_UNTAB, | 
					
						
							|  |  |  |   PANEL_STATE_ANIMATION, | 
					
						
							|  |  |  |   PANEL_STATE_EXIT, | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } uiHandlePanelState; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct uiHandlePanelData { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   uiHandlePanelState state; | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |   /* Animation. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   wmTimer *animtimer; | 
					
						
							|  |  |  |   double starttime; | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |   /* Dragging. */ | 
					
						
							| 
									
										
										
										
											2020-04-30 14:21:14 -05:00
										 |  |  |   bool is_drag_drop; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   int startx, starty; | 
					
						
							|  |  |  |   int startofsx, startofsy; | 
					
						
							|  |  |  |   int startsizex, startsizey; | 
					
						
							| 
									
										
										
										
											2020-06-05 10:01:20 -04:00
										 |  |  |   float start_cur_xmin, start_cur_ymin; | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } uiHandlePanelData; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | typedef struct PanelSort { | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |   Panel *panel; | 
					
						
							|  |  |  |   int new_offset_x; | 
					
						
							|  |  |  |   int new_offset_y; | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | } PanelSort; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 17:41:00 -05:00
										 |  |  | static void panel_set_expansion_from_list_data(const bContext *C, Panel *panel); | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  | static int get_panel_real_size_y(const Panel *panel); | 
					
						
							|  |  |  | static void panel_activate_state(const bContext *C, Panel *panel, uiHandlePanelState state); | 
					
						
							| 
									
										
										
										
											2020-09-19 22:38:36 -05:00
										 |  |  | static int compare_panel(const void *a, const void *b); | 
					
						
							| 
									
										
										
										
											2020-08-12 12:56:10 -04:00
										 |  |  | static bool panel_type_context_poll(ARegion *region, | 
					
						
							|  |  |  |                                     const PanelType *panel_type, | 
					
						
							|  |  |  |                                     const char *context); | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Local Functions
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  | static void panel_title_color_get(const Panel *panel, | 
					
						
							|  |  |  |                                   const bool show_background, | 
					
						
							|  |  |  |                                   const bool use_search_color, | 
					
						
							|  |  |  |                                   const bool region_search_filter_active, | 
					
						
							|  |  |  |                                   uchar r_color[4]) | 
					
						
							| 
									
										
										
										
											2018-12-19 13:09:05 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |   if (!show_background) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     /* Use menu colors for floating panels. */ | 
					
						
							|  |  |  |     bTheme *btheme = UI_GetTheme(); | 
					
						
							|  |  |  |     const uiWidgetColors *wcol = &btheme->tui.wcol_menu_back; | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |     copy_v4_v4_uchar(r_color, (const uchar *)wcol->text); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const bool search_match = UI_panel_matches_search_filter(panel); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (region_search_filter_active && use_search_color && search_match) { | 
					
						
							|  |  |  |     UI_GetThemeColor4ubv(TH_MATCH, r_color); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     UI_GetThemeColor4ubv(TH_TITLE, r_color); | 
					
						
							|  |  |  |     if (region_search_filter_active && !search_match) { | 
					
						
							|  |  |  |       r_color[0] *= 0.5; | 
					
						
							|  |  |  |       r_color[1] *= 0.5; | 
					
						
							|  |  |  |       r_color[2] *= 0.5; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-12-19 13:09:05 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  | static bool panel_active_animation_changed(ListBase *lb, | 
					
						
							|  |  |  |                                            Panel **r_panel_animation, | 
					
						
							|  |  |  |                                            bool *r_no_animation) | 
					
						
							| 
									
										
										
										
											2009-04-02 01:39:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   LISTBASE_FOREACH (Panel *, panel, lb) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     /* Detect panel active flag changes. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     if (!(panel->type && panel->type->parent)) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |       if ((panel->runtime_flag & PANEL_WAS_ACTIVE) && !(panel->runtime_flag & PANEL_ACTIVE)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |       if (!(panel->runtime_flag & PANEL_WAS_ACTIVE) && (panel->runtime_flag & PANEL_ACTIVE)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     if ((panel->runtime_flag & PANEL_ACTIVE) && !(panel->flag & PNL_CLOSED)) { | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |       if (panel_active_animation_changed(&panel->children, r_panel_animation, r_no_animation)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Detect animation. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     if (panel->activedata) { | 
					
						
							|  |  |  |       uiHandlePanelData *data = panel->activedata; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       if (data->state == PANEL_STATE_ANIMATION) { | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |         *r_panel_animation = panel; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         /* Don't animate while handling other interaction. */ | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |         *r_no_animation = true; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     if ((panel->runtime_flag & PANEL_ANIM_ALIGN) && !(*r_panel_animation)) { | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |       *r_panel_animation = panel; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2018-06-03 13:32:36 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-04-16 21:39:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  | static bool panels_need_realign(ScrArea *area, ARegion *region, Panel **r_panel_animation) | 
					
						
							| 
									
										
										
										
											2018-06-03 13:32:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   *r_panel_animation = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   if (area->spacetype == SPACE_PROPERTIES && region->regiontype == RGN_TYPE_WINDOW) { | 
					
						
							|  |  |  |     SpaceProperties *sbuts = area->spacedata.first; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (sbuts->mainbo != sbuts->mainb) { | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   else if (area->spacetype == SPACE_IMAGE && region->regiontype == RGN_TYPE_PREVIEW) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   else if (area->spacetype == SPACE_FILE && region->regiontype == RGN_TYPE_CHANNELS) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Detect if a panel was added or removed. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   Panel *panel_animation = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bool no_animation = false; | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   if (panel_active_animation_changed(®ion->panels, &panel_animation, &no_animation)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Detect panel marked for animation, if we're not already animating. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   if (panel_animation) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (!no_animation) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |       *r_panel_animation = panel_animation; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2009-04-02 01:39:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Functions for Instanced Panels
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 17:41:00 -05:00
										 |  |  | static Panel *panel_add_instanced(ARegion *region, | 
					
						
							|  |  |  |                                   ListBase *panels, | 
					
						
							|  |  |  |                                   PanelType *panel_type, | 
					
						
							|  |  |  |                                   PointerRNA *custom_data) | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   Panel *panel = MEM_callocN(sizeof(Panel), "instanced panel"); | 
					
						
							|  |  |  |   panel->type = panel_type; | 
					
						
							|  |  |  |   BLI_strncpy(panel->panelname, panel_type->idname, sizeof(panel->panelname)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 15:00:25 -04:00
										 |  |  |   panel->runtime.custom_data_ptr = custom_data; | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |   panel->runtime_flag |= PANEL_NEW_ADDED; | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Add the panel's children too. Although they aren't instanced panels, we can still use this
 | 
					
						
							|  |  |  |    * function to create them, as UI_panel_begin does other things we don't need to do. */ | 
					
						
							|  |  |  |   LISTBASE_FOREACH (LinkData *, child, &panel_type->children) { | 
					
						
							|  |  |  |     PanelType *child_type = child->data; | 
					
						
							| 
									
										
										
										
											2020-09-29 17:41:00 -05:00
										 |  |  |     panel_add_instanced(region, &panel->children, child_type, custom_data); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Make sure the panel is added to the end of the display-order as well. This is needed for
 | 
					
						
							|  |  |  |    * loading existing files. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * Note: We could use special behavior to place it after the panel that starts the list of | 
					
						
							|  |  |  |    * instanced panels, but that would add complexity that isn't needed for now. */ | 
					
						
							|  |  |  |   int max_sortorder = 0; | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, existing_panel, panels) { | 
					
						
							|  |  |  |     if (existing_panel->sortorder > max_sortorder) { | 
					
						
							|  |  |  |       max_sortorder = existing_panel->sortorder; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   panel->sortorder = max_sortorder + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BLI_addtail(panels, panel); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return panel; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-09-17 15:18:24 -05:00
										 |  |  |  * Called in situations where panels need to be added dynamically rather than | 
					
						
							|  |  |  |  * having only one panel corresponding to each #PanelType. | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-09-29 17:41:00 -05:00
										 |  |  | Panel *UI_panel_add_instanced(const bContext *C, | 
					
						
							|  |  |  |                               ARegion *region, | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |                               ListBase *panels, | 
					
						
							|  |  |  |                               char *panel_idname, | 
					
						
							|  |  |  |                               PointerRNA *custom_data) | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   ARegionType *region_type = region->type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PanelType *panel_type = BLI_findstring( | 
					
						
							|  |  |  |       ®ion_type->paneltypes, panel_idname, offsetof(PanelType, idname)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (panel_type == NULL) { | 
					
						
							|  |  |  |     printf("Panel type '%s' not found.\n", panel_idname); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 17:41:00 -05:00
										 |  |  |   Panel *new_panel = panel_add_instanced(region, panels, panel_type, custom_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Do this after #panel_add_instatnced so all subpanels are added. */ | 
					
						
							|  |  |  |   panel_set_expansion_from_list_data(C, new_panel); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return new_panel; | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |  * Find a unique key to append to the #PanelTyype.idname for the lookup to the panel's #uiBlock. | 
					
						
							|  |  |  |  * Needed for instanced panels, where there can be multiple with the same type and identifier. | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | void UI_list_panel_unique_str(Panel *panel, char *r_name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   /* The panel sortorder will be unique for a specific panel type because the instanced
 | 
					
						
							|  |  |  |    * panel list is regenerated for every change in the data order / length. */ | 
					
						
							|  |  |  |   snprintf(r_name, INSTANCED_PANEL_UNIQUE_STR_LEN, "%d", panel->sortorder); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-06-29 15:00:25 -04:00
										 |  |  |  * Free a panel and it's children. Custom data is shared by the panel and its children | 
					
						
							|  |  |  |  * and is freed by #UI_panels_free_instanced. | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \note The only panels that should need to be deleted at runtime are panels with the | 
					
						
							|  |  |  |  * #PNL_INSTANCED flag set. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-05 17:36:16 -04:00
										 |  |  | static void panel_delete(const bContext *C, ARegion *region, ListBase *panels, Panel *panel) | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   /* Recursively delete children. */ | 
					
						
							|  |  |  |   LISTBASE_FOREACH_MUTABLE (Panel *, child, &panel->children) { | 
					
						
							| 
									
										
										
										
											2020-08-05 17:36:16 -04:00
										 |  |  |     panel_delete(C, region, &panel->children, child); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   } | 
					
						
							|  |  |  |   BLI_freelistN(&panel->children); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BLI_remlink(panels, panel); | 
					
						
							|  |  |  |   if (panel->activedata) { | 
					
						
							|  |  |  |     MEM_freeN(panel->activedata); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   MEM_freeN(panel); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 09:06:54 -04:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Remove instanced panels from the region's panel list. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note Can be called with NULL \a C, but it should be avoided because | 
					
						
							|  |  |  |  * handlers might not be removed. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-12 12:59:19 -04:00
										 |  |  | void UI_panels_free_instanced(const bContext *C, ARegion *region) | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   /* Delete panels with the instanced flag. */ | 
					
						
							|  |  |  |   LISTBASE_FOREACH_MUTABLE (Panel *, panel, ®ion->panels) { | 
					
						
							|  |  |  |     if ((panel->type != NULL) && (panel->type->flag & PNL_INSTANCED)) { | 
					
						
							|  |  |  |       /* Make sure the panel's handler is removed before deleting it. */ | 
					
						
							| 
									
										
										
										
											2020-06-15 09:06:54 -04:00
										 |  |  |       if (C != NULL && panel->activedata != NULL) { | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |         panel_activate_state(C, panel, PANEL_STATE_EXIT); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-06-29 15:00:25 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       /* Free panel's custom data. */ | 
					
						
							|  |  |  |       if (panel->runtime.custom_data_ptr != NULL) { | 
					
						
							|  |  |  |         MEM_freeN(panel->runtime.custom_data_ptr); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 20:54:31 +10:00
										 |  |  |       /* Free the panel and its sub-panels. */ | 
					
						
							| 
									
										
										
										
											2020-08-05 17:36:16 -04:00
										 |  |  |       panel_delete(C, region, ®ion->panels, panel); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Check if the instanced panels in the region's panels correspond to the list of data the panels | 
					
						
							|  |  |  |  * represent. Returns false if the panels have been reordered or if the types from the list data | 
					
						
							|  |  |  |  * don't match in any way. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param data: The list of data to check against the instanced panels. | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |  * \param panel_idname_func: Function to find the #PanelType.idname for each item in the data list. | 
					
						
							| 
									
										
										
										
											2020-05-28 16:42:31 +10:00
										 |  |  |  * For a readability and generality, this lookup happens separately for each type of panel list. | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | bool UI_panel_list_matches_data(ARegion *region, | 
					
						
							|  |  |  |                                 ListBase *data, | 
					
						
							|  |  |  |                                 uiListPanelIDFromDataFunc panel_idname_func) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-19 12:40:48 -04:00
										 |  |  |   /* Check for NULL data. */ | 
					
						
							|  |  |  |   int data_len = 0; | 
					
						
							|  |  |  |   Link *data_link = NULL; | 
					
						
							|  |  |  |   if (data == NULL) { | 
					
						
							|  |  |  |     data_len = 0; | 
					
						
							|  |  |  |     data_link = NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     data_len = BLI_listbase_count(data); | 
					
						
							|  |  |  |     data_link = data->first; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   int i = 0; | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							|  |  |  |     if (panel->type != NULL && panel->type->flag & PNL_INSTANCED) { | 
					
						
							|  |  |  |       /* The panels were reordered by drag and drop. */ | 
					
						
							|  |  |  |       if (panel->flag & PNL_INSTANCED_LIST_ORDER_CHANGED) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /* We reached the last data item before the last instanced panel. */ | 
					
						
							|  |  |  |       if (data_link == NULL) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /* Check if the panel type matches the panel type from the data item. */ | 
					
						
							|  |  |  |       char panel_idname[MAX_NAME]; | 
					
						
							|  |  |  |       panel_idname_func(data_link, panel_idname); | 
					
						
							|  |  |  |       if (!STREQ(panel_idname, panel->type->idname)) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data_link = data_link->next; | 
					
						
							|  |  |  |       i++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* If we didn't make it to the last list item, the panel list isn't complete. */ | 
					
						
							|  |  |  |   if (i != data_len) { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *drag_panel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* Without a type we cannot access the reorder callback. */ | 
					
						
							|  |  |  |   if (drag_panel->type == NULL) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   /* Don't reorder if this instanced panel doesn't support drag and drop reordering. */ | 
					
						
							|  |  |  |   if (drag_panel->type->reorder == NULL) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-12 12:56:10 -04:00
										 |  |  |   char *context = NULL; | 
					
						
							|  |  |  |   if (!UI_panel_category_is_visible(region)) { | 
					
						
							|  |  |  |     context = drag_panel->type->context; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Find how many instanced panels with this context string. */ | 
					
						
							|  |  |  |   int list_panels_len = 0; | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							|  |  |  |     if (panel->type) { | 
					
						
							| 
									
										
										
										
											2020-08-12 12:56:10 -04:00
										 |  |  |       if (panel->type->flag & PNL_INSTANCED) { | 
					
						
							|  |  |  |         if (panel_type_context_poll(region, panel->type, context)) { | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |           list_panels_len++; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Sort the matching instanced panels by their display order. */ | 
					
						
							|  |  |  |   PanelSort *panel_sort = MEM_callocN(list_panels_len * sizeof(*panel_sort), "instancedpanelsort"); | 
					
						
							|  |  |  |   PanelSort *sort_index = panel_sort; | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							|  |  |  |     if (panel->type) { | 
					
						
							| 
									
										
										
										
											2020-08-12 12:56:10 -04:00
										 |  |  |       if (panel->type->flag & PNL_INSTANCED) { | 
					
						
							|  |  |  |         if (panel_type_context_poll(region, panel->type, context)) { | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |           sort_index->panel = panel; | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |           sort_index++; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   qsort(panel_sort, list_panels_len, sizeof(*panel_sort), compare_panel); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Find how many of those panels are above this panel. */ | 
					
						
							|  |  |  |   int move_to_index = 0; | 
					
						
							|  |  |  |   for (; move_to_index < list_panels_len; move_to_index++) { | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |     if (panel_sort[move_to_index].panel == drag_panel) { | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   MEM_freeN(panel_sort); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Set the bit to tell the interface to instanced the list. */ | 
					
						
							|  |  |  |   drag_panel->flag |= PNL_INSTANCED_LIST_ORDER_CHANGED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Finally, move this panel's list item to the new index in its list. */ | 
					
						
							|  |  |  |   drag_panel->type->reorder(C, drag_panel, move_to_index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-09-29 17:41:00 -05:00
										 |  |  |  * Recursive implementation for #panel_set_expansion_from_list_data. | 
					
						
							| 
									
										
										
										
											2020-06-10 11:16:55 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-06-25 23:13:02 +10:00
										 |  |  |  * \return Whether the closed flag for the panel or any sub-panels changed. | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-06-10 11:16:55 -04:00
										 |  |  | static bool panel_set_expand_from_list_data_recursive(Panel *panel, short flag, short *flag_index) | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const bool open = (flag & (1 << *flag_index)); | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |   bool changed = (open == (bool)(panel->flag & PNL_CLOSED)); | 
					
						
							|  |  |  |   SET_FLAG_FROM_TEST(panel->flag, !open, PNL_CLOSED); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   LISTBASE_FOREACH (Panel *, child, &panel->children) { | 
					
						
							|  |  |  |     *flag_index = *flag_index + 1; | 
					
						
							| 
									
										
										
										
											2020-06-10 11:16:55 -04:00
										 |  |  |     changed |= panel_set_expand_from_list_data_recursive(child, flag, flag_index); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-10 11:16:55 -04:00
										 |  |  |   return changed; | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-09-29 17:41:00 -05:00
										 |  |  |  * Set the expansion of the panel and its sub-panels from the flag stored in the | 
					
						
							|  |  |  |  * corresponding list data. The flag has expansion stored in each bit in depth first order. | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-09-29 17:41:00 -05:00
										 |  |  | static void panel_set_expansion_from_list_data(const bContext *C, Panel *panel) | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   BLI_assert(panel->type != NULL); | 
					
						
							|  |  |  |   BLI_assert(panel->type->flag & PNL_INSTANCED); | 
					
						
							|  |  |  |   if (panel->type->get_list_data_expand_flag == NULL) { | 
					
						
							|  |  |  |     /* Instanced panel doesn't support loading expansion. */ | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const short expand_flag = panel->type->get_list_data_expand_flag(C, panel); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   short flag_index = 0; | 
					
						
							| 
									
										
										
										
											2020-06-10 11:16:55 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Start panel animation if the open state was changed. */ | 
					
						
							|  |  |  |   if (panel_set_expand_from_list_data_recursive(panel, expand_flag, &flag_index)) { | 
					
						
							|  |  |  |     panel_activate_state(C, panel, PANEL_STATE_ANIMATION); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 15:34:27 -05:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Set expansion based on the data for instanced panels. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void region_panels_set_expansion_from_list_data(const bContext *C, ARegion *region) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							| 
									
										
										
										
											2020-09-29 17:19:57 -05:00
										 |  |  |     if (panel->runtime_flag & PANEL_ACTIVE) { | 
					
						
							|  |  |  |       PanelType *panel_type = panel->type; | 
					
						
							|  |  |  |       if (panel_type != NULL && panel->type->flag & PNL_INSTANCED) { | 
					
						
							| 
									
										
										
										
											2020-09-29 17:41:00 -05:00
										 |  |  |         panel_set_expansion_from_list_data(C, panel); | 
					
						
							| 
									
										
										
										
											2020-09-29 17:19:57 -05:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-09-15 15:34:27 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Recursive implementation for #set_panels_list_data_expand_flag. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void get_panel_expand_flag(Panel *panel, short *flag, short *flag_index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const bool open = !(panel->flag & PNL_CLOSED); | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |   SET_FLAG_FROM_TEST(*flag, open, (1 << *flag_index)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   LISTBASE_FOREACH (Panel *, child, &panel->children) { | 
					
						
							|  |  |  |     *flag_index = *flag_index + 1; | 
					
						
							|  |  |  |     get_panel_expand_flag(child, flag, flag_index); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |  * Call the callback to store the panel and sub-panel expansion settings in the list item that | 
					
						
							| 
									
										
										
										
											2020-09-17 15:18:24 -05:00
										 |  |  |  * corresponds to each instanced panel. | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \note This needs to iterate through all of the regions panels because the panel with changed | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |  * expansion could have been the sub-panel of a instanced panel, meaning it might not know | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |  * which list item it corresponds to. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  | static void set_panels_list_data_expand_flag(const bContext *C, const ARegion *region) | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							|  |  |  |     PanelType *panel_type = panel->type; | 
					
						
							|  |  |  |     if (panel_type == NULL) { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     /* Check for #PANEL_ACTIVE so we only set the expand flag for active panels. */ | 
					
						
							|  |  |  |     if (panel_type->flag & PNL_INSTANCED && panel->runtime_flag & PANEL_ACTIVE) { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |       short expand_flag; | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |       short flag_index = 0; | 
					
						
							|  |  |  |       get_panel_expand_flag(panel, &expand_flag, &flag_index); | 
					
						
							|  |  |  |       if (panel->type->set_list_data_expand_flag) { | 
					
						
							|  |  |  |         panel->type->set_list_data_expand_flag(C, panel, expand_flag); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Panels
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 13:37:59 -04:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-06-25 23:13:02 +10:00
										 |  |  |  * Set flag state for a panel and its sub-panels. | 
					
						
							| 
									
										
										
										
											2020-06-17 13:37:59 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \return True if this function changed any of the flags, false if it didn't. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static bool panel_set_flag_recursive(Panel *panel, int flag, bool value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const short flag_original = panel->flag; | 
					
						
							| 
									
										
										
										
											2020-06-17 13:37:59 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   SET_FLAG_FROM_TEST(panel->flag, value, flag); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   bool changed = (flag_original != panel->flag); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, child, &panel->children) { | 
					
						
							|  |  |  |     changed |= panel_set_flag_recursive(child, flag, value); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return changed; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  | static void panels_collapse_all(ARegion *region, const Panel *from_panel) | 
					
						
							| 
									
										
										
										
											2012-05-28 00:02:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   const bool has_category_tabs = UI_panel_category_is_visible(region); | 
					
						
							|  |  |  |   const char *category = has_category_tabs ? UI_panel_category_active_get(region, false) : NULL; | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   const PanelType *from_pt = from_panel->type; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 21:38:16 -04:00
										 |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     PanelType *pt = panel->type; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Close panels with headers in the same context. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (pt && from_pt && !(pt->flag & PNL_NO_HEADER)) { | 
					
						
							|  |  |  |       if (!pt->context[0] || !from_pt->context[0] || STREQ(pt->context, from_pt->context)) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |         if ((panel->flag & PNL_PIN) || !category || !pt->category[0] || | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             STREQ(pt->category, category)) { | 
					
						
							| 
									
										
										
										
											2020-08-20 23:41:10 -04:00
										 |  |  |           panel->flag |= PNL_CLOSED; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-12 12:56:10 -04:00
										 |  |  | static bool panel_type_context_poll(ARegion *region, | 
					
						
							|  |  |  |                                     const PanelType *panel_type, | 
					
						
							|  |  |  |                                     const char *context) | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-12 12:56:10 -04:00
										 |  |  |   if (UI_panel_category_is_visible(region)) { | 
					
						
							|  |  |  |     return STREQ(panel_type->category, UI_panel_category_active_get(region, false)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   if (panel_type->context[0] && STREQ(panel_type->context, context)) { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-12 12:56:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2012-05-28 00:02:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-03 13:32:36 +02:00
										 |  |  | Panel *UI_panel_find_by_type(ListBase *lb, PanelType *pt) | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const char *idname = pt->idname; | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 21:38:16 -04:00
										 |  |  |   LISTBASE_FOREACH (Panel *, panel, lb) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     if (STREQLEN(panel->panelname, idname, sizeof(panel->panelname))) { | 
					
						
							|  |  |  |       return panel; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |  * \note \a panel should be return value from #UI_panel_find_by_type and can be NULL. | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  | Panel *UI_panel_begin( | 
					
						
							|  |  |  |     ARegion *region, ListBase *lb, uiBlock *block, PanelType *pt, Panel *panel, bool *r_open) | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-15 21:38:16 -04:00
										 |  |  |   Panel *panel_last; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const char *drawname = CTX_IFACE_(pt->translation_context, pt->label); | 
					
						
							|  |  |  |   const char *idname = pt->idname; | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   const bool newpanel = (panel == NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   if (newpanel) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     panel = MEM_callocN(sizeof(Panel), "new panel"); | 
					
						
							|  |  |  |     panel->type = pt; | 
					
						
							|  |  |  |     BLI_strncpy(panel->panelname, idname, sizeof(panel->panelname)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (pt->flag & PNL_DEFAULT_CLOSED) { | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |       panel->flag |= PNL_CLOSED; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     panel->ofsx = 0; | 
					
						
							|  |  |  |     panel->ofsy = 0; | 
					
						
							|  |  |  |     panel->sizex = 0; | 
					
						
							|  |  |  |     panel->sizey = 0; | 
					
						
							|  |  |  |     panel->blocksizex = 0; | 
					
						
							|  |  |  |     panel->blocksizey = 0; | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     panel->runtime_flag |= PANEL_NEW_ADDED; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     BLI_addtail(lb, panel); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   else { | 
					
						
							|  |  |  |     /* Panel already exists. */ | 
					
						
							|  |  |  |     panel->type = pt; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Do not allow closed panels without headers! Else user could get "disappeared" UI! */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   if ((pt->flag & PNL_NO_HEADER) && (panel->flag & PNL_CLOSED)) { | 
					
						
							|  |  |  |     panel->flag &= ~PNL_CLOSED; | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Force update of panels' positions. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     panel->sizex = 0; | 
					
						
							|  |  |  |     panel->sizey = 0; | 
					
						
							|  |  |  |     panel->blocksizex = 0; | 
					
						
							|  |  |  |     panel->blocksizey = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   BLI_strncpy(panel->drawname, drawname, sizeof(panel->drawname)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* If a new panel is added, we insert it right after the panel that was last added.
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |    * This way new panels are inserted in the right place between versions. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   for (panel_last = lb->first; panel_last; panel_last = panel_last->next) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     if (panel_last->runtime_flag & PANEL_LAST_ADDED) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |       BLI_remlink(lb, panel); | 
					
						
							|  |  |  |       BLI_insertlinkafter(lb, panel_last, panel); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (newpanel) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     panel->sortorder = (panel_last) ? panel_last->sortorder + 1 : 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 21:38:16 -04:00
										 |  |  |     LISTBASE_FOREACH (Panel *, panel_next, lb) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |       if (panel_next != panel && panel_next->sortorder >= panel->sortorder) { | 
					
						
							|  |  |  |         panel_next->sortorder++; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   if (panel_last) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     panel_last->runtime_flag &= ~PANEL_LAST_ADDED; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Assign the new panel to the block. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   block->panel = panel; | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |   panel->runtime_flag |= PANEL_ACTIVE | PANEL_LAST_ADDED; | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if (region->alignment == RGN_ALIGN_FLOAT) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   *r_open = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   if (panel->flag & PNL_CLOSED) { | 
					
						
							|  |  |  |     return panel; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   *r_open = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   return panel; | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  | static float panel_region_offset_x_get(const ARegion *region) | 
					
						
							| 
									
										
										
										
											2020-01-21 16:02:30 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if (UI_panel_category_is_visible(region)) { | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     if (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) != RGN_ALIGN_RIGHT) { | 
					
						
							| 
									
										
										
										
											2020-01-21 16:02:30 +01:00
										 |  |  |       return UI_PANEL_CATEGORY_MARGIN_WIDTH; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  | void UI_panel_end(const ARegion *region, uiBlock *block, int width, int height, bool open) | 
					
						
							| 
									
										
										
										
											2009-04-16 21:39:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   Panel *panel = block->panel; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Set panel size excluding children. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   panel->blocksizex = width; | 
					
						
							|  |  |  |   panel->blocksizey = height; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Compute total panel size including children. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   LISTBASE_FOREACH (Panel *, pachild, &panel->children) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     if (pachild->runtime_flag & PANEL_ACTIVE) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       width = max_ii(width, pachild->sizex); | 
					
						
							|  |  |  |       height += get_panel_real_size_y(pachild); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Update total panel size. */ | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |   if (panel->runtime_flag & PANEL_NEW_ADDED) { | 
					
						
							|  |  |  |     panel->runtime_flag &= ~PANEL_NEW_ADDED; | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     panel->sizex = width; | 
					
						
							|  |  |  |     panel->sizey = height; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |     const int old_sizex = panel->sizex, old_sizey = panel->sizey; | 
					
						
							|  |  |  |     const int old_region_ofsx = panel->runtime.region_ofsx; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Update width/height if non-zero. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (width != 0) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |       panel->sizex = width; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-22 17:59:06 +03:00
										 |  |  |     if (height != 0 || open) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |       panel->sizey = height; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-22 17:59:06 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Check if we need to do an animation. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     if (panel->sizex != old_sizex || panel->sizey != old_sizey) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |       panel->runtime_flag |= PANEL_ANIM_ALIGN; | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |       panel->ofsy += old_sizey - panel->sizey; | 
					
						
							| 
									
										
										
										
											2019-05-22 17:59:06 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-21 16:02:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     panel->runtime.region_ofsx = panel_region_offset_x_get(region); | 
					
						
							| 
									
										
										
										
											2020-04-19 14:36:22 +02:00
										 |  |  |     if (old_region_ofsx != panel->runtime.region_ofsx) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |       panel->runtime_flag |= PANEL_ANIM_ALIGN; | 
					
						
							| 
									
										
										
										
											2020-01-21 16:02:30 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-04-16 21:39:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | static void ui_offset_panel_block(uiBlock *block) | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-15 17:32:25 +11:00
										 |  |  |   const uiStyle *style = UI_style_get_dpi(); | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Compute bounds and offset. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ui_block_bounds_calc(block); | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const int ofsy = block->panel->sizey - style->panelspace; | 
					
						
							| 
									
										
										
										
											2009-05-20 14:46:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |   LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     but->rect.ymin += ofsy; | 
					
						
							|  |  |  |     but->rect.ymax += ofsy; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   block->rect.xmax = block->panel->sizex; | 
					
						
							|  |  |  |   block->rect.ymax = block->panel->sizey; | 
					
						
							|  |  |  |   block->rect.xmin = block->rect.ymin = 0.0; | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-23 16:24:20 -05:00
										 |  |  | void ui_panel_tag_search_filter_match(struct Panel *panel) | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-23 16:24:20 -05:00
										 |  |  |   panel->runtime_flag |= PANEL_SEARCH_FILTER_MATCH; | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void panel_matches_search_filter_recursive(const Panel *panel, bool *filter_matches) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |   *filter_matches |= panel->runtime_flag & PANEL_SEARCH_FILTER_MATCH; | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* If the panel has no match we need to make sure that its children are too. */ | 
					
						
							|  |  |  |   if (!*filter_matches) { | 
					
						
							|  |  |  |     LISTBASE_FOREACH (const Panel *, child_panel, &panel->children) { | 
					
						
							|  |  |  |       panel_matches_search_filter_recursive(child_panel, filter_matches); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-09-16 15:28:02 +10:00
										 |  |  |  * Find whether a panel or any of its sub-panels contain a property that matches the search filter, | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |  * depending on the search process running in #UI_block_apply_search_filter earlier. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | bool UI_panel_matches_search_filter(const Panel *panel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   bool search_filter_matches = false; | 
					
						
							|  |  |  |   panel_matches_search_filter_recursive(panel, &search_filter_matches); | 
					
						
							|  |  |  |   return search_filter_matches; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 15:57:30 -05:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Expands a panel if it was tagged as having a result by property search, otherwise collapses it. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  | static void panel_set_expansion_from_seach_filter_recursive(const bContext *C, Panel *panel) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-29 09:33:48 -05:00
										 |  |  |   if (!(panel->type->flag & PNL_NO_HEADER)) { | 
					
						
							|  |  |  |     short start_flag = panel->flag; | 
					
						
							|  |  |  |     SET_FLAG_FROM_TEST(panel->flag, !UI_panel_matches_search_filter(panel), PNL_CLOSED); | 
					
						
							|  |  |  |     if (start_flag != panel->flag) { | 
					
						
							|  |  |  |       panel_activate_state(C, panel, PANEL_STATE_ANIMATION); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* If the panel is filtered (removed) we need to check that its children are too. */ | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, child_panel, &panel->children) { | 
					
						
							| 
									
										
										
										
											2020-09-29 09:33:48 -05:00
										 |  |  |     if (child_panel->runtime_flag & PANEL_ACTIVE) { | 
					
						
							|  |  |  |       panel_set_expansion_from_seach_filter_recursive(C, child_panel); | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Uses the panel's search filter flag to set its expansion, activating animation if it was closed | 
					
						
							|  |  |  |  * or opened. Note that this can't be set too often, or manual interaction becomes impossible. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void UI_panels_set_expansion_from_seach_filter(const bContext *C, ARegion *region) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							| 
									
										
										
										
											2020-09-18 16:39:43 -05:00
										 |  |  |     if (panel->runtime_flag & PANEL_ACTIVE) { | 
					
						
							| 
									
										
										
										
											2020-09-29 09:33:48 -05:00
										 |  |  |       panel_set_expansion_from_seach_filter_recursive(C, panel); | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-27 23:24:29 -05:00
										 |  |  | bool UI_panel_is_active(const Panel *panel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return panel->runtime_flag & PANEL_ACTIVE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Drawing
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2009-04-16 21:39:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 14:43:02 -05:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Draw panels, selected (panels currently being dragged) on top. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void UI_panels_draw(const bContext *C, ARegion *region) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* Draw in reverse order, because #uiBlocks are added in reverse order
 | 
					
						
							|  |  |  |    * and we need child panels to draw on top. */ | 
					
						
							|  |  |  |   LISTBASE_FOREACH_BACKWARD (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							|  |  |  |     if (block->active && block->panel && !(block->panel->flag & PNL_SELECT) && | 
					
						
							|  |  |  |         !UI_block_is_search_only(block)) { | 
					
						
							|  |  |  |       UI_block_draw(C, block); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   LISTBASE_FOREACH_BACKWARD (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							|  |  |  |     if (block->active && block->panel && (block->panel->flag & PNL_SELECT) && | 
					
						
							|  |  |  |         !UI_block_is_search_only(block)) { | 
					
						
							|  |  |  |       UI_block_draw(C, block); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  | /* Triangle 'icon' for panel header. */ | 
					
						
							| 
									
										
										
										
											2017-02-14 13:00:22 +01:00
										 |  |  | void UI_draw_icon_tri(float x, float y, char dir, const float color[4]) | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const float f3 = 0.05 * U.widget_unit; | 
					
						
							|  |  |  |   const float f5 = 0.15 * U.widget_unit; | 
					
						
							|  |  |  |   const float f7 = 0.25 * U.widget_unit; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (dir == 'h') { | 
					
						
							|  |  |  |     UI_draw_anti_tria(x - f3, y - f5, x - f3, y + f5, x + f7, y, color); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (dir == 't') { | 
					
						
							|  |  |  |     UI_draw_anti_tria(x - f5, y - f7, x + f5, y - f7, x, y + f3, color); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   else { /* 'v' = vertical, down. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     UI_draw_anti_tria(x - f5, y + f3, x + f5, y + f3, x, y - f7, color); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  | #define PNL_ICON UI_UNIT_X /* Could be UI_UNIT_Y too. */
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-06 13:28:40 +02:00
										 |  |  | /* For button layout next to label. */ | 
					
						
							| 
									
										
										
										
											2019-03-25 12:19:55 +11:00
										 |  |  | void UI_panel_label_offset(uiBlock *block, int *r_x, int *r_y) | 
					
						
							| 
									
										
										
										
											2018-06-06 13:28:40 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Panel *panel = block->panel; | 
					
						
							|  |  |  |   const bool is_subpanel = (panel->type && panel->type->parent); | 
					
						
							| 
									
										
										
										
											2018-06-06 13:28:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   *r_x = UI_UNIT_X * 1.0f; | 
					
						
							|  |  |  |   *r_y = UI_UNIT_Y * 1.5f; | 
					
						
							| 
									
										
										
										
											2018-06-06 13:28:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (is_subpanel) { | 
					
						
							|  |  |  |     *r_x += (0.7f * UI_UNIT_X); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-06 13:28:40 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-04-08 16:51:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  | static void ui_draw_aligned_panel_header(const uiStyle *style, | 
					
						
							|  |  |  |                                          const uiBlock *block, | 
					
						
							|  |  |  |                                          const rcti *rect, | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |                                          const bool show_background, | 
					
						
							|  |  |  |                                          const bool region_search_filter_active) | 
					
						
							| 
									
										
										
										
											2009-04-08 16:51:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |   const Panel *panel = block->panel; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const bool is_subpanel = (panel->type && panel->type->parent); | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |   const uiFontStyle *fontstyle = (is_subpanel) ? &style->widgetlabel : &style->paneltitle; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* + 0.001f to avoid flirting with float inaccuracy .*/ | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const int pnl_icons = (panel->labelofs + (1.1f * PNL_ICON)) / block->aspect + 0.001f; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |   /* Draw text labels. */ | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |   uchar col_title[4]; | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |   panel_title_color_get( | 
					
						
							|  |  |  |       panel, show_background, is_subpanel, region_search_filter_active, col_title); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   col_title[3] = 255; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |   rcti hrect = *rect; | 
					
						
							|  |  |  |   hrect.xmin = rect->xmin + pnl_icons; | 
					
						
							|  |  |  |   hrect.ymin -= 2.0f / block->aspect; | 
					
						
							|  |  |  |   UI_fontstyle_draw(fontstyle, | 
					
						
							|  |  |  |                     &hrect, | 
					
						
							|  |  |  |                     panel->drawname, | 
					
						
							|  |  |  |                     col_title, | 
					
						
							|  |  |  |                     &(struct uiFontStyleDraw_Params){ | 
					
						
							|  |  |  |                         .align = UI_STYLE_TEXT_LEFT, | 
					
						
							|  |  |  |                     }); | 
					
						
							| 
									
										
										
										
											2009-04-08 16:51:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |  * Draw a panel integrated in buttons-window, tool/property lists etc. | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  | void ui_draw_aligned_panel(const uiStyle *style, | 
					
						
							|  |  |  |                            const uiBlock *block, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                            const rcti *rect, | 
					
						
							|  |  |  |                            const bool show_pin, | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |                            const bool show_background, | 
					
						
							|  |  |  |                            const bool region_search_filter_active) | 
					
						
							| 
									
										
										
										
											2009-04-02 15:01:11 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |   const Panel *panel = block->panel; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   float color[4]; | 
					
						
							|  |  |  |   const bool is_subpanel = (panel->type && panel->type->parent); | 
					
						
							| 
									
										
										
										
											2019-05-01 11:09:22 +10:00
										 |  |  |   const bool show_drag = (!is_subpanel && | 
					
						
							|  |  |  |                           /* FIXME(campbell): currently no background means floating panel which
 | 
					
						
							|  |  |  |                            * can't be dragged. This may be changed in future. */ | 
					
						
							|  |  |  |                           show_background); | 
					
						
							| 
									
										
										
										
											2019-05-16 18:06:55 +10:00
										 |  |  |   const int panel_col = is_subpanel ? TH_PANEL_SUB_BACK : TH_PANEL_BACK; | 
					
						
							| 
									
										
										
										
											2020-06-18 12:21:38 +10:00
										 |  |  |   const bool draw_box_style = (panel->type && panel->type->flag & PNL_DRAW_BOX); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Use the theme for box widgets for box-style panels. */ | 
					
						
							|  |  |  |   uiWidgetColors *box_wcol = NULL; | 
					
						
							|  |  |  |   if (draw_box_style) { | 
					
						
							|  |  |  |     bTheme *btheme = UI_GetTheme(); | 
					
						
							|  |  |  |     box_wcol = &btheme->tui.wcol_box; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const uint pos = GPU_vertformat_attr_add( | 
					
						
							|  |  |  |       immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | 
					
						
							| 
									
										
										
										
											2013-06-24 12:18:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (panel->type && (panel->type->flag & PNL_NO_HEADER)) { | 
					
						
							| 
									
										
										
										
											2019-05-16 18:06:55 +10:00
										 |  |  |     if (show_background) { | 
					
						
							|  |  |  |       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | 
					
						
							|  |  |  |       immUniformThemeColor(panel_col); | 
					
						
							|  |  |  |       immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax); | 
					
						
							|  |  |  |       immUnbindProgram(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-04-16 21:39:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |   /* Calculate header rectangle with + 0.001f to prevent flicker due to float inaccuracy. */ | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   rcti headrect = { | 
					
						
							|  |  |  |       rect->xmin, rect->xmax, rect->ymax, rect->ymax + floor(PNL_HEADER / block->aspect + 0.001f)}; | 
					
						
							| 
									
										
										
										
											2013-06-24 12:18:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   /* Draw a panel and header backdrops with an opaque box backdrop for box style panels. */ | 
					
						
							|  |  |  |   if (draw_box_style && !is_subpanel) { | 
					
						
							|  |  |  |     /* Expand the top a tiny bit to give header buttons equal size above and below. */ | 
					
						
							|  |  |  |     rcti box_rect = {rect->xmin, | 
					
						
							|  |  |  |                      rect->xmax, | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |                      (panel->flag & PNL_CLOSED) ? headrect.ymin : rect->ymin, | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |                      headrect.ymax + U.pixelsize}; | 
					
						
							|  |  |  |     ui_draw_box_opaque(&box_rect, UI_CNR_ALL); | 
					
						
							| 
									
										
										
										
											2018-06-06 13:28:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Mimic the border between aligned box widgets for the bottom of the header. */ | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     if (!(panel->flag & PNL_CLOSED)) { | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | 
					
						
							| 
									
										
										
										
											2020-08-16 15:38:34 +02:00
										 |  |  |       GPU_blend(GPU_BLEND_ALPHA); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       immUniformColor4ubv(box_wcol->outline); | 
					
						
							|  |  |  |       immRectf(pos, rect->xmin, headrect.ymin - U.pixelsize, rect->xmax, headrect.ymin); | 
					
						
							|  |  |  |       uchar emboss_col[4]; | 
					
						
							|  |  |  |       UI_GetThemeColor4ubv(TH_WIDGET_EMBOSS, emboss_col); | 
					
						
							|  |  |  |       immUniformColor4ubv(emboss_col); | 
					
						
							|  |  |  |       immRectf(pos, | 
					
						
							|  |  |  |                rect->xmin, | 
					
						
							|  |  |  |                headrect.ymin - U.pixelsize, | 
					
						
							|  |  |  |                rect->xmax, | 
					
						
							|  |  |  |                headrect.ymin - U.pixelsize - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 15:38:34 +02:00
										 |  |  |       GPU_blend(GPU_BLEND_NONE); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |       immUnbindProgram(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-20 15:17:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   /* Draw the header backdrop. */ | 
					
						
							|  |  |  |   if (show_background && !is_subpanel && !draw_box_style) { | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |     const float minx = rect->xmin; | 
					
						
							|  |  |  |     const float y = headrect.ymax; | 
					
						
							| 
									
										
										
										
											2011-11-19 20:57:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |     immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | 
					
						
							| 
									
										
										
										
											2020-08-16 15:38:34 +02:00
										 |  |  |     GPU_blend(GPU_BLEND_ALPHA); | 
					
						
							| 
									
										
										
										
											2013-06-24 12:18:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Draw with background color. */ | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |     immUniformThemeColor(UI_panel_matches_search_filter(panel) ? TH_MATCH : TH_PANEL_HEADER); | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     immRectf(pos, minx, headrect.ymin, rect->xmax, y); | 
					
						
							| 
									
										
										
										
											2011-11-19 20:57:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     immBegin(GPU_PRIM_LINES, 4); | 
					
						
							| 
									
										
										
										
											2017-02-23 02:52:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     immVertex2f(pos, minx, y); | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     immVertex2f(pos, rect->xmax, y); | 
					
						
							| 
									
										
										
										
											2017-02-23 02:52:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     immVertex2f(pos, minx, y); | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     immVertex2f(pos, rect->xmax, y); | 
					
						
							| 
									
										
										
										
											2017-02-23 02:52:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     immEnd(); | 
					
						
							| 
									
										
										
										
											2011-11-19 20:57:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 15:38:34 +02:00
										 |  |  |     GPU_blend(GPU_BLEND_NONE); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |     immUnbindProgram(); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-06-24 12:18:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   /* draw optional pin icon */ | 
					
						
							|  |  |  |   if (show_pin && (block->panel->flag & PNL_PIN)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     uchar col_title[4]; | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |     panel_title_color_get(panel, show_background, false, region_search_filter_active, col_title); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 15:38:34 +02:00
										 |  |  |     GPU_blend(GPU_BLEND_ALPHA); | 
					
						
							| 
									
										
										
										
											2019-05-09 19:19:52 +02:00
										 |  |  |     UI_icon_draw_ex(headrect.xmax - ((PNL_ICON * 2.2f) / block->aspect), | 
					
						
							|  |  |  |                     headrect.ymin + (5.0f / block->aspect), | 
					
						
							|  |  |  |                     (panel->flag & PNL_PIN) ? ICON_PINNED : ICON_UNPINNED, | 
					
						
							| 
									
										
										
										
											2019-05-09 19:37:31 +02:00
										 |  |  |                     (block->aspect * U.inv_dpi_fac), | 
					
						
							| 
									
										
										
										
											2019-05-09 19:19:52 +02:00
										 |  |  |                     1.0f, | 
					
						
							|  |  |  |                     0.0f, | 
					
						
							| 
									
										
										
										
											2019-08-06 04:20:17 +10:00
										 |  |  |                     col_title, | 
					
						
							| 
									
										
										
										
											2019-05-09 17:37:26 +02:00
										 |  |  |                     false); | 
					
						
							| 
									
										
										
										
											2020-08-16 15:38:34 +02:00
										 |  |  |     GPU_blend(GPU_BLEND_NONE); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Draw the title. */ | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   rcti titlerect = headrect; | 
					
						
							|  |  |  |   if (is_subpanel) { | 
					
						
							|  |  |  |     titlerect.xmin += (0.7f * UI_UNIT_X) / block->aspect + 0.001f; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |   ui_draw_aligned_panel_header( | 
					
						
							|  |  |  |       style, block, &titlerect, show_background, region_search_filter_active); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |   if (show_drag) { | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Make `itemrect` smaller. */ | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     const float scale = 0.7; | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |     rctf itemrect; | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     itemrect.xmax = headrect.xmax - (0.2f * UI_UNIT_X); | 
					
						
							|  |  |  |     itemrect.xmin = itemrect.xmax - BLI_rcti_size_y(&headrect); | 
					
						
							|  |  |  |     itemrect.ymin = headrect.ymin; | 
					
						
							|  |  |  |     itemrect.ymax = headrect.ymax; | 
					
						
							|  |  |  |     BLI_rctf_scale(&itemrect, scale); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     GPU_matrix_push(); | 
					
						
							|  |  |  |     GPU_matrix_translate_2f(itemrect.xmin, itemrect.ymin); | 
					
						
							| 
									
										
										
										
											2020-04-06 16:31:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     const int col_tint = 84; | 
					
						
							|  |  |  |     float col_high[4], col_dark[4]; | 
					
						
							|  |  |  |     UI_GetThemeColorShade4fv(TH_PANEL_HEADER, col_tint, col_high); | 
					
						
							|  |  |  |     UI_GetThemeColorShade4fv(TH_PANEL_BACK, -col_tint, col_dark); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     GPUBatch *batch = GPU_batch_preset_panel_drag_widget( | 
					
						
							|  |  |  |         U.pixelsize, col_high, col_dark, BLI_rcti_size_y(&headrect) * scale); | 
					
						
							|  |  |  |     GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_FLAT_COLOR); | 
					
						
							|  |  |  |     GPU_batch_draw(batch); | 
					
						
							|  |  |  |     GPU_matrix_pop(); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |   /* Draw panel backdrop. */ | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |   if (!(panel->flag & PNL_CLOSED)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     /* in some occasions, draw a border */ | 
					
						
							| 
									
										
										
										
											2020-04-15 13:11:48 -05:00
										 |  |  |     if (panel->flag & PNL_SELECT && !is_subpanel) { | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |       float radius; | 
					
						
							| 
									
										
										
										
											2020-07-03 10:03:16 -04:00
										 |  |  |       if (draw_box_style) { | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |         UI_draw_roundbox_corner_set(UI_CNR_ALL); | 
					
						
							|  |  |  |         radius = box_wcol->roundness * U.widget_unit; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         UI_draw_roundbox_corner_set(UI_CNR_NONE); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |         radius = 0.0f; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       UI_GetThemeColorShade4fv(TH_BACK, -120, color); | 
					
						
							|  |  |  |       UI_draw_roundbox_aa(false, | 
					
						
							|  |  |  |                           0.5f + rect->xmin, | 
					
						
							|  |  |  |                           0.5f + rect->ymin, | 
					
						
							|  |  |  |                           0.5f + rect->xmax, | 
					
						
							|  |  |  |                           0.5f + headrect.ymax + 1, | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |                           radius, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                           color); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | 
					
						
							| 
									
										
										
										
											2020-08-16 15:38:34 +02:00
										 |  |  |     GPU_blend(GPU_BLEND_ALPHA); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-28 16:42:31 +10:00
										 |  |  |     /* Draw panel backdrop if it wasn't already been drawn by the single opaque round box earlier.
 | 
					
						
							|  |  |  |      * Note: Sub-panels blend with panels, so they can't be opaque. */ | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |     if (show_background && !(draw_box_style && !is_subpanel)) { | 
					
						
							| 
									
										
										
										
											2020-06-25 23:13:02 +10:00
										 |  |  |       /* Draw the bottom sub-panels. */ | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  |       if (draw_box_style) { | 
					
						
							|  |  |  |         if (panel->next) { | 
					
						
							|  |  |  |           immUniformThemeColor(panel_col); | 
					
						
							|  |  |  |           immRectf( | 
					
						
							|  |  |  |               pos, rect->xmin + U.pixelsize, rect->ymin, rect->xmax - U.pixelsize, rect->ymax); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |           /* Change the width a little bit to line up with sides. */ | 
					
						
							|  |  |  |           UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT); | 
					
						
							|  |  |  |           UI_GetThemeColor4fv(panel_col, color); | 
					
						
							|  |  |  |           UI_draw_roundbox_aa(true, | 
					
						
							|  |  |  |                               rect->xmin + U.pixelsize, | 
					
						
							|  |  |  |                               rect->ymin + U.pixelsize, | 
					
						
							|  |  |  |                               rect->xmax - U.pixelsize, | 
					
						
							|  |  |  |                               rect->ymax, | 
					
						
							|  |  |  |                               box_wcol->roundness * U.widget_unit, | 
					
						
							|  |  |  |                               color); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         immUniformThemeColor(panel_col); | 
					
						
							|  |  |  |         immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     immUnbindProgram(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Draw collapse icon. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |     rctf itemrect = {.xmin = titlerect.xmin, | 
					
						
							|  |  |  |                      .xmax = itemrect.xmin + BLI_rcti_size_y(&titlerect), | 
					
						
							|  |  |  |                      .ymin = titlerect.ymin, | 
					
						
							|  |  |  |                      .ymax = titlerect.ymax}; | 
					
						
							|  |  |  |     BLI_rctf_scale(&itemrect, 0.25f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uchar col_title[4]; | 
					
						
							| 
									
										
										
										
											2020-09-15 11:25:49 -05:00
										 |  |  |     panel_title_color_get(panel, show_background, false, region_search_filter_active, col_title); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     float tria_color[4]; | 
					
						
							|  |  |  |     rgb_uchar_to_float(tria_color, col_title); | 
					
						
							|  |  |  |     tria_color[3] = 1.0f; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     if (panel->flag & PNL_CLOSED) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       ui_draw_anti_tria_rect(&itemrect, 'h', tria_color); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       ui_draw_anti_tria_rect(&itemrect, 'v', tria_color); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-04-02 15:01:11 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Category Drawing (Tabs)
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static void imm_buf_append( | 
					
						
							|  |  |  |     float vbuf[][2], uchar cbuf[][3], float x, float y, const uchar col[3], int *index) | 
					
						
							| 
									
										
										
										
											2009-07-09 19:45:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   ARRAY_SET_ITEMS(vbuf[*index], x, y); | 
					
						
							|  |  |  |   ARRAY_SET_ITEMS(cbuf[*index], UNPACK3(col)); | 
					
						
							|  |  |  |   (*index)++; | 
					
						
							| 
									
										
										
										
											2009-07-09 19:45:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  | /* Based on UI_draw_roundbox, check on making a version which allows us to skip some sides. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static void ui_panel_category_draw_tab(bool filled, | 
					
						
							|  |  |  |                                        float minx, | 
					
						
							|  |  |  |                                        float miny, | 
					
						
							|  |  |  |                                        float maxx, | 
					
						
							|  |  |  |                                        float maxy, | 
					
						
							|  |  |  |                                        float rad, | 
					
						
							|  |  |  |                                        const int roundboxtype, | 
					
						
							|  |  |  |                                        const bool use_highlight, | 
					
						
							|  |  |  |                                        const bool use_shadow, | 
					
						
							|  |  |  |                                        const bool use_flip_x, | 
					
						
							|  |  |  |                                        const uchar highlight_fade[3], | 
					
						
							|  |  |  |                                        const uchar col[3]) | 
					
						
							| 
									
										
										
										
											2018-06-03 13:32:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   float vec[4][2] = {{0.195, 0.02}, {0.55, 0.169}, {0.831, 0.45}, {0.98, 0.805}}; | 
					
						
							| 
									
										
										
										
											2018-06-03 13:32:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   for (int a = 0; a < 4; a++) { | 
					
						
							|  |  |  |     mul_v2_fl(vec[a], rad); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-03 13:32:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   uint vert_len = 0; | 
					
						
							|  |  |  |   if (use_highlight) { | 
					
						
							|  |  |  |     vert_len += (roundboxtype & UI_CNR_TOP_RIGHT) ? 6 : 1; | 
					
						
							|  |  |  |     vert_len += (roundboxtype & UI_CNR_TOP_LEFT) ? 6 : 1; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (use_highlight && !use_shadow) { | 
					
						
							|  |  |  |     vert_len++; | 
					
						
							| 
									
										
										
										
											2020-04-30 18:58:05 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   else { | 
					
						
							|  |  |  |     vert_len += (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 6 : 1; | 
					
						
							|  |  |  |     vert_len += (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 6 : 1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   /* Maximum size. */ | 
					
						
							|  |  |  |   float vbuf[24][2]; | 
					
						
							|  |  |  |   uchar cbuf[24][3]; | 
					
						
							|  |  |  |   int buf_index = 0; | 
					
						
							| 
									
										
										
										
											2020-04-30 18:58:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Start right-top corner. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (use_highlight) { | 
					
						
							|  |  |  |     if (roundboxtype & UI_CNR_TOP_RIGHT) { | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, maxx, maxy - rad, col, &buf_index); | 
					
						
							|  |  |  |       for (int a = 0; a < 4; a++) { | 
					
						
							|  |  |  |         imm_buf_append(vbuf, cbuf, maxx - vec[a][1], maxy - rad + vec[a][0], col, &buf_index); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, maxx - rad, maxy, col, &buf_index); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, maxx, maxy, col, &buf_index); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Left top-corner. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     if (roundboxtype & UI_CNR_TOP_LEFT) { | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, minx + rad, maxy, col, &buf_index); | 
					
						
							|  |  |  |       for (int a = 0; a < 4; a++) { | 
					
						
							|  |  |  |         imm_buf_append(vbuf, cbuf, minx + rad - vec[a][0], maxy - vec[a][1], col, &buf_index); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, minx, maxy - rad, col, &buf_index); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, minx, maxy, col, &buf_index); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (use_highlight && !use_shadow) { | 
					
						
							|  |  |  |     imm_buf_append( | 
					
						
							|  |  |  |         vbuf, cbuf, minx, miny + rad, highlight_fade ? col : highlight_fade, &buf_index); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Left bottom-corner. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     if (roundboxtype & UI_CNR_BOTTOM_LEFT) { | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, minx, miny + rad, col, &buf_index); | 
					
						
							|  |  |  |       for (int a = 0; a < 4; a++) { | 
					
						
							|  |  |  |         imm_buf_append(vbuf, cbuf, minx + vec[a][1], miny + rad - vec[a][0], col, &buf_index); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, minx + rad, miny, col, &buf_index); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, minx, miny, col, &buf_index); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Right-bottom corner. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     if (roundboxtype & UI_CNR_BOTTOM_RIGHT) { | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, maxx - rad, miny, col, &buf_index); | 
					
						
							|  |  |  |       for (int a = 0; a < 4; a++) { | 
					
						
							|  |  |  |         imm_buf_append(vbuf, cbuf, maxx - rad + vec[a][0], miny + vec[a][1], col, &buf_index); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, maxx, miny + rad, col, &buf_index); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       imm_buf_append(vbuf, cbuf, maxx, miny, col, &buf_index); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (use_flip_x) { | 
					
						
							|  |  |  |     const float midx = (minx + maxx) / 2.0f; | 
					
						
							|  |  |  |     for (int i = 0; i < buf_index; i++) { | 
					
						
							|  |  |  |       vbuf[i][0] = midx - (vbuf[i][0] - midx); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-04-16 21:39:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   GPUVertFormat *format = immVertexFormat(); | 
					
						
							|  |  |  |   const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | 
					
						
							|  |  |  |   uint color = GPU_vertformat_attr_add( | 
					
						
							|  |  |  |       format, "color", GPU_COMP_U8, 3, GPU_FETCH_INT_TO_FLOAT_UNIT); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); | 
					
						
							|  |  |  |   immBegin(filled ? GPU_PRIM_TRI_FAN : GPU_PRIM_LINE_STRIP, vert_len); | 
					
						
							|  |  |  |   for (int i = 0; i < buf_index; i++) { | 
					
						
							|  |  |  |     immAttr3ubv(color, cbuf[i]); | 
					
						
							|  |  |  |     immVertex2fv(pos, vbuf[i]); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   immEnd(); | 
					
						
							|  |  |  |   immUnbindProgram(); | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |  * Draw vertical tabs on the left side of the region, one tab per category. | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |  */ | 
					
						
							|  |  |  | void UI_panel_category_draw_all(ARegion *region, const char *category_id_active) | 
					
						
							| 
									
										
										
										
											2018-06-03 13:32:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   // #define USE_FLAT_INACTIVE
 | 
					
						
							|  |  |  |   const bool is_left = RGN_ALIGN_ENUM_FROM_MASK(region->alignment != RGN_ALIGN_RIGHT); | 
					
						
							|  |  |  |   View2D *v2d = ®ion->v2d; | 
					
						
							|  |  |  |   const uiStyle *style = UI_style_get(); | 
					
						
							|  |  |  |   const uiFontStyle *fstyle = &style->widget; | 
					
						
							|  |  |  |   const int fontid = fstyle->uifont_id; | 
					
						
							|  |  |  |   short fstyle_points = fstyle->points; | 
					
						
							|  |  |  |   const float aspect = ((uiBlock *)region->uiblocks.first)->aspect; | 
					
						
							|  |  |  |   const float zoom = 1.0f / aspect; | 
					
						
							|  |  |  |   const int px = max_ii(1, round_fl_to_int(U.pixelsize)); | 
					
						
							|  |  |  |   const int px_x_sign = is_left ? px : -px; | 
					
						
							|  |  |  |   const int category_tabs_width = round_fl_to_int(UI_PANEL_CATEGORY_MARGIN_WIDTH * zoom); | 
					
						
							|  |  |  |   const float dpi_fac = UI_DPI_FAC; | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Padding of tabs around text. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   const int tab_v_pad_text = round_fl_to_int((2 + ((px * 3) * dpi_fac)) * zoom); | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Padding between tabs. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   const int tab_v_pad = round_fl_to_int((4 + (2 * px * dpi_fac)) * zoom); | 
					
						
							|  |  |  |   const float tab_curve_radius = ((px * 3) * dpi_fac) * zoom; | 
					
						
							|  |  |  |   /* We flip the tab drawing, so always use these flags. */ | 
					
						
							|  |  |  |   const int roundboxtype = UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT; | 
					
						
							|  |  |  |   bool is_alpha; | 
					
						
							|  |  |  |   bool do_scaletabs = false; | 
					
						
							|  |  |  | #ifdef USE_FLAT_INACTIVE
 | 
					
						
							|  |  |  |   bool is_active_prev = false; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   float scaletabs = 1.0f; | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Same for all tabs. */ | 
					
						
							|  |  |  |   /* Intentionally don't scale by 'px'. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   const int rct_xmin = is_left ? v2d->mask.xmin + 3 : (v2d->mask.xmax - category_tabs_width); | 
					
						
							|  |  |  |   const int rct_xmax = is_left ? v2d->mask.xmin + category_tabs_width : (v2d->mask.xmax - 3); | 
					
						
							|  |  |  |   const int text_v_ofs = (rct_xmax - rct_xmin) * 0.3f; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   int y_ofs = tab_v_pad; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Primary theme colors. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   uchar theme_col_back[4]; | 
					
						
							|  |  |  |   uchar theme_col_text[3]; | 
					
						
							|  |  |  |   uchar theme_col_text_hi[3]; | 
					
						
							| 
									
										
										
										
											2018-06-03 13:32:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Tab colors. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   uchar theme_col_tab_bg[4]; | 
					
						
							|  |  |  |   uchar theme_col_tab_active[3]; | 
					
						
							|  |  |  |   uchar theme_col_tab_inactive[3]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Secondary theme colors. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   uchar theme_col_tab_outline[3]; | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   uchar theme_col_tab_divider[3]; /* Line that divides tabs from the main region. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   uchar theme_col_tab_highlight[3]; | 
					
						
							|  |  |  |   uchar theme_col_tab_highlight_inactive[3]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   UI_GetThemeColor4ubv(TH_BACK, theme_col_back); | 
					
						
							|  |  |  |   UI_GetThemeColor3ubv(TH_TEXT, theme_col_text); | 
					
						
							|  |  |  |   UI_GetThemeColor3ubv(TH_TEXT_HI, theme_col_text_hi); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   UI_GetThemeColor4ubv(TH_TAB_BACK, theme_col_tab_bg); | 
					
						
							|  |  |  |   UI_GetThemeColor3ubv(TH_TAB_ACTIVE, theme_col_tab_active); | 
					
						
							|  |  |  |   UI_GetThemeColor3ubv(TH_TAB_INACTIVE, theme_col_tab_inactive); | 
					
						
							|  |  |  |   UI_GetThemeColor3ubv(TH_TAB_OUTLINE, theme_col_tab_outline); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   interp_v3_v3v3_uchar(theme_col_tab_divider, theme_col_back, theme_col_tab_outline, 0.3f); | 
					
						
							|  |  |  |   interp_v3_v3v3_uchar(theme_col_tab_highlight, theme_col_back, theme_col_text_hi, 0.2f); | 
					
						
							|  |  |  |   interp_v3_v3v3_uchar( | 
					
						
							|  |  |  |       theme_col_tab_highlight_inactive, theme_col_tab_inactive, theme_col_text_hi, 0.12f); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   is_alpha = (region->overlap && (theme_col_back[3] != 255)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (fstyle->kerning == 1) { | 
					
						
							|  |  |  |     BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   BLF_enable(fontid, BLF_ROTATION); | 
					
						
							|  |  |  |   BLF_rotation(fontid, M_PI_2); | 
					
						
							|  |  |  |   // UI_fontstyle_set(&style->widget);
 | 
					
						
							|  |  |  |   ui_fontscale(&fstyle_points, aspect / (U.pixelsize * 1.1f)); | 
					
						
							|  |  |  |   BLF_size(fontid, fstyle_points, U.dpi); | 
					
						
							| 
									
										
										
										
											2020-06-25 16:16:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   /* Check the region type supports categories to avoid an assert
 | 
					
						
							|  |  |  |    * for showing 3D view panels in the properties space. */ | 
					
						
							|  |  |  |   if ((1 << region->regiontype) & RGN_TYPE_HAS_CATEGORY_MASK) { | 
					
						
							|  |  |  |     BLI_assert(UI_panel_category_is_visible(region)); | 
					
						
							| 
									
										
										
										
											2020-06-25 16:16:29 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |   /* Calculate tab rectangle and check if we need to scale down. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   LISTBASE_FOREACH (PanelCategoryDyn *, pc_dyn, ®ion->panels_category) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     rcti *rct = &pc_dyn->rect; | 
					
						
							|  |  |  |     const char *category_id = pc_dyn->idname; | 
					
						
							|  |  |  |     const char *category_id_draw = IFACE_(category_id); | 
					
						
							|  |  |  |     const int category_width = BLF_width(fontid, category_id_draw, BLF_DRAW_STR_DUMMY_MAX); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     rct->xmin = rct_xmin; | 
					
						
							|  |  |  |     rct->xmax = rct_xmax; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     rct->ymin = v2d->mask.ymax - (y_ofs + category_width + (tab_v_pad_text * 2)); | 
					
						
							|  |  |  |     rct->ymax = v2d->mask.ymax - (y_ofs); | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     y_ofs += category_width + tab_v_pad + (tab_v_pad_text * 2); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (y_ofs > BLI_rcti_size_y(&v2d->mask)) { | 
					
						
							|  |  |  |     scaletabs = (float)BLI_rcti_size_y(&v2d->mask) / (float)y_ofs; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     LISTBASE_FOREACH (PanelCategoryDyn *, pc_dyn, ®ion->panels_category) { | 
					
						
							|  |  |  |       rcti *rct = &pc_dyn->rect; | 
					
						
							|  |  |  |       rct->ymin = ((rct->ymin - v2d->mask.ymax) * scaletabs) + v2d->mask.ymax; | 
					
						
							|  |  |  |       rct->ymax = ((rct->ymax - v2d->mask.ymax) * scaletabs) + v2d->mask.ymax; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     do_scaletabs = true; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Begin drawing. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   GPU_line_smooth(true); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   uint pos = GPU_vertformat_attr_add( | 
					
						
							|  |  |  |       immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); | 
					
						
							|  |  |  |   immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Draw the background. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (is_alpha) { | 
					
						
							|  |  |  |     GPU_blend(GPU_BLEND_ALPHA); | 
					
						
							|  |  |  |     immUniformColor4ubv(theme_col_tab_bg); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     immUniformColor3ubv(theme_col_tab_bg); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (is_left) { | 
					
						
							|  |  |  |     immRecti( | 
					
						
							|  |  |  |         pos, v2d->mask.xmin, v2d->mask.ymin, v2d->mask.xmin + category_tabs_width, v2d->mask.ymax); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   else { | 
					
						
							|  |  |  |     immRecti( | 
					
						
							|  |  |  |         pos, v2d->mask.xmax - category_tabs_width, v2d->mask.ymin, v2d->mask.xmax, v2d->mask.ymax); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-04-02 01:39:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (is_alpha) { | 
					
						
							|  |  |  |     GPU_blend(GPU_BLEND_NONE); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-03 13:32:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   immUnbindProgram(); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   const int divider_xmin = is_left ? (v2d->mask.xmin + (category_tabs_width - px)) : | 
					
						
							|  |  |  |                                      (v2d->mask.xmax - category_tabs_width) + px; | 
					
						
							|  |  |  |   const int divider_xmax = is_left ? (v2d->mask.xmin + category_tabs_width) : | 
					
						
							|  |  |  |                                      (v2d->mask.xmax - (category_tabs_width + px)) + px; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   LISTBASE_FOREACH (PanelCategoryDyn *, pc_dyn, ®ion->panels_category) { | 
					
						
							|  |  |  |     const rcti *rct = &pc_dyn->rect; | 
					
						
							|  |  |  |     const char *category_id = pc_dyn->idname; | 
					
						
							|  |  |  |     const char *category_id_draw = IFACE_(category_id); | 
					
						
							|  |  |  |     const int category_width = BLI_rcti_size_y(rct) - (tab_v_pad_text * 2); | 
					
						
							|  |  |  |     size_t category_draw_len = BLF_DRAW_STR_DUMMY_MAX; | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  |     int category_width = BLF_width(fontid, category_id_draw, BLF_DRAW_STR_DUMMY_MAX); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     const bool is_active = STREQ(category_id, category_id_active); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     GPU_blend(GPU_BLEND_ALPHA); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | #ifdef USE_FLAT_INACTIVE
 | 
					
						
							|  |  |  |     if (is_active) | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       const bool use_flip_x = !is_left; | 
					
						
							|  |  |  |       ui_panel_category_draw_tab(true, | 
					
						
							|  |  |  |                                  rct->xmin, | 
					
						
							|  |  |  |                                  rct->ymin, | 
					
						
							|  |  |  |                                  rct->xmax, | 
					
						
							|  |  |  |                                  rct->ymax, | 
					
						
							|  |  |  |                                  tab_curve_radius - px, | 
					
						
							|  |  |  |                                  roundboxtype, | 
					
						
							|  |  |  |                                  true, | 
					
						
							|  |  |  |                                  true, | 
					
						
							|  |  |  |                                  use_flip_x, | 
					
						
							|  |  |  |                                  NULL, | 
					
						
							|  |  |  |                                  is_active ? theme_col_tab_active : theme_col_tab_inactive); | 
					
						
							| 
									
										
										
										
											2011-11-20 14:31:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |       /* Tab outline. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       ui_panel_category_draw_tab(false, | 
					
						
							|  |  |  |                                  rct->xmin - px_x_sign, | 
					
						
							|  |  |  |                                  rct->ymin - px, | 
					
						
							|  |  |  |                                  rct->xmax - px_x_sign, | 
					
						
							|  |  |  |                                  rct->ymax + px, | 
					
						
							|  |  |  |                                  tab_curve_radius, | 
					
						
							|  |  |  |                                  roundboxtype, | 
					
						
							|  |  |  |                                  true, | 
					
						
							|  |  |  |                                  true, | 
					
						
							|  |  |  |                                  use_flip_x, | 
					
						
							|  |  |  |                                  NULL, | 
					
						
							|  |  |  |                                  theme_col_tab_outline); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |       /* Tab highlight (3d look). */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       ui_panel_category_draw_tab(false, | 
					
						
							|  |  |  |                                  rct->xmin, | 
					
						
							|  |  |  |                                  rct->ymin, | 
					
						
							|  |  |  |                                  rct->xmax, | 
					
						
							|  |  |  |                                  rct->ymax, | 
					
						
							|  |  |  |                                  tab_curve_radius, | 
					
						
							|  |  |  |                                  roundboxtype, | 
					
						
							|  |  |  |                                  true, | 
					
						
							|  |  |  |                                  false, | 
					
						
							|  |  |  |                                  use_flip_x, | 
					
						
							|  |  |  |                                  is_active ? theme_col_back : theme_col_tab_inactive, | 
					
						
							|  |  |  |                                  is_active ? theme_col_tab_highlight : | 
					
						
							|  |  |  |                                              theme_col_tab_highlight_inactive); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Tab black-line. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     if (!is_active) { | 
					
						
							|  |  |  |       pos = GPU_vertformat_attr_add( | 
					
						
							|  |  |  |           immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); | 
					
						
							|  |  |  |       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       immUniformColor3ubv(theme_col_tab_divider); | 
					
						
							|  |  |  |       immRecti(pos, divider_xmin, rct->ymin - tab_v_pad, divider_xmax, rct->ymax + tab_v_pad); | 
					
						
							|  |  |  |       immUnbindProgram(); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-12-26 13:05:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     if (do_scaletabs) { | 
					
						
							|  |  |  |       category_draw_len = BLF_width_to_strlen( | 
					
						
							|  |  |  |           fontid, category_id_draw, category_draw_len, category_width, NULL); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     BLF_position(fontid, rct->xmax - text_v_ofs, rct->ymin + tab_v_pad_text, 0.0f); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Tab titles. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Draw white shadow to give text more depth. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     BLF_color3ubv(fontid, theme_col_text); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Main tab title. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     BLF_draw(fontid, category_id_draw, category_draw_len); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     GPU_blend(GPU_BLEND_NONE); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Tab black-line remaining (last tab). */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     pos = GPU_vertformat_attr_add( | 
					
						
							|  |  |  |         immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); | 
					
						
							|  |  |  |     immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | 
					
						
							|  |  |  |     if (pc_dyn->prev == NULL) { | 
					
						
							|  |  |  |       immUniformColor3ubv(theme_col_tab_divider); | 
					
						
							|  |  |  |       immRecti(pos, divider_xmin, rct->ymax + px, divider_xmax, v2d->mask.ymax); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (pc_dyn->next == NULL) { | 
					
						
							|  |  |  |       immUniformColor3ubv(theme_col_tab_divider); | 
					
						
							|  |  |  |       immRecti(pos, divider_xmin, 0, divider_xmax, rct->ymin); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | #ifdef USE_FLAT_INACTIVE
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Draw line between inactive tabs. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     if (is_active == false && is_active_prev == false && pc_dyn->prev) { | 
					
						
							|  |  |  |       immUniformColor3ubv(theme_col_tab_divider); | 
					
						
							|  |  |  |       immRecti(pos, | 
					
						
							|  |  |  |                v2d->mask.xmin + (category_tabs_width / 5), | 
					
						
							|  |  |  |                rct->ymax + px, | 
					
						
							|  |  |  |                (v2d->mask.xmin + category_tabs_width) - (category_tabs_width / 5), | 
					
						
							|  |  |  |                rct->ymax + (px * 3)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     is_active_prev = is_active; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     immUnbindProgram(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Not essential, but allows events to be handled right up to the region edge (T38171). */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     if (is_left) { | 
					
						
							|  |  |  |       pc_dyn->rect.xmin = v2d->mask.xmin; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       pc_dyn->rect.xmax = v2d->mask.xmax; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   GPU_line_smooth(false); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   BLF_disable(fontid, BLF_ROTATION); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (fstyle->kerning == 1) { | 
					
						
							|  |  |  |     BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | #undef USE_FLAT_INACTIVE
 | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Panel Alignment
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static int get_panel_size_y(const Panel *panel) | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (panel->type && (panel->type->flag & PNL_NO_HEADER)) { | 
					
						
							|  |  |  |     return panel->sizey; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return PNL_HEADER + panel->sizey; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static int get_panel_real_size_y(const Panel *panel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const int sizey = (panel->flag & PNL_CLOSED) ? 0 : panel->sizey; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (panel->type && (panel->type->flag & PNL_NO_HEADER)) { | 
					
						
							|  |  |  |     return sizey; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return PNL_HEADER + sizey; | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | int UI_panel_size_y(const Panel *panel) | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return get_panel_real_size_y(panel); | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * This function is needed because #uiBlock and Panel itself don't | 
					
						
							|  |  |  |  * change #Panel.sizey or location when closed. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static int get_panel_real_ofsy(Panel *panel) | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (panel->flag & PNL_CLOSED) { | 
					
						
							|  |  |  |     return panel->ofsy + panel->sizey; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return panel->ofsy; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | bool UI_panel_is_dragging(const struct Panel *panel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   uiHandlePanelData *data = panel->activedata; | 
					
						
							|  |  |  |   if (!data) { | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return data->is_drag_drop; | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |  * \note about sorting: | 
					
						
							|  |  |  |  * The #Panel.sortorder has a lower value for new panels being added. | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |  * however, that only works to insert a single panel, when more new panels get | 
					
						
							|  |  |  |  * added the coordinates of existing panels and the previously stored to-be-inserted | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |  * panels do not match for sorting. | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  | static int find_highest_panel(const void *a, const void *b) | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   const Panel *panel_a = ((PanelSort *)a)->panel; | 
					
						
							|  |  |  |   const Panel *panel_b = ((PanelSort *)b)->panel; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   /* Stick uppermost header-less panels to the top of the region -
 | 
					
						
							|  |  |  |    * prevent them from being sorted (multiple header-less panels have to be sorted though). */ | 
					
						
							|  |  |  |   if (panel_a->type->flag & PNL_NO_HEADER && panel_b->type->flag & PNL_NO_HEADER) { | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Skip and check for `ofsy` and #Panel.sortorder below. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   if (panel_a->type->flag & PNL_NO_HEADER) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-23 12:06:42 -05:00
										 |  |  |   if (panel_b->type->flag & PNL_NO_HEADER) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     return 1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   if (panel_a->ofsy + panel_a->sizey < panel_b->ofsy + panel_b->sizey) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     return 1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   if (panel_a->ofsy + panel_a->sizey > panel_b->ofsy + panel_b->sizey) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   if (panel_a->sortorder > panel_b->sortorder) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     return 1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   if (panel_a->sortorder < panel_b->sortorder) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  | static int compare_panel(const void *a, const void *b) | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   const Panel *panel_a = ((PanelSort *)a)->panel; | 
					
						
							|  |  |  |   const Panel *panel_b = ((PanelSort *)b)->panel; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   if (panel_a->sortorder > panel_b->sortorder) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     return 1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-19 16:24:10 -05:00
										 |  |  |   if (panel_a->sortorder < panel_b->sortorder) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2015-04-25 12:56:24 +10:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static void align_sub_panels(Panel *panel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* Position sub panels. */ | 
					
						
							|  |  |  |   int ofsy = panel->ofsy + panel->sizey - panel->blocksizey; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   LISTBASE_FOREACH (Panel *, pachild, &panel->children) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     if (pachild->runtime_flag & PANEL_ACTIVE) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       pachild->ofsx = panel->ofsx; | 
					
						
							|  |  |  |       pachild->ofsy = ofsy - get_panel_size_y(pachild); | 
					
						
							|  |  |  |       ofsy -= get_panel_real_size_y(pachild); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       if (pachild->children.first) { | 
					
						
							|  |  |  |         align_sub_panels(pachild); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Calculate the position and order of panels as they are opened, closed, and dragged. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-09-17 22:58:07 -05:00
										 |  |  | static bool uiAlignPanelStep(ARegion *region, const float factor, const bool drag) | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Count active panels. */ | 
					
						
							| 
									
										
										
										
											2020-09-17 22:58:07 -05:00
										 |  |  |   int active_panels_len = 0; | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     if (panel->runtime_flag & PANEL_ACTIVE) { | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |       /* These panels should have types since they are currently displayed to the user. */ | 
					
						
							|  |  |  |       BLI_assert(panel->type != NULL); | 
					
						
							| 
									
										
										
										
											2020-09-17 22:58:07 -05:00
										 |  |  |       active_panels_len++; | 
					
						
							| 
									
										
										
										
											2019-05-13 16:53:40 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-17 22:58:07 -05:00
										 |  |  |   if (active_panels_len == 0) { | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Sort panels. */ | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |   PanelSort *panel_sort = MEM_mallocN(sizeof(PanelSort) * active_panels_len, __func__); | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     PanelSort *ps = panel_sort; | 
					
						
							|  |  |  |     LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							|  |  |  |       if (panel->runtime_flag & PANEL_ACTIVE) { | 
					
						
							|  |  |  |         ps->panel = panel; | 
					
						
							|  |  |  |         ps++; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-17 13:37:59 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (drag) { | 
					
						
							| 
									
										
										
										
											2020-09-17 22:58:07 -05:00
										 |  |  |     /* While dragging, sort based on location and update #Panel.sortorder. */ | 
					
						
							|  |  |  |     qsort(panel_sort, active_panels_len, sizeof(PanelSort), find_highest_panel); | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |     for (int i = 0; i < active_panels_len; i++) { | 
					
						
							|  |  |  |       panel_sort[i].panel->sortorder = i; | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Otherwise use #Panel.sortorder. */ | 
					
						
							| 
									
										
										
										
											2020-09-17 22:58:07 -05:00
										 |  |  |     qsort(panel_sort, active_panels_len, sizeof(PanelSort), compare_panel); | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |   /* X offset. */ | 
					
						
							|  |  |  |   const int region_offset_x = panel_region_offset_x_get(region); | 
					
						
							|  |  |  |   for (int i = 0; i < active_panels_len; i++) { | 
					
						
							|  |  |  |     PanelSort *ps = &panel_sort[i]; | 
					
						
							|  |  |  |     const bool use_box = ps->panel->type->flag & PNL_DRAW_BOX; | 
					
						
							|  |  |  |     ps->panel->runtime.region_ofsx = region_offset_x; | 
					
						
							|  |  |  |     ps->new_offset_x = region_offset_x + ((use_box) ? UI_PANEL_BOX_STYLE_MARGIN : 0); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |   /* Y offset. */ | 
					
						
							|  |  |  |   for (int i = 0, y = 0; i < active_panels_len; i++) { | 
					
						
							|  |  |  |     PanelSort *ps = &panel_sort[i]; | 
					
						
							|  |  |  |     y -= get_panel_real_size_y(ps->panel); | 
					
						
							| 
									
										
										
										
											2020-05-26 15:39:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |     const bool use_box = ps->panel->type->flag & PNL_DRAW_BOX; | 
					
						
							|  |  |  |     if (use_box) { | 
					
						
							|  |  |  |       y -= UI_PANEL_BOX_STYLE_MARGIN; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ps->new_offset_y = y; | 
					
						
							|  |  |  |     /* The header still draws offset by the size of closed panels, so apply the offset here. */ | 
					
						
							|  |  |  |     if (ps->panel->flag & PNL_CLOSED) { | 
					
						
							|  |  |  |       panel_sort[i].new_offset_y -= ps->panel->sizey; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 22:58:07 -05:00
										 |  |  |   /* Interpolate based on the input factor. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   bool changed = false; | 
					
						
							| 
									
										
										
										
											2020-09-17 23:15:20 -05:00
										 |  |  |   for (int i = 0; i < active_panels_len; i++) { | 
					
						
							|  |  |  |     PanelSort *ps = &panel_sort[i]; | 
					
						
							|  |  |  |     if (ps->panel->flag & PNL_SELECT) { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ps->new_offset_x != ps->panel->ofsx) { | 
					
						
							|  |  |  |       const float x = interpf((float)ps->new_offset_x, (float)ps->panel->ofsx, factor); | 
					
						
							|  |  |  |       ps->panel->ofsx = round_fl_to_int(x); | 
					
						
							|  |  |  |       changed = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (ps->new_offset_y != ps->panel->ofsy) { | 
					
						
							|  |  |  |       const float y = interpf((float)ps->new_offset_y, (float)ps->panel->ofsy, factor); | 
					
						
							|  |  |  |       ps->panel->ofsy = round_fl_to_int(y); | 
					
						
							|  |  |  |       changed = true; | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Set locations for tabbed and sub panels. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     if (panel->runtime_flag & PANEL_ACTIVE) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       if (panel->children.first) { | 
					
						
							|  |  |  |         align_sub_panels(panel); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 22:58:07 -05:00
										 |  |  |   MEM_freeN(panel_sort); | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return changed; | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static void ui_panels_size(ARegion *region, int *r_x, int *r_y) | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   int sizex = 0; | 
					
						
							|  |  |  |   int sizey = 0; | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Compute size taken up by panels, for setting in view2d. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |     if (panel->runtime_flag & PANEL_ACTIVE) { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       const int pa_sizex = panel->ofsx + panel->sizex; | 
					
						
							|  |  |  |       const int pa_sizey = get_panel_real_ofsy(panel); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       sizex = max_ii(sizex, pa_sizex); | 
					
						
							|  |  |  |       sizey = min_ii(sizey, pa_sizey); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (sizex == 0) { | 
					
						
							|  |  |  |     sizex = UI_PANEL_WIDTH; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (sizey == 0) { | 
					
						
							|  |  |  |     sizey = -UI_PANEL_WIDTH; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   *r_x = sizex; | 
					
						
							|  |  |  |   *r_y = sizey; | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static void ui_do_animate(bContext *C, Panel *panel) | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   uiHandlePanelData *data = panel->activedata; | 
					
						
							|  |  |  |   ARegion *region = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   float fac = (PIL_check_seconds_timer() - data->starttime) / ANIMATION_TIME; | 
					
						
							|  |  |  |   fac = min_ff(sqrtf(fac), 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* For max 1 second, interpolate positions. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (uiAlignPanelStep(region, fac, false)) { | 
					
						
							|  |  |  |     ED_region_tag_redraw(region); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     fac = 1.0f; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (fac >= 1.0f) { | 
					
						
							|  |  |  |     /* Store before data is freed. */ | 
					
						
							|  |  |  |     const bool is_drag_drop = data->is_drag_drop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     panel_activate_state(C, panel, PANEL_STATE_EXIT); | 
					
						
							|  |  |  |     if (is_drag_drop) { | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |       /* Note: doing this in #panel_activate_state would require removing `const` for context in
 | 
					
						
							|  |  |  |        * many other places. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       reorder_instanced_panel_list(C, region, panel); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2019-05-22 19:50:40 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-23 16:24:20 -05:00
										 |  |  | static void panels_layout_begin_clear_flags(ListBase *lb) | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | { | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, panel, lb) { | 
					
						
							| 
									
										
										
										
											2020-09-23 16:24:20 -05:00
										 |  |  |     /* Flags to copy over to the next layout pass. */ | 
					
						
							|  |  |  |     const short flag_copy = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const bool was_active = panel->runtime_flag & PANEL_ACTIVE; | 
					
						
							|  |  |  |     panel->runtime_flag &= flag_copy; | 
					
						
							|  |  |  |     if (was_active) { | 
					
						
							|  |  |  |       panel->runtime_flag |= PANEL_WAS_ACTIVE; | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-23 16:24:20 -05:00
										 |  |  |     panels_layout_begin_clear_flags(&panel->children); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | void UI_panels_begin(const bContext *UNUSED(C), ARegion *region) | 
					
						
							| 
									
										
										
										
											2019-05-22 19:50:40 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-23 16:24:20 -05:00
										 |  |  |   /* Set all panels as inactive, so that at the end we know which ones were used. Also
 | 
					
						
							| 
									
										
										
										
											2020-09-24 14:18:04 +10:00
										 |  |  |    * clear other flags so we know later that their values were set for the current redraw. */ | 
					
						
							| 
									
										
										
										
											2020-09-23 16:24:20 -05:00
										 |  |  |   panels_layout_begin_clear_flags(®ion->panels); | 
					
						
							| 
									
										
										
										
											2019-05-22 19:50:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | void UI_panels_end(const bContext *C, ARegion *region, int *r_x, int *r_y) | 
					
						
							| 
									
										
										
										
											2019-05-22 19:50:40 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   ScrArea *area = CTX_wm_area(C); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 15:34:27 -05:00
										 |  |  |   region_panels_set_expansion_from_list_data(C, region); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 15:57:30 -05:00
										 |  |  |   /* Update panel expansion based on property search results. */ | 
					
						
							|  |  |  |   if (region->flag & RGN_FLAG_SEARCH_FILTER_UPDATE) { | 
					
						
							|  |  |  |     /* Don't use the last update from the deactivation, or all the panels will be left closed. */ | 
					
						
							|  |  |  |     if (region->flag & RGN_FLAG_SEARCH_FILTER_ACTIVE) { | 
					
						
							|  |  |  |       UI_panels_set_expansion_from_seach_filter(C, region); | 
					
						
							|  |  |  |       set_panels_list_data_expand_flag(C, region); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |   /* Offset contents. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							|  |  |  |     if (block->active && block->panel) { | 
					
						
							|  |  |  |       ui_offset_panel_block(block); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-22 19:50:40 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Re-align, possibly with animation. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   Panel *panel; | 
					
						
							|  |  |  |   if (panels_need_realign(area, region, &panel)) { | 
					
						
							|  |  |  |     if (panel) { | 
					
						
							|  |  |  |       panel_activate_state(C, panel, PANEL_STATE_ANIMATION); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       uiAlignPanelStep(region, 1.0, false); | 
					
						
							| 
									
										
										
										
											2019-05-22 19:50:40 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 23:47:09 -05:00
										 |  |  |   /* Compute size taken up by panels. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   ui_panels_size(region, r_x, r_y); | 
					
						
							| 
									
										
										
										
											2019-05-22 19:50:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Panel Dragging
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | #define DRAG_REGION_PAD (PNL_HEADER * 0.5)
 | 
					
						
							|  |  |  | static void ui_do_drag(const bContext *C, const wmEvent *event, Panel *panel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   uiHandlePanelData *data = panel->activedata; | 
					
						
							|  |  |  |   ARegion *region = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   /* Keep the drag position in the region with a small pad to keep the panel visible. */ | 
					
						
							|  |  |  |   const int x = clamp_i(event->x, region->winrct.xmin, region->winrct.xmax + DRAG_REGION_PAD); | 
					
						
							|  |  |  |   const int y = clamp_i(event->y, region->winrct.ymin, region->winrct.ymax + DRAG_REGION_PAD); | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   float dx = (float)(x - data->startx); | 
					
						
							|  |  |  |   float dy = (float)(y - data->starty); | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   /* Adjust for region zoom. */ | 
					
						
							|  |  |  |   dx *= BLI_rctf_size_x(®ion->v2d.cur) / (float)BLI_rcti_size_x(®ion->winrct); | 
					
						
							|  |  |  |   dy *= BLI_rctf_size_y(®ion->v2d.cur) / (float)BLI_rcti_size_y(®ion->winrct); | 
					
						
							| 
									
										
										
										
											2018-09-27 16:21:57 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (data->state == PANEL_STATE_DRAG_SCALE) { | 
					
						
							|  |  |  |     panel->sizex = MAX2(data->startsizex + dx, UI_PANEL_MINX); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     if (data->startsizey - dy < UI_PANEL_MINY) { | 
					
						
							|  |  |  |       dy = -UI_PANEL_MINY + data->startsizey; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     panel->sizey = data->startsizey - dy; | 
					
						
							|  |  |  |     panel->ofsy = data->startofsy + dy; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Reset the panel snapping, to allow dragging away from snapped edges. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     panel->snap = PNL_SNAP_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Add the movement of the view due to edge scrolling while dragging. */ | 
					
						
							|  |  |  |     dx += ((float)region->v2d.cur.xmin - data->start_cur_xmin); | 
					
						
							|  |  |  |     dy += ((float)region->v2d.cur.ymin - data->start_cur_ymin); | 
					
						
							|  |  |  |     panel->ofsx = data->startofsx + round_fl_to_int(dx); | 
					
						
							|  |  |  |     panel->ofsy = data->startofsy + round_fl_to_int(dy); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uiAlignPanelStep(region, 0.2f, true); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   ED_region_tag_redraw(region); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #undef DRAG_REGION_PAD
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Region Level Panel Interaction
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | static uiPanelMouseState ui_panel_mouse_state_get(const uiBlock *block, | 
					
						
							|  |  |  |                                                   const Panel *panel, | 
					
						
							|  |  |  |                                                   const int mx, | 
					
						
							|  |  |  |                                                   const int my) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!IN_RANGE((float)mx, block->rect.xmin, block->rect.xmax)) { | 
					
						
							|  |  |  |     return PANEL_MOUSE_OUTSIDE; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (IN_RANGE((float)my, block->rect.ymax, block->rect.ymax + PNL_HEADER)) { | 
					
						
							|  |  |  |     return PANEL_MOUSE_INSIDE_HEADER; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (!(panel->flag & PNL_CLOSED)) { | 
					
						
							|  |  |  |     if (IN_RANGE((float)my, block->rect.ymin, block->rect.ymax + PNL_HEADER)) { | 
					
						
							|  |  |  |       return PANEL_MOUSE_INSIDE_CONTENT; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return PANEL_MOUSE_OUTSIDE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct uiPanelDragCollapseHandle { | 
					
						
							|  |  |  |   bool was_first_open; | 
					
						
							|  |  |  |   int xy_init[2]; | 
					
						
							|  |  |  | } uiPanelDragCollapseHandle; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ui_panel_drag_collapse_handler_remove(bContext *UNUSED(C), void *userdata) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   uiPanelDragCollapseHandle *dragcol_data = userdata; | 
					
						
							|  |  |  |   MEM_freeN(dragcol_data); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ui_panel_drag_collapse(const bContext *C, | 
					
						
							|  |  |  |                                    const uiPanelDragCollapseHandle *dragcol_data, | 
					
						
							|  |  |  |                                    const int xy_dst[2]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ARegion *region = CTX_wm_region(C); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							|  |  |  |     float xy_a_block[2] = {UNPACK2(dragcol_data->xy_init)}; | 
					
						
							|  |  |  |     float xy_b_block[2] = {UNPACK2(xy_dst)}; | 
					
						
							|  |  |  |     Panel *panel = block->panel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (panel == NULL || (panel->type && (panel->type->flag & PNL_NO_HEADER))) { | 
					
						
							|  |  |  |       continue; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     const int oldflag = panel->flag; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Lock axis. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     xy_b_block[0] = dragcol_data->xy_init[0]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Use cursor coords in block space. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     ui_window_to_block_fl(region, block, &xy_a_block[0], &xy_a_block[1]); | 
					
						
							|  |  |  |     ui_window_to_block_fl(region, block, &xy_b_block[0], &xy_b_block[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* Set up `rect` to match header size. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     rctf rect = block->rect; | 
					
						
							|  |  |  |     rect.ymin = rect.ymax; | 
					
						
							|  |  |  |     rect.ymax = rect.ymin + PNL_HEADER; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Touch all panels between last mouse coordinate and the current one. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     if (BLI_rctf_isect_segment(&rect, xy_a_block, xy_b_block)) { | 
					
						
							|  |  |  |       /* Force panel to open or close. */ | 
					
						
							|  |  |  |       SET_FLAG_FROM_TEST(panel->flag, dragcol_data->was_first_open, PNL_CLOSED); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |       /* If panel->flag has changed this means a panel was opened/closed here. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       if (panel->flag != oldflag) { | 
					
						
							|  |  |  |         panel_activate_state(C, panel, PANEL_STATE_ANIMATION); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   /* Update the instanced panel data expand flags with the changes made here. */ | 
					
						
							|  |  |  |   set_panels_list_data_expand_flag(C, region); | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |  * Panel drag-collapse (modal handler). | 
					
						
							|  |  |  |  * Clicking and dragging over panels toggles their collapse state based on the panel | 
					
						
							|  |  |  |  * that was first dragged over. If it was open all affected panels including the initial | 
					
						
							|  |  |  |  * one are closed and vice versa. | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static int ui_panel_drag_collapse_handler(bContext *C, const wmEvent *event, void *userdata) | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   wmWindow *win = CTX_wm_window(C); | 
					
						
							|  |  |  |   uiPanelDragCollapseHandle *dragcol_data = userdata; | 
					
						
							|  |  |  |   short retval = WM_UI_HANDLER_CONTINUE; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   switch (event->type) { | 
					
						
							|  |  |  |     case MOUSEMOVE: | 
					
						
							|  |  |  |       ui_panel_drag_collapse(C, dragcol_data, &event->x); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       retval = WM_UI_HANDLER_BREAK; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case LEFTMOUSE: | 
					
						
							|  |  |  |       if (event->val == KM_RELEASE) { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |         /* Done! */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |         WM_event_remove_ui_handler(&win->modalhandlers, | 
					
						
							|  |  |  |                                    ui_panel_drag_collapse_handler, | 
					
						
							|  |  |  |                                    ui_panel_drag_collapse_handler_remove, | 
					
						
							|  |  |  |                                    dragcol_data, | 
					
						
							|  |  |  |                                    true); | 
					
						
							|  |  |  |         ui_panel_drag_collapse_handler_remove(C, dragcol_data); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |       /* Don't let any left-mouse event fall through! */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       retval = WM_UI_HANDLER_BREAK; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return retval; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | static void ui_panel_drag_collapse_handler_add(const bContext *C, const bool was_open) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   wmWindow *win = CTX_wm_window(C); | 
					
						
							|  |  |  |   const wmEvent *event = win->eventstate; | 
					
						
							|  |  |  |   uiPanelDragCollapseHandle *dragcol_data = MEM_mallocN(sizeof(*dragcol_data), __func__); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   dragcol_data->was_first_open = was_open; | 
					
						
							|  |  |  |   copy_v2_v2_int(dragcol_data->xy_init, &event->x); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   WM_event_add_ui_handler(C, | 
					
						
							|  |  |  |                           &win->modalhandlers, | 
					
						
							|  |  |  |                           ui_panel_drag_collapse_handler, | 
					
						
							|  |  |  |                           ui_panel_drag_collapse_handler_remove, | 
					
						
							|  |  |  |                           dragcol_data, | 
					
						
							|  |  |  |                           0); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Supposing the block has a panel and isn't a menu, handle opening, closing, pinning, etc. | 
					
						
							|  |  |  |  * Code currently assumes layout style for location of widgets | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-09-08 09:10:17 +10:00
										 |  |  |  * \param mx: The mouse x coordinate, in panel space. | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |  */ | 
					
						
							|  |  |  | static void ui_handle_panel_header(const bContext *C, | 
					
						
							|  |  |  |                                    uiBlock *block, | 
					
						
							|  |  |  |                                    const int mx, | 
					
						
							|  |  |  |                                    short int event_type, | 
					
						
							|  |  |  |                                    const short ctrl, | 
					
						
							|  |  |  |                                    const short shift) | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   Panel *panel = block->panel; | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   ARegion *region = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   BLI_assert(panel->type != NULL); | 
					
						
							|  |  |  |   BLI_assert(!(panel->type->flag & PNL_NO_HEADER)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   const bool is_subpanel = (panel->type->parent != NULL); | 
					
						
							|  |  |  |   const bool use_pin = UI_panel_category_is_visible(region) && !is_subpanel; | 
					
						
							|  |  |  |   const bool show_pin = use_pin && (panel->flag & PNL_PIN); | 
					
						
							|  |  |  |   const bool show_drag = !is_subpanel; | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   /* Handle panel pinning. */ | 
					
						
							|  |  |  |   if (use_pin && ELEM(event_type, EVT_RETKEY, EVT_PADENTER, LEFTMOUSE) && shift) { | 
					
						
							|  |  |  |     panel->flag ^= PNL_PIN; | 
					
						
							|  |  |  |     ED_region_tag_redraw(region); | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   float expansion_area_xmax = block->rect.xmax; | 
					
						
							|  |  |  |   if (show_drag) { | 
					
						
							|  |  |  |     expansion_area_xmax -= (PNL_ICON * 1.5f); | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   if (show_pin) { | 
					
						
							|  |  |  |     expansion_area_xmax -= PNL_ICON; | 
					
						
							| 
									
										
										
										
											2019-05-10 13:43:07 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   /* Collapse and expand panels. */ | 
					
						
							|  |  |  |   if (ELEM(event_type, EVT_RETKEY, EVT_PADENTER, EVT_AKEY) || mx < expansion_area_xmax) { | 
					
						
							|  |  |  |     if (ctrl && !is_subpanel) { | 
					
						
							|  |  |  |       /* For parent panels, collapse all other panels or toggle children. */ | 
					
						
							|  |  |  |       if (panel->flag & PNL_CLOSED || BLI_listbase_is_empty(&panel->children)) { | 
					
						
							|  |  |  |         panels_collapse_all(region, panel); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |         /* Reset the view - we don't want to display a view without content. */ | 
					
						
							|  |  |  |         UI_view2d_offset(®ion->v2d, 0.0f, 1.0f); | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |       else { | 
					
						
							|  |  |  |         /* If a panel has sub-panels and it's open, toggle the expansion
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |          * of the sub-panels (based on the expansion of the first sub-panel). */ | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |         Panel *first_child = panel->children.first; | 
					
						
							|  |  |  |         BLI_assert(first_child != NULL); | 
					
						
							|  |  |  |         panel_set_flag_recursive(panel, PNL_CLOSED, !(first_child->flag & PNL_CLOSED)); | 
					
						
							|  |  |  |         panel->flag |= PNL_CLOSED; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     if (panel->flag & PNL_CLOSED) { | 
					
						
							|  |  |  |       panel->flag &= ~PNL_CLOSED; | 
					
						
							|  |  |  |       /* Snap back up so full panel aligns with screen edge. */ | 
					
						
							|  |  |  |       if (panel->snap & PNL_SNAP_BOTTOM) { | 
					
						
							|  |  |  |         panel->ofsy = 0; | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |       if (event_type == LEFTMOUSE) { | 
					
						
							|  |  |  |         ui_panel_drag_collapse_handler_add(C, false); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       /* Snap down to bottom screen edge. */ | 
					
						
							|  |  |  |       panel->flag |= PNL_CLOSED; | 
					
						
							|  |  |  |       if (panel->snap & PNL_SNAP_BOTTOM) { | 
					
						
							|  |  |  |         panel->ofsy = -panel->sizey; | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |       if (event_type == LEFTMOUSE) { | 
					
						
							|  |  |  |         ui_panel_drag_collapse_handler_add(C, true); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     set_panels_list_data_expand_flag(C, region); | 
					
						
							|  |  |  |     panel_activate_state(C, panel, PANEL_STATE_ANIMATION); | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Handle panel dragging. For now don't allow dragging in floating regions. */ | 
					
						
							|  |  |  |   if (show_drag && !(region->alignment == RGN_ALIGN_FLOAT)) { | 
					
						
							|  |  |  |     const float drag_area_xmin = block->rect.xmax - (PNL_ICON * 1.5f); | 
					
						
							|  |  |  |     const float drag_area_xmax = block->rect.xmax; | 
					
						
							|  |  |  |     if (IN_RANGE(mx, drag_area_xmin, drag_area_xmax)) { | 
					
						
							|  |  |  |       panel_activate_state(C, panel, PANEL_STATE_DRAG); | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Handle panel unpinning. */ | 
					
						
							|  |  |  |   if (show_pin) { | 
					
						
							|  |  |  |     const float pin_area_xmin = expansion_area_xmax; | 
					
						
							|  |  |  |     const float pin_area_xmax = pin_area_xmin + PNL_ICON; | 
					
						
							|  |  |  |     if (IN_RANGE(mx, pin_area_xmin, pin_area_xmax)) { | 
					
						
							|  |  |  |       panel->flag ^= PNL_PIN; | 
					
						
							|  |  |  |       ED_region_tag_redraw(region); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | bool UI_panel_category_is_visible(const ARegion *region) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Check for more than one category. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return region->panels_category.first && | 
					
						
							|  |  |  |          region->panels_category.first != region->panels_category.last; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | PanelCategoryDyn *UI_panel_category_find(ARegion *region, const char *idname) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return BLI_findstring(®ion->panels_category, idname, offsetof(PanelCategoryDyn, idname)); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | PanelCategoryStack *UI_panel_category_active_find(ARegion *region, const char *idname) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return BLI_findstring( | 
					
						
							|  |  |  |       ®ion->panels_category_active, idname, offsetof(PanelCategoryStack, idname)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ui_panel_category_active_set(ARegion *region, const char *idname, bool fallback) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ListBase *lb = ®ion->panels_category_active; | 
					
						
							|  |  |  |   PanelCategoryStack *pc_act = UI_panel_category_active_find(region, idname); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (pc_act) { | 
					
						
							|  |  |  |     BLI_remlink(lb, pc_act); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     pc_act = MEM_callocN(sizeof(PanelCategoryStack), __func__); | 
					
						
							|  |  |  |     BLI_strncpy(pc_act->idname, idname, sizeof(pc_act->idname)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (fallback) { | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |     /* For fall-backs, add at the end so explicitly chosen categories have priority. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     BLI_addtail(lb, pc_act); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |     BLI_addhead(lb, pc_act); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Validate all active panels. We could do this on load, they are harmless -
 | 
					
						
							|  |  |  |    * but we should remove them somewhere. | 
					
						
							|  |  |  |    * (Add-ons could define panels and gather cruft over time). */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   { | 
					
						
							|  |  |  |     PanelCategoryStack *pc_act_next; | 
					
						
							|  |  |  |     /* intentionally skip first */ | 
					
						
							|  |  |  |     pc_act_next = pc_act->next; | 
					
						
							|  |  |  |     while ((pc_act = pc_act_next)) { | 
					
						
							|  |  |  |       pc_act_next = pc_act->next; | 
					
						
							|  |  |  |       if (!BLI_findstring( | 
					
						
							|  |  |  |               ®ion->type->paneltypes, pc_act->idname, offsetof(PanelType, category))) { | 
					
						
							|  |  |  |         BLI_remlink(lb, pc_act); | 
					
						
							|  |  |  |         MEM_freeN(pc_act); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | void UI_panel_category_active_set(ARegion *region, const char *idname) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ui_panel_category_active_set(region, idname, false); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | void UI_panel_category_active_set_default(ARegion *region, const char *idname) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!UI_panel_category_active_find(region, idname)) { | 
					
						
							|  |  |  |     ui_panel_category_active_set(region, idname, true); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | const char *UI_panel_category_active_get(ARegion *region, bool set_fallback) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   LISTBASE_FOREACH (PanelCategoryStack *, pc_act, ®ion->panels_category_active) { | 
					
						
							|  |  |  |     if (UI_panel_category_find(region, pc_act->idname)) { | 
					
						
							|  |  |  |       return pc_act->idname; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   if (set_fallback) { | 
					
						
							|  |  |  |     PanelCategoryDyn *pc_dyn = region->panels_category.first; | 
					
						
							|  |  |  |     if (pc_dyn) { | 
					
						
							|  |  |  |       ui_panel_category_active_set(region, pc_dyn->idname, true); | 
					
						
							|  |  |  |       return pc_dyn->idname; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | PanelCategoryDyn *UI_panel_category_find_mouse_over_ex(ARegion *region, const int x, const int y) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   LISTBASE_FOREACH (PanelCategoryDyn *, ptd, ®ion->panels_category) { | 
					
						
							|  |  |  |     if (BLI_rcti_isect_pt(&ptd->rect, x, y)) { | 
					
						
							|  |  |  |       return ptd; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-14 04:15:54 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | PanelCategoryDyn *UI_panel_category_find_mouse_over(ARegion *region, const wmEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return UI_panel_category_find_mouse_over_ex(region, event->mval[0], event->mval[1]); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | void UI_panel_category_add(ARegion *region, const char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PanelCategoryDyn *pc_dyn = MEM_callocN(sizeof(*pc_dyn), __func__); | 
					
						
							|  |  |  |   BLI_addtail(®ion->panels_category, pc_dyn); | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  |   BLI_strncpy(pc_dyn->idname, name, sizeof(pc_dyn->idname)); | 
					
						
							| 
									
										
										
										
											2013-12-17 03:21:55 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* 'pc_dyn->rect' must be set on draw. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-04 13:55:40 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 12:33:27 -05:00
										 |  |  | void UI_panel_category_clear_all(ARegion *region) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   BLI_freelistN(®ion->panels_category); | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static int ui_handle_panel_category_cycling(const wmEvent *event, | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |                                             ARegion *region, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                                             const uiBut *active_but) | 
					
						
							| 
									
										
										
										
											2016-09-05 16:58:40 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const bool is_mousewheel = ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE); | 
					
						
							|  |  |  |   const bool inside_tabregion = | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |       ((RGN_ALIGN_ENUM_FROM_MASK(region->alignment) != RGN_ALIGN_RIGHT) ? | 
					
						
							|  |  |  |            (event->mval[0] < ((PanelCategoryDyn *)region->panels_category.first)->rect.xmax) : | 
					
						
							|  |  |  |            (event->mval[0] > ((PanelCategoryDyn *)region->panels_category.first)->rect.xmin)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* If mouse is inside non-tab region, ctrl key is required. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (is_mousewheel && !event->ctrl && !inside_tabregion) { | 
					
						
							|  |  |  |     return WM_UI_HANDLER_CONTINUE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (active_but && ui_but_supports_cycling(active_but)) { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |     /* Skip - exception to make cycling buttons using ctrl+mousewheel work in tabbed regions. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     const char *category = UI_panel_category_active_get(region, false); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (LIKELY(category)) { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |       PanelCategoryDyn *pc_dyn = UI_panel_category_find(region, category); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       if (LIKELY(pc_dyn)) { | 
					
						
							|  |  |  |         if (is_mousewheel) { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |           /* We can probably get rid of this and only allow ctrl-tabbing. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           pc_dyn = (event->type == WHEELDOWNMOUSE) ? pc_dyn->next : pc_dyn->prev; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |           const bool backwards = event->shift; | 
					
						
							|  |  |  |           pc_dyn = backwards ? pc_dyn->prev : pc_dyn->next; | 
					
						
							|  |  |  |           if (!pc_dyn) { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |             /* Proper cyclic behavior, back to first/last category (only used for ctrl+tab). */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |             pc_dyn = backwards ? region->panels_category.last : region->panels_category.first; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (pc_dyn) { | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |           /* Intentionally don't reset scroll in this case,
 | 
					
						
							|  |  |  |            * allowing for quick browsing between tabs. */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |           UI_panel_category_active_set(region, pc_dyn->idname); | 
					
						
							|  |  |  |           ED_region_tag_redraw(region); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return WM_UI_HANDLER_BREAK; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return WM_UI_HANDLER_CONTINUE; | 
					
						
							| 
									
										
										
										
											2016-09-05 16:58:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |  * Handle region panel events like opening and closing panels, changing categories, etc. | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |  * \note Could become a modal key-map. | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | int ui_handler_panel_region(bContext *C, | 
					
						
							|  |  |  |                             const wmEvent *event, | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |                             ARegion *region, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                             const uiBut *active_but) | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |   /* Mouse-move events are handled by separate handlers for dragging and drag collapsing. */ | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |   if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     return WM_UI_HANDLER_CONTINUE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* We only use KM_PRESS events in this function, so it's simpler to return early. */ | 
					
						
							|  |  |  |   if (event->val != KM_PRESS) { | 
					
						
							|  |  |  |     return WM_UI_HANDLER_CONTINUE; | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |   /* Scroll-bars can overlap panels now, they have handling priority. */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if (UI_view2d_mouse_in_scrollers(region, ®ion->v2d, event->x, event->y)) { | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     return WM_UI_HANDLER_CONTINUE; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   int retval = WM_UI_HANDLER_CONTINUE; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |   /* Handle category tabs. */ | 
					
						
							|  |  |  |   if (UI_panel_category_is_visible(region)) { | 
					
						
							|  |  |  |     if (event->type == LEFTMOUSE) { | 
					
						
							|  |  |  |       PanelCategoryDyn *pc_dyn = UI_panel_category_find_mouse_over(region, event); | 
					
						
							|  |  |  |       if (pc_dyn) { | 
					
						
							|  |  |  |         UI_panel_category_active_set(region, pc_dyn->idname); | 
					
						
							|  |  |  |         ED_region_tag_redraw(region); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |         /* Reset scroll to the top (T38348). */ | 
					
						
							|  |  |  |         UI_view2d_offset(®ion->v2d, -1.0f, 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         retval = WM_UI_HANDLER_BREAK; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     else if ((event->type == EVT_TABKEY && event->ctrl) || | 
					
						
							|  |  |  |              ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE)) { | 
					
						
							|  |  |  |       /* Cycle tabs. */ | 
					
						
							|  |  |  |       retval = ui_handle_panel_category_cycling(event, region, active_but); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (retval == WM_UI_HANDLER_BREAK) { | 
					
						
							|  |  |  |     return retval; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:36:01 -05:00
										 |  |  |   const bool region_has_active_button = (ui_region_find_active_but(region) != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 21:38:16 -04:00
										 |  |  |   LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							| 
									
										
										
										
											2020-08-20 23:38:39 -04:00
										 |  |  |     Panel *panel = block->panel; | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     if (panel == NULL || panel->type == NULL) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     /* We can't expand or collapse panels without headers, they would disappear. */ | 
					
						
							|  |  |  |     if (panel->type->flag & PNL_NO_HEADER) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     int mx = event->x; | 
					
						
							|  |  |  |     int my = event->y; | 
					
						
							|  |  |  |     ui_window_to_block(region, block, &mx, &my); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:36:01 -05:00
										 |  |  |     const uiPanelMouseState mouse_state = ui_panel_mouse_state_get(block, panel, mx, my); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     /* The panel collapse / expand key "A" is special as it takes priority over
 | 
					
						
							|  |  |  |      * active button handling. */ | 
					
						
							|  |  |  |     if (ELEM(mouse_state, PANEL_MOUSE_INSIDE_CONTENT, PANEL_MOUSE_INSIDE_HEADER)) { | 
					
						
							|  |  |  |       if (event->type == EVT_AKEY && !IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         retval = WM_UI_HANDLER_BREAK; | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |         ui_handle_panel_header(C, block, mx, event->type, event->ctrl, event->shift); | 
					
						
							| 
									
										
										
										
											2020-08-27 14:22:28 -05:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     /* Don't do any other panel handling with an active button. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 14:36:01 -05:00
										 |  |  |     if (region_has_active_button) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     /* All mouse clicks inside panels should return in break, but continue handling
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:19 +10:00
										 |  |  |      * in case there is a sub-panel header at the mouse location. */ | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     if (event->type == LEFTMOUSE && | 
					
						
							|  |  |  |         ELEM(mouse_state, PANEL_MOUSE_INSIDE_CONTENT, PANEL_MOUSE_INSIDE_HEADER)) { | 
					
						
							|  |  |  |       retval = WM_UI_HANDLER_BREAK; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |     if (mouse_state == PANEL_MOUSE_INSIDE_HEADER) { | 
					
						
							|  |  |  |       if (ELEM(event->type, EVT_RETKEY, EVT_PADENTER, LEFTMOUSE)) { | 
					
						
							|  |  |  |         retval = WM_UI_HANDLER_BREAK; | 
					
						
							|  |  |  |         ui_handle_panel_header(C, block, mx, event->type, event->ctrl, event->shift); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-08-27 14:02:14 -05:00
										 |  |  |       else if (event->type == RIGHTMOUSE) { | 
					
						
							|  |  |  |         retval = WM_UI_HANDLER_BREAK; | 
					
						
							|  |  |  |         ui_popup_context_menu_for_panel(C, region, block->panel); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return retval; | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 15:00:25 -04:00
										 |  |  | static void ui_panel_custom_data_set_recursive(Panel *panel, PointerRNA *custom_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   panel->runtime.custom_data_ptr = custom_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   LISTBASE_FOREACH (Panel *, child_panel, &panel->children) { | 
					
						
							|  |  |  |     ui_panel_custom_data_set_recursive(child_panel, custom_data); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void UI_panel_custom_data_set(Panel *panel, PointerRNA *custom_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   BLI_assert(panel->type != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 20:54:31 +10:00
										 |  |  |   /* Free the old custom data, which should be shared among all of the panel's sub-panels. */ | 
					
						
							| 
									
										
										
										
											2020-06-29 15:00:25 -04:00
										 |  |  |   if (panel->runtime.custom_data_ptr != NULL) { | 
					
						
							|  |  |  |     MEM_freeN(panel->runtime.custom_data_ptr); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ui_panel_custom_data_set_recursive(panel, custom_data); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  | PointerRNA *UI_panel_custom_data_get(const Panel *panel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return panel->runtime.custom_data_ptr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 15:00:25 -04:00
										 |  |  | PointerRNA *UI_region_panel_custom_data_under_cursor(const bContext *C, const wmEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ARegion *region = CTX_wm_region(C); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Panel *panel = NULL; | 
					
						
							|  |  |  |   LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							|  |  |  |     panel = block->panel; | 
					
						
							|  |  |  |     if (panel == NULL) { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int mx = event->x; | 
					
						
							|  |  |  |     int my = event->y; | 
					
						
							|  |  |  |     ui_window_to_block(region, block, &mx, &my); | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |     const int mouse_state = ui_panel_mouse_state_get(block, panel, mx, my); | 
					
						
							| 
									
										
										
										
											2020-06-29 15:00:25 -04:00
										 |  |  |     if (ELEM(mouse_state, PANEL_MOUSE_INSIDE_CONTENT, PANEL_MOUSE_INSIDE_HEADER)) { | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (panel == NULL) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   return UI_panel_custom_data_get(panel); | 
					
						
							| 
									
										
										
										
											2020-06-29 15:00:25 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Window Level Modal Panel Interaction
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  | /* Note, this is modal handler and should not swallow events for animation. */ | 
					
						
							| 
									
										
										
										
											2013-02-01 01:01:20 +00:00
										 |  |  | static int ui_handler_panel(bContext *C, const wmEvent *event, void *userdata) | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Panel *panel = userdata; | 
					
						
							|  |  |  |   uiHandlePanelData *data = panel->activedata; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 22:56:29 -05:00
										 |  |  |   /* Verify if we can stop. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { | 
					
						
							| 
									
										
										
										
											2020-08-19 11:37:21 -04:00
										 |  |  |     panel_activate_state(C, panel, PANEL_STATE_ANIMATION); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (event->type == MOUSEMOVE) { | 
					
						
							|  |  |  |     if (data->state == PANEL_STATE_DRAG) { | 
					
						
							|  |  |  |       ui_do_drag(C, event, panel); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (event->type == TIMER && event->customdata == data->animtimer) { | 
					
						
							|  |  |  |     if (data->state == PANEL_STATE_ANIMATION) { | 
					
						
							|  |  |  |       ui_do_animate(C, panel); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (data->state == PANEL_STATE_DRAG) { | 
					
						
							|  |  |  |       ui_do_drag(C, event, panel); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   data = panel->activedata; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (data && data->state == PANEL_STATE_ANIMATION) { | 
					
						
							|  |  |  |     return WM_UI_HANDLER_CONTINUE; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-07-03 14:20:10 +02:00
										 |  |  |   return WM_UI_HANDLER_BREAK; | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ui_handler_remove_panel(bContext *C, void *userdata) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   Panel *panel = userdata; | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   panel_activate_state(C, panel, PANEL_STATE_EXIT); | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  | static void panel_activate_state(const bContext *C, Panel *panel, uiHandlePanelState state) | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   uiHandlePanelData *data = panel->activedata; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   wmWindow *win = CTX_wm_window(C); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ARegion *region = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (data && data->state == state) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const bool was_drag_drop = (data && data->state == PANEL_STATE_DRAG); | 
					
						
							| 
									
										
										
										
											2020-04-30 14:21:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-25 23:13:02 +10:00
										 |  |  |   /* Set selection state for the panel and its sub-panels, which need to know they are selected
 | 
					
						
							| 
									
										
										
										
											2020-06-17 13:37:59 -04:00
										 |  |  |    * too so they can be drawn above their parent when it's dragged. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (state == PANEL_STATE_EXIT || state == PANEL_STATE_ANIMATION) { | 
					
						
							| 
									
										
										
										
											2020-06-17 13:37:59 -04:00
										 |  |  |     panel_set_flag_recursive(panel, PNL_SELECT, false); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-06-17 13:37:59 -04:00
										 |  |  |     panel_set_flag_recursive(panel, PNL_SELECT, true); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (data && data->animtimer) { | 
					
						
							|  |  |  |     WM_event_remove_timer(CTX_wm_manager(C), win, data->animtimer); | 
					
						
							|  |  |  |     data->animtimer = NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (state == PANEL_STATE_EXIT) { | 
					
						
							|  |  |  |     MEM_freeN(data); | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     panel->activedata = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     WM_event_remove_ui_handler( | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |         &win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, panel, false); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     if (!data) { | 
					
						
							|  |  |  |       data = MEM_callocN(sizeof(uiHandlePanelData), "uiHandlePanelData"); | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |       panel->activedata = data; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       WM_event_add_ui_handler( | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |           C, &win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, panel, 0); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ELEM(state, PANEL_STATE_ANIMATION, PANEL_STATE_DRAG)) { | 
					
						
							|  |  |  |       data->animtimer = WM_event_add_timer(CTX_wm_manager(C), win, TIMER, ANIMATION_INTERVAL); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 10:01:20 -04:00
										 |  |  |     /* Initiate edge panning during drags so we can move beyond the initial region view. */ | 
					
						
							|  |  |  |     if (state == PANEL_STATE_DRAG) { | 
					
						
							|  |  |  |       wmOperatorType *ot = WM_operatortype_find("VIEW2D_OT_edge_pan", true); | 
					
						
							|  |  |  |       ui_handle_afterfunc_add_operator(ot, WM_OP_INVOKE_DEFAULT, true); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     data->state = state; | 
					
						
							|  |  |  |     data->startx = win->eventstate->x; | 
					
						
							|  |  |  |     data->starty = win->eventstate->y; | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     data->startofsx = panel->ofsx; | 
					
						
							|  |  |  |     data->startofsy = panel->ofsy; | 
					
						
							|  |  |  |     data->startsizex = panel->sizex; | 
					
						
							|  |  |  |     data->startsizey = panel->sizey; | 
					
						
							| 
									
										
										
										
											2020-06-05 10:01:20 -04:00
										 |  |  |     data->start_cur_xmin = region->v2d.cur.xmin; | 
					
						
							|  |  |  |     data->start_cur_ymin = region->v2d.cur.ymin; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     data->starttime = PIL_check_seconds_timer(); | 
					
						
							| 
									
										
										
										
											2020-04-30 14:21:14 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Remember drag drop state even when animating to the aligned position after dragging. */ | 
					
						
							|  |  |  |     data->is_drag_drop = was_drag_drop; | 
					
						
							|  |  |  |     if (state == PANEL_STATE_DRAG) { | 
					
						
							|  |  |  |       data->is_drag_drop = true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_region_tag_redraw(region); | 
					
						
							| 
									
										
										
										
											2008-12-26 13:11:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-23 19:46:40 +02:00
										 |  |  | PanelType *UI_paneltype_find(int space_id, int region_id, const char *idname) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   SpaceType *st = BKE_spacetype_from_id(space_id); | 
					
						
							|  |  |  |   if (st) { | 
					
						
							|  |  |  |     ARegionType *art = BKE_regiontype_from_id(st, region_id); | 
					
						
							|  |  |  |     if (art) { | 
					
						
							|  |  |  |       return BLI_findstring(&art->paneltypes, idname, offsetof(PanelType, idname)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2018-05-23 19:46:40 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-28 14:25:23 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** \} */ |