Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2014-04-02 14:59:48 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2014-04-02 15:03:11 +0400
commit4faef1e10c9d1177eae6350b4471206e91afaff8 (patch)
tree507726457b31e3d27bac0669f709c2bf26804455 /source/blender/editors
parent11ee2d8b97ddbdde9ef5a7b77df2b9f9eb2d0e91 (diff)
Add drag-resize to uiTemplatePreview (mat/tex/etc. preview widget).
This is done by adding a new button type, GRIP, similar to other numbuttons (scroll, slider, ...), which here controls the preview height. Then, we add a new DNA struct to be able to save that height in Blend files (note I choose not to use Panel struct for this, because we would then have the same limitation we used to have with uiLists, only one preview per panel and no preview outside panel). This implies a change to template_preview UI RNA/py API (each preview needs an ID), but this is backward compatible, as by default datablock type will be used if no ID is given (which means e.g. all material previews with no ID will have same height). Reviewers: brecht Reviewed By: brecht Differential Revision: https://developer.blender.org/D342
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/include/UI_interface.h4
-rw-r--r--source/blender/editors/interface/interface.c2
-rw-r--r--source/blender/editors/interface/interface_handlers.c58
-rw-r--r--source/blender/editors/interface/interface_templates.c42
-rw-r--r--source/blender/editors/interface/interface_widgets.c4
5 files changed, 104 insertions, 6 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 2177b066c1f..7eb39fd4b3c 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -270,6 +270,7 @@ typedef enum {
SEARCH_MENU_UNLINK = (52 << 9),
NODESOCKET = (53 << 9),
SEPRLINE = (54 << 9),
+ GRIP = (55 << 9),
} eButType;
#define BUTTYPE (63 << 9)
@@ -832,7 +833,8 @@ void uiTemplatePathBuilder(uiLayout *layout, struct PointerRNA *ptr, const char
struct PointerRNA *root_ptr, const char *text);
uiLayout *uiTemplateModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
-void uiTemplatePreview(uiLayout *layout, struct ID *id, int show_buttons, struct ID *parent, struct MTex *slot);
+void uiTemplatePreview(uiLayout *layout, struct bContext *C, struct ID *id, int show_buttons, struct ID *parent,
+ struct MTex *slot, const char *preview_id);
void uiTemplateColorRamp(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int expand);
void uiTemplateIconView(uiLayout *layout, struct PointerRNA *ptr, const char *propname);
void uiTemplateHistogram(uiLayout *layout, struct PointerRNA *ptr, const char *propname);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 530f529f345..8a4233a97b0 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2994,7 +2994,7 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str,
}
/* keep track of UI_interface.h */
- if (ELEM10(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX, LISTBOX, BUTM, SCROLL, SEPR, SEPRLINE)) {}
+ if (ELEM11(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX, LISTBOX, BUTM, SCROLL, SEPR, SEPRLINE, GRIP)) {}
else if (but->type >= SEARCH_MENU) {}
else but->flag |= UI_BUT_UNDO;
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index e7c9900c325..c911e0d9ac9 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -1567,6 +1567,7 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
ui_apply_but_ROW(C, block, but, data);
break;
case SCROLL:
+ case GRIP:
case NUM:
case NUMSLI:
ui_apply_but_NUM(C, but, data);
@@ -3935,6 +3936,51 @@ static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
return retval;
}
+static int ui_do_but_GRIP(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
+{
+ int mx, my;
+ int retval = WM_UI_HANDLER_CONTINUE;
+ const bool horizontal = (BLI_rctf_size_x(&but->rect) < BLI_rctf_size_y(&but->rect));
+
+ mx = event->x;
+ my = event->y;
+ ui_window_to_block(data->region, block, &mx, &my);
+
+ if (data->state == BUTTON_STATE_HIGHLIGHT) {
+ if (event->val == KM_PRESS) {
+ if (event->type == LEFTMOUSE) {
+ data->dragstartx = event->x;
+ data->dragstarty = event->y;
+ button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
+ retval = WM_UI_HANDLER_BREAK;
+ }
+ }
+ }
+ else if (data->state == BUTTON_STATE_NUM_EDITING) {
+ if (event->type == ESCKEY) {
+ if (event->val == KM_PRESS) {
+ data->cancel = true;
+ data->escapecancel = true;
+ button_activate_state(C, but, BUTTON_STATE_EXIT);
+ }
+ }
+ else if (event->type == LEFTMOUSE && event->val != KM_PRESS) {
+ button_activate_state(C, but, BUTTON_STATE_EXIT);
+ }
+ else if (event->type == MOUSEMOVE) {
+ int dragstartx = data->dragstartx;
+ int dragstarty = data->dragstarty;
+ ui_window_to_block(data->region, block, &dragstartx, &dragstarty);
+ data->value = data->origvalue + (horizontal ? mx - dragstartx : dragstarty - my);
+ ui_numedit_apply(C, block, but, data);
+ }
+
+ retval = WM_UI_HANDLER_BREAK;
+ }
+
+ return retval;
+}
+
static int ui_do_but_LISTROW(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
{
if (data->state == BUTTON_STATE_HIGHLIGHT) {
@@ -6192,6 +6238,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
case SCROLL:
retval = ui_do_but_SCROLL(C, block, but, data, event);
break;
+ case GRIP:
+ retval = ui_do_but_GRIP(C, block, but, data, event);
+ break;
case NUM:
retval = ui_do_but_NUM(C, block, but, data, event);
break;
@@ -6819,6 +6868,11 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
else if (type == BUTTON_ACTIVATE_APPLY)
button_activate_state(C, but, BUTTON_STATE_WAIT_FLASH);
+
+ if (but->type == GRIP) {
+ const bool horizontal = (BLI_rctf_size_x(&but->rect) < BLI_rctf_size_y(&but->rect));
+ WM_cursor_modal_set(data->window, horizontal ? BC_EW_ARROWCURSOR : BC_NS_ARROWCURSOR);
+ }
}
static void button_activate_exit(bContext *C, uiBut *but, uiHandleButtonData *data,
@@ -6827,6 +6881,10 @@ static void button_activate_exit(bContext *C, uiBut *but, uiHandleButtonData *da
uiBlock *block = but->block;
uiBut *bt;
+ if (but->type == GRIP) {
+ WM_cursor_modal_restore(data->window);
+ }
+
/* ensure we are in the exit state */
if (data->state != BUTTON_STATE_EXIT)
button_activate_state(C, but, BUTTON_STATE_EXIT);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index a4937514a9d..9fd8acce3ee 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -55,6 +55,7 @@
#include "BKE_displist.h"
#include "BKE_dynamicpaint.h"
#include "BKE_global.h"
+#include "BKE_idcode.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_material.h"
@@ -1290,10 +1291,14 @@ static void do_preview_buttons(bContext *C, void *arg, int event)
}
}
-void uiTemplatePreview(uiLayout *layout, ID *id, int show_buttons, ID *parent, MTex *slot)
+void uiTemplatePreview(uiLayout *layout, bContext *C, ID *id, int show_buttons, ID *parent, MTex *slot,
+ const char *preview_id)
{
uiLayout *row, *col;
uiBlock *block;
+ uiPreview *ui_preview = NULL;
+ ARegion *ar;
+
Material *ma = NULL;
Tex *tex = (Tex *)id;
ID *pid, *pparent;
@@ -1301,6 +1306,8 @@ void uiTemplatePreview(uiLayout *layout, ID *id, int show_buttons, ID *parent, M
PointerRNA material_ptr;
PointerRNA texture_ptr;
+ char _preview_id[UI_MAX_NAME_STR];
+
if (id && !ELEM4(GS(id->name), ID_MA, ID_TE, ID_WO, ID_LA)) {
RNA_warning("Expected ID of type material, texture, lamp or world");
return;
@@ -1326,17 +1333,44 @@ void uiTemplatePreview(uiLayout *layout, ID *id, int show_buttons, ID *parent, M
}
}
+ if (!preview_id || (preview_id[0] == '\0')) {
+ /* If no identifier given, generate one from ID type. */
+ BLI_snprintf(_preview_id, UI_MAX_NAME_STR, "uiPreview_%s", BKE_idcode_to_name(GS(id->name)));
+ preview_id = _preview_id;
+ }
+
+ /* Find or add the uiPreview to the current Region. */
+ ar = CTX_wm_region(C);
+ ui_preview = BLI_findstring(&ar->ui_previews, preview_id, offsetof(uiPreview, preview_id));
+
+ if (!ui_preview) {
+ ui_preview = MEM_callocN(sizeof(uiPreview), "uiPreview");
+ BLI_strncpy(ui_preview->preview_id, preview_id, sizeof(ui_preview->preview_id));
+ ui_preview->height = (short)(UI_UNIT_Y * 5.6f);
+ BLI_addtail(&ar->ui_previews, ui_preview);
+ }
+
+ if (ui_preview->height < UI_UNIT_Y) {
+ ui_preview->height = UI_UNIT_Y;
+ }
+ else if (ui_preview->height > UI_UNIT_Y * 50) { /* Rather high upper limit, yet not insane! */
+ ui_preview->height = UI_UNIT_Y * 50;
+ }
+
/* layout */
block = uiLayoutGetBlock(layout);
row = uiLayoutRow(layout, false);
col = uiLayoutColumn(row, false);
uiLayoutSetKeepAspect(col, true);
-
+
/* add preview */
- uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6, pid, 0.0, 0.0, 0, 0, "");
+ uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X * 10, ui_preview->height, pid, 0.0, 0.0, 0, 0, "");
uiBlockSetDrawExtraFunc(block, ED_preview_draw, pparent, slot);
uiBlockSetHandleFunc(block, do_preview_buttons, NULL);
-
+
+ uiDefIconButS(block, GRIP, 0, ICON_GRIP, 0, 0, UI_UNIT_X * 10, (short)(UI_UNIT_Y * 0.3f), &ui_preview->height,
+ UI_UNIT_Y, UI_UNIT_Y * 50.0f, 0.0f, 0.0f, "");
+
/* add buttons */
if (pid && show_buttons) {
if (GS(pid->name) == ID_MA || (pparent && GS(pparent->name) == ID_MA)) {
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 5f970e4ef3a..ff749289636 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -3552,6 +3552,10 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
wt = widget_type(UI_WTYPE_SCROLL);
break;
+ case GRIP:
+ wt = widget_type(UI_WTYPE_ICON);
+ break;
+
case TRACKPREVIEW:
ui_draw_but_TRACKPREVIEW(ar, but, &tui->wcol_regular, rect);
break;