[Bf-blender-cvs] [74308df] wiggly-widgets: Support for custom cursors for widgets.
Antony Riakiotakis
noreply at git.blender.org
Fri Dec 12 16:27:19 CET 2014
Commit: 74308df3f051b6a90560fe00b9a9539a3dbaef19
Author: Antony Riakiotakis
Date: Fri Dec 12 15:22:31 2014 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB74308df3f051b6a90560fe00b9a9539a3dbaef19
Support for custom cursors for widgets.
They are set when a highlighted widget intersection is detected and on
area level.
There's a discussion about using owners and a stack or array for cursors
but that needs some more thought and design.
===================================================================
M source/blender/editors/screen/screen_edit.c
M source/blender/editors/space_sequencer/sequencer_view.c
M source/blender/makesrna/intern/rna_wm.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm_generic_widgets.c
M source/blender/windowmanager/intern/wm_widgets.c
M source/blender/windowmanager/wm.h
===================================================================
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index c179cfc..4627b86 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -1078,6 +1078,8 @@ static void region_cursor_set(wmWindow *win, int swinid, int swin_changed)
for (; ar; ar = ar->next) {
if (ar->swinid == swinid) {
if (swin_changed || (ar->type && ar->type->event_cursor)) {
+ if (WM_widgetmap_cursor_set(ar->widgetmaps.first, win))
+ return;
if (ar->type && ar->type->cursor)
ar->type->cursor(win, sa, ar);
else
diff --git a/source/blender/editors/space_sequencer/sequencer_view.c b/source/blender/editors/space_sequencer/sequencer_view.c
index 2a81442..71eb64a 100644
--- a/source/blender/editors/space_sequencer/sequencer_view.c
+++ b/source/blender/editors/space_sequencer/sequencer_view.c
@@ -287,7 +287,7 @@ static int sequencer_overdrop_transform_invoke(bContext *C, wmOperator *op, cons
/* no poll, lives always for the duration of the operator */
wmWidgetGroupType *cagetype = WM_widgetgrouptype_new(NULL, widgetgroup_overdrop_draw, CTX_data_main(C), "Seq_Canvas", SPACE_SEQ, RGN_TYPE_WINDOW, false);
struct wmEventHandler *handler = WM_event_add_modal_handler(C, op);
- OverDropTransformData *data = MEM_mallocN(sizeof(OverDropTransformData), "backdrop transform data");
+ OverDropTransformData *data = MEM_mallocN(sizeof(OverDropTransformData), "overdrop transform data");
WM_modal_handler_attach_widgetgroup(C, handler, cagetype, op);
RNA_float_set_array(op->ptr, "offset", sseq->overdrop_offset);
@@ -309,10 +309,16 @@ static void sequencer_overdrop_finish(bContext *C, OverDropTransformData *data)
{
ScrArea *sa = CTX_wm_area(C);
ED_area_headerprint(sa, NULL);
- WM_widgetgrouptype_unregister(CTX_data_main(C), data->cagetype);
+ WM_widgetgrouptype_unregister(C, CTX_data_main(C), data->cagetype);
MEM_freeN(data);
}
+static void sequencer_overdrop_cancel(struct bContext *C, struct wmOperator *op)
+{
+ OverDropTransformData *data = op->customdata;
+ sequencer_overdrop_finish(C, data);
+}
+
static int sequencer_overdrop_transform_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
OverDropTransformData *data = op->customdata;
@@ -380,6 +386,7 @@ void SEQUENCER_OT_overdrop_transform(struct wmOperatorType *ot)
ot->invoke = sequencer_overdrop_transform_invoke;
ot->modal = sequencer_overdrop_transform_modal;
ot->poll = sequencer_overdrop_transform_poll;
+ ot->cancel = sequencer_overdrop_cancel;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index e1273d1..c5e311b 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -1395,7 +1395,7 @@ static void rna_WidgetGroup_unregister(struct Main *bmain, StructRNA *type)
//RNA_struct_free_extension(type, &wgrouptype->ext);
- WM_widgetgrouptype_unregister(bmain, wgrouptype);
+ WM_widgetgrouptype_unregister(NULL, bmain, wgrouptype);
//WM_operatortype_remove_ptr(ot);
/* not to be confused with the RNA_struct_free that WM_operatortype_remove calls, they are 2 different srna's */
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 456e30d..e7efae5 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -487,15 +487,15 @@ void WM_widget_set_draw_on_hover_only(struct wmWidget *widget, bool draw);
void WM_widget_set_scale(struct wmWidget *widget, float scale);
struct wmWidgetMapType *WM_widgetmaptype_find(const char *idname, int spaceid, int regionid, bool is_3d, bool create);
-
struct wmWidgetGroupType *WM_widgetgrouptype_new(int (*poll)(const struct bContext *, struct wmWidgetGroupType *),
void (*draw)(const struct bContext *, struct wmWidgetGroup *),
struct Main *bmain, const char *mapidname, short spaceid, short regionid, bool is_3d);
-void WM_widgetgrouptype_unregister(struct Main *bmain, struct wmWidgetGroupType *wgroup);
+void WM_widgetgrouptype_unregister(struct bContext *C, struct Main *bmain, struct wmWidgetGroupType *wgroup);
/* creates a widgetmap with all registered widgets for that type */
struct wmWidgetMap *WM_widgetmap_from_type(const char *idname, int spaceid, int regionid, bool is_3d);
void WM_widgetmap_delete(struct wmWidgetMap *wmap);
+bool WM_widgetmap_cursor_set(struct wmWidgetMap *wmap, struct wmWindow *win);
void WM_widgetmaptypes_free(void);
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c b/source/blender/windowmanager/intern/wm_generic_widgets.c
index 69de4cd..4e89c56 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -656,45 +656,72 @@ static void rect_transform_draw_corners(rctf *r, float offsetx, float offsety)
static void rect_transform_draw_interaction(int highlighted, float half_w, float half_h, float w, float h)
{
- rctf r;
-
+ float verts[4][2];
+ unsigned short elems[4] = {0, 1, 3, 2};
switch (highlighted) {
case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEX_LEFT:
- r.xmin = -half_w;
- r.ymin = -half_h;
- r.xmax = -half_w + w;
- r.ymax = half_h;
+ verts[0][0] = -half_w + w;
+ verts[0][1] = -half_h;
+ verts[1][0] = -half_w;
+ verts[1][1] = -half_h;
+ verts[2][0] = -half_w;
+ verts[2][1] = half_h;
+ verts[3][0] = -half_w + w;
+ verts[3][1] = half_h;
break;
case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEX_RIGHT:
- r.xmin = half_w - w;
- r.ymin = -half_h;
- r.xmax = half_w;
- r.ymax = half_h;
+ verts[0][0] = half_w - w;
+ verts[0][1] = -half_h;
+ verts[1][0] = half_w;
+ verts[1][1] = -half_h;
+ verts[2][0] = half_w;
+ verts[2][1] = half_h;
+ verts[3][0] = half_w - w;
+ verts[3][1] = half_h;
break;
case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_DOWN:
- r.xmin = -half_w;
- r.ymin = -half_h;
- r.xmax = half_w;
- r.ymax = -half_h + h;
+ verts[0][0] = -half_w;
+ verts[0][1] = -half_h + h;
+ verts[1][0] = -half_w;
+ verts[1][1] = -half_h;
+ verts[2][0] = half_w;
+ verts[2][1] = -half_h;
+ verts[3][0] = half_w;
+ verts[3][1] = -half_h + h;
break;
case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_UP:
- r.xmin = -half_w;
- r.ymin = half_h - h;
- r.xmax = half_w;
- r.ymax = half_h;
+ verts[0][0] = -half_w;
+ verts[0][1] = half_h - h;
+ verts[1][0] = -half_w;
+ verts[1][1] = half_h;
+ verts[2][0] = half_w;
+ verts[2][1] = half_h;
+ verts[3][0] = half_w;
+ verts[3][1] = half_h - h;
break;
default:
return;
}
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glRectf(r.xmin, r.ymin, r.xmax, r.ymax);
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2, GL_FLOAT, 0, verts);
+ glLineWidth(3.0);
+ glColor3f(0.0, 0.0, 0.0);
+ glDrawArrays(GL_LINE_STRIP, 0, 3);
+ glLineWidth(1.0);
+ glColor3f(1.0, 1.0, 1.0);
+ glDrawArrays(GL_LINE_STRIP, 0, 3);
+
+ glEnable(GL_BLEND);
+ glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
+ glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, elems);
+ glDisable(GL_BLEND);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
static void widget_rect_transform_draw(struct wmWidget *widget, const struct bContext *UNUSED(C))
@@ -719,7 +746,7 @@ static void widget_rect_transform_draw(struct wmWidget *widget, const struct bCo
else
glScalef(cage->scale[0], cage->scale[1], 1.0);
- if (widget->flag & WM_WIDGET_HIGHLIGHT) {
+ if (widget->highlighted_part == WIDGET_RECT_TRANSFORM_INTERSECT_TRANSLATE) {
glEnable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
glRectf(r.xmin, r.ymin, r.xmax, r.ymax);
@@ -749,6 +776,22 @@ static void widget_rect_transform_draw(struct wmWidget *widget, const struct bCo
glPopMatrix();
}
+static int widget_rect_tranfrorm_get_cursor(wmWidget *widget)
+{
+ switch (widget->highlighted_part) {
+ case WIDGET_RECT_TRANSFORM_INTERSECT_TRANSLATE:
+ return BC_HANDCURSOR;
+ case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEX_LEFT:
+ case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEX_RIGHT:
+ return CURSOR_X_MOVE;
+ case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_DOWN:
+ case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_UP:
+ return CURSOR_Y_MOVE;
+ default:
+ return CURSOR_STD;
+ }
+}
+
static int widget_rect_tranfrorm_intersect(struct bContext *UNUSED(C), const struct wmEvent *event, struct wmWidget *widget)
{
RectTransformWidget *cage = (RectTransformWidget *)widget;
@@ -1000,6 +1043,7 @@ struct wmWidget *WIDGET_rect_transform_new(struct wmWidgetGroup *wgroup, int sty
cage->widget.bind_to_prop = widget_rect_transform_bind_to_prop;
cage->widget.handler = widget_rect_transform_handler;
cage->widget.intersect = widget_rect_tranfrorm_intersect;
+ cage->widget.get_cursor = widget_rect_tranfrorm_get_cursor;
cage->widget.max_prop = 2;
cage->scale[0] = cage->scale[1] = 1.0f;
cage->style = style;
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index 41a47b7..4afeedf 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -100,7 +100,7 @@ static ListBase widgetmaptypes = {NULL, NULL};
struct wmWidgetGroupType *WM_widgetgrouptype_new(
int (*poll)(const struct bContext *C, struct wmWidgetGroupType *),
void (*draw)(const struct bContext *, struct wmWidgetGroup *),
- Main *bmain, const char *mapidname, short spaceid, short regionid,bool is_3d
+ struct Main *bmain, const char *mapidname, short spaceid, short regionid,bool is_3d
)
{
bScreen *sc;
@@ -627,10 +627,22 @@ wmWidget *wm_widget_find_highlighted(struct wmWidgetMap *wmap, bContext *C, cons
return NULL;
}
+bool WM_widgetmap_cursor_set(wmWidgetMap *wmap, wmWindow *win)
+{
+ for (; wmap; wmap = wmap->next) {
+ wmWidget *widget = wmap->highlighted_widget;
+ if (widget && widget->get_cursor) {
+ WM_cursor_set(win, widget->get_cursor(widget));
+ return
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list