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:
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.c139
-rw-r--r--source/blender/editors/interface/interface_handlers.c215
-rw-r--r--source/blender/editors/interface/interface_intern.h2
-rw-r--r--source/blender/editors/interface/interface_widgets.c78
-rw-r--r--source/blender/editors/interface/resources.c2
5 files changed, 302 insertions, 134 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 9a06bd21ea2..5ffc6440dc4 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -398,18 +398,21 @@ void uiMenuPopupBoundsBlock(uiBlock *block, int addval, int mx, int my)
static void ui_draw_linkline(uiBut *but, uiLinkLine *line)
{
- float vec1[2], vec2[2];
+ rcti rect;
if(line->from==NULL || line->to==NULL) return;
- vec1[0]= (line->from->x1+line->from->x2)/2.0;
- vec1[1]= (line->from->y1+line->from->y2)/2.0;
- vec2[0]= (line->to->x1+line->to->x2)/2.0;
- vec2[1]= (line->to->y1+line->to->y2)/2.0;
+ rect.xmin= (line->from->x1+line->from->x2)/2.0;
+ rect.ymin= (line->from->y1+line->from->y2)/2.0;
+ rect.xmax= (line->to->x1+line->to->x2)/2.0;
+ rect.ymax= (line->to->y1+line->to->y2)/2.0;
- if(line->flag & UI_SELECT) glColor3ub(100,100,100);
- else glColor3ub(0,0,0);
- fdrawline(vec1[0], vec1[1], vec2[0], vec2[1]);
+ if(line->flag & UI_SELECT)
+ glColor3ub(100,100,100);
+ else
+ glColor3ub(0,0,0);
+
+ ui_draw_link_bezier(&rect);
}
static void ui_draw_links(uiBlock *block)
@@ -475,6 +478,8 @@ static int ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBut
but->selend= oldbut->selend;
but->softmin= oldbut->softmin;
but->softmax= oldbut->softmax;
+ but->linkto[0]= oldbut->linkto[0];
+ but->linkto[1]= oldbut->linkto[1];
found= 1;
oldbut->active= NULL;
@@ -733,8 +738,13 @@ static void ui_is_but_sel(uiBut *but)
/* XXX 2.50 no links supported yet */
-#if 0
-static uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval)
+static int uibut_contains_pt(uiBut *but, short *mval)
+{
+ return 0;
+
+}
+
+uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval)
{
uiBut *bt;
@@ -745,7 +755,7 @@ static uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval)
if (bt) {
if (but->type==LINK && bt->type==INLINK) {
- if( but->link->tocode == (int)bt->min ) {
+ if( but->link->tocode == (int)bt->hardmin ) {
return bt;
}
}
@@ -759,21 +769,6 @@ static uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval)
return NULL;
}
-static int ui_is_a_link(uiBut *from, uiBut *to)
-{
- uiLinkLine *line;
- uiLink *link;
-
- link= from->link;
- if(link) {
- line= link->lines.first;
- while(line) {
- if(line->from==from && line->to==to) return 1;
- line= line->next;
- }
- }
- return 0;
-}
static uiBut *ui_find_inlink(uiBlock *block, void *poin)
{
@@ -839,98 +834,6 @@ void uiComposeLinks(uiBlock *block)
}
}
-static void ui_add_link(uiBut *from, uiBut *to)
-{
- /* in 'from' we have to add a link to 'to' */
- uiLink *link;
- void **oldppoin;
- int a;
-
- if(ui_is_a_link(from, to)) {
- printf("already exists\n");
- return;
- }
-
- link= from->link;
-
- /* are there more pointers allowed? */
- if(link->ppoin) {
- oldppoin= *(link->ppoin);
-
- (*(link->totlink))++;
- *(link->ppoin)= MEM_callocN( *(link->totlink)*sizeof(void *), "new link");
-
- for(a=0; a< (*(link->totlink))-1; a++) {
- (*(link->ppoin))[a]= oldppoin[a];
- }
- (*(link->ppoin))[a]= to->poin;
-
- if(oldppoin) MEM_freeN(oldppoin);
- }
- else {
- *(link->poin)= to->poin;
- }
-
-}
-
-static int ui_do_but_LINK(uiBlock *block, uiBut *but)
-{
- /*
- * This button only visualizes, the dobutton mode
- * can add a new link, but then the whole system
- * should be redrawn/initialized.
- *
- */
- uiBut *bt=0, *bto=NULL;
- short sval[2], mval[2], mvalo[2], first= 1;
-
- uiGetMouse(curarea->win, sval);
- mvalo[0]= sval[0];
- mvalo[1]= sval[1];
-
- while (get_mbut() & L_MOUSE) {
- uiGetMouse(curarea->win, mval);
-
- if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1] || first) {
- /* clear completely, because of drawbuttons */
- bt= ui_get_valid_link_button(block, but, mval);
- if(bt) {
- bt->flag |= UI_ACTIVE;
- ui_draw_but(ar, bt);
- }
- if(bto && bto!=bt) {
- bto->flag &= ~UI_ACTIVE;
- ui_draw_but(ar, bto);
- }
- bto= bt;
-
- if (!first) {
- glutil_draw_front_xor_line(sval[0], sval[1], mvalo[0], mvalo[1]);
- }
- glutil_draw_front_xor_line(sval[0], sval[1], mval[0], mval[1]);
-
- mvalo[0]= mval[0];
- mvalo[1]= mval[1];
-
- first= 0;
- }
- else UI_wait_for_statechange();
- }
-
- if (!first) {
- glutil_draw_front_xor_line(sval[0], sval[1], mvalo[0], mvalo[1]);
- }
-
- if(bt) {
- if(but->type==LINK) ui_add_link(but, bt);
- else ui_add_link(bt, but);
-
- scrarea_queue_winredraw(curarea);
- }
-
- return 0;
-}
-#endif
/* ************************************************ */
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 6ec809b7178..fb5afbf5e36 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -165,6 +165,7 @@ typedef struct uiAfterFunc {
bContextStore *context;
} uiAfterFunc;
+static int ui_mouse_inside_button(ARegion *ar, uiBut *but, int x, int y);
static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state);
static int ui_handler_region_menu(bContext *C, wmEvent *event, void *userdata);
static int ui_handler_popup(bContext *C, wmEvent *event, void *userdata);
@@ -525,6 +526,149 @@ static void ui_apply_but_CHARTAB(bContext *C, uiBut *but, uiHandleButtonData *da
}
#endif
+
+static void ui_delete_active_linkline(uiBlock *block)
+{
+ uiBut *but;
+ uiLink *link;
+ uiLinkLine *line, *nline;
+ int a, b;
+
+ but= block->buttons.first;
+ while(but) {
+ if(but->type==LINK && but->link) {
+ line= but->link->lines.first;
+ while(line) {
+
+ nline= line->next;
+
+ if(line->flag & UI_SELECT) {
+ BLI_remlink(&but->link->lines, line);
+
+ link= line->from->link;
+
+ /* are there more pointers allowed? */
+ if(link->ppoin) {
+
+ if(*(link->totlink)==1) {
+ *(link->totlink)= 0;
+ MEM_freeN(*(link->ppoin));
+ *(link->ppoin)= NULL;
+ }
+ else {
+ b= 0;
+ for(a=0; a< (*(link->totlink)); a++) {
+
+ if( (*(link->ppoin))[a] != line->to->poin ) {
+ (*(link->ppoin))[b]= (*(link->ppoin))[a];
+ b++;
+ }
+ }
+ (*(link->totlink))--;
+ }
+ }
+ else {
+ *(link->poin)= NULL;
+ }
+
+ MEM_freeN(line);
+ }
+ line= nline;
+ }
+ }
+ but= but->next;
+ }
+}
+
+
+static uiLinkLine *ui_is_a_link(uiBut *from, uiBut *to)
+{
+ uiLinkLine *line;
+ uiLink *link;
+
+ link= from->link;
+ if(link) {
+ line= link->lines.first;
+ while(line) {
+ if(line->from==from && line->to==to) return line;
+ line= line->next;
+ }
+ }
+ return NULL;
+}
+
+static void ui_add_link(uiBut *from, uiBut *to)
+{
+ /* in 'from' we have to add a link to 'to' */
+ uiLink *link;
+ uiLinkLine *line;
+ void **oldppoin;
+ int a;
+
+ if( (line= ui_is_a_link(from, to)) ) {
+ line->flag |= UI_SELECT;
+ ui_delete_active_linkline(from->block);
+ printf("already exists, means deletion now\n");
+ return;
+ }
+
+ if (from->type==LINK && to->type==INLINK) {
+ if( from->link->tocode != (int)to->hardmin ) {
+ printf("cannot link\n");
+ return;
+ }
+ }
+ else if(from->type==INLINK && to->type==LINK) {
+ if( to->link->tocode == (int)from->hardmin ) {
+ printf("cannot link\n");
+ return;
+ }
+ }
+
+ link= from->link;
+
+ /* are there more pointers allowed? */
+ if(link->ppoin) {
+ oldppoin= *(link->ppoin);
+
+ (*(link->totlink))++;
+ *(link->ppoin)= MEM_callocN( *(link->totlink)*sizeof(void *), "new link");
+
+ for(a=0; a< (*(link->totlink))-1; a++) {
+ (*(link->ppoin))[a]= oldppoin[a];
+ }
+ (*(link->ppoin))[a]= to->poin;
+
+ if(oldppoin) MEM_freeN(oldppoin);
+ }
+ else {
+ *(link->poin)= to->poin;
+ }
+
+}
+
+
+static void ui_apply_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data)
+{
+ ARegion *ar= CTX_wm_region(C);
+ uiBut *bt;
+
+ for(bt= but->block->buttons.first; bt; bt= bt->next) {
+ if( ui_mouse_inside_button(ar, bt, but->linkto[0]+ar->winrct.xmin, but->linkto[1]+ar->winrct.ymin) )
+ break;
+ }
+ if(bt && bt!=but) {
+
+ if(but->type==LINK) ui_add_link(but, bt);
+ else ui_add_link(bt, but);
+
+ ui_apply_but_func(C, but);
+ data->retval= but->retval;
+ }
+ data->applied= 1;
+}
+
+
static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, int interactive)
{
char *editstr;
@@ -640,6 +784,7 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
#endif
case LINK:
case INLINK:
+ ui_apply_but_LINK(C, but, data);
break;
default:
break;
@@ -2806,6 +2951,38 @@ static int ui_do_but_CHARTAB(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
}
#endif
+
+static int ui_do_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data, wmEvent *event)
+{
+ ARegion *ar= CTX_wm_region(C);
+
+ but->linkto[0]= event->x-ar->winrct.xmin;
+ but->linkto[1]= event->y-ar->winrct.ymin;
+
+ if(data->state == BUTTON_STATE_HIGHLIGHT) {
+ if(event->type == LEFTMOUSE && event->val==KM_PRESS) {
+ button_activate_state(C, but, BUTTON_STATE_WAIT_RELEASE);
+ return WM_UI_HANDLER_BREAK;
+ }
+ else if(event->type == LEFTMOUSE && but->block->handle) {
+ button_activate_state(C, but, BUTTON_STATE_EXIT);
+ return WM_UI_HANDLER_BREAK;
+ }
+ }
+ else if(data->state == BUTTON_STATE_WAIT_RELEASE) {
+
+ if(event->type == LEFTMOUSE && event->val!=KM_PRESS) {
+ if(!(but->flag & UI_SELECT))
+ data->cancel= 1;
+ button_activate_state(C, but, BUTTON_STATE_EXIT);
+ return WM_UI_HANDLER_BREAK;
+ }
+ }
+
+ return WM_UI_HANDLER_CONTINUE;
+}
+
+
static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
{
uiHandleButtonData *data;
@@ -2951,13 +3128,11 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
retval= ui_do_but_CHARTAB(C, block, but, data, event);
break;
#endif
- /* XXX 2.50 links not implemented yet */
-#if 0
+
case LINK:
case INLINK:
- retval= retval= ui_do_but_LINK(block, but);
+ retval= ui_do_but_LINK(C, but, data, event);
break;
-#endif
}
return retval;
@@ -3421,21 +3596,29 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but)
else if(data->state == BUTTON_STATE_WAIT_RELEASE) {
switch(event->type) {
case MOUSEMOVE:
- /* deselect the button when moving the mouse away */
- if(ui_mouse_inside_button(ar, but, event->x, event->y)) {
- if(!(but->flag & UI_SELECT)) {
- but->flag |= UI_SELECT;
- data->cancel= 0;
- ED_region_tag_redraw(data->region);
- }
+
+ if(ELEM(but->type,LINK, INLINK)) {
+ but->flag |= UI_SELECT;
+ ui_do_button(C, block, but, event);
+ ED_region_tag_redraw(data->region);
}
else {
- if(but->flag & UI_SELECT) {
- but->flag &= ~UI_SELECT;
- data->cancel= 1;
- ED_region_tag_redraw(data->region);
+ /* deselect the button when moving the mouse away */
+ if(ui_mouse_inside_button(ar, but, event->x, event->y)) {
+ if(!(but->flag & UI_SELECT)) {
+ but->flag |= UI_SELECT;
+ data->cancel= 0;
+ ED_region_tag_redraw(data->region);
+ }
}
- }
+ else {
+ if(but->flag & UI_SELECT) {
+ but->flag &= ~UI_SELECT;
+ data->cancel= 1;
+ ED_region_tag_redraw(data->region);
+ }
+ }
+ }
break;
default:
/* otherwise catch mouse release event */
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 83d3ec7fc46..3aed2a7c299 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -181,6 +181,7 @@ struct uiBut {
void *search_arg;
uiLink *link;
+ short linkto[2];
char *tip, *lockstr;
@@ -408,6 +409,7 @@ extern int ui_button_is_active(struct ARegion *ar);
void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3);
void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect);
void ui_draw_search_back(struct uiStyle *style, uiBlock *block, rcti *rect);
+void ui_draw_link_bezier(rcti *rect);
extern void ui_draw_but(const struct bContext *C, ARegion *ar, struct uiStyle *style, uiBut *but, rcti *rect);
/* theme color init */
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 52a77be0b01..119fd8a3fe5 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -40,6 +40,7 @@
#include "BLI_rect.h"
#include "BKE_context.h"
+#include "BKE_curve.h"
#include "BKE_global.h"
#include "BKE_utildefines.h"
@@ -1550,6 +1551,76 @@ static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int round
}
+
+static int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol)
+{
+ float dist, vec[4][2];
+
+ vec[0][0]= rect->xmin;
+ vec[0][1]= rect->ymin;
+ vec[3][0]= rect->xmax;
+ vec[3][1]= rect->ymax;
+
+ dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
+
+ vec[1][0]= vec[0][0]+dist;
+ vec[1][1]= vec[0][1];
+
+ vec[2][0]= vec[3][0]-dist;
+ vec[2][1]= vec[3][1];
+
+ forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, 2);
+ forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, 2);
+
+ return 1;
+}
+
+#define LINK_RESOL 24
+void ui_draw_link_bezier(rcti *rect)
+{
+ float coord_array[LINK_RESOL+1][2];
+
+ if(ui_link_bezier_points(rect, coord_array, LINK_RESOL)) {
+ float dist;
+ int i;
+
+ /* we can reuse the dist variable here to increment the GL curve eval amount*/
+ dist = 1.0f/(float)LINK_RESOL;
+
+ glEnable(GL_BLEND);
+ glEnable(GL_LINE_SMOOTH);
+
+ glBegin(GL_LINE_STRIP);
+ for(i=0; i<=LINK_RESOL; i++) {
+ glVertex2fv(coord_array[i]);
+ }
+ glEnd();
+
+ glDisable(GL_BLEND);
+ glDisable(GL_LINE_SMOOTH);
+
+ }
+}
+
+
+static void widget_link(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
+{
+
+ if(but->flag & UI_SELECT) {
+ rcti rectlink;
+
+ UI_ThemeColor(TH_TEXT_HI);
+
+ rectlink.xmin= (rect->xmin+rect->xmax)/2;
+ rectlink.ymin= (rect->ymin+rect->ymax)/2;
+ rectlink.xmax= but->linkto[0];
+ rectlink.ymax= but->linkto[1];
+
+ ui_draw_link_bezier(&rectlink);
+ }
+}
+
+
static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
{
uiWidgetBase wtb, wtb1;
@@ -2077,6 +2148,13 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
case ROUNDBOX:
wt= widget_type(UI_WTYPE_BOX);
break;
+
+ case LINK:
+ case INLINK:
+ wt= widget_type(UI_WTYPE_ICON);
+ wt->custom= widget_link;
+
+ break;
case BUT_EXTRA:
widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index da0f66af02e..0a65718b708 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -614,6 +614,7 @@ void ui_theme_init_userdef(void)
/* space logic */
btheme->tlogic= btheme->tv3d;
+ SETCOL(btheme->tlogic.back, 100, 100, 100, 255);
}
@@ -1245,6 +1246,7 @@ void init_userdef_do_versions(void)
if(btheme->tlogic.syntaxn[3]==0) {
/* re-uses syntax color storage */
btheme->tlogic= btheme->tv3d;
+ SETCOL(btheme->tlogic.back, 100, 100, 100, 255);
}
}
}