Page Menu
Home
Search
Configure Global Search
Log In
Files
F23543
border_toggle.diff
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Campbell Barton (campbellbarton)
Nov 13 2013, 5:13 PM
Size
13 KB
Subscribers
None
border_toggle.diff
View Options
Index: source/blender/editors/include/UI_interface.h
===================================================================
--- source/blender/editors/include/UI_interface.h (revision 54829)
+++ source/blender/editors/include/UI_interface.h (working copy)
@@ -438,6 +438,7 @@
int UI_but_active_drop_name(struct bContext *C);
struct uiBut *ui_but_find_mouse_over(struct ARegion *ar, int x, int y);
+struct LinkNode *ui_but_find_rect_over(struct ARegion *ar, const rcti *rect);
void uiButSetFlag(uiBut *but, int flag);
void uiButClearFlag(uiBut *but, int flag);
Index: source/blender/editors/interface/interface_handlers.c
===================================================================
--- source/blender/editors/interface/interface_handlers.c (revision 54829)
+++ source/blender/editors/interface/interface_handlers.c (working copy)
@@ -48,6 +48,7 @@
#include "BLI_math.h"
#include "BLI_blenlib.h"
+#include "BLI_linklist.h"
#include "BLI_utildefines.h"
#include "BLI_string_cursor_utf8.h"
@@ -762,13 +763,13 @@
WM_gestures_remove(C);
if (ABS(data->dragstartx - event->x) + ABS(data->dragstarty - event->y) > U.dragthreshold) {
-
- button_activate_state(C, but, BUTTON_STATE_EXIT);
- data->cancel = TRUE;
-
if (ui_is_but_bool(but)) {
const bool is_set = (ui_get_but_val(but) != 0.0);
PointerRNA ptr;
+
+ data->cancel = TRUE;
+ button_activate_state(C, but, BUTTON_STATE_EXIT);
+
WM_operator_properties_create(&ptr, "UI_OT_drag_toggle");
RNA_boolean_set(&ptr, "state", !is_set);
RNA_int_set(&ptr, "last_x", data->dragstartx);
@@ -779,6 +780,9 @@
else {
wmDrag *drag;
+ button_activate_state(C, but, BUTTON_STATE_EXIT);
+ data->cancel = TRUE;
+
drag = WM_event_start_drag(C, but->icon, but->dragtype, but->dragpoin, ui_get_but_val(but));
if (but->imb)
WM_event_drag_image(drag, but->imb, but->imb_scale, BLI_rctf_size_x(&but->rect), BLI_rctf_size_y(&but->rect));
@@ -5337,6 +5341,13 @@
return BLI_rctf_isect_pt(&but->rect, mx, my);
}
+static int ui_but_contains_rect(uiBut *but, const rcti *rect)
+{
+ rctf rect_fl;
+ BLI_rctf_rcti_copy(&rect_fl, rect);
+ return BLI_rctf_isect(&but->rect, &rect_fl, NULL);
+}
+
static uiBut *ui_but_find_activated(ARegion *ar)
{
uiBlock *block;
@@ -5452,6 +5463,20 @@
return 1;
}
+static bool ui_is_but_clickable(uiBut *but)
+{
+ if (but->type == LABEL && but->dragpoin == NULL)
+ return false;
+ if (ELEM3(but->type, ROUNDBOX, SEPR, LISTBOX))
+ return false;
+ if (but->flag & UI_HIDDEN)
+ return false;
+ if (but->flag & UI_SCROLLED)
+ return false;
+
+ return true;
+}
+
uiBut *ui_but_find_mouse_over(ARegion *ar, int x, int y)
{
uiBlock *block;
@@ -5470,14 +5495,10 @@
for (but = block->buttons.first; but; but = but->next) {
/* note, LABEL is included for highlights, this allows drags */
- if (but->type == LABEL && but->dragpoin == NULL)
+
+ if (ui_is_but_clickable(but) == false)
continue;
- if (ELEM3(but->type, ROUNDBOX, SEPR, LISTBOX))
- continue;
- if (but->flag & UI_HIDDEN)
- continue;
- if (but->flag & UI_SCROLLED)
- continue;
+
if (ui_but_contains_pt(but, mx, my))
butover = but;
}
@@ -5494,6 +5515,37 @@
return butover;
}
+/**
+ * Use same rules as: #ui_but_find_mouse_over() for picking buttons.
+ */
+LinkNode *ui_but_find_rect_over(ARegion *ar, const rcti *rect)
+{
+ LinkNode *links = NULL;
+ uiBlock *block;
+ uiBut *but;
+ rcti rect_block;
+printf("AREA %p\n", ar);
+print_rcti("", rect);
+ for (block = ar->uiblocks.first; block; block = block->next) {
+ rect_block = *rect;
+
+ ui_window_to_block(ar, block, &rect_block.xmin, &rect_block.ymin);
+ ui_window_to_block(ar, block, &rect_block.xmax, &rect_block.ymax);
+
+ for (but = block->buttons.first; but; but = but->next) {
+ /* note, LABEL is included for highlights, this allows drags */
+ if (ui_is_but_clickable(but) == false)
+ continue;
+
+ if (ui_but_contains_rect(but, &rect_block)) {
+ BLI_linklist_prepend(&links, but);
+ }
+ }
+ }
+
+ return links;
+}
+
static uiBut *ui_list_find_mouse_over(ARegion *ar, int x, int y)
{
uiBlock *block;
Index: source/blender/editors/interface/interface_ops.c
===================================================================
--- source/blender/editors/interface/interface_ops.c (revision 54829)
+++ source/blender/editors/interface/interface_ops.c (working copy)
@@ -38,6 +38,7 @@
#include "DNA_text_types.h" /* for UI_OT_reports_to_text */
#include "BLI_blenlib.h"
+#include "BLI_linklist.h"
#include "BLI_math_color.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
@@ -74,6 +75,9 @@
#include "ED_node.h" /* for HDR color sampling */
#include "ED_clip.h" /* for HDR color sampling */
+/* callbacks */
+#include "ED_space_api.h"
+
/* ********************************************************** */
typedef struct Eyedropper {
@@ -1076,143 +1080,74 @@
/* Toggle Drag Operator */
typedef struct DragOpInfo {
- bool xy_lock[2];
- float but_cent_start[2];
eButType but_type_start;
+ void *draw_handle_pixel;
} DragOpInfo;
-typedef struct DragOpPlotData {
- bContext *C;
- ARegion *ar;
- bool is_set;
- eButType but_type_start;
- bool do_draw;
- const uiBut *but_prev;
-} DragOpPlotData;
-
-static const uiBut *ui_but_set_xy(bContext *C, ARegion *ar, const bool is_set, const eButType but_type_start,
- const int xy[2], const uiBut *but_prev)
+static void ui_drag_toggle_draw_cb(const struct bContext *UNUSED(C), ARegion *ar, void *arg)
{
- uiBut *but = ui_but_find_mouse_over(ar, xy[0], xy[1]);
+ wmOperator *op = arg;
+ rcti rect;
+ wmGesture *gesture = op->customdata;
+ DragOpInfo *drag_info = gesture->userdata;
+ LinkNode *links;
+ LinkNode *but_link;
- if (but_prev == but) {
- return but_prev;
- }
+ const bool is_set = RNA_boolean_get(op->ptr, "state");
- if (but && ui_is_but_bool(but) && but->type == but_type_start) {
- /* is it pressed? */
- bool is_set_but = (ui_get_but_val(but) != 0.0);
- BLI_assert(ui_is_but_bool(but) == true);
- if (is_set_but != is_set) {
- uiButExecute(C, but);
- return but;
- }
- }
+ WM_operator_properties_border_to_rcti(op, &rect);
+ BLI_rcti_translate(&rect, ar->winrct.xmin, ar->winrct.ymin);
- return but_prev;
-}
+ links = ui_but_find_rect_over(ar, &rect);
-static int ui_but_set_cb(int x, int y, void *data_v)
-{
- DragOpPlotData *data = data_v;
- int xy[2] = {x, y};
- data->but_prev = ui_but_set_xy(data->C, data->ar, data->is_set, data->but_type_start, xy, data->but_prev);
- return 1; /* keep going */
-}
+ for (but_link = links; but_link; but_link = but_link->next) {
+ uiBut *but = but_link->link;
-/* operates on buttons between 2 mouse-points */
-static bool ui_but_set_xy_xy(bContext *C, ARegion *ar, const bool is_set, const eButType but_type_start,
- const int xy_src[2], const int xy_dst[2])
-{
- DragOpPlotData data;
- data.C = C;
- data.ar = ar;
- data.is_set = is_set;
- data.but_type_start = but_type_start;
- data.do_draw = false;
- data.but_prev = NULL;
+ if (drag_info->but_type_start == but->type) {
+ bool is_set_but = (ui_get_but_val(but) != 0.0);
+ rctf rect_winspace = but->rect;
+ ui_block_to_window_fl(ar, but->block, &rect_winspace.xmin, &rect_winspace.ymin);
+ ui_block_to_window_fl(ar, but->block, &rect_winspace.xmax, &rect_winspace.ymax);
+ uiSetRoundBox(UI_CNR_ALL);
+ BLI_assert(ui_is_but_bool(but) == true);
+ if (is_set_but != is_set) {
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ glColor4ub(255, 255, 255, 32);
+ }
+ else {
+ /* dont draw if we wont change.. */
+ continue;
+ //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ //glColor4ub(128, 128, 128, 96);
+ }
- /* prevent dragging too fast loosing buttons */
- plot_line_v2v2i(xy_src, xy_dst, ui_but_set_cb, &data);
-
- return data.do_draw;
-}
-
-static void ui_drag_but_set(bContext *C, wmOperator *op, const int xy_input[2])
-{
- ARegion *ar = CTX_wm_region(C);
- DragOpInfo *drag_info = op->customdata;
- bool do_draw = false;
-
- const bool is_set = RNA_boolean_get(op->ptr, "state");
- const int xy_last[2] = {RNA_int_get(op->ptr, "last_x"),
- RNA_int_get(op->ptr, "last_y")};
-
- int xy[2];
-
- /**
- * Initialize Locking:
- *
- * Check if we need to initialize the lock axis by finding if the first
- * button we mouse over is X or Y aligned, then lock the mouse to that axis after.
- */
- if (drag_info->xy_lock[0] == false && drag_info->xy_lock[1] == false) {
- ARegion *ar = CTX_wm_region(C);
-
- /* first store the buttons original coords */
- uiBut *but = ui_but_find_mouse_over(ar, xy_input[0], xy_input[1]);
- if (but) {
- const float but_cent_new[2] = {BLI_rctf_cent_x(&but->rect),
- BLI_rctf_cent_y(&but->rect)};
-
- /* check if this is a different button, chances are high the button wont move about :) */
- if (len_manhattan_v2v2(drag_info->but_cent_start, but_cent_new) > 1.0f) {
- if (fabsf(drag_info->but_cent_start[0] - but_cent_new[0]) <
- fabsf(drag_info->but_cent_start[1] - but_cent_new[1]))
- {
- drag_info->xy_lock[0] = true;
- }
- else {
- drag_info->xy_lock[1] = true;
- }
- }
+ uiRoundBox(rect_winspace.xmin - ar->winrct.xmin, rect_winspace.ymin - ar->winrct.ymin,
+ rect_winspace.xmax - ar->winrct.xmin, rect_winspace.ymax - ar->winrct.ymin, U.widget_unit * 0.2f);
}
}
- /* done with axis locking */
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- xy[0] = (drag_info->xy_lock[0] == false) ? xy_input[0] : xy_last[0];
- xy[1] = (drag_info->xy_lock[1] == false) ? xy_input[1] : xy_last[1];
-
-
- /* touch all buttons between last mouse coord and this one */
- do_draw = ui_but_set_xy_xy(C, ar, is_set, drag_info->but_type_start, xy_last, xy);
-
- if (do_draw) {
- ED_region_tag_redraw(ar);
- }
-
- RNA_int_set(op->ptr, "last_x", xy[0]);
- RNA_int_set(op->ptr, "last_y", xy[1]);
+ BLI_linklist_free(links, NULL);
}
static int ui_drag_toggle_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
+ wmEvent event_fake = *event;
+ bScreen *screen = CTX_wm_screen(C);
int xy_last[2] = {RNA_int_get(op->ptr, "last_x"),
RNA_int_get(op->ptr, "last_y")};
- float but_cent_start[2];
+ ARegion *ar = CTX_wm_region(C);
+
eButType but_type_start;
DragOpInfo *drag_info;
{
/* find the button where we started dragging */
- ARegion *ar = CTX_wm_region(C);
uiBut *but = ui_but_find_mouse_over(ar, xy_last[0], xy_last[1]);
if (but) {
- but_cent_start[0] = BLI_rctf_cent_x(&but->rect);
- but_cent_start[1] = BLI_rctf_cent_y(&but->rect);
but_type_start = but->type;
}
else {
@@ -1220,15 +1155,29 @@
}
}
- drag_info = op->customdata = MEM_callocN(sizeof(DragOpInfo), __func__);
- copy_v2_v2(drag_info->but_cent_start, but_cent_start);
- drag_info->but_type_start = but_type_start;
+ /* use the original mousedown location */
+ event_fake.x = xy_last[0];
+ event_fake.y = xy_last[1];
+ copy_v2_v2_int(event_fake.mval, xy_last);
- /* set the initial button */
- ui_drag_but_set(C, op, xy_last);
- ui_drag_but_set(C, op, &event->x);
+ event_fake.mval[0] -= ar->winrct.xmin;
+ event_fake.mval[1] -= ar->winrct.ymin;
+ op->customdata = WM_gesture_new(C, &event_fake, WM_GESTURE_RECT);
WM_event_add_modal_handler(C, op);
+ if (screen) {
+ screen->do_draw_gesture = TRUE;
+ }
+
+ {
+ wmGesture *gesture = op->customdata;
+
+ drag_info = MEM_callocN(sizeof(DragOpInfo), __func__);
+ gesture->userdata = drag_info;
+ drag_info->but_type_start = but_type_start;
+ drag_info->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ui_drag_toggle_draw_cb, op, REGION_DRAW_POST_PIXEL);
+ }
+
return OPERATOR_RUNNING_MODAL;
}
@@ -1246,13 +1195,51 @@
}
case MOUSEMOVE:
{
- ui_drag_but_set(C, op, &event->x);
+ WM_border_select_modal(C, op, event);
+ ED_region_tag_redraw(CTX_wm_region(C));
break;
}
}
if (done) {
- MEM_freeN(op->customdata);
+ ARegion *ar = CTX_wm_region(C);
+
+ /* apply to all buttons */
+ const bool is_set = RNA_boolean_get(op->ptr, "state");
+ rcti rect;
+ wmGesture *gesture = op->customdata;
+ DragOpInfo *drag_info = gesture->userdata;
+ LinkNode *links;
+ LinkNode *but_link;
+
+ WM_operator_properties_border_to_rcti(op, &rect);
+ BLI_rcti_translate(&rect, ar->winrct.xmin, ar->winrct.ymin);
+
+ links = ui_but_find_rect_over(ar, &rect);
+
+
+ for (but_link = links; but_link; but_link = but_link->next) {
+ uiBut *but = but_link->link;
+
+ if (drag_info->but_type_start == but->type) {
+ bool is_set_but = (ui_get_but_val(but) != 0.0);
+ BLI_assert(ui_is_but_bool(but) == true);
+ if (is_set_but != is_set) {
+ uiButExecute(C, but);
+ }
+ }
+ }
+
+ BLI_linklist_free(links, NULL);
+
+ WM_gesture_end(C, gesture);
+
+ if (drag_info->draw_handle_pixel)
+ ED_region_draw_cb_exit(ar->type, drag_info->draw_handle_pixel);
+
+ op->customdata = NULL;
+
+ ED_region_tag_redraw(ar);
return OPERATOR_FINISHED;
}
else {
@@ -1285,6 +1272,8 @@
RNA_def_boolean(ot->srna, "state", true, "State", "");
RNA_def_int(ot->srna, "last_x", 0, 0, INT_MAX, "X", "", 0, INT_MAX);
RNA_def_int(ot->srna, "last_y", 0, 0, INT_MAX, "Y", "", 0, INT_MAX);
+
+ WM_operator_properties_gesture_border(ot, false);
}
/* ********************************************************* */
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
64/a4/310614aeec22061196828841c775
Event Timeline
Log In to Comment