Blender V4.3
view2d_ops.cc File Reference
#include <cmath>
#include "MEM_guardedalloc.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
#include "BLI_time.h"
#include "BLI_utildefines.h"
#include "BKE_context.hh"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "ED_screen.hh"
#include "UI_interface.hh"
#include "UI_view2d.hh"
#include "view2d_intern.hh"

Go to the source code of this file.

Classes

struct  v2dViewPanData
 
struct  v2dViewZoomData
 
struct  SmoothView2DStore
 
struct  v2dScrollerMove
 

Functions

Internal Utilities
static bool view2d_poll (bContext *C)
 
static float view2d_scroll_delta_y_snap_page_size (const View2D &v2d, const float delta_y)
 
View Pan Shared Utilities
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 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 *, wmOperator *op)
 
static void VIEW2D_OT_pan (wmOperatorType *ot)
 
View Edge Pan Operator (modal)

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

static int view_edge_pan_invoke (bContext *C, wmOperator *op, const wmEvent *)
 
static int view_edge_pan_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
static void view_edge_pan_cancel (bContext *, wmOperator *op)
 
static void VIEW2D_OT_edge_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 Shared Utilities
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)
 
View Zoom Operator (single step)
static void view_zoomstep_exit (bContext *C, 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

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.

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 (const bContext *C, ARegion *region, const rctf *cur, const int smooth_viewtx)
 
static int view2d_smoothview_invoke (bContext *C, wmOperator *, const wmEvent *event)
 
static void VIEW2D_OT_smoothview (wmOperatorType *ot)
 
View Reset Operator
static int reset_exec (bContext *C, wmOperator *)
 
static void VIEW2D_OT_reset (wmOperatorType *ot)
 
Registration
void ED_operatortypes_view2d ()
 
void ED_keymap_view2d (wmKeyConfig *keyconf)
 

Scroll Bar Move Operator

enum  {
  SCROLLHANDLE_MIN = -1 , SCROLLHANDLE_BAR , SCROLLHANDLE_MAX , SCROLLHANDLE_MIN_OUTSIDE ,
  SCROLLHANDLE_MAX_OUTSIDE
}
 
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)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SCROLLHANDLE_MIN 
SCROLLHANDLE_BAR 
SCROLLHANDLE_MAX 
SCROLLHANDLE_MIN_OUTSIDE 
SCROLLHANDLE_MAX_OUTSIDE 

Definition at line 1810 of file view2d_ops.cc.

Function Documentation

◆ ED_keymap_view2d()

void ED_keymap_view2d ( wmKeyConfig * keyconf)

Definition at line 2361 of file view2d_ops.cc.

References RGN_TYPE_WINDOW, SPACE_EMPTY, and WM_keymap_ensure().

Referenced by ED_spacetypes_keymap().

◆ ED_operatortypes_view2d()

◆ 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 1825 of file view2d_ops.cc.

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()

◆ scroller_activate_apply()

◆ scroller_activate_cancel()

static void scroller_activate_cancel ( bContext * C,
wmOperator * op )
static

Definition at line 1994 of file view2d_ops.cc.

References scroller_activate_exit().

Referenced by VIEW2D_OT_scroller_activate().

◆ scroller_activate_exit()

◆ scroller_activate_init()

◆ scroller_activate_invoke()

◆ scroller_activate_modal()

◆ 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 1600 of file view2d_ops.cc.

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().

◆ UI_view2d_smooth_view()

◆ VIEW2D_OT_edge_pan()

◆ VIEW2D_OT_pan()

◆ VIEW2D_OT_reset()

◆ VIEW2D_OT_scroll_down()

◆ VIEW2D_OT_scroll_left()

◆ VIEW2D_OT_scroll_right()

◆ VIEW2D_OT_scroll_up()

◆ VIEW2D_OT_scroller_activate()

◆ VIEW2D_OT_smoothview()

◆ VIEW2D_OT_zoom()

◆ VIEW2D_OT_zoom_border()

◆ VIEW2D_OT_zoom_in()

◆ VIEW2D_OT_zoom_out()

◆ view2d_poll()

static bool view2d_poll ( bContext * C)
static

Definition at line 40 of file view2d_ops.cc.

References CTX_wm_region(), and V2D_IS_INIT.

Referenced by scroller_activate_poll(), VIEW2D_OT_reset(), and VIEW2D_OT_smoothview().

◆ view2d_scroll_delta_y_snap_page_size()

static float view2d_scroll_delta_y_snap_page_size ( const View2D & v2d,
const float delta_y )
static

Calculate a scrolling delta that is the closest to a multiple of the page size (as returned by view2d_page_size_y). So when scrolling for more than half a page size, a delta to the next page is returned. No scrolling change should be applied when this returns 0.

Definition at line 52 of file view2d_ops.cc.

References abs(), int, and view2d_page_size_y().

Referenced by scroller_activate_modal(), and view_pan_modal().

◆ view2d_smoothview_invoke()

◆ view_borderzoom_exec()

◆ view_edge_pan_cancel()

static void view_edge_pan_cancel ( bContext * ,
wmOperator * op )
static

Definition at line 414 of file view2d_ops.cc.

References wmOperator::customdata, View2D::flag, MEM_SAFE_FREE, and v2dViewPanData::v2d.

Referenced by VIEW2D_OT_edge_pan().

◆ view_edge_pan_invoke()

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

◆ view_edge_pan_modal()

◆ view_pan_apply()

◆ view_pan_apply_ex()

◆ view_pan_cancel()

static void view_pan_cancel ( bContext * ,
wmOperator * op )
static

Definition at line 344 of file view2d_ops.cc.

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 221 of file view2d_ops.cc.

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

Referenced by VIEW2D_OT_pan().

◆ view_pan_exit()

◆ view_pan_init()

◆ view_pan_invoke()

◆ view_pan_modal()

◆ view_pan_poll()

◆ view_scrolldown_exec()

◆ view_scrollleft_exec()

◆ view_scrollright_exec()

◆ view_scrollup_exec()

◆ 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 than locking flags, for ndof and +/- keys

Definition at line 677 of file view2d_ops.cc.

References CTX_wm_area(), CTX_wm_region(), RGN_TYPE_WINDOW, and SPACE_SEQ.

Referenced by view_zoomin_exec(), and view_zoomout_exec().

◆ view_zoom_poll()

◆ view_zoomdrag_apply()

◆ view_zoomdrag_cancel()

static void view_zoomdrag_cancel ( bContext * C,
wmOperator * op )
static

Definition at line 1117 of file view2d_ops.cc.

References view_zoomdrag_exit().

Referenced by VIEW2D_OT_zoom().

◆ view_zoomdrag_exec()

static int view_zoomdrag_exec ( bContext * C,
wmOperator * op )
static

◆ view_zoomdrag_exit()

◆ view_zoomdrag_init()

◆ view_zoomdrag_invoke()

◆ view_zoomdrag_modal()

◆ view_zoomin_exec()

◆ view_zoomin_invoke()

◆ view_zoomout_exec()

◆ view_zoomout_invoke()

◆ view_zoomstep_apply()

static void view_zoomstep_apply ( bContext * C,
wmOperator * op )
static

◆ view_zoomstep_apply_ex()

◆ view_zoomstep_exit()

static void view_zoomstep_exit ( bContext * C,
wmOperator * op )
static