Blender V5.3
area_utils.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <limits>
12
13#include "BKE_screen.hh"
14
15#include "BLI_rect.hh"
16#include "BLI_utildefines.hh"
17
18#include "WM_message.hh"
19
20#include "ED_screen.hh"
21
22#include "UI_interface.hh"
23
24namespace blender {
25
26/* -------------------------------------------------------------------- */
29
31{
32 wmMsgBus *mbus = params->message_bus;
33 ARegion *region = params->region;
34
35 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
36 msg_sub_value_region_tag_redraw.owner = region;
37 msg_sub_value_region_tag_redraw.user_data = region;
38 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
39 WM_msg_subscribe_rna_anon_prop(mbus, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
40}
41
42int 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 column = UI_TOOLBAR_COLUMN / aspect;
49 const float margin = UI_TOOLBAR_MARGIN / aspect;
50 const float snap_units[] = {
51 column + margin,
52 (2.0f * column) + margin,
53 (2.7f * column) + margin,
54 };
55 int best_diff = std::numeric_limits<int>::max();
56 int best_size = size;
57 /* Only snap if less than last snap unit. */
58 if (size <= snap_units[ARRAY_SIZE(snap_units) - 1]) {
59 for (uint i = 0; i < ARRAY_SIZE(snap_units); i += 1) {
60 const int test_size = snap_units[i];
61 const int test_diff = abs(test_size - size);
62 if (test_diff < best_diff) {
63 best_size = test_size;
64 best_diff = test_diff;
65 }
66 }
67 }
68 return best_size;
69 }
70 return size;
71}
72
73int ED_region_generic_panel_region_snap_size(const ARegion *region, int size, int axis)
74{
75 if (axis == 0) {
77 return size;
78 }
79
80 /* Using Y axis avoids slight feedback loop when adjusting X. */
81 const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
82 (BLI_rcti_size_y(&region->v2d.mask) + 1);
83 return int(UI_PANEL_CATEGORY_MIN_WIDTH / aspect);
84 }
85 return size;
86}
87
89
90} // namespace blender
#define UI_TOOLBAR_MARGIN
#define UI_PANEL_CATEGORY_MIN_WIDTH
#define UI_TOOLBAR_COLUMN
#define abs
bool panel_category_tabs_is_visible(const ARegion *region)
BMesh Iterators.
void ED_region_generic_tools_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
Definition area_utils.cc:30
unsigned int uint
Definition BKE_text.h:55
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
int ED_region_generic_panel_region_snap_size(const ARegion *region, int size, int axis)
Definition area_utils.cc:73
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, int axis)
Definition area_utils.cc:42
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:394
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)