Blender  V2.93
area_utils.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
23 #include "DNA_userdef_types.h"
24 
25 #include "BKE_screen.h"
26 
27 #include "BLI_blenlib.h"
28 #include "BLI_utildefines.h"
29 
30 #include "RNA_access.h"
31 #include "RNA_types.h"
32 
33 #include "WM_message.h"
34 
35 #include "ED_screen.h"
36 
37 #include "UI_interface_icons.h"
38 
39 /* -------------------------------------------------------------------- */
47 {
48  struct wmMsgBus *mbus = params->message_bus;
49  ARegion *region = params->region;
50 
51  wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
52  .owner = region,
53  .user_data = region,
55  };
56  WM_msg_subscribe_rna_anon_prop(mbus, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
57 }
58 
62 int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, int axis)
63 {
64  if (axis == 0) {
65  /* Using Y axis avoids slight feedback loop when adjusting X. */
66  const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
67  (BLI_rcti_size_y(&region->v2d.mask) + 1);
68  const float icon_size = ICON_DEFAULT_HEIGHT_TOOLBAR / aspect;
69  const float column = 1.25f * icon_size;
70  const float margin = 0.5f * icon_size;
71  const float snap_units[] = {
72  column + margin,
73  (2.0f * column) + margin,
74  (2.7f * column) + margin,
75  };
76  int best_diff = INT_MAX;
77  int best_size = size;
78  /* Only snap if less than last snap unit. */
79  if (size <= snap_units[ARRAY_SIZE(snap_units) - 1]) {
80  for (uint i = 0; i < ARRAY_SIZE(snap_units); i += 1) {
81  const int test_size = snap_units[i];
82  const int test_diff = abs(test_size - size);
83  if (test_diff < best_diff) {
84  best_size = test_size;
85  best_diff = test_diff;
86  }
87  }
88  }
89  return best_size;
90  }
91  return size;
92 }
93 
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:157
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:165
unsigned int uint
Definition: BLI_sys_types.h:83
#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:62
void ED_region_generic_tools_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
Definition: area_utils.c:46
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)