Blender  V3.3
Classes
view2d.cc File Reference
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
#include "DNA_userdef_types.h"
#include "BLI_array.h"
#include "BLI_easing.h"
#include "BLI_link_utils.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_timecode.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_screen.h"
#include "GPU_immediate.h"
#include "GPU_matrix.h"
#include "GPU_state.h"
#include "WM_api.h"
#include "BLF_api.h"
#include "ED_screen.h"
#include "UI_interface.h"
#include "UI_view2d.h"
#include "interface_intern.h"

Go to the source code of this file.

Classes

struct  View2DScrollers
 
struct  View2DString
 

Functions

View2D Refresh and Validation (Spatial)
static void ui_view2d_curRect_validate_resize (View2D *v2d, bool resize)
 
void UI_view2d_region_reinit (View2D *v2d, short type, int winx, int winy)
 
void UI_view2d_curRect_validate (View2D *v2d)
 
void UI_view2d_curRect_changed (const bContext *C, View2D *v2d)
 
bool UI_view2d_area_supports_sync (ScrArea *area)
 
void UI_view2d_sync (bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
 
void UI_view2d_curRect_reset (View2D *v2d)
 
void UI_view2d_totRect_set_resize (View2D *v2d, int width, int height, bool resize)
 
void UI_view2d_totRect_set (View2D *v2d, int width, int height)
 
void UI_view2d_zoom_cache_reset (void)
 
Internal Utilities
BLI_INLINE int clamp_float_to_int (const float f)
 
BLI_INLINE void clamp_rctf_to_rcti (rcti *dst, const rctf *src)
 
Internal Scroll & Mask Utilities
static int view2d_scroll_mapped (int scroll)
 
void UI_view2d_mask_from_win (const View2D *v2d, rcti *r_mask)
 
static void view2d_masks (View2D *v2d, const rcti *mask_scroll)
 
View2D Matrix Setup
static void view2d_map_cur_using_mask (const View2D *v2d, rctf *r_curmasked)
 
void UI_view2d_view_ortho (const View2D *v2d)
 
void UI_view2d_view_orthoSpecial (ARegion *region, View2D *v2d, const bool xaxis)
 
void UI_view2d_view_restore (const bContext *C)
 
Grid-Line Drawing
void UI_view2d_multi_grid_draw (const View2D *v2d, int colorid, float step, int level_size, int totlevels)
 
static void grid_axis_start_and_count (const float step, const float min, const float max, float *r_start, int *r_count)
 
void UI_view2d_dot_grid_draw (const View2D *v2d, const int grid_color_id, const float min_step, const int grid_subdivisions)
 
Scrollers
void UI_view2d_scrollers_calc (View2D *v2d, const rcti *mask_custom, struct View2DScrollers *r_scrollers)
 
void UI_view2d_scrollers_draw_ex (View2D *v2d, const rcti *mask_custom, bool use_full_hide)
 
void UI_view2d_scrollers_draw (View2D *v2d, const rcti *mask_custom)
 
List View Utilities
void UI_view2d_listview_view_to_cell (float columnwidth, float rowheight, float startx, float starty, float viewx, float viewy, int *r_column, int *r_row)
 
Coordinate Conversions
float UI_view2d_region_to_view_x (const struct View2D *v2d, float x)
 
float UI_view2d_region_to_view_y (const struct View2D *v2d, float y)
 
void UI_view2d_region_to_view (const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y)
 
void UI_view2d_region_to_view_rctf (const View2D *v2d, const rctf *rect_src, rctf *rect_dst)
 
float UI_view2d_view_to_region_x (const View2D *v2d, float x)
 
float UI_view2d_view_to_region_y (const View2D *v2d, float y)
 
bool UI_view2d_view_to_region_clip (const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y)
 
void UI_view2d_view_to_region (const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y)
 
void UI_view2d_view_to_region_fl (const View2D *v2d, float x, float y, float *r_region_x, float *r_region_y)
 
bool UI_view2d_view_to_region_segment_clip (const View2D *v2d, const float xy_a[2], const float xy_b[2], int r_region_a[2], int r_region_b[2])
 
void UI_view2d_view_to_region_rcti (const View2D *v2d, const rctf *rect_src, rcti *rect_dst)
 
void UI_view2d_view_to_region_m4 (const View2D *v2d, float matrix[4][4])
 
bool UI_view2d_view_to_region_rcti_clip (const View2D *v2d, const rctf *rect_src, rcti *rect_dst)
 
Utilities
View2DUI_view2d_fromcontext (const bContext *C)
 
View2DUI_view2d_fromcontext_rwin (const bContext *C)
 
void UI_view2d_scroller_size_get (const View2D *v2d, bool mapped, float *r_x, float *r_y)
 
void UI_view2d_scale_get (const View2D *v2d, float *r_x, float *r_y)
 
float UI_view2d_scale_get_x (const View2D *v2d)
 
float UI_view2d_scale_get_y (const View2D *v2d)
 
void UI_view2d_scale_get_inverse (const View2D *v2d, float *r_x, float *r_y)
 
void UI_view2d_center_get (const struct View2D *v2d, float *r_x, float *r_y)
 
void UI_view2d_center_set (struct View2D *v2d, float x, float y)
 
void UI_view2d_offset (struct View2D *v2d, float xfac, float yfac)
 
char UI_view2d_mouse_in_scrollers_ex (const ARegion *region, const View2D *v2d, const int xy[2], int *r_scroll)
 
char UI_view2d_rect_in_scrollers_ex (const ARegion *region, const View2D *v2d, const rcti *rect, int *r_scroll)
 
char UI_view2d_mouse_in_scrollers (const ARegion *region, const View2D *v2d, const int xy[2])
 
char UI_view2d_rect_in_scrollers (const ARegion *region, const View2D *v2d, const rcti *rect)
 

View2D Text Drawing Cache

static MemArenag_v2d_strings_arena = nullptr
 
static View2DStringg_v2d_strings = nullptr
 
void UI_view2d_text_cache_add (View2D *v2d, float x, float y, const char *str, size_t str_len, const uchar col[4])
 
void UI_view2d_text_cache_add_rectf (View2D *v2d, const rctf *rect_view, const char *str, size_t str_len, const uchar col[4])
 
void UI_view2d_text_cache_draw (ARegion *region)
 

Function Documentation

◆ clamp_float_to_int()

BLI_INLINE int clamp_float_to_int ( const float  f)

Definition at line 54 of file view2d.cc.

References float(), max, min, and UNLIKELY.

Referenced by clamp_rctf_to_rcti(), and UI_view2d_view_to_region().

◆ clamp_rctf_to_rcti()

BLI_INLINE void clamp_rctf_to_rcti ( rcti dst,
const rctf src 
)

use instead of BLI_rcti_rctf_copy so we have consistent behavior with users of clamp_float_to_int.

Definition at line 72 of file view2d.cc.

References clamp_float_to_int(), src, rcti::xmax, rcti::xmin, rcti::ymax, and rcti::ymin.

Referenced by UI_view2d_view_to_region_rcti(), and UI_view2d_view_to_region_rcti_clip().

◆ grid_axis_start_and_count()

static void grid_axis_start_and_count ( const float  step,
const float  min,
const float  max,
float r_start,
int *  r_count 
)
static

Definition at line 1254 of file view2d.cc.

References fabs(), float(), max, and min.

Referenced by UI_view2d_dot_grid_draw().

◆ UI_view2d_area_supports_sync()

bool UI_view2d_area_supports_sync ( ScrArea area)

Definition at line 846 of file view2d.cc.

References blender::compositor::area(), ELEM, SPACE_ACTION, SPACE_CLIP, SPACE_GRAPH, SPACE_NLA, and SPACE_SEQ.

Referenced by UI_view2d_sync().

◆ UI_view2d_center_get()

void UI_view2d_center_get ( const struct View2D v2d,
float r_x,
float r_y 
)

Simple functions for consistent center offset access. Used by node editor to shift view center for each individual node tree.

Definition at line 1936 of file view2d.cc.

References BLI_rctf_cent_x(), BLI_rctf_cent_y(), and View2D::cur.

Referenced by actkeys_viewall(), nlaedit_viewall(), and blender::ed::space_node::node_draw_space().

◆ UI_view2d_center_set()

void UI_view2d_center_set ( struct View2D v2d,
float  x,
float  y 
)

◆ UI_view2d_curRect_changed()

void UI_view2d_curRect_changed ( const bContext C,
View2D v2d 
)

◆ UI_view2d_curRect_reset()

void UI_view2d_curRect_reset ( struct View2D v2d)

Restore 'cur' rect to standard orientation (i.e. optimal maximum view of tot). This does not take into account if zooming the view on an axis will improve the view (if allowed).

Definition at line 914 of file view2d.cc.

References View2D::align, BLI_rcti_size_x(), BLI_rcti_size_y(), View2D::cur, float(), height, View2D::mask, V2D_ALIGN_NO_NEG_X, V2D_ALIGN_NO_NEG_Y, V2D_ALIGN_NO_POS_X, V2D_ALIGN_NO_POS_Y, width, rctf::xmax, rctf::xmin, rctf::ymax, and rctf::ymin.

◆ UI_view2d_curRect_validate()

void UI_view2d_curRect_validate ( View2D v2d)

◆ ui_view2d_curRect_validate_resize()

static void ui_view2d_curRect_validate_resize ( View2D v2d,
bool  resize 
)
static

◆ UI_view2d_dot_grid_draw()

void UI_view2d_dot_grid_draw ( const View2D v2d,
const int  grid_color_id,
const float  min_step,
const int  grid_subdivisions 
)

◆ UI_view2d_fromcontext()

View2D* UI_view2d_fromcontext ( const bContext C)

Definition at line 1852 of file view2d.cc.

References blender::compositor::area(), C, CTX_wm_area(), CTX_wm_region(), and ARegion::v2d.

◆ UI_view2d_fromcontext_rwin()

View2D* UI_view2d_fromcontext_rwin ( const bContext C)

◆ UI_view2d_listview_view_to_cell()

void UI_view2d_listview_view_to_cell ( float  columnwidth,
float  rowheight,
float  startx,
float  starty,
float  viewx,
float  viewy,
int *  r_column,
int *  r_row 
)

Get the 'cell' (row, column) that the given 2D-view coordinates (i.e. in 'tot' rect space) lie in.

Parameters
columnwidth,rowheightsize of each 'cell'
startx,startycoordinates (in 'tot' rect space) that the list starts from. This should be (0,0) for most views. However, for those where the starting row was offsetted (like for Animation Editor channel lists, to make the first entry more visible), these will be the min-coordinates of the first item.
viewx,viewy2D-coordinates (in 2D-view / 'tot' rect space) to get the cell for
r_column,r_rowThe 'coordinates' of the relevant 'cell'.

Definition at line 1619 of file view2d.cc.

References floorf.

Referenced by actkeys_find_list_element_at_position(), animchannels_channel_get(), animchannels_mouseclick_invoke(), nlachannels_mouseclick_invoke(), and nlaedit_strip_at_region_position().

◆ UI_view2d_mask_from_win()

void UI_view2d_mask_from_win ( const View2D v2d,
rcti r_mask 
)

Definition at line 107 of file view2d.cc.

References View2D::winx, View2D::winy, rcti::xmax, rcti::xmin, rcti::ymax, and rcti::ymin.

Referenced by view2d_masks().

◆ UI_view2d_mouse_in_scrollers()

char UI_view2d_mouse_in_scrollers ( const ARegion region,
const View2D v2d,
const int  xy[2] 
)

Definition at line 2033 of file view2d.cc.

References UI_view2d_mouse_in_scrollers_ex(), and xy.

◆ UI_view2d_mouse_in_scrollers_ex()

char UI_view2d_mouse_in_scrollers_ex ( const ARegion region,
const View2D v2d,
const int  xy[2],
int *  r_scroll 
)

◆ UI_view2d_multi_grid_draw()

void UI_view2d_multi_grid_draw ( const View2D v2d,
int  colorid,
float  step,
int  level_size,
int  totlevels 
)

◆ UI_view2d_offset()

void UI_view2d_offset ( struct View2D v2d,
float  xfac,
float  yfac 
)

Simple pan function (0.0, 0.0) bottom left (0.5, 0.5) center (1.0, 1.0) top right.

Definition at line 1954 of file view2d.cc.

References BLI_rctf_size_x(), BLI_rctf_size_y(), View2D::cur, View2D::tot, UI_view2d_curRect_validate(), rctf::xmax, rctf::xmin, rctf::ymax, and rctf::ymin.

Referenced by ui_handle_panel_header(), and ui_handler_panel_region().

◆ UI_view2d_rect_in_scrollers()

char UI_view2d_rect_in_scrollers ( const ARegion region,
const View2D v2d,
const rcti rect 
)

Definition at line 2039 of file view2d.cc.

References UI_view2d_rect_in_scrollers_ex().

◆ UI_view2d_rect_in_scrollers_ex()

char UI_view2d_rect_in_scrollers_ex ( const ARegion region,
const View2D v2d,
const rcti rect,
int *  r_scroll 
)

◆ UI_view2d_region_reinit()

void UI_view2d_region_reinit ( struct View2D v2d,
short  type,
int  winx,
int  winy 
)

Refresh and validation (of view rects).

Initialize all relevant View2D data (including view rects if first time) and/or refresh mask sizes after view resize.

  • For some of these presets, it is expected that the region will have defined some additional settings necessary for the customization of the 2D viewport to its requirements
  • This function should only be called from region init() callbacks, where it is expected that this is called before #UI_view2d_size_update(), as this one checks that the rects are properly initialized.

Definition at line 217 of file view2d.cc.

References View2D::align, View2D::alpha_hor, View2D::alpha_vert, View2D::cur, View2D::flag, float(), View2D::keepofs, View2D::keeptot, View2D::keepzoom, View2D::max, View2D::maxzoom, View2D::min, View2D::minzoom, uiStyle::panelzoom, View2D::scroll, View2D::tot, type, UI_style_get(), ui_view2d_curRect_validate_resize(), UI_view2d_totRect_set_resize(), V2D_ALIGN_NO_NEG_X, V2D_ALIGN_NO_NEG_Y, V2D_ALIGN_NO_POS_Y, V2D_COMMONVIEW_HEADER, V2D_COMMONVIEW_LIST, V2D_COMMONVIEW_PANELS_UI, V2D_COMMONVIEW_STACK, V2D_COMMONVIEW_STANDARD, V2D_IS_INIT, V2D_KEEPASPECT, V2D_KEEPTOT_BOUNDS, V2D_KEEPTOT_STRICT, V2D_KEEPZOOM, V2D_LIMITZOOM, V2D_LOCKOFS_Y, V2D_LOCKZOOM_X, V2D_LOCKZOOM_Y, V2D_SCROLL_HORIZONTAL_HIDE, V2D_SCROLL_VERTICAL_HIDE, view2d_masks(), View2D::winx, View2D::winy, rctf::xmax, rctf::xmin, rctf::ymax, and rctf::ymin.

Referenced by action_channel_region_init(), action_main_region_init(), clip_channels_region_init(), clip_preview_region_init(), console_main_region_init(), ED_region_header_init(), ED_region_panels_init(), file_main_region_draw(), file_main_region_init(), graph_channel_region_init(), graph_main_region_init(), hud_region_layout(), info_main_region_init(), nla_channel_region_init(), nla_main_region_init(), blender::ed::space_node::node_main_region_init(), outliner_main_region_init(), script_main_region_init(), sequencer_channel_region_init(), sequencer_main_region_init(), sequencer_preview_region_init(), spreadsheet_main_region_init(), text_main_region_init(), and topbar_main_region_init().

◆ UI_view2d_region_to_view()

void UI_view2d_region_to_view ( const View2D v2d,
float  x,
float  y,
float r_view_x,
float r_view_y 
)

Definition at line 1666 of file view2d.cc.

References UI_view2d_region_to_view_x(), UI_view2d_region_to_view_y(), x, and y.

◆ UI_view2d_region_to_view_rctf()

void UI_view2d_region_to_view_rctf ( const View2D v2d,
const rctf rect_src,
rctf rect_dst 
)

◆ UI_view2d_region_to_view_x()

float UI_view2d_region_to_view_x ( const struct View2D v2d,
float  x 
)

◆ UI_view2d_region_to_view_y()

float UI_view2d_region_to_view_y ( const struct View2D v2d,
float  y 
)

◆ UI_view2d_scale_get()

void UI_view2d_scale_get ( const View2D v2d,
float r_x,
float r_y 
)

Definition at line 1909 of file view2d.cc.

References UI_view2d_scale_get_x(), and UI_view2d_scale_get_y().

◆ UI_view2d_scale_get_inverse()

void UI_view2d_scale_get_inverse ( const View2D v2d,
float r_x,
float r_y 
)

◆ UI_view2d_scale_get_x()

float UI_view2d_scale_get_x ( const View2D v2d)

Definition at line 1918 of file view2d.cc.

References BLI_rctf_size_x(), BLI_rcti_size_x(), View2D::cur, and View2D::mask.

Referenced by UI_view2d_scale_get().

◆ UI_view2d_scale_get_y()

float UI_view2d_scale_get_y ( const View2D v2d)

Definition at line 1922 of file view2d.cc.

References BLI_rctf_size_y(), BLI_rcti_size_y(), View2D::cur, and View2D::mask.

Referenced by UI_view2d_scale_get().

◆ UI_view2d_scroller_size_get()

void UI_view2d_scroller_size_get ( const View2D v2d,
bool  mapped,
float r_x,
float r_y 
)

◆ UI_view2d_scrollers_calc()

void UI_view2d_scrollers_calc ( View2D v2d,
const rcti mask_custom,
struct View2DScrollers r_scrollers 
)

◆ UI_view2d_scrollers_draw()

void UI_view2d_scrollers_draw ( View2D v2d,
const rcti mask_custom 
)

Definition at line 1608 of file view2d.cc.

References UI_view2d_scrollers_draw_ex().

◆ UI_view2d_scrollers_draw_ex()

void UI_view2d_scrollers_draw_ex ( View2D v2d,
const rcti mask_custom,
bool  use_full_hide 
)

◆ UI_view2d_sync()

void UI_view2d_sync ( struct bScreen screen,
struct ScrArea area,
struct View2D v2dcur,
int  flag 
)

◆ UI_view2d_text_cache_add()

void UI_view2d_text_cache_add ( struct View2D v2d,
float  x,
float  y,
const char *  str,
size_t  str_len,
const unsigned char  col[4] 
)

◆ UI_view2d_text_cache_add_rectf()

void UI_view2d_text_cache_add_rectf ( View2D v2d,
const rctf rect_view,
const char *  str,
size_t  str_len,
const uchar  col[4] 
)

◆ UI_view2d_text_cache_draw()

void UI_view2d_text_cache_draw ( ARegion region)

◆ UI_view2d_totRect_set()

void UI_view2d_totRect_set ( View2D v2d,
int  width,
int  height 
)

◆ UI_view2d_totRect_set_resize()

void UI_view2d_totRect_set_resize ( struct View2D v2d,
int  width,
int  height,
bool  resize 
)

◆ UI_view2d_view_ortho()

void UI_view2d_view_ortho ( const View2D v2d)

◆ UI_view2d_view_orthoSpecial()

void UI_view2d_view_orthoSpecial ( struct ARegion region,
struct View2D v2d,
bool  xaxis 
)

Set view matrices to only use one axis of 'cur' only

Parameters
xaxisif non-zero, only use cur x-axis, otherwise use cur-yaxis (mostly this will be used for x).

Definition at line 1122 of file view2d.cc.

References view2d_map_cur_using_mask(), ARegion::winx, ARegion::winy, wmOrtho2(), rctf::xmax, rctf::xmin, rctf::ymax, and rctf::ymin.

Referenced by action_main_region_draw(), draw_timeline_seq(), graph_main_region_draw(), and nla_main_region_draw().

◆ UI_view2d_view_restore()

void UI_view2d_view_restore ( const bContext C)

◆ UI_view2d_view_to_region()

void UI_view2d_view_to_region ( const View2D v2d,
float  x,
float  y,
int *  r_region_x,
int *  r_region_y 
)

◆ UI_view2d_view_to_region_clip()

bool UI_view2d_view_to_region_clip ( const View2D v2d,
float  x,
float  y,
int *  r_region_x,
int *  r_region_y 
)

◆ UI_view2d_view_to_region_fl()

void UI_view2d_view_to_region_fl ( const View2D v2d,
float  x,
float  y,
float r_region_x,
float r_region_y 
)

◆ UI_view2d_view_to_region_m4()

void UI_view2d_view_to_region_m4 ( const View2D v2d,
float  matrix[4][4] 
)

◆ UI_view2d_view_to_region_rcti()

void UI_view2d_view_to_region_rcti ( const View2D v2d,
const rctf rect_src,
rcti rect_dst 
)

◆ UI_view2d_view_to_region_rcti_clip()

bool UI_view2d_view_to_region_rcti_clip ( const View2D v2d,
const rctf rect_src,
rcti rect_dst 
)

◆ UI_view2d_view_to_region_segment_clip()

bool UI_view2d_view_to_region_segment_clip ( const View2D v2d,
const float  xy_a[2],
const float  xy_b[2],
int  r_region_a[2],
int  r_region_b[2] 
)

◆ UI_view2d_view_to_region_x()

float UI_view2d_view_to_region_x ( const View2D v2d,
float  x 
)

◆ UI_view2d_view_to_region_y()

float UI_view2d_view_to_region_y ( const View2D v2d,
float  y 
)

◆ UI_view2d_zoom_cache_reset()

void UI_view2d_zoom_cache_reset ( void  )

◆ view2d_map_cur_using_mask()

static void view2d_map_cur_using_mask ( const View2D v2d,
rctf r_curmasked 
)
static

◆ view2d_masks()

static void view2d_masks ( View2D v2d,
const rcti mask_scroll 
)
static

◆ view2d_scroll_mapped()

static int view2d_scroll_mapped ( int  scroll)
static

helper to allow scrollbars to dynamically hide

  • returns a copy of the scrollbar settings with the flags to display horizontal/vertical scrollbars removed
  • input scroll value is the v2d->scroll var
  • hide flags are set per region at drawtime

Definition at line 96 of file view2d.cc.

References V2D_SCROLL_HORIZONTAL, V2D_SCROLL_HORIZONTAL_FULLR, V2D_SCROLL_VERTICAL, and V2D_SCROLL_VERTICAL_FULLR.

Referenced by UI_view2d_mouse_in_scrollers_ex(), UI_view2d_rect_in_scrollers_ex(), UI_view2d_scroller_size_get(), UI_view2d_scrollers_calc(), UI_view2d_scrollers_draw_ex(), and view2d_map_cur_using_mask().

Variable Documentation

◆ g_v2d_strings

View2DString* g_v2d_strings = nullptr
static

◆ g_v2d_strings_arena

MemArena* g_v2d_strings_arena = nullptr
static