| 
									
										
										
										
											2017-11-03 20:26:35 +11: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 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |  * | 
					
						
							|  |  |  |  * PopUp Region (Generic) | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdarg.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_userdef_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_listbase.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | #include "BLI_rect.h"
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "UI_interface.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "interface_intern.h"
 | 
					
						
							|  |  |  | #include "interface_regions_intern.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Utility Functions
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Translate any popup regions (so we can drag them). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  | void ui_popup_translate(ARegion *region, const int mdiff[2]) | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   BLI_rcti_translate(®ion->winrct, UNPACK2(mdiff)); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_region_update_rect(region); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_region_tag_redraw(region); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* update blocks */ | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |   LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							| 
									
										
										
										
											2019-01-18 16:55:18 +11:00
										 |  |  |     uiPopupBlockHandle *handle = block->handle; | 
					
						
							|  |  |  |     /* Make empty, will be initialized on next use, see T60608. */ | 
					
						
							|  |  |  |     BLI_rctf_init(&handle->prev_block_rect, 0, 0, 0, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |     LISTBASE_FOREACH (uiSafetyRct *, saferct, &block->saferct) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       BLI_rctf_translate(&saferct->parent, UNPACK2(mdiff)); | 
					
						
							|  |  |  |       BLI_rctf_translate(&saferct->safety, UNPACK2(mdiff)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* position block relative to but, result is in window space */ | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  | static void ui_popup_block_position(wmWindow *window, | 
					
						
							|  |  |  |                                     ARegion *butregion, | 
					
						
							|  |  |  |                                     uiBut *but, | 
					
						
							|  |  |  |                                     uiBlock *block) | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   uiPopupBlockHandle *handle = block->handle; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   /* Compute button position in window coordinates using the source
 | 
					
						
							|  |  |  |    * button region/block, to position the popup attached to it. */ | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   rctf butrct; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   if (!handle->refresh) { | 
					
						
							|  |  |  |     ui_block_to_window_rctf(butregion, but->block, &butrct, &but->rect); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     /* widget_roundbox_set has this correction too, keep in sync */ | 
					
						
							|  |  |  |     if (but->type != UI_BTYPE_PULLDOWN) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (but->drawflag & UI_BUT_ALIGN_TOP) { | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |         butrct.ymax += U.pixelsize; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (but->drawflag & UI_BUT_ALIGN_LEFT) { | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |         butrct.xmin -= U.pixelsize; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     handle->prev_butrct = butrct; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     /* For refreshes, keep same button position so popup doesn't move. */ | 
					
						
							|  |  |  |     butrct = handle->prev_butrct; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   /* Compute block size in window space, based on buttons contained in it. */ | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) { | 
					
						
							|  |  |  |     if (block->buttons.first) { | 
					
						
							|  |  |  |       BLI_rctf_init_minmax(&block->rect); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |       LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | 
					
						
							| 
									
										
										
										
											2018-09-11 15:08:08 +10:00
										 |  |  |         if (block->content_hints & UI_BLOCK_CONTAINS_SUBMENU_BUT) { | 
					
						
							| 
									
										
										
										
											2018-07-06 19:26:12 +02:00
										 |  |  |           bt->rect.xmax += UI_MENU_SUBMENU_PADDING; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |         BLI_rctf_union(&block->rect, &bt->rect); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       /* we're nice and allow empty blocks too */ | 
					
						
							|  |  |  |       block->rect.xmin = block->rect.ymin = 0; | 
					
						
							|  |  |  |       block->rect.xmax = block->rect.ymax = 20; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   ui_block_to_window_rctf(butregion, but->block, &block->rect, &block->rect); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   /* Compute direction relative to button, based on available space. */ | 
					
						
							|  |  |  |   const int size_x = BLI_rctf_size_x(&block->rect) + 0.2f * UI_UNIT_X; /* 4 for shadow */ | 
					
						
							|  |  |  |   const int size_y = BLI_rctf_size_y(&block->rect) + 0.2f * UI_UNIT_Y; | 
					
						
							|  |  |  |   const int center_x = (block->direction & UI_DIR_CENTER_X) ? size_x / 2 : 0; | 
					
						
							|  |  |  |   const int center_y = (block->direction & UI_DIR_CENTER_Y) ? size_y / 2 : 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   short dir1 = 0, dir2 = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   if (!handle->refresh) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     bool left = 0, right = 0, top = 0, down = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 19:22:10 +02:00
										 |  |  |     const int win_x = WM_window_pixels_x(window); | 
					
						
							|  |  |  |     const int win_y = WM_window_pixels_y(window); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     /* Take into account maximum size so we don't have to flip on refresh. */ | 
					
						
							|  |  |  |     const float max_size_x = max_ff(size_x, handle->max_size_x); | 
					
						
							|  |  |  |     const float max_size_y = max_ff(size_y, handle->max_size_y); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     /* check if there's space at all */ | 
					
						
							|  |  |  |     if (butrct.xmin - max_size_x + center_x > 0.0f) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       left = 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (butrct.xmax + max_size_x - center_x < win_x) { | 
					
						
							|  |  |  |       right = 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (butrct.ymin - max_size_y + center_y > 0.0f) { | 
					
						
							|  |  |  |       down = 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (butrct.ymax + max_size_y - center_y < win_y) { | 
					
						
							|  |  |  |       top = 1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     if (top == 0 && down == 0) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (butrct.ymin - max_size_y < win_y - butrct.ymax - max_size_y) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |         top = 1; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |         down = 1; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     dir1 = (block->direction & UI_DIR_ALL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 19:22:10 +02:00
										 |  |  |     /* Secondary directions. */ | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     if (dir1 & (UI_DIR_UP | UI_DIR_DOWN)) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (dir1 & UI_DIR_LEFT) { | 
					
						
							|  |  |  |         dir2 = UI_DIR_LEFT; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else if (dir1 & UI_DIR_RIGHT) { | 
					
						
							|  |  |  |         dir2 = UI_DIR_RIGHT; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       dir1 &= (UI_DIR_UP | UI_DIR_DOWN); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     if ((dir2 == 0) && (dir1 == UI_DIR_LEFT || dir1 == UI_DIR_RIGHT)) { | 
					
						
							|  |  |  |       dir2 = UI_DIR_DOWN; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((dir2 == 0) && (dir1 == UI_DIR_UP || dir1 == UI_DIR_DOWN)) { | 
					
						
							|  |  |  |       dir2 = UI_DIR_LEFT; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* no space at all? don't change */ | 
					
						
							|  |  |  |     if (left || right) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (dir1 == UI_DIR_LEFT && left == 0) { | 
					
						
							|  |  |  |         dir1 = UI_DIR_RIGHT; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (dir1 == UI_DIR_RIGHT && right == 0) { | 
					
						
							|  |  |  |         dir1 = UI_DIR_LEFT; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       /* this is aligning, not append! */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (dir2 == UI_DIR_LEFT && right == 0) { | 
					
						
							|  |  |  |         dir2 = UI_DIR_RIGHT; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (dir2 == UI_DIR_RIGHT && left == 0) { | 
					
						
							|  |  |  |         dir2 = UI_DIR_LEFT; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     if (down || top) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (dir1 == UI_DIR_UP && top == 0) { | 
					
						
							|  |  |  |         dir1 = UI_DIR_DOWN; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (dir1 == UI_DIR_DOWN && down == 0) { | 
					
						
							|  |  |  |         dir1 = UI_DIR_UP; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       BLI_assert(dir2 != UI_DIR_UP); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       //          if (dir2 == UI_DIR_UP   && top == 0)  { dir2 = UI_DIR_DOWN; }
 | 
					
						
							|  |  |  |       if (dir2 == UI_DIR_DOWN && down == 0) { | 
					
						
							|  |  |  |         dir2 = UI_DIR_UP; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     handle->prev_dir1 = dir1; | 
					
						
							|  |  |  |     handle->prev_dir2 = dir2; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     /* For refreshes, keep same popup direct so popup doesn't move
 | 
					
						
							|  |  |  |      * to a totally different position while editing in it. */ | 
					
						
							|  |  |  |     dir1 = handle->prev_dir1; | 
					
						
							|  |  |  |     dir2 = handle->prev_dir2; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   /* Compute offset based on direction. */ | 
					
						
							| 
									
										
										
										
											2019-04-24 20:16:40 +10:00
										 |  |  |   float offset_x = 0, offset_y = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Ensure buttons don't come between the parent button and the popup, see: T63566. */ | 
					
						
							|  |  |  |   const float offset_overlap = max_ff(U.pixelsize, 1.0f); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   if (dir1 == UI_DIR_LEFT) { | 
					
						
							| 
									
										
										
										
											2019-04-24 20:16:40 +10:00
										 |  |  |     offset_x = (butrct.xmin - block->rect.xmax) + offset_overlap; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     if (dir2 == UI_DIR_UP) { | 
					
						
							|  |  |  |       offset_y = butrct.ymin - block->rect.ymin - center_y - UI_MENU_PADDING; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       offset_y = butrct.ymax - block->rect.ymax + center_y + UI_MENU_PADDING; | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   else if (dir1 == UI_DIR_RIGHT) { | 
					
						
							| 
									
										
										
										
											2019-04-24 20:16:40 +10:00
										 |  |  |     offset_x = (butrct.xmax - block->rect.xmin) - offset_overlap; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     if (dir2 == UI_DIR_UP) { | 
					
						
							|  |  |  |       offset_y = butrct.ymin - block->rect.ymin - center_y - UI_MENU_PADDING; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       offset_y = butrct.ymax - block->rect.ymax + center_y + UI_MENU_PADDING; | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   else if (dir1 == UI_DIR_UP) { | 
					
						
							| 
									
										
										
										
											2019-04-24 20:16:40 +10:00
										 |  |  |     offset_y = (butrct.ymax - block->rect.ymin) - offset_overlap; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     if (dir2 == UI_DIR_RIGHT) { | 
					
						
							|  |  |  |       offset_x = butrct.xmax - block->rect.xmax + center_x; | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       offset_x = butrct.xmin - block->rect.xmin - center_x; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     /* changed direction? */ | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     if ((dir1 & block->direction) == 0) { | 
					
						
							|  |  |  |       /* TODO: still do */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       UI_block_order_flip(block); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   else if (dir1 == UI_DIR_DOWN) { | 
					
						
							| 
									
										
										
										
											2019-04-24 20:16:40 +10:00
										 |  |  |     offset_y = (butrct.ymin - block->rect.ymax) + offset_overlap; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     if (dir2 == UI_DIR_RIGHT) { | 
					
						
							|  |  |  |       offset_x = butrct.xmax - block->rect.xmax + center_x; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     else { | 
					
						
							|  |  |  |       offset_x = butrct.xmin - block->rect.xmin - center_x; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     /* changed direction? */ | 
					
						
							|  |  |  |     if ((dir1 & block->direction) == 0) { | 
					
						
							|  |  |  |       /* TODO: still do */ | 
					
						
							|  |  |  |       UI_block_order_flip(block); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   /* Center over popovers for eg. */ | 
					
						
							|  |  |  |   if (block->direction & UI_DIR_CENTER_X) { | 
					
						
							|  |  |  |     offset_x += BLI_rctf_size_x(&butrct) / ((dir2 == UI_DIR_LEFT) ? 2 : -2); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   /* Apply offset, buttons in window coords. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |   LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | 
					
						
							| 
									
										
										
										
											2018-04-22 19:22:10 +02:00
										 |  |  |     ui_block_to_window_rctf(butregion, but->block, &bt->rect, &bt->rect); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 19:22:10 +02:00
										 |  |  |     BLI_rctf_translate(&bt->rect, offset_x, offset_y); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* ui_but_update recalculates drawstring size in pixels */ | 
					
						
							|  |  |  |     ui_but_update(bt); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 19:22:10 +02:00
										 |  |  |   BLI_rctf_translate(&block->rect, offset_x, offset_y); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   /* Safety calculus. */ | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   { | 
					
						
							|  |  |  |     const float midx = BLI_rctf_cent_x(&butrct); | 
					
						
							|  |  |  |     const float midy = BLI_rctf_cent_y(&butrct); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* when you are outside parent button, safety there should be smaller */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |     const int s1 = 40 * U.dpi_fac; | 
					
						
							|  |  |  |     const int s2 = 3 * U.dpi_fac; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* parent button to left */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     if (midx < block->rect.xmin) { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |       block->safety.xmin = block->rect.xmin - s2; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |       block->safety.xmin = block->rect.xmin - s1; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* parent button to right */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     if (midx > block->rect.xmax) { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |       block->safety.xmax = block->rect.xmax + s2; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |       block->safety.xmax = block->rect.xmax + s1; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* parent button on bottom */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     if (midy < block->rect.ymin) { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |       block->safety.ymin = block->rect.ymin - s2; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |       block->safety.ymin = block->rect.ymin - s1; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* parent button on top */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     if (midy > block->rect.ymax) { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |       block->safety.ymax = block->rect.ymax + s2; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |       block->safety.ymax = block->rect.ymax + s1; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* exception for switched pulldowns... */ | 
					
						
							|  |  |  |     if (dir1 && (dir1 & block->direction) == 0) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (dir2 == UI_DIR_RIGHT) { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |         block->safety.xmax = block->rect.xmax + s2; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (dir2 == UI_DIR_LEFT) { | 
					
						
							| 
									
										
										
										
											2020-11-23 16:56:01 -08:00
										 |  |  |         block->safety.xmin = block->rect.xmin - s2; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     block->direction = dir1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 15:38:14 +11:00
										 |  |  |   /* Keep a list of these, needed for pull-down menus. */ | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   uiSafetyRct *saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct"); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   saferct->parent = butrct; | 
					
						
							|  |  |  |   saferct->safety = block->safety; | 
					
						
							|  |  |  |   BLI_freelistN(&block->saferct); | 
					
						
							|  |  |  |   BLI_duplicatelist(&block->saferct, &but->block->saferct); | 
					
						
							|  |  |  |   BLI_addhead(&block->saferct, saferct); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Menu Block Creation
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  | static void ui_block_region_refresh(const bContext *C, ARegion *region) | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-09 19:24:31 +02:00
										 |  |  |   ScrArea *ctx_area = CTX_wm_area(C); | 
					
						
							|  |  |  |   ARegion *ctx_region = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if (region->do_draw & RGN_REFRESH_UI) { | 
					
						
							| 
									
										
										
										
											2018-04-09 19:24:31 +02:00
										 |  |  |     ScrArea *handle_ctx_area; | 
					
						
							|  |  |  |     ARegion *handle_ctx_region; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     region->do_draw &= ~RGN_REFRESH_UI; | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |     LISTBASE_FOREACH_MUTABLE (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							| 
									
										
										
										
											2018-04-27 19:30:25 +02:00
										 |  |  |       uiPopupBlockHandle *handle = block->handle; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:30:25 +02:00
										 |  |  |       if (handle->can_refresh) { | 
					
						
							|  |  |  |         handle_ctx_area = handle->ctx_area; | 
					
						
							|  |  |  |         handle_ctx_region = handle->ctx_region; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 19:24:31 +02:00
										 |  |  |         if (handle_ctx_area) { | 
					
						
							|  |  |  |           CTX_wm_area_set((bContext *)C, handle_ctx_area); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (handle_ctx_region) { | 
					
						
							|  |  |  |           CTX_wm_region_set((bContext *)C, handle_ctx_region); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-27 19:30:25 +02:00
										 |  |  |         uiBut *but = handle->popup_create_vars.but; | 
					
						
							|  |  |  |         ARegion *butregion = handle->popup_create_vars.butregion; | 
					
						
							|  |  |  |         ui_popup_block_refresh((bContext *)C, handle, butregion, but); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 19:24:31 +02:00
										 |  |  |   CTX_wm_area_set((bContext *)C, ctx_area); | 
					
						
							|  |  |  |   CTX_wm_region_set((bContext *)C, ctx_region); | 
					
						
							| 
									
										
										
										
											2018-04-27 10:22:37 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  | static void ui_block_region_draw(const bContext *C, ARegion *region) | 
					
						
							| 
									
										
										
										
											2018-04-27 10:22:37 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |   LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     UI_block_draw(C, block); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Use to refresh centered popups on screen resizing (for splash). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-01-19 12:59:00 +11:00
										 |  |  | static void ui_block_region_popup_window_listener(const wmRegionListenerParams *params) | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-18 17:28:47 -06:00
										 |  |  |   ARegion *region = params->region; | 
					
						
							|  |  |  |   wmNotifier *wmn = params->notifier; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   switch (wmn->category) { | 
					
						
							|  |  |  |     case NC_WINDOW: { | 
					
						
							|  |  |  |       switch (wmn->action) { | 
					
						
							|  |  |  |         case NA_EDITED: { | 
					
						
							|  |  |  |           /* window resize */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |           ED_region_tag_refresh_ui(region); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |           break; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ui_popup_block_clip(wmWindow *window, uiBlock *block) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-10 11:18:18 +11:00
										 |  |  |   const float xmin_orig = block->rect.xmin; | 
					
						
							|  |  |  |   const int margin = UI_SCREEN_MARGIN; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   int winx, winy; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   if (block->flag & UI_BLOCK_NO_WIN_CLIP) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   winx = WM_window_pixels_x(window); | 
					
						
							|  |  |  |   winy = WM_window_pixels_y(window); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-10 11:18:18 +11:00
										 |  |  |   /* shift to left if outside of view */ | 
					
						
							|  |  |  |   if (block->rect.xmax > winx - margin) { | 
					
						
							|  |  |  |     const float xofs = winx - margin - block->rect.xmax; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     block->rect.xmin += xofs; | 
					
						
							|  |  |  |     block->rect.xmax += xofs; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-01-10 11:18:18 +11:00
										 |  |  |   /* shift menus to right if outside of view */ | 
					
						
							|  |  |  |   if (block->rect.xmin < margin) { | 
					
						
							|  |  |  |     const float xofs = (margin - block->rect.xmin); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     block->rect.xmin += xofs; | 
					
						
							|  |  |  |     block->rect.xmax += xofs; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-10 11:18:18 +11:00
										 |  |  |   if (block->rect.ymin < margin) { | 
					
						
							|  |  |  |     block->rect.ymin = margin; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (block->rect.ymax > winy - UI_POPUP_MENU_TOP) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     block->rect.ymax = winy - UI_POPUP_MENU_TOP; | 
					
						
							| 
									
										
										
										
											2019-01-10 11:18:18 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* ensure menu items draw inside left/right boundary */ | 
					
						
							| 
									
										
										
										
											2019-01-10 11:18:18 +11:00
										 |  |  |   const float xofs = block->rect.xmin - xmin_orig; | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |   LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     bt->rect.xmin += xofs; | 
					
						
							|  |  |  |     bt->rect.xmax += xofs; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ui_popup_block_scrolltest(uiBlock *block) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   block->flag &= ~(UI_BLOCK_CLIPBOTTOM | UI_BLOCK_CLIPTOP); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |   LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     bt->flag &= ~UI_SCROLLED; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   if (block->buttons.first == block->buttons.last) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* mark buttons that are outside boundary */ | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |   LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     if (bt->rect.ymin < block->rect.ymin) { | 
					
						
							|  |  |  |       bt->flag |= UI_SCROLLED; | 
					
						
							|  |  |  |       block->flag |= UI_BLOCK_CLIPBOTTOM; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (bt->rect.ymax > block->rect.ymax) { | 
					
						
							|  |  |  |       bt->flag |= UI_SCROLLED; | 
					
						
							|  |  |  |       block->flag |= UI_BLOCK_CLIPTOP; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* mark buttons overlapping arrows, if we have them */ | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |   LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     if (block->flag & UI_BLOCK_CLIPBOTTOM) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (bt->rect.ymin < block->rect.ymin + UI_MENU_SCROLL_ARROW) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |         bt->flag |= UI_SCROLLED; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (block->flag & UI_BLOCK_CLIPTOP) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (bt->rect.ymax > block->rect.ymax - UI_MENU_SCROLL_ARROW) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |         bt->flag |= UI_SCROLLED; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ui_popup_block_remove(bContext *C, uiPopupBlockHandle *handle) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-01-29 15:00:31 +01:00
										 |  |  |   wmWindow *ctx_win = CTX_wm_window(C); | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   ScrArea *ctx_area = CTX_wm_area(C); | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |   ARegion *ctx_region = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2020-01-29 15:00:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   wmWindowManager *wm = CTX_wm_manager(C); | 
					
						
							|  |  |  |   wmWindow *win = ctx_win; | 
					
						
							| 
									
										
										
										
											2020-04-03 14:23:21 +02:00
										 |  |  |   bScreen *screen = CTX_wm_screen(C); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 15:00:31 +01:00
										 |  |  |   /* There may actually be a different window active than the one showing the popup, so lookup real
 | 
					
						
							|  |  |  |    * one. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 14:23:21 +02:00
										 |  |  |   if (BLI_findindex(&screen->regionbase, handle->region) == -1) { | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |     LISTBASE_FOREACH (wmWindow *, win_iter, &wm->windows) { | 
					
						
							|  |  |  |       screen = WM_window_get_active_screen(win_iter); | 
					
						
							| 
									
										
										
										
											2020-04-03 14:23:21 +02:00
										 |  |  |       if (BLI_findindex(&screen->regionbase, handle->region) != -1) { | 
					
						
							| 
									
										
										
										
											2020-08-18 21:46:29 -04:00
										 |  |  |         win = win_iter; | 
					
						
							| 
									
										
										
										
											2020-01-29 15:00:31 +01:00
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 14:23:21 +02:00
										 |  |  |   BLI_assert(win && screen); | 
					
						
							| 
									
										
										
										
											2020-01-29 15:00:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   CTX_wm_window_set(C, win); | 
					
						
							| 
									
										
										
										
											2020-04-03 14:23:21 +02:00
										 |  |  |   ui_region_temp_remove(C, screen, handle->region); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |   /* Reset context (area and region were NULL'ed when changing context window). */ | 
					
						
							| 
									
										
										
										
											2020-01-29 15:00:31 +01:00
										 |  |  |   CTX_wm_window_set(C, ctx_win); | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   CTX_wm_area_set(C, ctx_area); | 
					
						
							| 
									
										
										
										
											2020-04-03 12:51:03 +02:00
										 |  |  |   CTX_wm_region_set(C, ctx_region); | 
					
						
							| 
									
										
										
										
											2020-01-29 15:00:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* reset to region cursor (only if there's not another menu open) */ | 
					
						
							| 
									
										
										
										
											2020-04-03 14:23:21 +02:00
										 |  |  |   if (BLI_listbase_is_empty(&screen->regionbase)) { | 
					
						
							| 
									
										
										
										
											2020-02-25 09:19:31 +11:00
										 |  |  |     win->tag_cursor_refresh = true; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   if (handle->scrolltimer) { | 
					
						
							| 
									
										
										
										
											2020-01-29 15:00:31 +01:00
										 |  |  |     WM_event_remove_timer(wm, win, handle->scrolltimer); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Called for creating new popups and refreshing existing ones. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | uiBlock *ui_popup_block_refresh(bContext *C, | 
					
						
							|  |  |  |                                 uiPopupBlockHandle *handle, | 
					
						
							|  |  |  |                                 ARegion *butregion, | 
					
						
							|  |  |  |                                 uiBut *but) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const int margin = UI_POPUP_MARGIN; | 
					
						
							|  |  |  |   wmWindow *window = CTX_wm_window(C); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ARegion *region = handle->region; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |   const uiBlockCreateFunc create_func = handle->popup_create_vars.create_func; | 
					
						
							|  |  |  |   const uiBlockHandleCreateFunc handle_create_func = handle->popup_create_vars.handle_create_func; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   void *arg = handle->popup_create_vars.arg; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   uiBlock *block_old = region->uiblocks.first; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   uiBlock *block; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |   handle->refresh = (block_old != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BLI_assert(!handle->refresh || handle->can_refresh); | 
					
						
							| 
									
										
										
										
											2018-04-30 10:27:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |   wmEvent *event_back = window->eventstate; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* create ui block */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   if (create_func) { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     block = create_func(C, region, arg); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     block = handle_create_func(C, handle, arg); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* callbacks _must_ leave this for us, otherwise we can't call UI_block_update_from_old */ | 
					
						
							|  |  |  |   BLI_assert(!block->endblock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ensure we don't use mouse coords here! */ | 
					
						
							|  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |   window->eventstate = NULL; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (block->handle) { | 
					
						
							|  |  |  |     memcpy(block->handle, handle, sizeof(uiPopupBlockHandle)); | 
					
						
							|  |  |  |     MEM_freeN(handle); | 
					
						
							|  |  |  |     handle = block->handle; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   else { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     block->handle = handle; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   region->regiondata = handle; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* set UI_BLOCK_NUMSELECT before UI_block_end() so we get alphanumeric keys assigned */ | 
					
						
							|  |  |  |   if (but == NULL) { | 
					
						
							|  |  |  |     block->flag |= UI_BLOCK_POPUP; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   block->flag |= UI_BLOCK_LOOP; | 
					
						
							| 
									
										
										
										
											2018-09-11 10:56:08 +10:00
										 |  |  |   UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* defer this until blocks are translated (below) */ | 
					
						
							|  |  |  |   block->oldblock = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   if (!block->endblock) { | 
					
						
							|  |  |  |     UI_block_end_ex( | 
					
						
							|  |  |  |         C, block, handle->popup_create_vars.event_xy, handle->popup_create_vars.event_xy); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* if this is being created from a button */ | 
					
						
							|  |  |  |   if (but) { | 
					
						
							|  |  |  |     block->aspect = but->block->aspect; | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     ui_popup_block_position(window, butregion, but, block); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     handle->direction = block->direction; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     uiSafetyRct *saferct; | 
					
						
							| 
									
										
										
										
											2021-02-20 15:38:14 +11:00
										 |  |  |     /* Keep a list of these, needed for pull-down menus. */ | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct"); | 
					
						
							|  |  |  |     saferct->safety = block->safety; | 
					
						
							|  |  |  |     BLI_addhead(&block->saferct, saferct); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   if (block->flag & UI_BLOCK_RADIAL) { | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |     const int win_width = UI_SCREEN_MARGIN; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     int winx, winy; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     int x_offset = 0, y_offset = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     winx = WM_window_pixels_x(window); | 
					
						
							|  |  |  |     winy = WM_window_pixels_y(window); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     copy_v2_v2(block->pie_data.pie_center_init, block->pie_data.pie_center_spawned); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* only try translation if area is large enough */ | 
					
						
							|  |  |  |     if (BLI_rctf_size_x(&block->rect) < winx - (2.0f * win_width)) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (block->rect.xmin < win_width) { | 
					
						
							|  |  |  |         x_offset += win_width - block->rect.xmin; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (block->rect.xmax > winx - win_width) { | 
					
						
							|  |  |  |         x_offset += winx - win_width - block->rect.xmax; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     if (BLI_rctf_size_y(&block->rect) < winy - (2.0f * win_width)) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (block->rect.ymin < win_width) { | 
					
						
							|  |  |  |         y_offset += win_width - block->rect.ymin; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (block->rect.ymax > winy - win_width) { | 
					
						
							|  |  |  |         y_offset += winy - win_width - block->rect.ymax; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* if we are offsetting set up initial data for timeout functionality */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     if ((x_offset != 0) || (y_offset != 0)) { | 
					
						
							|  |  |  |       block->pie_data.pie_center_spawned[0] += x_offset; | 
					
						
							|  |  |  |       block->pie_data.pie_center_spawned[1] += y_offset; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-13 18:23:21 +02:00
										 |  |  |       UI_block_translate(block, x_offset, y_offset); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       if (U.pie_initial_timeout > 0) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |         block->pie_data.flags |= UI_PIE_INITIAL_DIRECTION; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     region->winrct.xmin = 0; | 
					
						
							|  |  |  |     region->winrct.xmax = winx; | 
					
						
							|  |  |  |     region->winrct.ymin = 0; | 
					
						
							|  |  |  |     region->winrct.ymax = winy; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     ui_block_calc_pie_segment(block, block->pie_data.pie_center_init); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* lastly set the buttons at the center of the pie menu, ready for animation */ | 
					
						
							|  |  |  |     if (U.pie_animation_timeout > 0) { | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |       LISTBASE_FOREACH (uiBut *, but_iter, &block->buttons) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |         if (but_iter->pie_dir != UI_RADIAL_NONE) { | 
					
						
							|  |  |  |           BLI_rctf_recenter(&but_iter->rect, UNPACK2(block->pie_data.pie_center_spawned)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2020-03-06 16:38:58 +01:00
										 |  |  |     /* Add an offset to draw the popover arrow. */ | 
					
						
							|  |  |  |     if ((block->flag & UI_BLOCK_POPOVER) && ELEM(block->direction, UI_DIR_UP, UI_DIR_DOWN)) { | 
					
						
							|  |  |  |       /* Keep sync with 'ui_draw_popover_back_impl'. */ | 
					
						
							|  |  |  |       const float unit_size = U.widget_unit / block->aspect; | 
					
						
							|  |  |  |       const float unit_half = unit_size * (block->direction == UI_DIR_DOWN ? 0.5 : -0.5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       UI_block_translate(block, 0, -unit_half); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* clip block with window boundary */ | 
					
						
							|  |  |  |     ui_popup_block_clip(window, block); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-29 08:45:57 +02:00
										 |  |  |     /* Avoid menu moving down and losing cursor focus by keeping it at
 | 
					
						
							|  |  |  |      * the same height. */ | 
					
						
							| 
									
										
										
										
											2018-05-06 18:08:27 +02:00
										 |  |  |     if (handle->refresh && handle->prev_block_rect.ymax > block->rect.ymax) { | 
					
						
							| 
									
										
										
										
											2019-08-19 14:51:16 +02:00
										 |  |  |       if (block->bounds_type != UI_BLOCK_BOUNDS_POPUP_CENTER) { | 
					
						
							| 
									
										
										
										
											2020-08-26 10:11:13 +10:00
										 |  |  |         const float offset = handle->prev_block_rect.ymax - block->rect.ymax; | 
					
						
							| 
									
										
										
										
											2019-08-19 14:51:16 +02:00
										 |  |  |         UI_block_translate(block, 0, offset); | 
					
						
							|  |  |  |         block->rect.ymin = handle->prev_block_rect.ymin; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-04-29 08:45:57 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-29 08:45:57 +02:00
										 |  |  |     handle->prev_block_rect = block->rect; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     /* the block and buttons were positioned in window space as in 2.4x, now
 | 
					
						
							|  |  |  |      * these menu blocks are regions so we bring it back to region space. | 
					
						
							|  |  |  |      * additionally we add some padding for the menu shadow or rounded menus */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     region->winrct.xmin = block->rect.xmin - margin; | 
					
						
							|  |  |  |     region->winrct.xmax = block->rect.xmax + margin; | 
					
						
							|  |  |  |     region->winrct.ymin = block->rect.ymin - margin; | 
					
						
							|  |  |  |     region->winrct.ymax = block->rect.ymax + UI_POPUP_MENU_TOP; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     UI_block_translate(block, -region->winrct.xmin, -region->winrct.ymin); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-13 18:23:21 +02:00
										 |  |  |     /* apply scroll offset */ | 
					
						
							|  |  |  |     if (handle->scrolloffset != 0.0f) { | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |       LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | 
					
						
							| 
									
										
										
										
											2018-05-13 18:23:21 +02:00
										 |  |  |         bt->rect.ymin += handle->scrolloffset; | 
					
						
							|  |  |  |         bt->rect.ymax += handle->scrolloffset; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   if (block_old) { | 
					
						
							|  |  |  |     block->oldblock = block_old; | 
					
						
							|  |  |  |     UI_block_update_from_old(C, block); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |     UI_blocklist_free_inactive(C, ®ion->uiblocks); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* checks which buttons are visible, sets flags to prevent draw (do after region init) */ | 
					
						
							|  |  |  |   ui_popup_block_scrolltest(block); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* adds subwindow */ | 
					
						
							| 
									
										
										
										
											2020-08-01 13:02:21 +10:00
										 |  |  |   ED_region_floating_init(region); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* get winmat now that we actually have the subwindow */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   wmGetProjectionMatrix(block->winmat, ®ion->winrct); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* notify change and redraw */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_region_tag_redraw(region); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_region_update_rect(region); | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  |   window->eventstate = event_back; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return block; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | uiPopupBlockHandle *ui_popup_block_create(bContext *C, | 
					
						
							|  |  |  |                                           ARegion *butregion, | 
					
						
							|  |  |  |                                           uiBut *but, | 
					
						
							|  |  |  |                                           uiBlockCreateFunc create_func, | 
					
						
							|  |  |  |                                           uiBlockHandleCreateFunc handle_create_func, | 
					
						
							| 
									
										
										
										
											2019-05-14 15:38:51 +02:00
										 |  |  |                                           void *arg, | 
					
						
							|  |  |  |                                           void (*arg_free)(void *arg)) | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  | { | 
					
						
							|  |  |  |   wmWindow *window = CTX_wm_window(C); | 
					
						
							|  |  |  |   uiBut *activebut = UI_context_active_but_get(C); | 
					
						
							|  |  |  |   static ARegionType type; | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ARegion *region; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   uiBlock *block; | 
					
						
							|  |  |  |   uiPopupBlockHandle *handle; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* disable tooltips from buttons below */ | 
					
						
							|  |  |  |   if (activebut) { | 
					
						
							|  |  |  |     UI_but_tooltip_timer_remove(C, activebut); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   /* standard cursor by default */ | 
					
						
							| 
									
										
										
										
											2019-09-26 14:31:48 +02:00
										 |  |  |   WM_cursor_set(window, WM_CURSOR_DEFAULT); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* create handle */ | 
					
						
							|  |  |  |   handle = MEM_callocN(sizeof(uiPopupBlockHandle), "uiPopupBlockHandle"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* store context for operator */ | 
					
						
							|  |  |  |   handle->ctx_area = CTX_wm_area(C); | 
					
						
							|  |  |  |   handle->ctx_region = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 02:09:12 +02:00
										 |  |  |   /* store vars to refresh popup (RGN_REFRESH_UI) */ | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   handle->popup_create_vars.create_func = create_func; | 
					
						
							|  |  |  |   handle->popup_create_vars.handle_create_func = handle_create_func; | 
					
						
							|  |  |  |   handle->popup_create_vars.arg = arg; | 
					
						
							| 
									
										
										
										
											2019-05-14 15:38:51 +02:00
										 |  |  |   handle->popup_create_vars.arg_free = arg_free; | 
					
						
							| 
									
										
										
										
											2018-04-27 19:30:25 +02:00
										 |  |  |   handle->popup_create_vars.but = but; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   handle->popup_create_vars.butregion = but ? butregion : NULL; | 
					
						
							|  |  |  |   copy_v2_v2_int(handle->popup_create_vars.event_xy, &window->eventstate->x); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-30 10:27:28 +02:00
										 |  |  |   /* don't allow by default, only if popup type explicitly supports it */ | 
					
						
							|  |  |  |   handle->can_refresh = false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* create area region */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   region = ui_region_temp_add(CTX_wm_screen(C)); | 
					
						
							|  |  |  |   handle->region = region; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   memset(&type, 0, sizeof(ARegionType)); | 
					
						
							|  |  |  |   type.draw = ui_block_region_draw; | 
					
						
							| 
									
										
										
										
											2018-04-29 12:24:08 +02:00
										 |  |  |   type.layout = ui_block_region_refresh; | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   type.regionid = RGN_TYPE_TEMPORARY; | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   region->type = &type; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   UI_region_handlers_add(®ion->handlers); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   block = ui_popup_block_refresh(C, handle, butregion, but); | 
					
						
							|  |  |  |   handle = block->handle; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   /* keep centered on window resizing */ | 
					
						
							| 
									
										
										
										
											2018-04-30 10:27:28 +02:00
										 |  |  |   if (block->bounds_type == UI_BLOCK_BOUNDS_POPUP_CENTER) { | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |     type.listener = ui_block_region_popup_window_listener; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   return handle; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ui_popup_block_free(bContext *C, uiPopupBlockHandle *handle) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-19 10:22:44 +02:00
										 |  |  |   /* If this popup is created from a popover which does NOT have keep-open flag set,
 | 
					
						
							|  |  |  |    * then close the popover too. We could extend this to other popup types too. */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ARegion *region = handle->popup_create_vars.butregion; | 
					
						
							|  |  |  |   if (region != NULL) { | 
					
						
							| 
									
										
										
										
											2020-04-03 19:15:01 +02:00
										 |  |  |     LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { | 
					
						
							| 
									
										
										
										
											2018-05-19 10:22:44 +02:00
										 |  |  |       if (block->handle && (block->flag & UI_BLOCK_POPOVER) && | 
					
						
							|  |  |  |           (block->flag & UI_BLOCK_KEEP_OPEN) == 0) { | 
					
						
							|  |  |  |         uiPopupBlockHandle *menu = block->handle; | 
					
						
							|  |  |  |         menu->menuretval = UI_RETURN_OK; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-05-19 10:22:44 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 15:38:51 +02:00
										 |  |  |   if (handle->popup_create_vars.arg_free) { | 
					
						
							|  |  |  |     handle->popup_create_vars.arg_free(handle->popup_create_vars.arg); | 
					
						
							| 
									
										
										
										
											2018-04-27 19:30:25 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   ui_popup_block_remove(C, handle); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 20:26:35 +11:00
										 |  |  |   MEM_freeN(handle); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ |