Blender  V3.3
area_utils.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include "DNA_userdef_types.h"
10 
11 #include "BKE_screen.h"
12 
13 #include "BLI_blenlib.h"
14 #include "BLI_utildefines.h"
15 
16 #include "RNA_access.h"
17 #include "RNA_types.h"
18 
19 #include "WM_message.h"
20 
21 #include "ED_screen.h"
22 
23 #include "UI_interface_icons.h"
24 
25 /* -------------------------------------------------------------------- */
30 {
31  struct wmMsgBus *mbus = params->message_bus;
32  ARegion *region = params->region;
33 
34  wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
35  .owner = region,
36  .user_data = region,
38  };
39  WM_msg_subscribe_rna_anon_prop(mbus, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
40 }
41 
42 int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, int axis)
43 {
44  if (axis == 0) {
45  /* Using Y axis avoids slight feedback loop when adjusting X. */
46  const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
47  (BLI_rcti_size_y(&region->v2d.mask) + 1);
48  const float icon_size = ICON_DEFAULT_HEIGHT_TOOLBAR / aspect;
49  const float column = 1.25f * icon_size;
50  const float margin = 0.5f * icon_size;
51  const float snap_units[] = {
52  column + margin,
53  (2.0f * column) + margin,
54  (2.7f * column) + margin,
55  };
56  int best_diff = INT_MAX;
57  int best_size = size;
58  /* Only snap if less than last snap unit. */
59  if (size <= snap_units[ARRAY_SIZE(snap_units) - 1]) {
60  for (uint i = 0; i < ARRAY_SIZE(snap_units); i += 1) {
61  const int test_size = snap_units[i];
62  const int test_diff = abs(test_size - size);
63  if (test_diff < best_diff) {
64  best_size = test_size;
65  best_diff = test_diff;
66  }
67  }
68  }
69  return best_size;
70  }
71  return size;
72 }
73 
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:190
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:198
unsigned int uint
Definition: BLI_sys_types.h:67
#define ARRAY_SIZE(arr)
void ED_region_do_msg_notify_tag_redraw(struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val)
#define ICON_DEFAULT_HEIGHT_TOOLBAR
int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, int axis)
Definition: area_utils.c:42
void ED_region_generic_tools_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
Definition: area_utils.c:29
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
T abs(const T &a)
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)