| 
									
										
										
										
											2018-06-12 10:11:32 +02: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, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2008 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup edinterface | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Floating Persistent Region | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 11:37:18 -03:00
										 |  |  | #include "DNA_screen_types.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | #include "DNA_userdef_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_listbase.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "BLI_rect.h"
 | 
					
						
							|  |  |  | #include "BLI_string.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "UI_interface.h"
 | 
					
						
							|  |  |  | #include "UI_view2d.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLT_translation.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_screen.h"
 | 
					
						
							|  |  |  | #include "ED_undo.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-27 19:07:23 -06:00
										 |  |  | #include "GPU_framebuffer.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "interface_intern.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Utilities
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2019-07-30 16:00:41 +02:00
										 |  |  | struct HudRegionData { | 
					
						
							|  |  |  |   short regionid; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 16:00:41 +02:00
										 |  |  | static bool last_redo_poll(const bContext *C, short region_type) | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   wmOperator *op = WM_operator_last_redo(C); | 
					
						
							|  |  |  |   if (op == NULL) { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-07-30 16:00:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   bool success = false; | 
					
						
							| 
									
										
										
										
											2019-07-30 16:00:41 +02:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2019-08-01 13:53:25 +10:00
										 |  |  |     /* Make sure that we are using the same region type as the original
 | 
					
						
							| 
									
										
										
										
											2019-07-30 16:00:41 +02:00
										 |  |  |      * operator call. Otherwise we would be polling the operator with the | 
					
						
							|  |  |  |      * wrong context. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |     ScrArea *area = CTX_wm_area(C); | 
					
						
							|  |  |  |     ARegion *region_op = (region_type != -1) ? BKE_area_find_region_type(area, region_type) : NULL; | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |     ARegion *region_prev = CTX_wm_region(C); | 
					
						
							|  |  |  |     CTX_wm_region_set((bContext *)C, region_op); | 
					
						
							| 
									
										
										
										
											2019-07-30 16:00:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (WM_operator_repeat_check(C, op) && WM_operator_check_ui_empty(op->type) == false) { | 
					
						
							|  |  |  |       success = WM_operator_poll((bContext *)C, op->type); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |     CTX_wm_region_set((bContext *)C, region_prev); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   return success; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  | static void hud_region_hide(ARegion *region) | 
					
						
							| 
									
										
										
										
											2018-11-12 14:59:05 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   region->flag |= RGN_FLAG_HIDDEN; | 
					
						
							| 
									
										
										
										
											2018-11-12 14:59:05 +11:00
										 |  |  |   /* Avoids setting 'AREA_FLAG_REGION_SIZE_UPDATE'
 | 
					
						
							|  |  |  |    * since other regions don't depend on this. */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   BLI_rcti_init(®ion->winrct, 0, 0, 0, 0); | 
					
						
							| 
									
										
										
										
											2018-11-12 14:59:05 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Redo Panel
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 12:03:56 +02:00
										 |  |  | static bool hud_panel_operator_redo_poll(const bContext *C, PanelType *UNUSED(pt)) | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   ScrArea *area = CTX_wm_area(C); | 
					
						
							|  |  |  |   ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_HUD); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if (region != NULL) { | 
					
						
							|  |  |  |     struct HudRegionData *hrd = region->regiondata; | 
					
						
							| 
									
										
										
										
											2019-07-30 16:00:41 +02:00
										 |  |  |     if (hrd != NULL) { | 
					
						
							|  |  |  |       return last_redo_poll(C, hrd->regionid); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  | static void hud_panel_operator_redo_draw_header(const bContext *C, Panel *panel) | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   wmOperator *op = WM_operator_last_redo(C); | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   BLI_strncpy(panel->drawname, WM_operatortype_name(op->type, op->ptr), sizeof(panel->drawname)); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  | static void hud_panel_operator_redo_draw(const bContext *C, Panel *panel) | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   wmOperator *op = WM_operator_last_redo(C); | 
					
						
							|  |  |  |   if (op == NULL) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (!WM_operator_check_ui_enabled(C, op->type->name)) { | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |     uiLayoutSetEnabled(panel->layout, false); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-04-03 22:20:25 -05:00
										 |  |  |   uiLayout *col = uiLayoutColumn(panel->layout, false); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   uiTemplateOperatorRedoProperties(col, C); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void hud_panels_register(ARegionType *art, int space_type, int region_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PanelType *pt; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   pt = MEM_callocN(sizeof(PanelType), __func__); | 
					
						
							|  |  |  |   strcpy(pt->idname, "OPERATOR_PT_redo"); | 
					
						
							|  |  |  |   strcpy(pt->label, N_("Redo")); | 
					
						
							|  |  |  |   strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); | 
					
						
							|  |  |  |   pt->draw_header = hud_panel_operator_redo_draw_header; | 
					
						
							|  |  |  |   pt->draw = hud_panel_operator_redo_draw; | 
					
						
							|  |  |  |   pt->poll = hud_panel_operator_redo_poll; | 
					
						
							|  |  |  |   pt->space_type = space_type; | 
					
						
							|  |  |  |   pt->region_type = region_type; | 
					
						
							| 
									
										
										
										
											2020-11-13 13:56:55 -05:00
										 |  |  |   pt->flag |= PANEL_TYPE_DEFAULT_CLOSED; | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   BLI_addtail(&art->paneltypes, pt); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Callbacks for Floating Region
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  | static void hud_region_init(wmWindowManager *wm, ARegion *region) | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_region_panels_init(wm, region); | 
					
						
							|  |  |  |   UI_region_handlers_add(®ion->handlers); | 
					
						
							|  |  |  |   region->flag |= RGN_FLAG_TEMP_REGIONDATA; | 
					
						
							| 
									
										
										
										
											2018-06-14 22:32:01 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  | static void hud_region_free(ARegion *region) | 
					
						
							| 
									
										
										
										
											2018-06-14 22:32:01 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   MEM_SAFE_FREE(region->regiondata); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  | static void hud_region_layout(const bContext *C, ARegion *region) | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   struct HudRegionData *hrd = region->regiondata; | 
					
						
							| 
									
										
										
										
											2019-07-30 16:00:41 +02:00
										 |  |  |   if (hrd == NULL || !last_redo_poll(C, hrd->regionid)) { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     ED_region_tag_redraw(region); | 
					
						
							|  |  |  |     hud_region_hide(region); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-22 18:33:23 +02:00
										 |  |  |   ScrArea *area = CTX_wm_area(C); | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const int size_y = region->sizey; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_region_panels_layout(C, region); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-22 18:33:23 +02:00
										 |  |  |   if (region->panels.first && | 
					
						
							|  |  |  |       ((area->flag & AREA_FLAG_REGION_SIZE_UPDATE) || (region->sizey != size_y))) { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     int winx_new = UI_DPI_FAC * (region->sizex + 0.5f); | 
					
						
							|  |  |  |     int winy_new = UI_DPI_FAC * (region->sizey + 0.5f); | 
					
						
							|  |  |  |     View2D *v2d = ®ion->v2d; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     if (region->flag & RGN_FLAG_SIZE_CLAMP_X) { | 
					
						
							|  |  |  |       CLAMP_MAX(winx_new, region->winx); | 
					
						
							| 
									
										
										
										
											2019-03-14 09:58:20 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     if (region->flag & RGN_FLAG_SIZE_CLAMP_Y) { | 
					
						
							|  |  |  |       CLAMP_MAX(winy_new, region->winy); | 
					
						
							| 
									
										
										
										
											2019-03-14 09:58:20 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     region->winx = winx_new; | 
					
						
							|  |  |  |     region->winy = winy_new; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     region->winrct.xmax = (region->winrct.xmin + region->winx) - 1; | 
					
						
							|  |  |  |     region->winrct.ymax = (region->winrct.ymin + region->winy) - 1; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 19:49:48 +02:00
										 |  |  |     UI_view2d_region_reinit(v2d, V2D_COMMONVIEW_LIST, region->winx, region->winy); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 08:44:38 +02:00
										 |  |  |     /* Weak, but needed to avoid glitches, especially with hi-dpi
 | 
					
						
							|  |  |  |      * (where resizing the view glitches often). | 
					
						
							| 
									
										
										
										
											2018-09-11 09:18:26 +10:00
										 |  |  |      * Fortunately this only happens occasionally. */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     ED_region_panels_layout(C, region); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   /* restore view matrix */ | 
					
						
							|  |  |  |   UI_view2d_view_restore(C); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  | static void hud_region_draw(const bContext *C, ARegion *region) | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   UI_view2d_view_ortho(®ion->v2d); | 
					
						
							|  |  |  |   wmOrtho2_region_pixelspace(region); | 
					
						
							| 
									
										
										
										
											2020-08-23 11:11:27 +02:00
										 |  |  |   GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if ((region->flag & RGN_FLAG_HIDDEN) == 0) { | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |     ui_draw_menu_back(NULL, | 
					
						
							|  |  |  |                       NULL, | 
					
						
							|  |  |  |                       &(rcti){ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |                           .xmax = region->winx, | 
					
						
							|  |  |  |                           .ymax = region->winy, | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |                       }); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     ED_region_panels_draw(C, region); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ARegionType *ED_area_type_hud(int space_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ARegionType *art = MEM_callocN(sizeof(ARegionType), __func__); | 
					
						
							|  |  |  |   art->regionid = RGN_TYPE_HUD; | 
					
						
							|  |  |  |   art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D; | 
					
						
							|  |  |  |   art->layout = hud_region_layout; | 
					
						
							|  |  |  |   art->draw = hud_region_draw; | 
					
						
							|  |  |  |   art->init = hud_region_init; | 
					
						
							| 
									
										
										
										
											2018-06-14 22:32:01 +02:00
										 |  |  |   art->free = hud_region_free; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 11:37:18 -03:00
										 |  |  |   /* We need to indicate a preferred size to avoid false `RGN_FLAG_TOO_SMALL`
 | 
					
						
							|  |  |  |    * the first time the region is created. */ | 
					
						
							|  |  |  |   art->prefsizex = AREAMINX; | 
					
						
							|  |  |  |   art->prefsizey = HEADERY; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   hud_panels_register(art, space_type, art->regionid); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   art->lock = 1; /* can become flag, see BKE_spacedata_draw_locks */ | 
					
						
							|  |  |  |   return art; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  | static ARegion *hud_region_add(ScrArea *area) | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ARegion *region = MEM_callocN(sizeof(ARegion), "area region"); | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   ARegion *region_win = BKE_area_find_region_type(area, RGN_TYPE_WINDOW); | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |   if (region_win) { | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |     BLI_insertlinkbefore(&area->regionbase, region_win, region); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |     BLI_addtail(&area->regionbase, region); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   region->regiontype = RGN_TYPE_HUD; | 
					
						
							|  |  |  |   region->alignment = RGN_ALIGN_FLOAT; | 
					
						
							|  |  |  |   region->overlap = true; | 
					
						
							|  |  |  |   region->flag |= RGN_FLAG_DYNAMIC_SIZE; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |   if (region_win) { | 
					
						
							| 
									
										
										
										
											2019-12-04 16:00:03 +01:00
										 |  |  |     float x, y; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |     UI_view2d_scroller_size_get(®ion_win->v2d, &x, &y); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     region->runtime.offset_x = x; | 
					
						
							|  |  |  |     region->runtime.offset_y = y; | 
					
						
							| 
									
										
										
										
											2019-12-04 16:00:03 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   return region; | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  | void ED_area_type_hud_clear(wmWindowManager *wm, ScrArea *area_keep) | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |   LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | 
					
						
							| 
									
										
										
										
											2018-06-12 16:49:52 +02:00
										 |  |  |     bScreen *screen = WM_window_get_active_screen(win); | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |     LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |       if (area != area_keep) { | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |         LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |           if (region->regiontype == RGN_TYPE_HUD) { | 
					
						
							|  |  |  |             if ((region->flag & RGN_FLAG_HIDDEN) == 0) { | 
					
						
							|  |  |  |               hud_region_hide(region); | 
					
						
							|  |  |  |               ED_region_tag_redraw(region); | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |               ED_area_tag_redraw(area); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-12 16:49:52 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  | void ED_area_type_hud_ensure(bContext *C, ScrArea *area) | 
					
						
							| 
									
										
										
										
											2018-06-12 16:49:52 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   wmWindowManager *wm = CTX_wm_manager(C); | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   ED_area_type_hud_clear(wm, area); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   ARegionType *art = BKE_regiontype_from_id(area->type, RGN_TYPE_HUD); | 
					
						
							| 
									
										
										
										
											2018-06-12 17:38:04 +02:00
										 |  |  |   if (art == NULL) { | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_HUD); | 
					
						
							| 
									
										
										
										
											2019-04-18 13:49:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if (region && (region->flag & RGN_FLAG_HIDDEN_BY_USER)) { | 
					
						
							| 
									
										
										
										
											2019-04-18 13:49:21 +02:00
										 |  |  |     /* The region is intentionally hidden by the user, don't show it. */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     hud_region_hide(region); | 
					
						
							| 
									
										
										
										
											2019-04-18 13:49:21 +02:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 17:43:23 +11:00
										 |  |  |   bool init = false; | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const bool was_hidden = region == NULL || region->visible == false; | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |   ARegion *region_op = CTX_wm_region(C); | 
					
						
							|  |  |  |   BLI_assert((region_op == NULL) || (region_op->regiontype != RGN_TYPE_HUD)); | 
					
						
							|  |  |  |   if (!last_redo_poll(C, region_op ? region_op->regiontype : -1)) { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     if (region) { | 
					
						
							|  |  |  |       ED_region_tag_redraw(region); | 
					
						
							|  |  |  |       hud_region_hide(region); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if (region == NULL) { | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |     init = true; | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |     region = hud_region_add(area); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     region->type = art; | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   /* Let 'ED_area_update_region_sizes' do the work of placing the region.
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |    * Otherwise we could set the 'region->winrct' & 'region->winx/winy' here. */ | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   if (init) { | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |     area->flag |= AREA_FLAG_REGION_SIZE_UPDATE; | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     if (region->flag & RGN_FLAG_HIDDEN) { | 
					
						
							| 
									
										
										
										
											2020-05-22 18:33:23 +02:00
										 |  |  |       /* Also forces recalculating HUD size in hud_region_layout(). */ | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |       area->flag |= AREA_FLAG_REGION_SIZE_UPDATE; | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     region->flag &= ~RGN_FLAG_HIDDEN; | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-14 22:32:01 +02:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     struct HudRegionData *hrd = region->regiondata; | 
					
						
							| 
									
										
										
										
											2018-06-14 22:32:01 +02:00
										 |  |  |     if (hrd == NULL) { | 
					
						
							|  |  |  |       hrd = MEM_callocN(sizeof(*hrd), __func__); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |       region->regiondata = hrd; | 
					
						
							| 
									
										
										
										
											2018-06-14 22:32:01 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |     if (region_op) { | 
					
						
							|  |  |  |       hrd->regionid = region_op->regiontype; | 
					
						
							| 
									
										
										
										
											2018-06-14 22:32:01 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       hrd->regionid = -1; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-06-14 22:32:01 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 15:43:42 +11:00
										 |  |  |   if (init) { | 
					
						
							|  |  |  |     /* This is needed or 'winrct' will be invalid. */ | 
					
						
							|  |  |  |     wmWindow *win = CTX_wm_window(C); | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |     ED_area_update_region_sizes(wm, win, area); | 
					
						
							| 
									
										
										
										
											2018-11-08 15:43:42 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-01 13:02:21 +10:00
										 |  |  |   ED_region_floating_init(region); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_region_tag_redraw(region); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 15:43:42 +11:00
										 |  |  |   /* Reset zoom level (not well supported). */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   region->v2d.cur = region->v2d.tot = (rctf){ | 
					
						
							|  |  |  |       .xmax = region->winx, | 
					
						
							|  |  |  |       .ymax = region->winy, | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   region->v2d.minzoom = 1.0f; | 
					
						
							|  |  |  |   region->v2d.maxzoom = 1.0f; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   region->visible = !(region->flag & RGN_FLAG_HIDDEN); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  |   /* We shouldn't need to do this every time :S */ | 
					
						
							|  |  |  |   /* XXX, this is evil! - it also makes the menu show on first draw. :( */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if (region->visible) { | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |     ARegion *region_prev = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     CTX_wm_region_set((bContext *)C, region); | 
					
						
							|  |  |  |     hud_region_layout(C, region); | 
					
						
							| 
									
										
										
										
											2018-11-26 17:43:23 +11:00
										 |  |  |     if (was_hidden) { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |       region->winx = region->v2d.winx; | 
					
						
							|  |  |  |       region->winy = region->v2d.winy; | 
					
						
							|  |  |  |       region->v2d.cur = region->v2d.tot = (rctf){ | 
					
						
							|  |  |  |           .xmax = region->winx, | 
					
						
							|  |  |  |           .ymax = region->winy, | 
					
						
							| 
									
										
										
										
											2019-01-07 00:58:10 +11:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2018-11-26 17:43:23 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |     CTX_wm_region_set((bContext *)C, region_prev); | 
					
						
							| 
									
										
										
										
											2018-11-26 17:29:02 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   region->visible = !((region->flag & RGN_FLAG_HIDDEN) || (region->flag & RGN_FLAG_TOO_SMALL)); | 
					
						
							| 
									
										
										
										
											2018-06-12 10:11:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ |