Blender  V2.93
Classes
view2d_ops.c File Reference
#include <math.h>
#include "MEM_guardedalloc.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
#include "BLI_blenlib.h"
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_screen.h"
#include "UI_interface.h"
#include "UI_view2d.h"
#include "PIL_time.h"

Go to the source code of this file.

Classes

struct  v2dViewPanData
 
struct  v2dViewZoomData
 
struct  SmoothView2DStore
 
struct  v2dScrollerMove
 
struct  View2DScrollers
 

Functions

Internal Utilities
static bool view2d_poll (bContext *C)
 
View Pan Operator (modal drag-pan)
static int view_pan_exec (bContext *C, wmOperator *op)
 
static int view_pan_invoke (bContext *C, wmOperator *op, const wmEvent *event)
 
static int view_pan_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
static void view_pan_cancel (bContext *UNUSED(C), wmOperator *op)
 
static void VIEW2D_OT_pan (wmOperatorType *ot)
 
View Pan Operator (single step)
static int view_scrollright_exec (bContext *C, wmOperator *op)
 
static void VIEW2D_OT_scroll_right (wmOperatorType *ot)
 
static int view_scrollleft_exec (bContext *C, wmOperator *op)
 
static void VIEW2D_OT_scroll_left (wmOperatorType *ot)
 
static int view_scrolldown_exec (bContext *C, wmOperator *op)
 
static void VIEW2D_OT_scroll_down (wmOperatorType *ot)
 
static int view_scrollup_exec (bContext *C, wmOperator *op)
 
static void VIEW2D_OT_scroll_up (wmOperatorType *ot)
 
View Zoom Operator (single step)
static void view_zoomstep_exit (wmOperator *op)
 
static int view_zoomin_exec (bContext *C, wmOperator *op)
 
static int view_zoomin_invoke (bContext *C, wmOperator *op, const wmEvent *event)
 
static void VIEW2D_OT_zoom_in (wmOperatorType *ot)
 
static int view_zoomout_exec (bContext *C, wmOperator *op)
 
static int view_zoomout_invoke (bContext *C, wmOperator *op, const wmEvent *event)
 
static void VIEW2D_OT_zoom_out (wmOperatorType *ot)
 
View Zoom Operator (modal drag-zoom)
static void view_zoomdrag_apply (bContext *C, wmOperator *op)
 
static void view_zoomdrag_exit (bContext *C, wmOperator *op)
 
static void view_zoomdrag_cancel (bContext *C, wmOperator *op)
 
static int view_zoomdrag_exec (bContext *C, wmOperator *op)
 
static int view_zoomdrag_invoke (bContext *C, wmOperator *op, const wmEvent *event)
 
static int view_zoomdrag_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
static void VIEW2D_OT_zoom (wmOperatorType *ot)
 
Border Zoom Operator
static int view_borderzoom_exec (bContext *C, wmOperator *op)
 
static void VIEW2D_OT_zoom_border (wmOperatorType *ot)
 
Smooth View Operator
static float smooth_view_rect_to_fac (const rctf *rect_a, const rctf *rect_b)
 
void UI_view2d_smooth_view (bContext *C, ARegion *region, const rctf *cur, const int smooth_viewtx)
 
static int view2d_smoothview_invoke (bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
 
static void VIEW2D_OT_smoothview (wmOperatorType *ot)
 
View Reset Operator
static int reset_exec (bContext *C, wmOperator *UNUSED(op))
 
static void VIEW2D_OT_reset (wmOperatorType *ot)
 
Registration
void ED_operatortypes_view2d (void)
 
void ED_keymap_view2d (wmKeyConfig *keyconf)
 

View Edge Pan Operator (modal)

Scroll the region if the mouse is dragged to an edge. "Invisible" operator that always passes through.

#define EDGE_PAN_REGION_PAD   (U.widget_unit)
 
#define EDGE_PAN_SPEED_PER_PIXEL   (25.0f * (float)U.dpi_fac)
 
#define EDGE_PAN_DELAY   1.0f
 
static int view_edge_pan_invoke (bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 
static void edge_pan_manage_delay_timers (v2dViewPanData *vpd, int pan_dir_x, int pan_dir_y, const double current_time)
 
static float smootherstep (const float domain_max, float x)
 
static float edge_pan_speed (v2dViewPanData *vpd, int event_loc, bool x_dir, const double current_time)
 
static int view_edge_pan_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
static void view_edge_pan_cancel (bContext *UNUSED(C), wmOperator *op)
 
static void VIEW2D_OT_edge_pan (wmOperatorType *ot)
 

Scroll Bar Move Operator

enum  {
  SCROLLHANDLE_MIN = -1 , SCROLLHANDLE_BAR , SCROLLHANDLE_MAX , SCROLLHANDLE_MIN_OUTSIDE ,
  SCROLLHANDLE_MAX_OUTSIDE
}
 
typedef struct v2dScrollerMove v2dScrollerMove
 
static short mouse_in_scroller_handle (int mouse, int sc_min, int sc_max, int sh_min, int sh_max)
 
static bool scroller_activate_poll (bContext *C)
 
static void scroller_activate_init (bContext *C, wmOperator *op, const wmEvent *event, const char in_scroller)
 
static void scroller_activate_exit (bContext *C, wmOperator *op)
 
static void scroller_activate_cancel (bContext *C, wmOperator *op)
 
static void scroller_activate_apply (bContext *C, wmOperator *op)
 
static int scroller_activate_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
static int scroller_activate_invoke (bContext *C, wmOperator *op, const wmEvent *event)
 
static void VIEW2D_OT_scroller_activate (wmOperatorType *ot)
 

View Pan Shared Utilities

typedef struct v2dViewPanData v2dViewPanData
 
static bool view_pan_poll (bContext *C)
 
static void view_pan_init (bContext *C, wmOperator *op)
 
static void view_pan_apply_ex (bContext *C, v2dViewPanData *vpd, float dx, float dy)
 
static void view_pan_apply (bContext *C, wmOperator *op)
 
static void view_pan_exit (wmOperator *op)
 

View Zoom Shared Utilities

typedef struct v2dViewZoomData v2dViewZoomData
 
static void view_zoom_axis_lock_defaults (bContext *C, bool r_do_zoom_xy[2])
 
static bool view_zoom_poll (bContext *C)
 
static void view_zoomdrag_init (bContext *C, wmOperator *op)
 
static void view_zoomstep_apply_ex (bContext *C, v2dViewZoomData *vzd, const float facx, const float facy)
 
static void view_zoomstep_apply (bContext *C, wmOperator *op)
 

Macro Definition Documentation

◆ EDGE_PAN_DELAY

#define EDGE_PAN_DELAY   1.0f

Delay before drag panning in seconds.

Definition at line 349 of file view2d_ops.c.

◆ EDGE_PAN_REGION_PAD

#define EDGE_PAN_REGION_PAD   (U.widget_unit)

Distance from the edge of the region within which to start panning.

Definition at line 345 of file view2d_ops.c.

◆ EDGE_PAN_SPEED_PER_PIXEL

#define EDGE_PAN_SPEED_PER_PIXEL   (25.0f * (float)U.dpi_fac)

Speed factor in pixels per second per pixel of distance from edge pan zone beginning.

Definition at line 347 of file view2d_ops.c.

Typedef Documentation

◆ v2dScrollerMove

Scrollers should behave in the following ways, when clicked on with LMB (and dragged):

  1. 'Handles' on end of 'bubble' - when the axis that the scroller represents is zoomable, enlarge 'cur' rect on the relevant side.
  2. 'Bubble'/'bar' - just drag, and bar should move with mouse (view pans opposite).

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)

◆ v2dViewPanData

This group of operators come in several forms:

  1. Modal 'dragging' with MMB - where movement of mouse dictates amount to pan view by
  2. Scroll-wheel 'steps' - rolling mouse-wheel by one step moves view by predefined amount

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) Temporary custom-data for operator.

◆ v2dViewZoomData

This group of operators come in several forms:

  1. Scroll-wheel 'steps' - rolling mouse-wheel by one step zooms view by predefined amount.
  2. Scroll-wheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y). XXX this could be implemented...
  3. Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount.

In order to make sure this works, each operator must define the following RNA-Operator Props:

  • 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. Temporary custom-data for operator.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SCROLLHANDLE_MIN 
SCROLLHANDLE_BAR 
SCROLLHANDLE_MAX 
SCROLLHANDLE_MIN_OUTSIDE 
SCROLLHANDLE_MAX_OUTSIDE 

Definition at line 1900 of file view2d_ops.c.

Function Documentation

◆ ED_keymap_view2d()

void ED_keymap_view2d ( wmKeyConfig keyconf)

Definition at line 2420 of file view2d_ops.c.

References WM_keymap_ensure().

Referenced by ED_spacetypes_keymap().

◆ ED_operatortypes_view2d()

void ED_operatortypes_view2d ( void  )

◆ edge_pan_manage_delay_timers()

static void edge_pan_manage_delay_timers ( v2dViewPanData vpd,
int  pan_dir_x,
int  pan_dir_y,
const double  current_time 
)
static

Reset the edge pan timers if the mouse isn't in the scroll zone and start the timers when the mouse enters a scroll zone.

Definition at line 372 of file view2d_ops.c.

References v2dViewPanData::edge_pan_start_time_x, and v2dViewPanData::edge_pan_start_time_y.

Referenced by view_edge_pan_modal().

◆ edge_pan_speed()

static float edge_pan_speed ( v2dViewPanData vpd,
int  event_loc,
bool  x_dir,
const double  current_time 
)
static

◆ mouse_in_scroller_handle()

static short mouse_in_scroller_handle ( int  mouse,
int  sc_min,
int  sc_max,
int  sh_min,
int  sh_max 
)
static

Check if mouse is within scroller handle.

Parameters
mouserelevant mouse coordinate in region space.
sc_min,sc_maxextents of scroller 'groove' (potential available space for scroller).
sh_min,sh_maxpositions of scrollbar handles.

Definition at line 1915 of file view2d_ops.c.

References SCROLLHANDLE_BAR, SCROLLHANDLE_MAX, SCROLLHANDLE_MAX_OUTSIDE, SCROLLHANDLE_MIN, SCROLLHANDLE_MIN_OUTSIDE, and V2D_SCROLL_HANDLE_SIZE_HOTSPOT.

Referenced by scroller_activate_init().

◆ reset_exec()

static int reset_exec ( bContext C,
wmOperator UNUSEDop 
)
static

◆ scroller_activate_apply()

static void scroller_activate_apply ( bContext C,
wmOperator op 
)
static

◆ scroller_activate_cancel()

static void scroller_activate_cancel ( bContext C,
wmOperator op 
)
static

Definition at line 2070 of file view2d_ops.c.

References C, and scroller_activate_exit().

Referenced by VIEW2D_OT_scroller_activate().

◆ scroller_activate_exit()

static void scroller_activate_exit ( bContext C,
wmOperator op 
)
static

◆ scroller_activate_init()

static void scroller_activate_init ( bContext C,
wmOperator op,
const wmEvent event,
const char  in_scroller 
)
static

◆ scroller_activate_invoke()

static int scroller_activate_invoke ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ scroller_activate_modal()

static int scroller_activate_modal ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ scroller_activate_poll()

static bool scroller_activate_poll ( bContext C)
static

◆ smooth_view_rect_to_fac()

static float smooth_view_rect_to_fac ( const rctf rect_a,
const rctf rect_b 
)
static

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.

Definition at line 1673 of file view2d_ops.c.

References BLI_rctf_cent_x(), BLI_rctf_cent_y(), BLI_rctf_size_x(), BLI_rctf_size_y(), fabsf, max_ff(), and min_ff().

Referenced by UI_view2d_smooth_view().

◆ smootherstep()

static float smootherstep ( const float  domain_max,
float  x 
)
static

Used to calculate a "fade in" factor for edge panning to make the interaction feel smooth and more purposeful.

Note
Assumes a domain_min of 0.0f.

Definition at line 397 of file view2d_ops.c.

References clamp_f(), and x.

Referenced by edge_pan_speed().

◆ UI_view2d_smooth_view()

void UI_view2d_smooth_view ( bContext C,
ARegion region,
const rctf cur,
const int  smooth_viewtx 
)

◆ VIEW2D_OT_edge_pan()

static void VIEW2D_OT_edge_pan ( wmOperatorType ot)
static

◆ VIEW2D_OT_pan()

static void VIEW2D_OT_pan ( wmOperatorType ot)
static

◆ VIEW2D_OT_reset()

static void VIEW2D_OT_reset ( wmOperatorType ot)
static

◆ VIEW2D_OT_scroll_down()

static void VIEW2D_OT_scroll_down ( wmOperatorType ot)
static

◆ VIEW2D_OT_scroll_left()

static void VIEW2D_OT_scroll_left ( wmOperatorType ot)
static

◆ VIEW2D_OT_scroll_right()

static void VIEW2D_OT_scroll_right ( wmOperatorType ot)
static

◆ VIEW2D_OT_scroll_up()

static void VIEW2D_OT_scroll_up ( wmOperatorType ot)
static

◆ VIEW2D_OT_scroller_activate()

static void VIEW2D_OT_scroller_activate ( wmOperatorType ot)
static

◆ VIEW2D_OT_smoothview()

static void VIEW2D_OT_smoothview ( wmOperatorType ot)
static

◆ VIEW2D_OT_zoom()

static void VIEW2D_OT_zoom ( wmOperatorType ot)
static

◆ VIEW2D_OT_zoom_border()

static void VIEW2D_OT_zoom_border ( wmOperatorType ot)
static

◆ VIEW2D_OT_zoom_in()

static void VIEW2D_OT_zoom_in ( wmOperatorType ot)
static

◆ VIEW2D_OT_zoom_out()

static void VIEW2D_OT_zoom_out ( wmOperatorType ot)
static

◆ view2d_poll()

static bool view2d_poll ( bContext C)
static

◆ view2d_smoothview_invoke()

static int view2d_smoothview_invoke ( bContext C,
wmOperator UNUSEDop,
const wmEvent event 
)
static

◆ view_borderzoom_exec()

static int view_borderzoom_exec ( bContext C,
wmOperator op 
)
static

The user defines a rect using standard box select tools, and we use this rect to define the new zoom-level of the view in the following ways:

  1. LEFTMOUSE - zoom in to view
  2. RIGHTMOUSE - zoom out of view

Currently, these key mappings are hardcoded, but it shouldn't be too important to have custom keymappings for this...

Definition at line 1495 of file view2d_ops.c.

References BLI_rctf_cent_x(), BLI_rctf_cent_y(), BLI_rctf_size_x(), BLI_rctf_size_y(), C, center, CTX_wm_region(), View2D::cur, View2D::keepzoom, OPERATOR_FINISHED, wmOperator::ptr, RNA_boolean_get(), size(), UI_view2d_region_to_view_rctf(), UI_view2d_smooth_view(), ARegion::v2d, V2D_LOCKZOOM_X, V2D_LOCKZOOM_Y, WM_operator_properties_border_to_rctf(), WM_operator_smooth_viewtx_get(), rctf::xmax, rctf::xmin, rctf::ymax, and rctf::ymin.

Referenced by VIEW2D_OT_zoom_border().

◆ view_edge_pan_cancel()

static void view_edge_pan_cancel ( bContext UNUSEDC,
wmOperator op 
)
static

Definition at line 497 of file view2d_ops.c.

References view_pan_exit().

Referenced by VIEW2D_OT_edge_pan().

◆ view_edge_pan_invoke()

static int view_edge_pan_invoke ( bContext C,
wmOperator op,
const wmEvent UNUSEDevent 
)
static

◆ view_edge_pan_modal()

static int view_edge_pan_modal ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ view_pan_apply()

static void view_pan_apply ( bContext C,
wmOperator op 
)
static

◆ view_pan_apply_ex()

static void view_pan_apply_ex ( bContext C,
v2dViewPanData vpd,
float  dx,
float  dy 
)
static

◆ view_pan_cancel()

static void view_pan_cancel ( bContext UNUSEDC,
wmOperator op 
)
static

Definition at line 308 of file view2d_ops.c.

References view_pan_exit().

Referenced by VIEW2D_OT_pan().

◆ view_pan_exec()

static int view_pan_exec ( bContext C,
wmOperator op 
)
static

Definition at line 203 of file view2d_ops.c.

References C, OPERATOR_FINISHED, view_pan_apply(), view_pan_exit(), and view_pan_init().

Referenced by VIEW2D_OT_pan().

◆ view_pan_exit()

static void view_pan_exit ( wmOperator op)
static

◆ view_pan_init()

static void view_pan_init ( bContext C,
wmOperator op 
)
static

◆ view_pan_invoke()

static int view_pan_invoke ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ view_pan_modal()

static int view_pan_modal ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ view_pan_poll()

static bool view_pan_poll ( bContext C)
static

◆ view_scrolldown_exec()

static int view_scrolldown_exec ( bContext C,
wmOperator op 
)
static

◆ view_scrollleft_exec()

static int view_scrollleft_exec ( bContext C,
wmOperator op 
)
static

◆ view_scrollright_exec()

static int view_scrollright_exec ( bContext C,
wmOperator op 
)
static

◆ view_scrollup_exec()

static int view_scrollup_exec ( bContext C,
wmOperator op 
)
static

◆ view_zoom_axis_lock_defaults()

static void view_zoom_axis_lock_defaults ( bContext C,
bool  r_do_zoom_xy[2] 
)
static

Clamp by convention rather then locking flags, for ndof and +/- keys

Definition at line 763 of file view2d_ops.c.

References blender::compositor::area(), C, CTX_wm_area(), CTX_wm_region(), ARegion::regiontype, RGN_TYPE_WINDOW, and SPACE_SEQ.

Referenced by view_zoomin_exec(), and view_zoomout_exec().

◆ view_zoom_poll()

static bool view_zoom_poll ( bContext C)
static

◆ view_zoomdrag_apply()

static void view_zoomdrag_apply ( bContext C,
wmOperator op 
)
static

◆ view_zoomdrag_cancel()

static void view_zoomdrag_cancel ( bContext C,
wmOperator op 
)
static

Definition at line 1192 of file view2d_ops.c.

References C, and view_zoomdrag_exit().

Referenced by VIEW2D_OT_zoom().

◆ view_zoomdrag_exec()

static int view_zoomdrag_exec ( bContext C,
wmOperator op 
)
static

◆ view_zoomdrag_exit()

static void view_zoomdrag_exit ( bContext C,
wmOperator op 
)
static

◆ view_zoomdrag_init()

static void view_zoomdrag_init ( bContext C,
wmOperator op 
)
static

◆ view_zoomdrag_invoke()

static int view_zoomdrag_invoke ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ view_zoomdrag_modal()

static int view_zoomdrag_modal ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ view_zoomin_exec()

static int view_zoomin_exec ( bContext C,
wmOperator op 
)
static

◆ view_zoomin_invoke()

static int view_zoomin_invoke ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ view_zoomout_exec()

static int view_zoomout_exec ( bContext C,
wmOperator op 
)
static

◆ view_zoomout_invoke()

static int view_zoomout_invoke ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ view_zoomstep_apply()

static void view_zoomstep_apply ( bContext C,
wmOperator op 
)
static

◆ view_zoomstep_apply_ex()

static void view_zoomstep_apply_ex ( bContext C,
v2dViewZoomData vzd,
const float  facx,
const float  facy 
)
static

◆ view_zoomstep_exit()

static void view_zoomstep_exit ( wmOperator op)
static