| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  |  * of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2008 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup edinterface | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | #include <math.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | #include "DNA_userdef_types.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-26 19:49:25 +02:00
										 |  |  | #include "DNA_windowmanager_types.h"
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-03 13:44:16 +00:00
										 |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-12 19:41:47 +00:00
										 |  |  | #include "BLI_math_base.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-03 13:44:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-18 02:56:48 +00:00
										 |  |  | #include "BKE_context.h"
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-16 12:28:00 +00:00
										 |  |  | #include "ED_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | #include "UI_view2d.h"
 | 
					
						
							| 
									
										
										
										
											2011-07-16 18:28:24 +00:00
										 |  |  | #include "UI_interface.h"
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | #include "PIL_time.h" /* USER_ZOOM_CONT */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 11:47:00 +02:00
										 |  |  | static bool view2d_poll(bContext *C) | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return (ar != NULL) && (ar->v2d.flag & V2D_IS_INITIALISED); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-02 09:43:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | /* ********************************************************* */ | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | /* VIEW PANNING OPERATOR								 */ | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * This group of operators come in several forms: | 
					
						
							|  |  |  |  * -# Modal 'dragging' with MMB - where movement of mouse dictates amount to pan view by | 
					
						
							|  |  |  |  * -# Scrollwheel 'steps' - rolling mousewheel by one step moves view by predefined amount | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  |  * In order to make sure this works, each operator must define the following RNA-Operator Props: | 
					
						
							|  |  |  |  * - `deltax, deltay` - define how much to move view by (relative to zoom-correction factor) | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | /* ------------------ Shared 'core' stuff ---------------------- */ | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | /* temp customdata for operator */ | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | typedef struct v2dViewPanData { | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/** screen where view pan was initiated */ | 
					
						
							|  |  |  | 	bScreen *sc; | 
					
						
							|  |  |  | 	/** area where view pan was initiated */ | 
					
						
							|  |  |  | 	ScrArea *sa; | 
					
						
							|  |  |  | 	/** region where view pan was initiated */ | 
					
						
							|  |  |  | 	ARegion *ar; | 
					
						
							|  |  |  | 	/** view2d we're operating in */ | 
					
						
							|  |  |  | 	View2D *v2d; | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/** amount to move view relative to zoom */ | 
					
						
							|  |  |  | 	float facx, facy; | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* options for version 1 */ | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/** mouse x/y values in window when operator was initiated */ | 
					
						
							|  |  |  | 	int startx, starty; | 
					
						
							|  |  |  | 	/** previous x/y values of mouse in window */ | 
					
						
							|  |  |  | 	int lastx, lasty; | 
					
						
							|  |  |  | 	/** event starting pan, for modal exit */ | 
					
						
							|  |  |  | 	int invoke_event; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** for MMB in scrollers (old feature in past, but now not that useful) */ | 
					
						
							|  |  |  | 	short in_scroller; | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | } v2dViewPanData; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  | /* initialize panning customdata */ | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | static int view_pan_init(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	v2dViewPanData *vpd; | 
					
						
							|  |  |  | 	View2D *v2d; | 
					
						
							|  |  |  | 	float winx, winy; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	/* regions now have v2d-data by default, so check for region */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (ar == NULL) { | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	/* check if panning is allowed at all */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	v2d = &ar->v2d; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if ((v2d->keepofs & V2D_LOCKOFS_X) && (v2d->keepofs & V2D_LOCKOFS_Y)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	/* set custom-data for operator */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vpd = MEM_callocN(sizeof(v2dViewPanData), "v2dViewPanData"); | 
					
						
							|  |  |  | 	op->customdata = vpd; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	/* set pointers to owners */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vpd->sc = CTX_wm_screen(C); | 
					
						
							|  |  |  | 	vpd->sa = CTX_wm_area(C); | 
					
						
							|  |  |  | 	vpd->v2d = v2d; | 
					
						
							| 
									
										
										
										
											2010-03-30 07:57:07 +00:00
										 |  |  | 	vpd->ar = ar; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	/* calculate translation factor - based on size of view */ | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 	winx = (float)(BLI_rcti_size_x(&ar->winrct) + 1); | 
					
						
							|  |  |  | 	winy = (float)(BLI_rcti_size_y(&ar->winrct) + 1); | 
					
						
							|  |  |  | 	vpd->facx = (BLI_rctf_size_x(&v2d->cur)) / winx; | 
					
						
							|  |  |  | 	vpd->facy = (BLI_rctf_size_y(&v2d->cur)) / winy; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 10:36:06 +02:00
										 |  |  | #ifdef WITH_INPUT_NDOF
 | 
					
						
							| 
									
										
										
										
											2018-07-02 11:47:00 +02:00
										 |  |  | static bool view_pan_poll(bContext *C) | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | { | 
					
						
							|  |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 	View2D *v2d; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* check if there's a region in context to work with */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (ar == NULL) { | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	v2d = &ar->v2d; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* check that 2d-view can pan */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if ((v2d->keepofs & V2D_LOCKOFS_X) && (v2d->keepofs & V2D_LOCKOFS_Y)) { | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* view can pan */ | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-08-18 10:36:06 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | /* apply transform to view (i.e. adjust 'cur' rect) */ | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | static void view_pan_apply_ex(bContext *C, v2dViewPanData *vpd, float dx, float dy) | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	View2D *v2d = vpd->v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	/* calculate amount to move view by */ | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	dx *= vpd->facx; | 
					
						
							|  |  |  | 	dy *= vpd->facy; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	/* only move view on an axis if change is allowed */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	if ((v2d->keepofs & V2D_LOCKOFS_X) == 0) { | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 		v2d->cur.xmin += dx; | 
					
						
							|  |  |  | 		v2d->cur.xmax += dx; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	if ((v2d->keepofs & V2D_LOCKOFS_Y) == 0) { | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 		v2d->cur.ymin += dy; | 
					
						
							|  |  |  | 		v2d->cur.ymax += dy; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* validate that view is in valid configuration after this operation */ | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | 	UI_view2d_curRect_validate(v2d); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 14:41:49 +02:00
										 |  |  | 	/* don't rebuild full tree in outliner, since we're just changing our view */ | 
					
						
							|  |  |  | 	ED_region_tag_redraw_no_rebuild(vpd->ar); | 
					
						
							| 
									
										
										
										
											2018-05-15 12:49:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* request updates to be done... */ | 
					
						
							|  |  |  | 	WM_event_add_mousemove(C); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	UI_view2d_sync(vpd->sc, vpd->sa, v2d, V2D_LOCK_COPY); | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | static void view_pan_apply(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	v2dViewPanData *vpd = op->customdata; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-01 19:57:31 +02:00
										 |  |  | 	view_pan_apply_ex( | 
					
						
							|  |  |  | 	        C, vpd, | 
					
						
							|  |  |  | 	        RNA_int_get(op->ptr, "deltax"), | 
					
						
							|  |  |  | 	        RNA_int_get(op->ptr, "deltay")); | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | /* cleanup temp customdata  */ | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | static void view_pan_exit(wmOperator *op) | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (op->customdata) { | 
					
						
							|  |  |  | 		MEM_freeN(op->customdata); | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		op->customdata = NULL; | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | /* ------------------ Modal Drag Version (1) ---------------------- */ | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | /* for 'redo' only, with no user input */ | 
					
						
							|  |  |  | static int view_pan_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_pan_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-24 08:46:48 +00:00
										 |  |  | 	view_pan_apply(C, op); | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 	view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | /* set up modal operator and relevant settings */ | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int view_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	wmWindow *window = CTX_wm_window(C); | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	v2dViewPanData *vpd; | 
					
						
							|  |  |  | 	View2D *v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* set up customdata */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_pan_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vpd = op->customdata; | 
					
						
							|  |  |  | 	v2d = vpd->v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* set initial settings */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vpd->startx = vpd->lastx = event->x; | 
					
						
							|  |  |  | 	vpd->starty = vpd->lasty = event->y; | 
					
						
							|  |  |  | 	vpd->invoke_event = event->type; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 11:14:36 +00:00
										 |  |  | 	if (event->type == MOUSEPAN) { | 
					
						
							|  |  |  | 		RNA_int_set(op->ptr, "deltax", event->prevx - event->x); | 
					
						
							|  |  |  | 		RNA_int_set(op->ptr, "deltay", event->prevy - event->y); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-24 08:46:48 +00:00
										 |  |  | 		view_pan_apply(C, op); | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 		view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2010-01-11 11:14:36 +00:00
										 |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	RNA_int_set(op->ptr, "deltax", 0); | 
					
						
							|  |  |  | 	RNA_int_set(op->ptr, "deltay", 0); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (v2d->keepofs & V2D_LOCKOFS_X) { | 
					
						
							| 
									
										
										
										
											2013-09-06 22:34:29 +00:00
										 |  |  | 		WM_cursor_modal_set(window, BC_NS_SCROLLCURSOR); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (v2d->keepofs & V2D_LOCKOFS_Y) { | 
					
						
							| 
									
										
										
										
											2013-09-06 22:34:29 +00:00
										 |  |  | 		WM_cursor_modal_set(window, BC_EW_SCROLLCURSOR); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2013-09-06 22:34:29 +00:00
										 |  |  | 		WM_cursor_modal_set(window, BC_NSEW_SCROLLCURSOR); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	/* add temp handler */ | 
					
						
							| 
									
										
										
										
											2009-09-18 12:43:36 +00:00
										 |  |  | 	WM_event_add_modal_handler(C, op); | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_RUNNING_MODAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | /* handle user input - calculations of mouse-movement
 | 
					
						
							|  |  |  |  * need to be done here, not in the apply callback! */ | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int view_pan_modal(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	v2dViewPanData *vpd = op->customdata; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	/* execute the events */ | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	switch (event->type) { | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 		case MOUSEMOVE: | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			/* calculate new delta transform, then store mouse-coordinates for next-time */ | 
					
						
							| 
									
										
										
										
											2008-12-09 06:23:40 +00:00
										 |  |  | 			RNA_int_set(op->ptr, "deltax", (vpd->lastx - event->x)); | 
					
						
							|  |  |  | 			RNA_int_set(op->ptr, "deltay", (vpd->lasty - event->y)); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			vpd->lastx = event->x; | 
					
						
							|  |  |  | 			vpd->lasty = event->y; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-24 08:46:48 +00:00
										 |  |  | 			view_pan_apply(C, op); | 
					
						
							| 
									
										
										
										
											2013-07-19 15:23:42 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-07-18 19:02:39 +10:00
										 |  |  | 		/* XXX - Mode switching isn't implemented. See comments in 36818.
 | 
					
						
							|  |  |  | 		 * switch to zoom */ | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2009-09-01 17:31:33 +00:00
										 |  |  | 		case LEFTMOUSE: | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			if (event->val == KM_PRESS) { | 
					
						
							|  |  |  | 				/* calculate overall delta mouse-movement for redo */ | 
					
						
							| 
									
										
										
										
											2010-01-06 12:22:59 +00:00
										 |  |  | 				RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx)); | 
					
						
							|  |  |  | 				RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty)); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 				view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2013-09-06 22:34:29 +00:00
										 |  |  | 				WM_cursor_modal_restore(CTX_wm_window(C)); | 
					
						
							| 
									
										
										
										
											2010-01-06 12:22:59 +00:00
										 |  |  | 				WM_operator_name_call(C, "VIEW2D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL); | 
					
						
							|  |  |  | 				return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-05-12 13:49:47 +00:00
										 |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			if (event->type == vpd->invoke_event || event->type == ESCKEY) { | 
					
						
							|  |  |  | 				if (event->val == KM_RELEASE) { | 
					
						
							| 
									
										
										
										
											2011-05-12 13:49:47 +00:00
										 |  |  | 					/* calculate overall delta mouse-movement for redo */ | 
					
						
							|  |  |  | 					RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx)); | 
					
						
							|  |  |  | 					RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty)); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-12 13:49:47 +00:00
										 |  |  | 					view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2013-09-06 22:34:29 +00:00
										 |  |  | 					WM_cursor_modal_restore(CTX_wm_window(C)); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-12 13:49:47 +00:00
										 |  |  | 					return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_RUNNING_MODAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-30 23:08:53 +00:00
										 |  |  | static void view_pan_cancel(bContext *UNUSED(C), wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-11-20 10:21:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 	view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2009-11-20 10:21:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_pan(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Pan View"; | 
					
						
							|  |  |  | 	ot->description = "Pan the view"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_pan"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = view_pan_exec; | 
					
						
							|  |  |  | 	ot->invoke = view_pan_invoke; | 
					
						
							|  |  |  | 	ot->modal = view_pan_modal; | 
					
						
							|  |  |  | 	ot->cancel = view_pan_cancel; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 	/* operator is modal */ | 
					
						
							| 
									
										
										
										
											2015-04-27 18:44:27 +10:00
										 |  |  | 	ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* rna - must keep these in sync with the other operators */ | 
					
						
							| 
									
										
										
										
											2011-09-15 13:20:18 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX); | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX); | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------ Scrollwheel Versions (2) ---------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-26 12:02:29 +00:00
										 |  |  | /* this operator only needs this single callback, where it calls the view_pan_*() methods */ | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | static int view_scrollright_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	v2dViewPanData *vpd; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  | 	/* initialize default settings (and validate if ok to run) */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_pan_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	/* also, check if can pan in horizontal axis */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vpd = op->customdata; | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	if (vpd->v2d->keepofs & V2D_LOCKOFS_X) { | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 		view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* set RNA-Props - only movement in positive x-direction */ | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:01 +02:00
										 |  |  | 	RNA_int_set(op->ptr, "deltax", 40); | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	RNA_int_set(op->ptr, "deltay", 0); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* apply movement, then we're done */ | 
					
						
							| 
									
										
										
										
											2013-08-24 08:46:48 +00:00
										 |  |  | 	view_pan_apply(C, op); | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 	view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_scroll_right(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Scroll Right"; | 
					
						
							|  |  |  | 	ot->description = "Scroll the view right"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_scroll_right"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = view_scrollright_exec; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* rna - must keep these in sync with the other operators */ | 
					
						
							| 
									
										
										
										
											2011-09-15 13:20:18 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX); | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX); | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-26 12:02:29 +00:00
										 |  |  | /* this operator only needs this single callback, where it calls the view_pan_*() methods */ | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | static int view_scrollleft_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	v2dViewPanData *vpd; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  | 	/* initialize default settings (and validate if ok to run) */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_pan_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	/* also, check if can pan in horizontal axis */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vpd = op->customdata; | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	if (vpd->v2d->keepofs & V2D_LOCKOFS_X) { | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 		view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* set RNA-Props - only movement in negative x-direction */ | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:01 +02:00
										 |  |  | 	RNA_int_set(op->ptr, "deltax", -40); | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	RNA_int_set(op->ptr, "deltay", 0); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* apply movement, then we're done */ | 
					
						
							| 
									
										
										
										
											2013-08-24 08:46:48 +00:00
										 |  |  | 	view_pan_apply(C, op); | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 	view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_scroll_left(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Scroll Left"; | 
					
						
							|  |  |  | 	ot->description = "Scroll the view left"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_scroll_left"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = view_scrollleft_exec; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* rna - must keep these in sync with the other operators */ | 
					
						
							| 
									
										
										
										
											2011-09-15 13:20:18 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX); | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX); | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-26 11:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-26 12:02:29 +00:00
										 |  |  | /* this operator only needs this single callback, where it calls the view_pan_*() methods */ | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | static int view_scrolldown_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	v2dViewPanData *vpd; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  | 	/* initialize default settings (and validate if ok to run) */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_pan_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	/* also, check if can pan in vertical axis */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vpd = op->customdata; | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) { | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 		view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-17 13:11:09 +00:00
										 |  |  | 	/* set RNA-Props */ | 
					
						
							| 
									
										
										
										
											2009-03-01 06:22:03 +00:00
										 |  |  | 	RNA_int_set(op->ptr, "deltax", 0); | 
					
						
							| 
									
										
										
										
											2010-03-10 02:06:28 +00:00
										 |  |  | 	RNA_int_set(op->ptr, "deltay", -40); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 12:52:26 +01:00
										 |  |  | 	PropertyRNA *prop = RNA_struct_find_property(op->ptr, "page"); | 
					
						
							|  |  |  | 	if (RNA_property_is_set(op->ptr, prop) && RNA_property_boolean_get(op->ptr, prop)) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2011-01-08 18:37:11 +00:00
										 |  |  | 		RNA_int_set(op->ptr, "deltay", ar->v2d.mask.ymin - ar->v2d.mask.ymax); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* apply movement, then we're done */ | 
					
						
							| 
									
										
										
										
											2013-08-24 08:46:48 +00:00
										 |  |  | 	view_pan_apply(C, op); | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 	view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_scroll_down(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Scroll Down"; | 
					
						
							|  |  |  | 	ot->description = "Scroll the view down"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_scroll_down"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = view_scrolldown_exec; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* rna - must keep these in sync with the other operators */ | 
					
						
							| 
									
										
										
										
											2011-09-15 13:20:18 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX); | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX); | 
					
						
							| 
									
										
										
										
											2011-09-19 12:26:20 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "page", 0, "Page", "Scroll down one page"); | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-26 12:02:29 +00:00
										 |  |  | /* this operator only needs this single callback, where it calls the view_pan_*() methods */ | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | static int view_scrollup_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	v2dViewPanData *vpd; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  | 	/* initialize default settings (and validate if ok to run) */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_pan_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	/* also, check if can pan in vertical axis */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vpd = op->customdata; | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 	if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) { | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 		view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-17 13:11:09 +00:00
										 |  |  | 	/* set RNA-Props */ | 
					
						
							| 
									
										
										
										
											2009-03-01 06:22:03 +00:00
										 |  |  | 	RNA_int_set(op->ptr, "deltax", 0); | 
					
						
							| 
									
										
										
										
											2010-03-10 02:06:28 +00:00
										 |  |  | 	RNA_int_set(op->ptr, "deltay", 40); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 12:52:26 +01:00
										 |  |  | 	PropertyRNA *prop = RNA_struct_find_property(op->ptr, "page"); | 
					
						
							|  |  |  | 	if (RNA_property_is_set(op->ptr, prop) && RNA_property_boolean_get(op->ptr, prop)) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 		RNA_int_set(op->ptr, "deltay", BLI_rcti_size_y(&ar->v2d.mask)); | 
					
						
							| 
									
										
										
										
											2011-01-08 18:37:11 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* apply movement, then we're done */ | 
					
						
							| 
									
										
										
										
											2013-08-24 08:46:48 +00:00
										 |  |  | 	view_pan_apply(C, op); | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 	view_pan_exit(op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_scroll_up(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Scroll Up"; | 
					
						
							|  |  |  | 	ot->description = "Scroll the view up"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_scroll_up"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = view_scrollup_exec; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 00:20:19 +00:00
										 |  |  | 	/* rna - must keep these in sync with the other operators */ | 
					
						
							| 
									
										
										
										
											2011-09-15 13:20:18 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX); | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "deltay", 0, INT_MIN, INT_MAX, "Delta Y", "", INT_MIN, INT_MAX); | 
					
						
							| 
									
										
										
										
											2011-09-19 12:26:20 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "page", 0, "Page", "Scroll up one page"); | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | /* ********************************************************* */ | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | /* SINGLE-STEP VIEW ZOOMING OPERATOR						 */ | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * This group of operators come in several forms: | 
					
						
							|  |  |  |  * -# Scrollwheel 'steps' - rolling mousewheel by one step zooms view by predefined amount. | 
					
						
							|  |  |  |  * -# Scrollwheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y). | 
					
						
							|  |  |  |  *    XXX this could be implemented... | 
					
						
							|  |  |  |  * -# Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount. | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-07-21 16:21:42 +00:00
										 |  |  |  * In order to make sure this works, each operator must define the following RNA-Operator Props: | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  |  * | 
					
						
							|  |  |  |  * - zoomfacx, zoomfacy - These two zoom factors allow for non-uniform scaling. | 
					
						
							|  |  |  |  *   It is safe to scale by 0, as these factors are used to determine. | 
					
						
							|  |  |  |  *   amount to enlarge 'cur' by. | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | /* ------------------ 'Shared' stuff ------------------------ */ | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* temp customdata for operator */ | 
					
						
							|  |  |  | typedef struct v2dViewZoomData { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	View2D *v2d;            /* view2d we're operating in */ | 
					
						
							| 
									
										
										
										
											2010-03-30 07:57:07 +00:00
										 |  |  | 	ARegion *ar; | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* needed for continuous zoom */ | 
					
						
							|  |  |  | 	wmTimer *timer; | 
					
						
							|  |  |  | 	double timer_lastdraw; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	int lastx, lasty;       /* previous x/y values of mouse in window */ | 
					
						
							|  |  |  | 	int invoke_event;       /* event type that invoked, for modal exits */ | 
					
						
							|  |  |  | 	float dx, dy;           /* running tally of previous delta values (for obtaining final zoom) */ | 
					
						
							|  |  |  | 	float mx_2d, my_2d;     /* initial mouse location in v2d coords */ | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | } v2dViewZoomData; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Clamp by convention rather then locking flags, | 
					
						
							|  |  |  |  * for ndof and +/- keys | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void view_zoom_axis_lock_defaults(bContext *C, bool r_do_zoom_xy[2]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ScrArea *sa = CTX_wm_area(C); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	r_do_zoom_xy[0] = true; | 
					
						
							|  |  |  | 	r_do_zoom_xy[1] = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* default not to zoom the sequencer vertically */ | 
					
						
							|  |  |  | 	if (sa && sa->spacetype == SPACE_SEQ) { | 
					
						
							|  |  |  | 		ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		if (ar && ar->regiontype == RGN_TYPE_WINDOW) { | 
					
						
							| 
									
										
										
										
											2014-03-01 15:28:51 +11:00
										 |  |  | 			r_do_zoom_xy[1] = false; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  | /* initialize panning customdata */ | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | static int view_zoomdrag_init(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	v2dViewZoomData *vzd; | 
					
						
							|  |  |  | 	View2D *v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	/* regions now have v2d-data by default, so check for region */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (ar == NULL) { | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	v2d = &ar->v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	/* check that 2d-view is zoomable */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y)) { | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	/* set custom-data for operator */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vzd = MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData"); | 
					
						
							|  |  |  | 	op->customdata = vzd; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	/* set pointers to owners */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vzd->v2d = v2d; | 
					
						
							| 
									
										
										
										
											2010-03-30 07:57:07 +00:00
										 |  |  | 	vzd->ar = ar; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | /* check if step-zoom can be applied */ | 
					
						
							| 
									
										
										
										
											2018-07-02 11:47:00 +02:00
										 |  |  | static bool view_zoom_poll(bContext *C) | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | 	View2D *v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | 	/* check if there's a region in context to work with */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (ar == NULL) { | 
					
						
							| 
									
										
										
										
											2015-10-09 22:24:58 +02:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-09 22:24:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Do not show that in 3DView context. */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (CTX_wm_region_view3d(C)) { | 
					
						
							| 
									
										
										
										
											2015-10-09 22:24:58 +02:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-09 22:24:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	v2d = &ar->v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | 	/* check that 2d-view is zoomable */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y)) { | 
					
						
							| 
									
										
										
										
											2015-10-09 22:24:58 +02:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | 	/* view is zoomable */ | 
					
						
							| 
									
										
										
										
											2015-10-09 22:24:58 +02:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | /* apply transform to view (i.e. adjust 'cur' rect) */ | 
					
						
							| 
									
										
										
										
											2015-05-05 03:13:47 +10:00
										 |  |  | static void view_zoomstep_apply_ex( | 
					
						
							|  |  |  |         bContext *C, v2dViewZoomData *vzd, const bool use_mousepos, | 
					
						
							|  |  |  |         const float facx, const float facy) | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 	View2D *v2d = &ar->v2d; | 
					
						
							| 
									
										
										
										
											2015-02-08 22:33:58 +01:00
										 |  |  | 	const rctf cur_old = v2d->cur; | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	float dx, dy; | 
					
						
							| 
									
										
										
										
											2018-04-26 12:01:44 +02:00
										 |  |  | 	const int snap_test = ED_region_snap_size_test(ar); | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-29 22:57:53 +00:00
										 |  |  | 	/* calculate amount to move view by, ensuring symmetry so the
 | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 	 * old zoom level is restored after zooming back the same amount | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	if (facx >= 0.0f) { | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 		dx = BLI_rctf_size_x(&v2d->cur) * facx; | 
					
						
							|  |  |  | 		dy = BLI_rctf_size_y(&v2d->cur) * facy; | 
					
						
							| 
									
										
										
										
											2009-07-29 22:57:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 		dx = (BLI_rctf_size_x(&v2d->cur) / (1.0f + 2.0f * facx)) * facx; | 
					
						
							|  |  |  | 		dy = (BLI_rctf_size_y(&v2d->cur) / (1.0f + 2.0f * facy)) * facy; | 
					
						
							| 
									
										
										
										
											2009-07-29 22:57:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-07 10:39:20 +00:00
										 |  |  | 	/* only resize view on an axis if change is allowed */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) { | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		if (v2d->keepofs & V2D_LOCKOFS_X) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			v2d->cur.xmax -= 2 * dx; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-07-29 22:57:53 +00:00
										 |  |  | 		else if (v2d->keepofs & V2D_KEEPOFS_X) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if (v2d->align & V2D_ALIGN_NO_POS_X) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 				v2d->cur.xmin += 2 * dx; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 				v2d->cur.xmax -= 2 * dx; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-07-29 22:57:53 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2015-02-08 22:33:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			v2d->cur.xmin += dx; | 
					
						
							|  |  |  | 			v2d->cur.xmax -= dx; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 			if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 				/* get zoom fac the same way as in
 | 
					
						
							|  |  |  | 				 * ui_view2d_curRect_validate_resize - better keep in sync! */ | 
					
						
							| 
									
										
										
										
											2015-02-08 22:33:58 +01:00
										 |  |  | 				const float zoomx = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* only move view to mouse if zoom fac is inside minzoom/maxzoom */ | 
					
						
							| 
									
										
										
										
											2015-04-21 13:10:32 +10:00
										 |  |  | 				if (((v2d->keepzoom & V2D_LIMITZOOM) == 0) || | 
					
						
							|  |  |  | 				    IN_RANGE_INCL(zoomx, v2d->minzoom, v2d->maxzoom)) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2015-02-08 22:33:58 +01:00
										 |  |  | 					float mval_fac = (vzd->mx_2d - cur_old.xmin) / BLI_rctf_size_x(&cur_old); | 
					
						
							|  |  |  | 					float mval_faci = 1.0f - mval_fac; | 
					
						
							|  |  |  | 					float ofs = (mval_fac * dx) - (mval_faci * dx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					v2d->cur.xmin += ofs; | 
					
						
							|  |  |  | 					v2d->cur.xmax += ofs; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) { | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		if (v2d->keepofs & V2D_LOCKOFS_Y) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			v2d->cur.ymax -= 2 * dy; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-07-29 22:57:53 +00:00
										 |  |  | 		else if (v2d->keepofs & V2D_KEEPOFS_Y) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if (v2d->align & V2D_ALIGN_NO_POS_Y) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 				v2d->cur.ymin += 2 * dy; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 				v2d->cur.ymax -= 2 * dy; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-07-29 22:57:53 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2015-02-08 22:33:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			v2d->cur.ymin += dy; | 
					
						
							|  |  |  | 			v2d->cur.ymax -= dy; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 			if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 				/* get zoom fac the same way as in
 | 
					
						
							|  |  |  | 				 * ui_view2d_curRect_validate_resize - better keep in sync! */ | 
					
						
							| 
									
										
										
										
											2015-02-08 22:33:58 +01:00
										 |  |  | 				const float zoomy = (float)(BLI_rcti_size_y(&v2d->mask) + 1) / BLI_rctf_size_y(&v2d->cur); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* only move view to mouse if zoom fac is inside minzoom/maxzoom */ | 
					
						
							| 
									
										
										
										
											2015-04-21 13:10:32 +10:00
										 |  |  | 				if (((v2d->keepzoom & V2D_LIMITZOOM) == 0) || | 
					
						
							|  |  |  | 				    IN_RANGE_INCL(zoomy, v2d->minzoom, v2d->maxzoom)) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2015-02-08 22:33:58 +01:00
										 |  |  | 					float mval_fac = (vzd->my_2d - cur_old.ymin) / BLI_rctf_size_y(&cur_old); | 
					
						
							|  |  |  | 					float mval_faci = 1.0f - mval_fac; | 
					
						
							|  |  |  | 					float ofs = (mval_fac * dy) - (mval_faci * dy); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					v2d->cur.ymin += ofs; | 
					
						
							|  |  |  | 					v2d->cur.ymax += ofs; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-29 22:57:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* validate that view is in valid configuration after this operation */ | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | 	UI_view2d_curRect_validate(v2d); | 
					
						
							| 
									
										
										
										
											2009-07-29 22:57:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-26 12:01:44 +02:00
										 |  |  | 	if (ED_region_snap_size_apply(ar, snap_test)) { | 
					
						
							|  |  |  | 		ScrArea *sa = CTX_wm_area(C); | 
					
						
							|  |  |  | 		ED_area_tag_redraw(sa); | 
					
						
							|  |  |  | 		WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* request updates to be done... */ | 
					
						
							| 
									
										
										
										
											2018-05-22 14:41:49 +02:00
										 |  |  | 	ED_region_tag_redraw_no_rebuild(vzd->ar); | 
					
						
							| 
									
										
										
										
											2008-12-21 11:56:42 +00:00
										 |  |  | 	UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | static void view_zoomstep_apply(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	v2dViewZoomData *vzd = op->customdata; | 
					
						
							| 
									
										
										
										
											2018-07-01 19:57:31 +02:00
										 |  |  | 	view_zoomstep_apply_ex( | 
					
						
							|  |  |  | 	        C, vzd, true, | 
					
						
							|  |  |  | 	        RNA_float_get(op->ptr, "zoomfacx"), | 
					
						
							|  |  |  | 	        RNA_float_get(op->ptr, "zoomfacy")); | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | /* --------------- Individual Operators ------------------- */ | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | /* cleanup temp customdata  */ | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | static void view_zoomstep_exit(wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-20 12:43:56 +11:00
										 |  |  | 	UI_view2d_zoom_cache_reset(); | 
					
						
							| 
									
										
										
										
											2014-01-19 14:57:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	if (op->customdata) { | 
					
						
							|  |  |  | 		MEM_freeN(op->customdata); | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		op->customdata = NULL; | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | /* this operator only needs this single callback, where it calls the view_zoom_*() methods */ | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | static int view_zoomin_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	bool do_zoom_xy[2]; | 
					
						
							| 
									
										
										
										
											2012-08-23 14:49:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* check that there's an active region, as View2D data resides there */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_zoom_poll(C)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-26 16:41:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	view_zoom_axis_lock_defaults(C, do_zoom_xy); | 
					
						
							| 
									
										
										
										
											2012-08-23 14:49:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* set RNA-Props - zooming in by uniform factor */ | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	RNA_float_set(op->ptr, "zoomfacx", do_zoom_xy[0] ? 0.0375f : 0.0f); | 
					
						
							|  |  |  | 	RNA_float_set(op->ptr, "zoomfacy", do_zoom_xy[1] ? 0.0375f : 0.0f); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* apply movement, then we're done */ | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	view_zoomstep_apply(C, op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 	view_zoomstep_exit(op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int view_zoomin_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	v2dViewZoomData *vzd; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_zoomdrag_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vzd = op->customdata; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 	if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 		/* store initial mouse position (in view space) */ | 
					
						
							| 
									
										
										
										
											2018-07-01 19:57:31 +02:00
										 |  |  | 		UI_view2d_region_to_view( | 
					
						
							|  |  |  | 		        &ar->v2d, | 
					
						
							|  |  |  | 		        event->mval[0], event->mval[1], | 
					
						
							|  |  |  | 		        &vzd->mx_2d, &vzd->my_2d); | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	return view_zoomin_exec(C, op); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_zoom_in(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-30 16:38:06 +02:00
										 |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Zoom In"; | 
					
						
							|  |  |  | 	ot->description = "Zoom in the view"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_zoom_in"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->invoke = view_zoomin_invoke; | 
					
						
							| 
									
										
										
										
											2012-08-26 16:41:03 +00:00
										 |  |  | 	ot->exec = view_zoomin_exec;  // XXX, needs view_zoomdrag_init called first.
 | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->poll = view_zoom_poll; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* rna - must keep these in sync with the other operators */ | 
					
						
							| 
									
										
										
										
											2014-08-30 16:38:06 +02:00
										 |  |  | 	prop = RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX); | 
					
						
							|  |  |  | 	RNA_def_property_flag(prop, PROP_HIDDEN); | 
					
						
							|  |  |  | 	prop = RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX); | 
					
						
							|  |  |  | 	RNA_def_property_flag(prop, PROP_HIDDEN); | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-08-30 16:38:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-26 12:02:29 +00:00
										 |  |  | /* this operator only needs this single callback, where it calls the view_zoom_*() methods */ | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | static int view_zoomout_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	bool do_zoom_xy[2]; | 
					
						
							| 
									
										
										
										
											2012-08-23 14:49:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* check that there's an active region, as View2D data resides there */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_zoom_poll(C)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	view_zoom_axis_lock_defaults(C, do_zoom_xy); | 
					
						
							| 
									
										
										
										
											2012-08-23 14:49:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* set RNA-Props - zooming in by uniform factor */ | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	RNA_float_set(op->ptr, "zoomfacx", do_zoom_xy[0] ? -0.0375f : 0.0f); | 
					
						
							|  |  |  | 	RNA_float_set(op->ptr, "zoomfacy", do_zoom_xy[1] ? -0.0375f : 0.0f); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* apply movement, then we're done */ | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	view_zoomstep_apply(C, op); | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 12:29:02 +00:00
										 |  |  | 	view_zoomstep_exit(op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int view_zoomout_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	v2dViewZoomData *vzd; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_zoomdrag_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vzd = op->customdata; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 		/* store initial mouse position (in view space) */ | 
					
						
							| 
									
										
										
										
											2018-07-01 19:57:31 +02:00
										 |  |  | 		UI_view2d_region_to_view( | 
					
						
							|  |  |  | 		        &ar->v2d, | 
					
						
							|  |  |  | 		        event->mval[0], event->mval[1], | 
					
						
							|  |  |  | 		        &vzd->mx_2d, &vzd->my_2d); | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 08:13:31 +00:00
										 |  |  | 	return view_zoomout_exec(C, op); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_zoom_out(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-30 16:38:06 +02:00
										 |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Zoom Out"; | 
					
						
							|  |  |  | 	ot->description = "Zoom out the view"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_zoom_out"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->invoke = view_zoomout_invoke; | 
					
						
							|  |  |  | //	ot->exec = view_zoomout_exec; // XXX, needs view_zoomdrag_init called first.
 | 
					
						
							|  |  |  | 	ot->poll = view_zoom_poll; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | 	/* rna - must keep these in sync with the other operators */ | 
					
						
							| 
									
										
										
										
											2014-08-30 16:38:06 +02:00
										 |  |  | 	prop = RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX); | 
					
						
							|  |  |  | 	RNA_def_property_flag(prop, PROP_HIDDEN); | 
					
						
							|  |  |  | 	prop = RNA_def_float(ot->srna, "zoomfacy", 0, -FLT_MAX, FLT_MAX, "Zoom Factor Y", "", -FLT_MAX, FLT_MAX); | 
					
						
							|  |  |  | 	RNA_def_property_flag(prop, PROP_HIDDEN); | 
					
						
							| 
									
										
										
										
											2008-12-01 11:37:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 09:43:23 +00:00
										 |  |  | /* ********************************************************* */ | 
					
						
							| 
									
										
										
										
											2011-09-25 12:31:21 +00:00
										 |  |  | /* DRAG-ZOOM OPERATOR									 */ | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * MMB Drag - allows non-uniform scaling by dragging mouse | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  |  * In order to make sure this works, each operator must define the following RNA-Operator Props: | 
					
						
							|  |  |  |  * - `deltax, deltay` - amounts to add to each side of the 'cur' rect | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* apply transform to view (i.e. adjust 'cur' rect) */ | 
					
						
							|  |  |  | static void view_zoomdrag_apply(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	v2dViewZoomData *vzd = op->customdata; | 
					
						
							|  |  |  | 	View2D *v2d = vzd->v2d; | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	float dx, dy; | 
					
						
							| 
									
										
										
										
											2018-04-26 12:01:44 +02:00
										 |  |  | 	const int snap_test = ED_region_snap_size_test(vzd->ar); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* get amount to move view by */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	dx = RNA_float_get(op->ptr, "deltax"); | 
					
						
							|  |  |  | 	dy = RNA_float_get(op->ptr, "deltay"); | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 16:42:12 +00:00
										 |  |  | 	if (U.uiflag & USER_ZOOM_INVERT) { | 
					
						
							|  |  |  | 		dx *= -1; | 
					
						
							|  |  |  | 		dy *= -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-03 11:45:08 +00:00
										 |  |  | 	/* continuous zoom shouldn't move that fast... */ | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 	if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		double time = PIL_check_seconds_timer(); | 
					
						
							|  |  |  | 		float time_step = (float)(time - vzd->timer_lastdraw); | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		dx *= time_step * 0.5f; | 
					
						
							|  |  |  | 		dy *= time_step * 0.5f; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		vzd->timer_lastdraw = time; | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* only move view on an axis if change is allowed */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) { | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		if (v2d->keepofs & V2D_LOCKOFS_X) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			v2d->cur.xmax -= 2 * dx; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 			if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) { | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 				float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur); | 
					
						
							| 
									
										
										
										
											2011-03-27 14:52:16 +00:00
										 |  |  | 				float mval_faci = 1.0f - mval_fac; | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 				float ofs = (mval_fac * dx) - (mval_faci * dx); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 16:42:12 +00:00
										 |  |  | 				v2d->cur.xmin += ofs + dx; | 
					
						
							|  |  |  | 				v2d->cur.xmax += ofs - dx; | 
					
						
							| 
									
										
										
										
											2009-12-22 08:39:59 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-10-13 16:42:12 +00:00
										 |  |  | 				v2d->cur.xmin += dx; | 
					
						
							|  |  |  | 				v2d->cur.xmax -= dx; | 
					
						
							| 
									
										
										
										
											2009-12-22 08:39:59 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) { | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		if (v2d->keepofs & V2D_LOCKOFS_Y) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			v2d->cur.ymax -= 2 * dy; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 			if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) { | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 				float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur); | 
					
						
							| 
									
										
										
										
											2011-03-27 14:52:16 +00:00
										 |  |  | 				float mval_faci = 1.0f - mval_fac; | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 				float ofs = (mval_fac * dy) - (mval_faci * dy); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 16:42:12 +00:00
										 |  |  | 				v2d->cur.ymin += ofs + dy; | 
					
						
							|  |  |  | 				v2d->cur.ymax += ofs - dy; | 
					
						
							| 
									
										
										
										
											2009-12-22 08:39:59 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-10-13 16:42:12 +00:00
										 |  |  | 				v2d->cur.ymin += dy; | 
					
						
							|  |  |  | 				v2d->cur.ymax -= dy; | 
					
						
							| 
									
										
										
										
											2009-12-22 08:39:59 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* validate that view is in valid configuration after this operation */ | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | 	UI_view2d_curRect_validate(v2d); | 
					
						
							| 
									
										
										
										
											2018-04-26 12:01:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ED_region_snap_size_apply(vzd->ar, snap_test)) { | 
					
						
							|  |  |  | 		ScrArea *sa = CTX_wm_area(C); | 
					
						
							|  |  |  | 		ED_area_tag_redraw(sa); | 
					
						
							|  |  |  | 		WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* request updates to be done... */ | 
					
						
							| 
									
										
										
										
											2018-05-22 14:41:49 +02:00
										 |  |  | 	ED_region_tag_redraw_no_rebuild(vzd->ar); | 
					
						
							| 
									
										
										
										
											2008-12-21 11:56:42 +00:00
										 |  |  | 	UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* cleanup temp customdata  */ | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | static void view_zoomdrag_exit(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-20 12:43:56 +11:00
										 |  |  | 	UI_view2d_zoom_cache_reset(); | 
					
						
							| 
									
										
										
										
											2014-01-19 14:57:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	if (op->customdata) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		v2dViewZoomData *vzd = op->customdata; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		if (vzd->timer) { | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 			WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), vzd->timer); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 		MEM_freeN(op->customdata); | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		op->customdata = NULL; | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-30 23:08:53 +00:00
										 |  |  | static void view_zoomdrag_cancel(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-06-06 11:04:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	view_zoomdrag_exit(C, op); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | /* for 'redo' only, with no user input */ | 
					
						
							|  |  |  | static int view_zoomdrag_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_zoomdrag_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	view_zoomdrag_apply(C, op); | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 	view_zoomdrag_exit(C, op); | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* set up modal operator and relevant settings */ | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int view_zoomdrag_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	wmWindow *window = CTX_wm_window(C); | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	v2dViewZoomData *vzd; | 
					
						
							|  |  |  | 	View2D *v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* set up customdata */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (!view_zoomdrag_init(C, op)) { | 
					
						
							| 
									
										
										
										
											2008-12-27 04:30:26 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vzd = op->customdata; | 
					
						
							|  |  |  | 	v2d = vzd->v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-29 13:21:01 +00:00
										 |  |  | 	if (event->type == MOUSEZOOM || event->type == MOUSEPAN) { | 
					
						
							| 
									
										
										
										
											2010-01-11 11:14:36 +00:00
										 |  |  | 		float dx, dy, fac; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		vzd->lastx = event->prevx; | 
					
						
							|  |  |  | 		vzd->lasty = event->prevy; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 11:14:36 +00:00
										 |  |  | 		/* As we have only 1D information (magnify value), feed both axes
 | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 		 * with magnify information that is stored in x axis | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2013-01-06 11:16:49 +00:00
										 |  |  | 		fac = 0.01f * (event->prevx - event->x); | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 		dx = fac * BLI_rctf_size_x(&v2d->cur) / 10.0f; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		if (event->type == MOUSEPAN) { | 
					
						
							| 
									
										
										
										
											2013-01-06 11:16:49 +00:00
										 |  |  | 			fac = 0.01f * (event->prevy - event->y); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 		dy = fac * BLI_rctf_size_y(&v2d->cur) / 10.0f; | 
					
						
							| 
									
										
										
										
											2010-01-11 11:14:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 		/* support trackpad zoom to always zoom entirely - the v2d code uses portrait or
 | 
					
						
							|  |  |  | 		 * landscape exceptions */ | 
					
						
							| 
									
										
										
										
											2013-01-12 11:00:27 +00:00
										 |  |  | 		if (v2d->keepzoom & V2D_KEEPASPECT) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if (fabsf(dx) > fabsf(dy)) { | 
					
						
							| 
									
										
										
										
											2013-01-12 11:00:27 +00:00
										 |  |  | 				dy = dx; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2013-01-12 11:00:27 +00:00
										 |  |  | 				dx = dy; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-01-12 11:00:27 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-01-11 11:14:36 +00:00
										 |  |  | 		RNA_float_set(op->ptr, "deltax", dx); | 
					
						
							|  |  |  | 		RNA_float_set(op->ptr, "deltay", dy); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 11:14:36 +00:00
										 |  |  | 		view_zoomdrag_apply(C, op); | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		view_zoomdrag_exit(C, op); | 
					
						
							| 
									
										
										
										
											2010-01-11 11:14:36 +00:00
										 |  |  | 		return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2012-10-21 05:46:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* set initial settings */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vzd->lastx = event->x; | 
					
						
							|  |  |  | 	vzd->lasty = event->y; | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	RNA_float_set(op->ptr, "deltax", 0); | 
					
						
							|  |  |  | 	RNA_float_set(op->ptr, "deltay", 0); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-12 13:49:47 +00:00
										 |  |  | 	/* for modal exit test */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vzd->invoke_event = event->type; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 	if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 		/* store initial mouse position (in view space) */ | 
					
						
							| 
									
										
										
										
											2018-07-01 19:57:31 +02:00
										 |  |  | 		UI_view2d_region_to_view( | 
					
						
							|  |  |  | 		        &ar->v2d, | 
					
						
							|  |  |  | 		        event->mval[0], event->mval[1], | 
					
						
							|  |  |  | 		        &vzd->mx_2d, &vzd->my_2d); | 
					
						
							| 
									
										
										
										
											2009-12-22 08:39:59 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (v2d->keepofs & V2D_LOCKOFS_X) { | 
					
						
							| 
									
										
										
										
											2013-09-06 22:34:29 +00:00
										 |  |  | 		WM_cursor_modal_set(window, BC_NS_SCROLLCURSOR); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (v2d->keepofs & V2D_LOCKOFS_Y) { | 
					
						
							| 
									
										
										
										
											2013-09-06 22:34:29 +00:00
										 |  |  | 		WM_cursor_modal_set(window, BC_EW_SCROLLCURSOR); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2013-09-06 22:34:29 +00:00
										 |  |  | 		WM_cursor_modal_set(window, BC_NSEW_SCROLLCURSOR); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* add temp handler */ | 
					
						
							| 
									
										
										
										
											2009-09-18 12:43:36 +00:00
										 |  |  | 	WM_event_add_modal_handler(C, op); | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 	if (U.viewzoom == USER_ZOOM_CONT) { | 
					
						
							|  |  |  | 		/* needs a timer to continue redrawing */ | 
					
						
							| 
									
										
										
										
											2014-04-30 07:48:54 +10:00
										 |  |  | 		vzd->timer = WM_event_add_timer(CTX_wm_manager(C), window, TIMER, 0.01f); | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		vzd->timer_lastdraw = PIL_check_seconds_timer(); | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	return OPERATOR_RUNNING_MODAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | /* handle user input - calculations of mouse-movement need to be done here,
 | 
					
						
							|  |  |  |  * not in the apply callback! */ | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int view_zoomdrag_modal(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	v2dViewZoomData *vzd = op->customdata; | 
					
						
							|  |  |  | 	View2D *v2d = vzd->v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* execute the events */ | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 	if (event->type == TIMER && event->customdata == vzd->timer) { | 
					
						
							|  |  |  | 		view_zoomdrag_apply(C, op); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	else if (event->type == MOUSEMOVE) { | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		float dx, dy; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		/* calculate new delta transform, based on zooming mode */ | 
					
						
							|  |  |  | 		if (U.viewzoom == USER_ZOOM_SCALE) { | 
					
						
							|  |  |  | 			/* 'scale' zooming */ | 
					
						
							|  |  |  | 			float dist; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 			/* x-axis transform */ | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 			dist = BLI_rcti_size_x(&v2d->mask) / 2.0f; | 
					
						
							| 
									
										
										
										
											2012-12-21 16:11:50 +00:00
										 |  |  | 			dx = 1.0f - (fabsf(vzd->lastx - vzd->ar->winrct.xmin - dist) + 2.0f) / (fabsf(event->mval[0] - dist) + 2.0f); | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 			dx *= 0.5f * BLI_rctf_size_x(&v2d->cur); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 			/* y-axis transform */ | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 			dist = BLI_rcti_size_y(&v2d->mask) / 2.0f; | 
					
						
							| 
									
										
										
										
											2012-12-22 01:08:42 +00:00
										 |  |  | 			dy = 1.0f - (fabsf(vzd->lasty - vzd->ar->winrct.ymin - dist) + 2.0f) / (fabsf(event->mval[1] - dist) + 2.0f); | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 			dy *= 0.5f * BLI_rctf_size_y(&v2d->cur); | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			/* 'continuous' or 'dolly' */ | 
					
						
							| 
									
										
										
										
											2013-02-27 17:12:57 +00:00
										 |  |  | 			float fac, zoomfac = 0.01f; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-18 15:14:34 +00:00
										 |  |  | 			/* some view2d's (graph) don't have min/max zoom, or extreme ones */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if (v2d->maxzoom > 0.0f) { | 
					
						
							| 
									
										
										
										
											2018-06-17 11:50:56 +02:00
										 |  |  | 				zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 			/* x-axis transform */ | 
					
						
							| 
									
										
										
										
											2013-02-18 15:14:34 +00:00
										 |  |  | 			fac = zoomfac * (event->x - vzd->lastx); | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 			dx = fac * BLI_rctf_size_x(&v2d->cur); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 			/* y-axis transform */ | 
					
						
							| 
									
										
										
										
											2013-02-18 15:14:34 +00:00
										 |  |  | 			fac = zoomfac * (event->y - vzd->lasty); | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 			dy = fac * BLI_rctf_size_y(&v2d->cur); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 		/* support zoom to always zoom entirely - the v2d code uses portrait or
 | 
					
						
							|  |  |  | 		 * landscape exceptions */ | 
					
						
							| 
									
										
										
										
											2013-01-12 11:00:27 +00:00
										 |  |  | 		if (v2d->keepzoom & V2D_KEEPASPECT) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if (fabsf(dx) > fabsf(dy)) { | 
					
						
							| 
									
										
										
										
											2013-01-12 11:00:27 +00:00
										 |  |  | 				dy = dx; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2013-01-12 11:00:27 +00:00
										 |  |  | 				dx = dy; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-01-12 11:00:27 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		/* set transform amount, and add current deltas to stored total delta (for redo) */ | 
					
						
							| 
									
										
										
										
											2012-10-08 17:41:27 +00:00
										 |  |  | 		RNA_float_set(op->ptr, "deltax", dx); | 
					
						
							|  |  |  | 		RNA_float_set(op->ptr, "deltay", dy); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		vzd->dx += dx; | 
					
						
							|  |  |  | 		vzd->dy += dy; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		/* store mouse coordinates for next time, if not doing continuous zoom
 | 
					
						
							| 
									
										
										
										
											2018-11-14 12:53:15 +11:00
										 |  |  | 		 * - continuous zoom only depends on distance of mouse to starting point to determine rate of change | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		 */ | 
					
						
							|  |  |  | 		if (U.viewzoom != USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			vzd->lastx = event->x; | 
					
						
							|  |  |  | 			vzd->lasty = event->y; | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 		/* apply zooming */ | 
					
						
							|  |  |  | 		view_zoomdrag_apply(C, op); | 
					
						
							| 
									
										
										
										
											2012-10-21 05:46:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	else if (event->type == vzd->invoke_event || event->type == ESCKEY) { | 
					
						
							| 
									
										
										
										
											2011-05-12 13:49:47 +00:00
										 |  |  | 		if (event->val == KM_RELEASE) { | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 			/* for redo, store the overall deltas - need to respect zoom-locks here... */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) { | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 				RNA_float_set(op->ptr, "deltax", vzd->dx); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 				RNA_float_set(op->ptr, "deltax", 0); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) { | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 				RNA_float_set(op->ptr, "deltay", vzd->dy); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 				RNA_float_set(op->ptr, "deltay", 0); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 			/* free customdata */ | 
					
						
							|  |  |  | 			view_zoomdrag_exit(C, op); | 
					
						
							| 
									
										
										
										
											2013-09-06 22:34:29 +00:00
										 |  |  | 			WM_cursor_modal_restore(CTX_wm_window(C)); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-05 03:54:54 +00:00
										 |  |  | 			return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_RUNNING_MODAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_zoom(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-30 16:38:06 +02:00
										 |  |  | 	PropertyRNA *prop; | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Zoom 2D View"; | 
					
						
							|  |  |  | 	ot->description = "Zoom in/out the view"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_zoom"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = view_zoomdrag_exec; | 
					
						
							|  |  |  | 	ot->invoke = view_zoomdrag_invoke; | 
					
						
							|  |  |  | 	ot->modal = view_zoomdrag_modal; | 
					
						
							|  |  |  | 	ot->cancel = view_zoomdrag_cancel; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->poll = view_zoom_poll; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* operator is repeatable */ | 
					
						
							| 
									
										
										
										
											2015-04-27 18:44:27 +10:00
										 |  |  | 	ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | 	/* rna - must keep these in sync with the other operators */ | 
					
						
							| 
									
										
										
										
											2014-08-30 16:38:06 +02:00
										 |  |  | 	prop = RNA_def_float(ot->srna, "deltax", 0, -FLT_MAX, FLT_MAX, "Delta X", "", -FLT_MAX, FLT_MAX); | 
					
						
							|  |  |  | 	RNA_def_property_flag(prop, PROP_HIDDEN); | 
					
						
							|  |  |  | 	prop = RNA_def_float(ot->srna, "deltay", 0, -FLT_MAX, FLT_MAX, "Delta Y", "", -FLT_MAX, FLT_MAX); | 
					
						
							|  |  |  | 	RNA_def_property_flag(prop, PROP_HIDDEN); | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | /* ********************************************************* */ | 
					
						
							|  |  |  | /* BORDER-ZOOM */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2018-10-05 10:27:04 +10:00
										 |  |  |  * The user defines a rect using standard box select tools, and we use this rect to | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  |  * define the new zoom-level of the view in the following ways: | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  |  * | 
					
						
							|  |  |  |  * -# LEFTMOUSE - zoom in to view | 
					
						
							|  |  |  |  * -# RIGHTMOUSE - zoom out of view | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Currently, these key mappings are hardcoded, but it shouldn't be too important to | 
					
						
							|  |  |  |  * have custom keymappings for this... | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | static int view_borderzoom_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 	View2D *v2d = &ar->v2d; | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 	rctf rect; | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 	rctf cur_new = v2d->cur; | 
					
						
							| 
									
										
										
										
											2013-09-16 04:04:44 +00:00
										 |  |  | 	const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 	/* convert coordinates of rect to 'tot' rect coordinates */ | 
					
						
							| 
									
										
										
										
											2014-04-21 16:47:16 +10:00
										 |  |  | 	WM_operator_properties_border_to_rctf(op, &rect); | 
					
						
							|  |  |  | 	UI_view2d_region_to_view_rctf(v2d, &rect, &rect); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 	/* check if zooming in/out view */ | 
					
						
							| 
									
										
										
										
											2017-10-16 21:58:51 +11:00
										 |  |  | 	const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out"); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-16 21:58:51 +11:00
										 |  |  | 	if (zoom_in) { | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 		/* zoom in:
 | 
					
						
							| 
									
										
										
										
											2018-11-14 12:53:15 +11:00
										 |  |  | 		 * - 'cur' rect will be defined by the coordinates of the border region | 
					
						
							|  |  |  | 		 * - just set the 'cur' rect to have the same coordinates as the border region | 
					
						
							|  |  |  | 		 *   if zoom is allowed to be changed | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) { | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 			cur_new.xmin = rect.xmin; | 
					
						
							|  |  |  | 			cur_new.xmax = rect.xmax; | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) { | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 			cur_new.ymin = rect.ymin; | 
					
						
							|  |  |  | 			cur_new.ymax = rect.ymax; | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-16 21:58:51 +11:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 		/* zoom out:
 | 
					
						
							| 
									
										
										
										
											2018-11-14 12:53:15 +11:00
										 |  |  | 		 * - the current 'cur' rect coordinates are going to end up where the 'rect' ones are, | 
					
						
							|  |  |  | 		 *   but the 'cur' rect coordinates will need to be adjusted to take in more of the view | 
					
						
							|  |  |  | 		 * - calculate zoom factor, and adjust using center-point | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 		 */ | 
					
						
							|  |  |  | 		float zoom, center, size; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 		/* TODO: is this zoom factor calculation valid?
 | 
					
						
							|  |  |  | 		 * It seems to produce same results every time... */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) { | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 			size = BLI_rctf_size_x(&cur_new); | 
					
						
							|  |  |  | 			zoom = size / BLI_rctf_size_x(&rect); | 
					
						
							|  |  |  | 			center = BLI_rctf_cent_x(&cur_new); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 			cur_new.xmin = center - (size * zoom); | 
					
						
							|  |  |  | 			cur_new.xmax = center + (size * zoom); | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) { | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 			size = BLI_rctf_size_y(&cur_new); | 
					
						
							|  |  |  | 			zoom = size / BLI_rctf_size_y(&rect); | 
					
						
							|  |  |  | 			center = BLI_rctf_cent_y(&cur_new); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 			cur_new.ymin = center - (size * zoom); | 
					
						
							|  |  |  | 			cur_new.ymax = center + (size * zoom); | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 04:04:44 +00:00
										 |  |  | 	UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_zoom_border(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Zoom to Border"; | 
					
						
							|  |  |  | 	ot->description = "Zoom in the view to the nearest item contained in the border"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_zoom_border"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2018-10-05 10:27:04 +10:00
										 |  |  | 	ot->invoke = WM_gesture_box_invoke; | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = view_borderzoom_exec; | 
					
						
							| 
									
										
										
										
											2018-10-05 10:27:04 +10:00
										 |  |  | 	ot->modal = WM_gesture_box_modal; | 
					
						
							|  |  |  | 	ot->cancel = WM_gesture_box_cancel; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->poll = view_zoom_poll; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | 	/* rna */ | 
					
						
							| 
									
										
										
										
											2018-10-05 10:27:04 +10:00
										 |  |  | 	WM_operator_properties_gesture_box_zoom(ot); | 
					
						
							| 
									
										
										
										
											2008-12-25 11:09:25 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 00:21:55 -04:00
										 |  |  | #ifdef WITH_INPUT_NDOF
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | static int view2d_ndof_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (event->type != NDOF_MOTION) { | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2014-02-22 16:19:02 +11:00
										 |  |  | 		const wmNDOFMotionData *ndof = event->customdata; | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* tune these until it feels right */ | 
					
						
							|  |  |  | 		const float zoom_sensitivity = 0.5f; | 
					
						
							| 
									
										
										
										
											2014-02-22 16:19:02 +11:00
										 |  |  | 		const float speed = 10.0f;  /* match view3d ortho */ | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 		const bool has_translate = (ndof->tvec[0] && ndof->tvec[1]) && view_pan_poll(C); | 
					
						
							|  |  |  | 		const bool has_zoom = (ndof->tvec[2] != 0.0f) && view_zoom_poll(C); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (has_translate) { | 
					
						
							|  |  |  | 			if (view_pan_init(C, op)) { | 
					
						
							|  |  |  | 				v2dViewPanData *vpd; | 
					
						
							| 
									
										
										
										
											2014-02-18 23:51:11 +11:00
										 |  |  | 				float pan_vec[3]; | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-18 23:51:11 +11:00
										 |  |  | 				WM_event_ndof_pan_get(ndof, pan_vec, false); | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-22 16:19:02 +11:00
										 |  |  | 				pan_vec[0] *= speed; | 
					
						
							|  |  |  | 				pan_vec[1] *= speed; | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				vpd = op->customdata; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				view_pan_apply_ex(C, vpd, pan_vec[0], pan_vec[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				view_pan_exit(op); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (has_zoom) { | 
					
						
							|  |  |  | 			if (view_zoomdrag_init(C, op)) { | 
					
						
							|  |  |  | 				v2dViewZoomData *vzd; | 
					
						
							| 
									
										
										
										
											2014-02-22 16:19:02 +11:00
										 |  |  | 				float zoom_factor = zoom_sensitivity * ndof->dt * -ndof->tvec[2]; | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				bool do_zoom_xy[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 				if (U.ndof_flag & NDOF_ZOOM_INVERT) { | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 					zoom_factor = -zoom_factor; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				view_zoom_axis_lock_defaults(C, do_zoom_xy); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				vzd = op->customdata; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-01 19:57:31 +02:00
										 |  |  | 				view_zoomstep_apply_ex( | 
					
						
							|  |  |  | 				        C, vzd, false, | 
					
						
							|  |  |  | 				        do_zoom_xy[0] ? zoom_factor : 0.0f, | 
					
						
							|  |  |  | 				        do_zoom_xy[1] ? zoom_factor : 0.0f); | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				view_zoomstep_exit(op); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void VIEW2D_OT_ndof(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "NDOF Pan/Zoom"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_ndof"; | 
					
						
							|  |  |  | 	ot->description = "Use a 3D mouse device to pan/zoom the view"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->invoke = view2d_ndof_invoke; | 
					
						
							| 
									
										
										
										
											2014-02-26 13:48:41 +11:00
										 |  |  | 	ot->poll = view2d_poll; | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_LOCK_BYPASS; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-08-18 00:21:55 -04:00
										 |  |  | #endif /* WITH_INPUT_NDOF */
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | /* ********************************************************* */ | 
					
						
							|  |  |  | /* SMOOTH VIEW */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct SmoothView2DStore { | 
					
						
							|  |  |  | 	rctf orig_cur, new_cur; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	double time_allowed; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 19:35:47 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * function to get a factor out of a rectangle | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * note: this doesn't always work as well as it might because the target size | 
					
						
							|  |  |  |  *       may not be reached because of clamping the desired rect, we _could_ | 
					
						
							|  |  |  |  *       attempt to clamp the rect before working out the zoom factor but its | 
					
						
							|  |  |  |  *       not really worthwhile for the few cases this happens. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static float smooth_view_rect_to_fac(const rctf *rect_a, const rctf *rect_b) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-01 19:57:31 +02:00
										 |  |  | 	const float size_a[2] = { | 
					
						
							|  |  |  | 		BLI_rctf_size_x(rect_a), | 
					
						
							|  |  |  | 		BLI_rctf_size_y(rect_a)}; | 
					
						
							|  |  |  | 	const float size_b[2] = { | 
					
						
							|  |  |  | 		BLI_rctf_size_x(rect_b), | 
					
						
							|  |  |  | 		BLI_rctf_size_y(rect_b)}; | 
					
						
							|  |  |  | 	const float cent_a[2] = { | 
					
						
							|  |  |  | 		BLI_rctf_cent_x(rect_a), | 
					
						
							|  |  |  | 		BLI_rctf_cent_y(rect_a)}; | 
					
						
							|  |  |  | 	const float cent_b[2] = { | 
					
						
							|  |  |  | 		BLI_rctf_cent_x(rect_b), | 
					
						
							|  |  |  | 		BLI_rctf_cent_y(rect_b)}; | 
					
						
							| 
									
										
										
										
											2012-08-12 19:35:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	float fac_max = 0.0f; | 
					
						
							|  |  |  | 	float tfac; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < 2; i++) { | 
					
						
							|  |  |  | 		/* axis translation normalized to scale */ | 
					
						
							| 
									
										
										
										
											2012-10-23 13:28:22 +00:00
										 |  |  | 		tfac = fabsf(cent_a[i] - cent_b[i]) / min_ff(size_a[i], size_b[i]); | 
					
						
							|  |  |  | 		fac_max = max_ff(fac_max, tfac); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		if (fac_max >= 1.0f) { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-12 19:35:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* axis scale difference, x2 so doubling or half gives 1.0f */ | 
					
						
							| 
									
										
										
										
											2012-10-23 13:28:22 +00:00
										 |  |  | 		tfac = (1.0f - (min_ff(size_a[i], size_b[i]) / max_ff(size_a[i], size_b[i]))) * 2.0f; | 
					
						
							|  |  |  | 		fac_max = max_ff(fac_max, tfac); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		if (fac_max >= 1.0f) { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-12 19:35:47 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-10-23 13:28:22 +00:00
										 |  |  | 	return min_ff(fac_max, 1.0f); | 
					
						
							| 
									
										
										
										
											2012-08-12 19:35:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | /* will start timer if appropriate */ | 
					
						
							|  |  |  | /* the arguments are the desired situation */ | 
					
						
							| 
									
										
										
										
											2015-05-05 03:13:47 +10:00
										 |  |  | void UI_view2d_smooth_view( | 
					
						
							|  |  |  |         bContext *C, ARegion *ar, | 
					
						
							|  |  |  |         const rctf *cur, const int smooth_viewtx) | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	wmWindowManager *wm = CTX_wm_manager(C); | 
					
						
							|  |  |  | 	wmWindow *win = CTX_wm_window(C); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	View2D *v2d = &ar->v2d; | 
					
						
							|  |  |  | 	struct SmoothView2DStore sms = {{0}}; | 
					
						
							| 
									
										
										
										
											2014-01-04 17:16:19 +11:00
										 |  |  | 	bool ok = false; | 
					
						
							| 
									
										
										
										
											2012-08-12 19:35:47 +00:00
										 |  |  | 	float fac = 1.0f; | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* initialize sms */ | 
					
						
							|  |  |  | 	sms.new_cur = v2d->cur; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* store the options we want to end with */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (cur) { | 
					
						
							|  |  |  | 		sms.new_cur = *cur; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 19:35:47 +00:00
										 |  |  | 	if (cur) { | 
					
						
							|  |  |  | 		fac = smooth_view_rect_to_fac(&v2d->cur, cur); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 04:04:44 +00:00
										 |  |  | 	if (smooth_viewtx && fac > FLT_EPSILON) { | 
					
						
							| 
									
										
										
										
											2013-11-26 06:39:14 +11:00
										 |  |  | 		bool changed = false; | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		if (BLI_rctf_compare(&sms.new_cur, &v2d->cur, FLT_EPSILON) == false) { | 
					
						
							| 
									
										
										
										
											2013-11-26 06:39:14 +11:00
										 |  |  | 			changed = true; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* The new view is different from the old one
 | 
					
						
							|  |  |  | 		 * so animate the view */ | 
					
						
							|  |  |  | 		if (changed) { | 
					
						
							|  |  |  | 			sms.orig_cur = v2d->cur; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 04:04:44 +00:00
										 |  |  | 			sms.time_allowed = (double)smooth_viewtx / 1000.0; | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 19:35:47 +00:00
										 |  |  | 			/* scale the time allowed the change in view */ | 
					
						
							|  |  |  | 			sms.time_allowed *= (double)fac; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 			/* keep track of running timer! */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if (v2d->sms == NULL) { | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 				v2d->sms = MEM_mallocN(sizeof(struct SmoothView2DStore), "smoothview v2d"); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 			*v2d->sms = sms; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if (v2d->smooth_timer) { | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 				WM_event_remove_timer(wm, win, v2d->smooth_timer); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 			/* TIMER1 is hardcoded in keymap */ | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 			/* max 30 frs/sec */ | 
					
						
							|  |  |  | 			v2d->smooth_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 100.0); | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-04 17:16:19 +11:00
										 |  |  | 			ok = true; | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* if we get here nothing happens */ | 
					
						
							| 
									
										
										
										
											2014-01-04 17:16:19 +11:00
										 |  |  | 	if (ok == false) { | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 		v2d->cur = sms.new_cur; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		UI_view2d_curRect_validate(v2d); | 
					
						
							| 
									
										
										
										
											2018-05-22 14:41:49 +02:00
										 |  |  | 		ED_region_tag_redraw_no_rebuild(ar); | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 		UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* only meant for timer usage */ | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int view2d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 	View2D *v2d = &ar->v2d; | 
					
						
							|  |  |  | 	struct SmoothView2DStore *sms = v2d->sms; | 
					
						
							|  |  |  | 	float step; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* escape if not our timer */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (v2d->smooth_timer == NULL || v2d->smooth_timer != event->customdata) { | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (sms->time_allowed != 0.0) { | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 		step = (float)((v2d->smooth_timer->duration) / sms->time_allowed); | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 		step = 1.0f; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* end timer */ | 
					
						
							|  |  |  | 	if (step >= 1.0f) { | 
					
						
							|  |  |  | 		v2d->cur = sms->new_cur; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MEM_freeN(v2d->sms); | 
					
						
							|  |  |  | 		v2d->sms = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), v2d->smooth_timer); | 
					
						
							|  |  |  | 		v2d->smooth_timer = NULL; | 
					
						
							| 
									
										
										
										
											2018-01-22 14:06:32 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Event handling won't know if a UI item has been moved under the pointer. */ | 
					
						
							|  |  |  | 		WM_event_add_mousemove(C); | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* ease in/out */ | 
					
						
							|  |  |  | 		step = (3.0f * step * step - 2.0f * step * step * step); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BLI_rctf_interp(&v2d->cur, &sms->orig_cur, &sms->new_cur, step); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	UI_view2d_curRect_validate(v2d); | 
					
						
							|  |  |  | 	UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); | 
					
						
							| 
									
										
										
										
											2018-05-22 14:41:49 +02:00
										 |  |  | 	ED_region_tag_redraw_no_rebuild(ar); | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 12:43:56 +11:00
										 |  |  | 	if (v2d->sms == NULL) { | 
					
						
							|  |  |  | 		UI_view2d_zoom_cache_reset(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void VIEW2D_OT_smoothview(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Smooth View 2D"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_smoothview"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->invoke = view2d_smoothview_invoke; | 
					
						
							|  |  |  | 	ot->poll = view2d_poll; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-30 05:50:41 +00:00
										 |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_INTERNAL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 	/* rna */ | 
					
						
							| 
									
										
										
										
											2018-10-05 10:27:04 +10:00
										 |  |  | 	WM_operator_properties_gesture_box(ot); | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  | /* ********************************************************* */ | 
					
						
							|  |  |  | /* SCROLLERS */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Scrollers should behave in the following ways, when clicked on with LMB (and dragged): | 
					
						
							|  |  |  |  * -# 'Handles' on end of 'bubble' - when the axis that the scroller represents is zoomable, | 
					
						
							|  |  |  |  *    enlarge 'cur' rect on the relevant side. | 
					
						
							|  |  |  |  * -# 'Bubble'/'bar' - just drag, and bar should move with mouse (view pans opposite). | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  |  * In order to make sure this works, each operator must define the following RNA-Operator Props: | 
					
						
							|  |  |  |  * - `deltax, deltay` - define how much to move view by (relative to zoom-correction factor) | 
					
						
							| 
									
										
										
										
											2008-12-07 23:54:41 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-12-02 09:43:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | /* customdata for scroller-invoke data */ | 
					
						
							|  |  |  | typedef struct v2dScrollerMove { | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/** View2D data that this operation affects */ | 
					
						
							|  |  |  | 	View2D *v2d; | 
					
						
							|  |  |  | 	/** region that the scroller is in */ | 
					
						
							|  |  |  | 	ARegion *ar; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** scroller that mouse is in ('h' or 'v') */ | 
					
						
							|  |  |  | 	char scroller; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/* XXX find some way to provide visual feedback of this (active color?) */ | 
					
						
							|  |  |  | 	/** -1 is min zoomer, 0 is bar, 1 is max zoomer */ | 
					
						
							|  |  |  | 	short zone; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/** view adjustment factor, based on size of region */ | 
					
						
							|  |  |  | 	float fac; | 
					
						
							|  |  |  | 	/** for pixel rounding (avoid visible UI jitter) */ | 
					
						
							|  |  |  | 	float fac_round; | 
					
						
							|  |  |  | 	/** amount moved by mouse on axis of interest */ | 
					
						
							|  |  |  | 	float delta; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/** width of the scrollbar itself, used for page up/down clicks */ | 
					
						
							|  |  |  | 	float scrollbarwidth; | 
					
						
							|  |  |  | 	/** initial location of scrollbar x/y, mouse relative */ | 
					
						
							|  |  |  | 	int scrollbar_orig; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/** previous mouse coordinates (in screen coordinates) for determining movement */ | 
					
						
							|  |  |  | 	int lastx, lasty; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | } v2dScrollerMove; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * #View2DScrollers is typedef'd in UI_view2d.h | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  |  * This is a CUT DOWN VERSION of the 'real' version, which is defined in view2d.c, as we only need focus bubble info | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \warning: The start of this struct must not change, so that it stays in sync with the 'real' version | 
					
						
							|  |  |  |  * For now, we don't need to have a separate (internal) header for structs like this... | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | struct View2DScrollers { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	/* focus bubbles */ | 
					
						
							|  |  |  | 	int vert_min, vert_max; /* vertical scrollbar */ | 
					
						
							|  |  |  | 	int hor_min, hor_max;   /* horizontal scrollbar */ | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* quick enum for vsm->zone (scroller handles) */ | 
					
						
							| 
									
										
										
										
											2011-02-17 22:34:41 +00:00
										 |  |  | enum { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	SCROLLHANDLE_MIN = -1, | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	SCROLLHANDLE_BAR, | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 	SCROLLHANDLE_MAX, | 
					
						
							|  |  |  | 	SCROLLHANDLE_MIN_OUTSIDE, | 
					
						
							|  |  |  | 	SCROLLHANDLE_MAX_OUTSIDE | 
					
						
							| 
									
										
										
										
											2011-02-17 22:34:41 +00:00
										 |  |  | } /*eV2DScrollerHandle_Zone*/; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Check if mouse is within scroller handle. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param mouse: relevant mouse coordinate in region space. | 
					
						
							|  |  |  |  * \param sc_min, sc_max: extents of scroller 'groove' (potential available space for scroller). | 
					
						
							|  |  |  |  * \param sh_min, sh_max: positions of scrollbar handles. | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static short mouse_in_scroller_handle(int mouse, int sc_min, int sc_max, int sh_min, int sh_max) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-27 09:49:31 +10:00
										 |  |  | 	bool in_min, in_max, in_bar, out_min, out_max, in_view = 1; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* firstly, check if
 | 
					
						
							| 
									
										
										
										
											2018-11-14 12:53:15 +11:00
										 |  |  | 	 * - 'bubble' fills entire scroller | 
					
						
							|  |  |  | 	 * - 'bubble' completely out of view on either side | 
					
						
							| 
									
										
										
										
											2008-12-08 00:48:27 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if ((sh_min <= sc_min) && (sh_max >= sc_max)) { | 
					
						
							|  |  |  | 		in_view = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-14 11:50:28 +00:00
										 |  |  | 	if (sh_min == sh_max) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		if (sh_min <= sc_min) { | 
					
						
							|  |  |  | 			in_view = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (sh_max >= sc_max) { | 
					
						
							|  |  |  | 			in_view = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-12-14 11:50:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		if (sh_max <= sc_min) { | 
					
						
							|  |  |  | 			in_view = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (sh_min >= sc_max) { | 
					
						
							|  |  |  | 			in_view = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-12-14 11:50:28 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-14 11:50:28 +00:00
										 |  |  | 	if (in_view == 0) { | 
					
						
							| 
									
										
										
										
											2009-07-03 13:21:09 +00:00
										 |  |  | 		return SCROLLHANDLE_BAR; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* check if mouse is in or past either handle */ | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 	/* TODO: check if these extents are still valid or not */ | 
					
						
							| 
									
										
										
										
											2014-08-27 09:49:31 +10:00
										 |  |  | 	in_max = ((mouse >= (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse <= (sh_max + V2D_SCROLLER_HANDLE_SIZE))); | 
					
						
							|  |  |  | 	in_min = ((mouse <= (sh_min + V2D_SCROLLER_HANDLE_SIZE)) && (mouse >= (sh_min - V2D_SCROLLER_HANDLE_SIZE))); | 
					
						
							|  |  |  | 	in_bar = ((mouse < (sh_max - V2D_SCROLLER_HANDLE_SIZE)) && (mouse > (sh_min + V2D_SCROLLER_HANDLE_SIZE))); | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	out_min = mouse < (sh_min - V2D_SCROLLER_HANDLE_SIZE); | 
					
						
							|  |  |  | 	out_max = mouse > (sh_max + V2D_SCROLLER_HANDLE_SIZE); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	if (in_bar) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		return SCROLLHANDLE_BAR; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (in_max) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		return SCROLLHANDLE_MAX; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (in_min) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		return SCROLLHANDLE_MIN; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (out_min) { | 
					
						
							| 
									
										
										
										
											2012-10-21 05:46:41 +00:00
										 |  |  | 		return SCROLLHANDLE_MIN_OUTSIDE; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (out_max) { | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 		return SCROLLHANDLE_MAX_OUTSIDE; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* unlikely to happen, though we just cover it in case */ | 
					
						
							| 
									
										
										
										
											2008-12-14 08:32:21 +00:00
										 |  |  | 	return SCROLLHANDLE_BAR; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 12:03:56 +02:00
										 |  |  | static bool scroller_activate_poll(bContext *C) | 
					
						
							| 
									
										
										
										
											2018-06-26 19:49:25 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!view2d_poll(C)) { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wmWindow *win = CTX_wm_window(C); | 
					
						
							|  |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 	View2D *v2d = &ar->v2d; | 
					
						
							|  |  |  | 	wmEvent *event = win->eventstate; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* check if mouse in scrollbars, if they're enabled */ | 
					
						
							|  |  |  | 	return (UI_view2d_mouse_in_scrollers(ar, v2d, event->x, event->y) != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  | /* initialize customdata for scroller manipulation operator */ | 
					
						
							| 
									
										
										
										
											2018-11-07 18:14:21 +11:00
										 |  |  | static void scroller_activate_init(bContext *C, wmOperator *op, const wmEvent *event, const char in_scroller) | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	v2dScrollerMove *vsm; | 
					
						
							|  |  |  | 	View2DScrollers *scrollers; | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 	View2D *v2d = &ar->v2d; | 
					
						
							| 
									
										
										
										
											2012-09-28 09:12:02 +00:00
										 |  |  | 	rctf tot_cur_union; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	float mask_size; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* set custom-data for operator */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vsm = MEM_callocN(sizeof(v2dScrollerMove), "v2dScrollerMove"); | 
					
						
							|  |  |  | 	op->customdata = vsm; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* set general data */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	vsm->v2d = v2d; | 
					
						
							|  |  |  | 	vsm->ar = ar; | 
					
						
							|  |  |  | 	vsm->scroller = in_scroller; | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */ | 
					
						
							|  |  |  | 	vsm->lastx = event->x; | 
					
						
							|  |  |  | 	vsm->lasty = event->y; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 	/* 'zone' depends on where mouse is relative to bubble
 | 
					
						
							| 
									
										
										
										
											2018-11-14 12:53:15 +11:00
										 |  |  | 	 * - zooming must be allowed on this axis, otherwise, default to pan | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-10-22 16:41:18 +11:00
										 |  |  | 	scrollers = UI_view2d_scrollers_calc(C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/* use a union of 'cur' & 'tot' incase the current view is far outside 'tot'. In this cases
 | 
					
						
							|  |  |  | 	 * moving the scroll bars has far too little effect and the view can get stuck T31476. */ | 
					
						
							| 
									
										
										
										
											2012-09-28 09:12:02 +00:00
										 |  |  | 	tot_cur_union = v2d->tot; | 
					
						
							|  |  |  | 	BLI_rctf_union(&tot_cur_union, &v2d->cur); | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	if (in_scroller == 'h') { | 
					
						
							|  |  |  | 		/* horizontal scroller - calculate adjustment factor first */ | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 		mask_size = (float)BLI_rcti_size_x(&v2d->hor); | 
					
						
							| 
									
										
										
										
											2012-09-28 09:12:02 +00:00
										 |  |  | 		vsm->fac = BLI_rctf_size_x(&tot_cur_union) / mask_size; | 
					
						
							| 
									
										
										
										
											2014-08-14 13:44:04 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* pixel rounding */ | 
					
						
							|  |  |  | 		vsm->fac_round = (BLI_rctf_size_x(&v2d->cur)) / (float)(BLI_rcti_size_x(&ar->winrct) + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		/* get 'zone' (i.e. which part of scroller is activated) */ | 
					
						
							| 
									
										
										
										
											2018-07-01 19:57:31 +02:00
										 |  |  | 		vsm->zone = mouse_in_scroller_handle( | 
					
						
							|  |  |  | 		        event->mval[0], | 
					
						
							|  |  |  | 		        v2d->hor.xmin, v2d->hor.xmax, | 
					
						
							|  |  |  | 		        scrollers->hor_min, scrollers->hor_max); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 		if ((v2d->keepzoom & V2D_LOCKZOOM_X) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 			/* default to scroll, as handles not usable */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			vsm->zone = SCROLLHANDLE_BAR; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		vsm->scrollbarwidth = scrollers->hor_max - scrollers->hor_min; | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 		vsm->scrollbar_orig = ((scrollers->hor_max + scrollers->hor_min) / 2) + ar->winrct.xmin; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* vertical scroller - calculate adjustment factor first */ | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 		mask_size = (float)BLI_rcti_size_y(&v2d->vert); | 
					
						
							| 
									
										
										
										
											2012-09-28 09:12:02 +00:00
										 |  |  | 		vsm->fac = BLI_rctf_size_y(&tot_cur_union) / mask_size; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-14 13:44:04 +10:00
										 |  |  | 		/* pixel rounding */ | 
					
						
							|  |  |  | 		vsm->fac_round = (BLI_rctf_size_y(&v2d->cur)) / (float)(BLI_rcti_size_y(&ar->winrct) + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		/* get 'zone' (i.e. which part of scroller is activated) */ | 
					
						
							| 
									
										
										
										
											2018-07-01 19:57:31 +02:00
										 |  |  | 		vsm->zone = mouse_in_scroller_handle( | 
					
						
							|  |  |  | 		        event->mval[1], | 
					
						
							|  |  |  | 		        v2d->vert.ymin, v2d->vert.ymax, | 
					
						
							|  |  |  | 		        scrollers->vert_min, scrollers->vert_max); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 		if ((v2d->keepzoom & V2D_LOCKZOOM_Y) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 			/* default to scroll, as handles not usable */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			vsm->zone = SCROLLHANDLE_BAR; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 		vsm->scrollbarwidth = scrollers->vert_max - scrollers->vert_min; | 
					
						
							| 
									
										
										
										
											2012-09-28 09:00:42 +00:00
										 |  |  | 		vsm->scrollbar_orig = ((scrollers->vert_max + scrollers->vert_min) / 2) + ar->winrct.ymin; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	UI_view2d_scrollers_free(scrollers); | 
					
						
							| 
									
										
										
										
											2018-05-22 14:41:49 +02:00
										 |  |  | 	ED_region_tag_redraw_no_rebuild(ar); | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* cleanup temp customdata  */ | 
					
						
							|  |  |  | static void scroller_activate_exit(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (op->customdata) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		v2dScrollerMove *vsm = op->customdata; | 
					
						
							| 
									
										
										
										
											2009-07-02 18:12:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		vsm->v2d->scroll_ui &= ~(V2D_SCROLL_H_ACTIVE | V2D_SCROLL_V_ACTIVE); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		MEM_freeN(op->customdata); | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		op->customdata = NULL; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 14:41:49 +02:00
										 |  |  | 		ED_region_tag_redraw_no_rebuild(CTX_wm_region(C)); | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-06 11:04:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-30 23:08:53 +00:00
										 |  |  | static void scroller_activate_cancel(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-06-06 11:04:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	scroller_activate_exit(C, op); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* apply transform to view (i.e. adjust 'cur' rect) */ | 
					
						
							|  |  |  | static void scroller_activate_apply(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	v2dScrollerMove *vsm = op->customdata; | 
					
						
							|  |  |  | 	View2D *v2d = vsm->v2d; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	float temp; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* calculate amount to move view by */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	temp = vsm->fac * vsm->delta; | 
					
						
							| 
									
										
										
										
											2014-08-14 13:44:04 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* round to pixel */ | 
					
						
							| 
									
										
										
										
											2014-10-29 11:10:07 +01:00
										 |  |  | 	temp = roundf(temp / vsm->fac_round) * vsm->fac_round; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* type of movement */ | 
					
						
							|  |  |  | 	switch (vsm->zone) { | 
					
						
							|  |  |  | 		case SCROLLHANDLE_MIN: | 
					
						
							|  |  |  | 			/* only expand view on axis if zoom is allowed */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X)) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 				v2d->cur.xmin -= temp; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y)) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 				v2d->cur.ymin -= temp; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-11-19 04:13:18 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-19 04:13:18 +00:00
										 |  |  | 		case SCROLLHANDLE_MAX: | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 			/* only expand view on axis if zoom is allowed */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X)) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 				v2d->cur.xmax += temp; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y)) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 				v2d->cur.ymax += temp; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 		case SCROLLHANDLE_MIN_OUTSIDE: | 
					
						
							|  |  |  | 		case SCROLLHANDLE_MAX_OUTSIDE: | 
					
						
							|  |  |  | 		case SCROLLHANDLE_BAR: | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 			/* only move view on an axis if panning is allowed */ | 
					
						
							|  |  |  | 			if ((vsm->scroller == 'h') && !(v2d->keepofs & V2D_LOCKOFS_X)) { | 
					
						
							|  |  |  | 				v2d->cur.xmin += temp; | 
					
						
							|  |  |  | 				v2d->cur.xmax += temp; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if ((vsm->scroller == 'v') && !(v2d->keepofs & V2D_LOCKOFS_Y)) { | 
					
						
							|  |  |  | 				v2d->cur.ymin += temp; | 
					
						
							|  |  |  | 				v2d->cur.ymax += temp; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* validate that view is in valid configuration after this operation */ | 
					
						
							| 
									
										
										
										
											2008-12-10 09:07:15 +00:00
										 |  |  | 	UI_view2d_curRect_validate(v2d); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* request updates to be done... */ | 
					
						
							| 
									
										
										
										
											2018-05-22 14:41:49 +02:00
										 |  |  | 	ED_region_tag_redraw_no_rebuild(vsm->ar); | 
					
						
							| 
									
										
										
										
											2008-12-21 11:56:42 +00:00
										 |  |  | 	UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 14:20:03 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Handle user input for scrollers - calculations of mouse-movement need to be done here, | 
					
						
							|  |  |  |  * not in the apply callback! | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int scroller_activate_modal(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	v2dScrollerMove *vsm = op->customdata; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* execute the events */ | 
					
						
							|  |  |  | 	switch (event->type) { | 
					
						
							|  |  |  | 		case MOUSEMOVE: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			/* calculate new delta transform, then store mouse-coordinates for next-time */ | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 			if (ELEM(vsm->zone, SCROLLHANDLE_BAR, SCROLLHANDLE_MAX)) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 				/* if using bar (i.e. 'panning') or 'max' zoom widget */ | 
					
						
							|  |  |  | 				switch (vsm->scroller) { | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 					case 'h': /* horizontal scroller - so only horizontal movement
 | 
					
						
							|  |  |  | 					           * ('cur' moves opposite to mouse) */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 						vsm->delta = (float)(event->x - vsm->lastx); | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 						break; | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 					case 'v': /* vertical scroller - so only vertical movement
 | 
					
						
							|  |  |  | 					           * ('cur' moves opposite to mouse) */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 						vsm->delta = (float)(event->y - vsm->lasty); | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 			else if (vsm->zone == SCROLLHANDLE_MIN) { | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 				/* using 'min' zoom widget */ | 
					
						
							|  |  |  | 				switch (vsm->scroller) { | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 					case 'h': /* horizontal scroller - so only horizontal movement
 | 
					
						
							|  |  |  | 					           * ('cur' moves with mouse) */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 						vsm->delta = (float)(vsm->lastx - event->x); | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 						break; | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 					case 'v': /* vertical scroller - so only vertical movement
 | 
					
						
							|  |  |  | 					           * ('cur' moves with to mouse) */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 						vsm->delta = (float)(vsm->lasty - event->y); | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 			/* store previous coordinates */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			vsm->lastx = event->x; | 
					
						
							|  |  |  | 			vsm->lasty = event->y; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 			scroller_activate_apply(C, op); | 
					
						
							| 
									
										
										
										
											2013-07-19 15:23:42 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		case LEFTMOUSE: | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 		case MIDDLEMOUSE: | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			if (event->val == KM_RELEASE) { | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 				/* single-click was in empty space outside bubble, so scroll by 1 'page' */ | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 				if (ELEM(vsm->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) { | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 					if (vsm->zone == SCROLLHANDLE_MIN_OUTSIDE) { | 
					
						
							| 
									
										
										
										
											2011-03-27 14:52:16 +00:00
										 |  |  | 						vsm->delta = -vsm->scrollbarwidth * 0.8f; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					else if (vsm->zone == SCROLLHANDLE_MAX_OUTSIDE) { | 
					
						
							| 
									
										
										
										
											2011-03-27 14:52:16 +00:00
										 |  |  | 						vsm->delta = vsm->scrollbarwidth * 0.8f; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 					scroller_activate_apply(C, op); | 
					
						
							|  |  |  | 					scroller_activate_exit(C, op); | 
					
						
							|  |  |  | 					return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-08 04:32:48 +00:00
										 |  |  | 				/* otherwise, end the drag action  */ | 
					
						
							|  |  |  | 				if (vsm->lastx || vsm->lasty) { | 
					
						
							|  |  |  | 					scroller_activate_exit(C, op); | 
					
						
							|  |  |  | 					return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_RUNNING_MODAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | /* a click (or click drag in progress)
 | 
					
						
							|  |  |  |  * should have occurred, so check if it happened in scrollbar */ | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int scroller_activate_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 	View2D *v2d = &ar->v2d; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* check if mouse in scrollbars, if they're enabled */ | 
					
						
							| 
									
										
										
										
											2018-11-07 18:14:21 +11:00
										 |  |  | 	const char in_scroller = UI_view2d_mouse_in_scrollers(ar, v2d, event->x, event->y); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 	/* if in a scroller, init customdata then set modal handler which will
 | 
					
						
							|  |  |  | 	 * catch mousedown to start doing useful stuff */ | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	if (in_scroller) { | 
					
						
							|  |  |  | 		v2dScrollerMove *vsm; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 16:05:54 +00:00
										 |  |  | 		/* initialize customdata */ | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		scroller_activate_init(C, op, event, in_scroller); | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 		vsm = (v2dScrollerMove *)op->customdata; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 		/* support for quick jump to location - gtk and qt do this on linux */ | 
					
						
							|  |  |  | 		if (event->type == MIDDLEMOUSE) { | 
					
						
							|  |  |  | 			switch (vsm->scroller) { | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 				case 'h': /* horizontal scroller - so only horizontal movement
 | 
					
						
							|  |  |  | 				           * ('cur' moves opposite to mouse) */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 					vsm->delta = (float)(event->x - vsm->scrollbar_orig); | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 				case 'v': /* vertical scroller - so only vertical movement
 | 
					
						
							|  |  |  | 				           * ('cur' moves opposite to mouse) */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 					vsm->delta = (float)(event->y - vsm->scrollbar_orig); | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			scroller_activate_apply(C, op); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			vsm->zone = SCROLLHANDLE_BAR; | 
					
						
							| 
									
										
										
										
											2012-01-15 17:26:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 11:13:31 +00:00
										 |  |  | 		/* check if zoom zones are inappropriate (i.e. zoom widgets not shown), so cannot continue
 | 
					
						
							|  |  |  | 		 * NOTE: see view2d.c for latest conditions, and keep this in sync with that | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) { | 
					
						
							| 
									
										
										
										
											2012-09-09 00:00:21 +00:00
										 |  |  | 			if (((vsm->scroller == 'h') && (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) == 0) || | 
					
						
							|  |  |  | 			    ((vsm->scroller == 'v') && (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) == 0)) | 
					
						
							| 
									
										
										
										
											2010-01-31 11:13:31 +00:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				/* switch to bar (i.e. no scaling gets handled) */ | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 				vsm->zone = SCROLLHANDLE_BAR; | 
					
						
							| 
									
										
										
										
											2010-01-31 11:13:31 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		/* check if zone is inappropriate (i.e. 'bar' but panning is banned), so cannot continue */ | 
					
						
							|  |  |  | 		if (vsm->zone == SCROLLHANDLE_BAR) { | 
					
						
							| 
									
										
										
										
											2012-09-09 00:00:21 +00:00
										 |  |  | 			if (((vsm->scroller == 'h') && (v2d->keepofs & V2D_LOCKOFS_X)) || | 
					
						
							|  |  |  | 			    ((vsm->scroller == 'v') && (v2d->keepofs & V2D_LOCKOFS_Y))) | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2012-03-18 07:38:51 +00:00
										 |  |  | 				/* free customdata initialized */ | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 				scroller_activate_exit(C, op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 				/* can't catch this event for ourselves, so let it go to someone else? */ | 
					
						
							|  |  |  | 				return OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2012-10-21 05:46:41 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-18 10:37:32 +00:00
										 |  |  | 		/* zone is also inappropriate if scroller is not visible... */ | 
					
						
							| 
									
										
										
										
											2012-12-26 13:05:39 +00:00
										 |  |  | 		if (((vsm->scroller == 'h') && (v2d->scroll & (V2D_SCROLL_HORIZONTAL_FULLR))) || | 
					
						
							|  |  |  | 		    ((vsm->scroller == 'v') && (v2d->scroll & (V2D_SCROLL_VERTICAL_FULLR))) ) | 
					
						
							| 
									
										
										
										
											2009-11-18 10:37:32 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2012-03-18 07:38:51 +00:00
										 |  |  | 			/* free customdata initialized */ | 
					
						
							| 
									
										
										
										
											2010-01-31 11:13:31 +00:00
										 |  |  | 			scroller_activate_exit(C, op); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-18 10:37:32 +00:00
										 |  |  | 			/* can't catch this event for ourselves, so let it go to someone else? */ | 
					
						
							| 
									
										
										
										
											2010-11-29 17:10:46 +00:00
										 |  |  | 			/* XXX note: if handlers use mask rect to clip input, input will fail for this case */ | 
					
						
							| 
									
										
										
										
											2009-11-18 10:37:32 +00:00
										 |  |  | 			return OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 11:13:31 +00:00
										 |  |  | 		/* activate the scroller */ | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		if (vsm->scroller == 'h') { | 
					
						
							| 
									
										
										
										
											2009-07-02 18:12:46 +00:00
										 |  |  | 			v2d->scroll_ui |= V2D_SCROLL_H_ACTIVE; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2009-07-02 18:12:46 +00:00
										 |  |  | 			v2d->scroll_ui |= V2D_SCROLL_V_ACTIVE; | 
					
						
							| 
									
										
										
										
											2019-03-25 10:15:20 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		/* still ok, so can add */ | 
					
						
							| 
									
										
										
										
											2009-09-18 12:43:36 +00:00
										 |  |  | 		WM_event_add_modal_handler(C, op); | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		return OPERATOR_RUNNING_MODAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2019-01-15 23:24:20 +11:00
										 |  |  | 		/* not in scroller, so nothing happened...
 | 
					
						
							|  |  |  | 		 * (pass through let's something else catch event) */ | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 		return OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* LMB-Drag in Scrollers - not repeatable operator! */ | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_scroller_activate(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Scroller Activate"; | 
					
						
							|  |  |  | 	ot->description = "Scroll view by mouse click and drag"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_scroller_activate"; | 
					
						
							| 
									
										
										
										
											2009-07-11 14:51:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->flag = OPTYPE_BLOCKING; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->invoke = scroller_activate_invoke; | 
					
						
							|  |  |  | 	ot->modal = scroller_activate_modal; | 
					
						
							|  |  |  | 	ot->cancel = scroller_activate_cancel; | 
					
						
							| 
									
										
										
										
											2011-06-06 11:04:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 19:49:25 +02:00
										 |  |  | 	ot->poll = scroller_activate_poll; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ********************************************************* */ | 
					
						
							|  |  |  | /* RESET */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 01:36:14 +00:00
										 |  |  | static int reset_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-11-09 21:20:40 +01:00
										 |  |  | 	uiStyle *style = UI_style_get(); | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 	View2D *v2d = &ar->v2d; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 	int winx, winy; | 
					
						
							| 
									
										
										
										
											2018-04-26 12:01:44 +02:00
										 |  |  | 	const int snap_test = ED_region_snap_size_test(ar); | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* zoom 1.0 */ | 
					
						
							| 
									
										
										
										
											2012-09-15 11:48:20 +00:00
										 |  |  | 	winx = (float)(BLI_rcti_size_x(&v2d->mask) + 1); | 
					
						
							|  |  |  | 	winy = (float)(BLI_rcti_size_y(&v2d->mask) + 1); | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 	v2d->cur.xmax = v2d->cur.xmin + winx; | 
					
						
							|  |  |  | 	v2d->cur.ymax = v2d->cur.ymin + winy; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 	/* align */ | 
					
						
							| 
									
										
										
										
											2010-06-08 00:51:57 +00:00
										 |  |  | 	if (v2d->align) { | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		/* posx and negx flags are mutually exclusive, so watch out */ | 
					
						
							|  |  |  | 		if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) { | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 			v2d->cur.xmax = 0.0f; | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			v2d->cur.xmin = -winx * style->panelzoom; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			v2d->cur.xmax = winx * style->panelzoom; | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 			v2d->cur.xmin = 0.0f; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* - posx and negx flags are mutually exclusive, so watch out */ | 
					
						
							|  |  |  | 		if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) { | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 			v2d->cur.ymax = 0.0f; | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			v2d->cur.ymin = -winy * style->panelzoom; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) { | 
					
						
							| 
									
										
										
										
											2012-03-30 01:51:25 +00:00
										 |  |  | 			v2d->cur.ymax = winy * style->panelzoom; | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 			v2d->cur.ymin = 0.0f; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* validate that view is in valid configuration after this operation */ | 
					
						
							|  |  |  | 	UI_view2d_curRect_validate(v2d); | 
					
						
							| 
									
										
										
										
											2018-04-26 12:01:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ED_region_snap_size_apply(ar, snap_test)) { | 
					
						
							|  |  |  | 		ScrArea *sa = CTX_wm_area(C); | 
					
						
							|  |  |  | 		ED_area_tag_redraw(sa); | 
					
						
							|  |  |  | 		WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 	/* request updates to be done... */ | 
					
						
							| 
									
										
										
										
											2010-03-30 07:57:07 +00:00
										 |  |  | 	ED_region_tag_redraw(ar); | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 	UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 12:43:56 +11:00
										 |  |  | 	UI_view2d_zoom_cache_reset(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-20 12:43:56 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void VIEW2D_OT_reset(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Reset View"; | 
					
						
							|  |  |  | 	ot->description = "Reset the view"; | 
					
						
							|  |  |  | 	ot->idname = "VIEW2D_OT_reset"; | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = reset_exec; | 
					
						
							|  |  |  | 	ot->poll = view2d_poll; | 
					
						
							| 
									
										
										
										
											2008-12-07 12:15:04 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | /* ********************************************************* */ | 
					
						
							|  |  |  | /* Registration */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 22:11:14 +11:00
										 |  |  | void ED_operatortypes_view2d(void) | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-29 02:15:13 +00:00
										 |  |  | 	WM_operatortype_append(VIEW2D_OT_pan); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-29 02:15:13 +00:00
										 |  |  | 	WM_operatortype_append(VIEW2D_OT_scroll_left); | 
					
						
							|  |  |  | 	WM_operatortype_append(VIEW2D_OT_scroll_right); | 
					
						
							|  |  |  | 	WM_operatortype_append(VIEW2D_OT_scroll_up); | 
					
						
							|  |  |  | 	WM_operatortype_append(VIEW2D_OT_scroll_down); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-29 02:15:13 +00:00
										 |  |  | 	WM_operatortype_append(VIEW2D_OT_zoom_in); | 
					
						
							|  |  |  | 	WM_operatortype_append(VIEW2D_OT_zoom_out); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-29 02:15:13 +00:00
										 |  |  | 	WM_operatortype_append(VIEW2D_OT_zoom); | 
					
						
							|  |  |  | 	WM_operatortype_append(VIEW2D_OT_zoom_border); | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 00:21:55 -04:00
										 |  |  | #ifdef WITH_INPUT_NDOF
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 	WM_operatortype_append(VIEW2D_OT_ndof); | 
					
						
							| 
									
										
										
										
											2016-08-18 00:21:55 -04:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-18 11:44:26 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-12 01:07:31 +00:00
										 |  |  | 	WM_operatortype_append(VIEW2D_OT_smoothview); | 
					
						
							| 
									
										
										
										
											2018-05-23 10:47:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-29 02:15:13 +00:00
										 |  |  | 	WM_operatortype_append(VIEW2D_OT_scroller_activate); | 
					
						
							| 
									
										
										
										
											2009-05-19 17:13:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WM_operatortype_append(VIEW2D_OT_reset); | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 22:11:14 +11:00
										 |  |  | void ED_keymap_view2d(wmKeyConfig *keyconf) | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-08 15:59:51 +11:00
										 |  |  | 	WM_keymap_ensure(keyconf, "View2D", 0, 0); | 
					
						
							| 
									
										
										
										
											2008-11-30 06:15:33 +00:00
										 |  |  | } |