Page MenuHome

text_selection.txt

Authored By
Matt Ebb (broken)
Nov 13 2013, 1:00 PM
Size
17 KB
Subscribers
None

text_selection.txt

Index: source/blender//include/BIF_resources.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/include/BIF_resources.h,v
retrieving revision 1.47
diff -u -r1.47 BIF_resources.h
--- source/blender//include/BIF_resources.h 19 Nov 2005 10:55:06 -0000 1.47
+++ source/blender//include/BIF_resources.h 19 Nov 2005 21:38:18 -0000
@@ -409,6 +409,8 @@
TH_REDALERT,
TH_CUSTOM,
+ TH_BUT_TEXTFIELD_HI,
+
TH_THEMEUI,
// common colors among spaces
Index: source/blender//include/interface.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/include/interface.h,v
retrieving revision 1.26
diff -u -r1.26 interface.h
--- source/blender//include/interface.h 19 Nov 2005 15:16:34 -0000 1.26
+++ source/blender//include/interface.h 19 Nov 2005 21:38:18 -0000
@@ -63,7 +63,11 @@
#define PNL_TABBED 8
#define PNL_OVERLAP 16
-
+/* Button text selection:
+ * extension direction, selextend, inside ui_do_but_TEX */
+#define EXTEND_LEFT 1
+#define EXTEND_RIGHT 2
+#define SELWIDTH (but->selend - but->selsta)
typedef struct {
short xim, yim;
@@ -103,7 +107,7 @@
struct uiBut {
uiBut *next, *prev;
- short type, pointype, bit, bitnr, retval, strwidth, ofs, pos;
+ short type, pointype, bit, bitnr, retval, strwidth, ofs, pos, selsta, selend;
int flag;
char *str;
Index: source/blender//makesdna/DNA_userdef_types.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_userdef_types.h,v
retrieving revision 1.50
diff -u -r1.50 DNA_userdef_types.h
--- source/blender//makesdna/DNA_userdef_types.h 19 Nov 2005 15:16:34 -0000 1.50
+++ source/blender//makesdna/DNA_userdef_types.h 19 Nov 2005 21:38:18 -0000
@@ -48,6 +48,7 @@
char setting2[4];
char num[4];
char textfield[4];
+ char textfield_hi[4];
char popup[4];
char text[4];
char text_hi[4];
@@ -56,10 +57,9 @@
char menu_hilite[4];
char menu_text[4];
char menu_text_hi[4];
-
- char but_drawtype, pad;
- short pad1;
- int pad2;
+
+ char but_drawtype;
+ char pad1[3];
} ThemeUI;
Index: source/blender//python/api2_2x/windowTheme.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/windowTheme.c,v
retrieving revision 1.9
diff -u -r1.9 windowTheme.c
--- source/blender//python/api2_2x/windowTheme.c 19 Nov 2005 10:55:06 -0000 1.9
+++ source/blender//python/api2_2x/windowTheme.c 19 Nov 2005 21:38:21 -0000
@@ -361,6 +361,7 @@
ELSEIF_TUI_RGBA( setting2 )
ELSEIF_TUI_RGBA( num )
ELSEIF_TUI_RGBA( textfield )
+ ELSEIF_TUI_RGBA( textfield_hi )
ELSEIF_TUI_RGBA( popup )
ELSEIF_TUI_RGBA( text )
ELSEIF_TUI_RGBA( text_hi )
@@ -375,7 +376,7 @@
attrib = Py_BuildValue( "[ssssssssssssssssss]", "theme",
"outline", "neutral", "action",
"setting", "setting1", "setting2",
- "num", "textfield", "popup", "text",
+ "num", "textfield", "textfield_hi", "popup", "text",
"text_hi", "menu_back", "menu_item",
"menu_hilite", "menu_text",
"menu_text_hi", "drawType" );
@@ -401,6 +402,7 @@
ELSEIF_TUI_RGBA( setting2 )
ELSEIF_TUI_RGBA( num )
ELSEIF_TUI_RGBA( textfield )
+ ELSEIF_TUI_RGBA( textfield_hi )
ELSEIF_TUI_RGBA( popup )
ELSEIF_TUI_RGBA( text )
ELSEIF_TUI_RGBA( text_hi )
Index: source/blender//python/api2_2x/doc/Theme.py
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/doc/Theme.py,v
retrieving revision 1.5
diff -u -r1.5 Theme.py
--- source/blender//python/api2_2x/doc/Theme.py 11 Oct 2005 15:11:39 -0000 1.5
+++ source/blender//python/api2_2x/doc/Theme.py 19 Nov 2005 21:38:21 -0000
@@ -130,6 +130,7 @@
@ivar setting2: theme rgba var.
@ivar num: theme rgba var.
@ivar textfield: theme rgba var.
+ @ivar textfield_hi: theme rgba var.
@ivar popup: theme rgba var.
@ivar text: theme rgba var.
@ivar text_hi: theme rgba var.
Index: source/blender//src/interface.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/interface.c,v
retrieving revision 1.213
diff -u -r1.213 interface.c
--- source/blender//src/interface.c 19 Nov 2005 15:16:34 -0000 1.213
+++ source/blender//src/interface.c 19 Nov 2005 21:38:22 -0000
@@ -1283,6 +1283,51 @@
return NULL;
}
+
+/* ************* IN-BUTTON TEXT SELECTION/EDITING ************* */
+
+static short ui_delete_selection_edittext(uiBut *but)
+{
+ int x;
+ short deletedwidth=0;
+ char *str;
+
+ str= (char *)but->poin;
+
+ deletedwidth = SELWIDTH;
+
+ for(x=0; x< strlen(str); x++) {
+ if (but->selend + x <= strlen(str) ) {
+ str[but->selsta + x]= str[but->selend + x];
+ } else {
+ str[but->selsta + x]= '\0';
+ break;
+ }
+ }
+ but->pos = but->selend = but->selsta;
+
+ return deletedwidth;
+}
+
+static void ui_set_cursor_pos_edittext(uiBut *but, short sx)
+{
+ char backstr[UI_MAX_DRAW_STR];
+
+ BLI_strncpy(backstr, but->drawstr, UI_MAX_DRAW_STR);
+ but->pos= strlen(backstr)-but->ofs;
+
+ while((but->aspect*BIF_GetStringWidth(but->font, backstr+but->ofs, 0) + but->x1) > sx) {
+ if (but->pos <= 0) break;
+ but->pos--;
+ backstr[but->pos+but->ofs] = 0;
+ }
+
+ but->pos -= strlen(but->str);
+ but->pos += but->ofs;
+ if(but->pos<0) but->pos= 0;
+}
+
+
/* ************* EVENTS ************* */
void uiGetMouse(int win, short *adr)
@@ -1495,9 +1540,9 @@
static int ui_do_but_TEX(uiBut *but)
{
unsigned short dev;
- short x, mval[2], len=0, dodraw;
+ short x, mval[2], len=0, dodraw, selextend=0;
char *str, backstr[UI_MAX_DRAW_STR];
- short capturing;
+ short capturing, sx, sy;
str= (char *)but->poin;
@@ -1505,20 +1550,15 @@
uiGetMouse(mywinget(), mval);
- /* calculate cursor pos with current mousecoords */
+
BLI_strncpy(backstr, but->drawstr, UI_MAX_DRAW_STR);
- but->pos= strlen(backstr)-but->ofs;
-
- while((but->aspect*BIF_GetStringWidth(but->font, backstr+but->ofs, 0) + but->x1) > mval[0]) {
- if (but->pos <= 0) break;
- but->pos--;
- backstr[but->pos+but->ofs] = 0;
- }
- but->pos -= strlen(but->str);
- but->pos += but->ofs;
- if(but->pos<0) but->pos= 0;
-
+ /* set cursor pos to the end of the text */
+ but->pos = strlen(but->str);
+
+ but->selsta = 0;
+ but->selend = strlen(but->drawstr) - strlen(but->str);
+
/* backup */
BLI_strncpy(backstr, but->poin, UI_MAX_DRAW_STR);
@@ -1538,21 +1578,59 @@
dev = extern_qread_ext(&val, &ascii);
if(dev==INPUTCHANGE) break;
- else if(get_mbut() & L_MOUSE) break;
else if(get_mbut() & R_MOUSE) break;
+ else if(get_mbut() & L_MOUSE) {
+ uiGetMouse(mywinget(), mval);
+ sx = mval[0]; sy = mval[1];
+
+ if ((but->y1 <= sy) && (sy <= but->y2) && (but->x1 <= sx) && (sx <= but->x2)) {
+ ui_set_cursor_pos_edittext(but, mval[0]);
+
+ but->selsta = but->selend = but->pos;
+
+ /* drag text select */
+ while (get_mbut() & L_MOUSE) {
+ uiGetMouse(mywinget(), mval);
+
+ if (mval[0] > sx) selextend = EXTEND_RIGHT;
+ else if (mval[0] < sx) selextend = EXTEND_LEFT;
+
+ ui_set_cursor_pos_edittext(but, mval[0]);
+
+ if (selextend == EXTEND_RIGHT) but->selend = but->pos;
+ if (selextend == EXTEND_LEFT) but->selsta = but->pos;
+
+ ui_check_but(but);
+ ui_draw_but(but);
+ ui_block_flush_back(but->block);
+
+ PIL_sleep_ms(10);
+ }
+ dodraw= 1;
+ } else break;
+ }
else if(dev==ESCKEY) break;
else if(dev==MOUSEX) val= 0;
else if(dev==MOUSEY) val= 0;
if(ascii) {
- if(len < but->max) {
- for(x= but->max; x>but->pos; x--)
- str[x]= str[x-1];
- str[but->pos]= ascii;
- but->pos++;
- len++;
- str[len]= '\0';
- dodraw= 1;
+ if(len <= but->max) {
+
+ /* type over the current selection */
+ if (SELWIDTH > 0) {
+ len -= ui_delete_selection_edittext(but);
+ }
+
+ /* add ascii characters */
+ if(len < but->max) {
+ for(x= but->max; x>but->pos; x--)
+ str[x]= str[x-1];
+ str[but->pos]= ascii;
+ but->pos++;
+ len++;
+ str[len]= '\0';
+ dodraw= 1;
+ }
}
}
else if(val) {
@@ -1560,25 +1638,125 @@
switch (dev) {
case RIGHTARROWKEY:
- if(G.qual & LR_SHIFTKEY) but->pos= strlen(str);
- else but->pos++;
- if(but->pos>strlen(str)) but->pos= strlen(str);
+ /* if there's a selection */
+ if (SELWIDTH > 0) {
+ /* extend the selection based on the first direction taken */
+ if(G.qual & LR_SHIFTKEY) {
+ if (!selextend) {
+ selextend = EXTEND_RIGHT;
+ }
+ if (selextend == EXTEND_RIGHT) {
+ but->selend++;
+ if (but->selend > len) but->selend = len;
+ } else if (selextend == EXTEND_LEFT) {
+ but->selsta++;
+ /* if the selection start has gone past the end,
+ * flip them so they're in sync again */
+ if (but->selsta == but->selend) {
+ but->pos = but->selsta;
+ selextend = EXTEND_RIGHT;
+ }
+ }
+ } else {
+ but->selsta = but->pos = but->selend;
+ selextend = 0;
+ }
+ } else {
+ if(G.qual & LR_SHIFTKEY) {
+ /* make a selection, starting from the cursor position */
+ but->selsta = but->pos;
+
+ but->pos++;
+ if(but->pos>strlen(str)) but->pos= strlen(str);
+
+ but->selend = but->pos;
+ } else if(G.qual & LR_CTRLKEY) {
+ while(but->pos < len){
+ but->pos++;
+#ifdef WIN32
+ if(str[but->pos]=='\\') break;
+#else
+ if(str[but->pos]=='/') break;
+#endif
+ }
+ } else {
+ but->pos++;
+ if(but->pos>strlen(str)) but->pos= strlen(str);
+ }
+ }
dodraw= 1;
break;
case LEFTARROWKEY:
- if(G.qual & LR_SHIFTKEY) but->pos= 0;
- else if(but->pos>0) but->pos--;
+ /* if there's a selection */
+ if (SELWIDTH > 0) {
+ /* extend the selection based on the first direction taken */
+ if(G.qual & LR_SHIFTKEY) {
+ if (!selextend) {
+ selextend = EXTEND_LEFT;
+ }
+ if (selextend == EXTEND_LEFT) {
+ but->selsta--;
+ if (but->selsta < 0) but->selsta = 0;
+ } else if (selextend == EXTEND_RIGHT) {
+ but->selend--;
+ /* if the selection start has gone past the end,
+ * flip them so they're in sync again */
+ if (but->selsta == but->selend) {
+ but->pos = but->selsta;
+ selextend = EXTEND_LEFT;
+ }
+ }
+ } else {
+ but->pos = but->selend = but->selsta;
+ selextend = 0;
+ }
+ } else {
+ if(G.qual & LR_SHIFTKEY) {
+ /* make a selection, starting from the cursor position */
+ but->selend = but->pos;
+
+ but->pos--;
+ if(but->pos<0) but->pos= 0;
+
+ but->selsta = but->pos;
+ } else if(G.qual & LR_CTRLKEY) {
+ while(but->pos > 0){
+ but->pos--;
+#ifdef WIN32
+ if(str[but->pos]=='\\') break;
+#else
+ if(str[but->pos]=='/') break;
+#endif
+ }
+ } else {
+ if(but->pos>0) but->pos--;
+ }
+ }
dodraw= 1;
break;
+ case DOWNARROWKEY:
case ENDKEY:
- but->pos= strlen(str);
+ if(G.qual & LR_SHIFTKEY) {
+ but->selsta = but->pos;
+ but->selend = strlen(str);
+ selextend = EXTEND_RIGHT;
+ } else {
+ but->selsta = but->selend = but->pos= strlen(str);
+ }
dodraw= 1;
break;
-
+
+ case UPARROWKEY:
case HOMEKEY:
- but->pos= 0;
+ if(G.qual & LR_SHIFTKEY) {
+ but->selend = but->pos;
+ but->selsta = 0;
+ selextend = EXTEND_LEFT;
+ } else {
+ but->selsta = but->selend = but->pos= 0;
+ }
dodraw= 1;
break;
@@ -1588,7 +1766,13 @@
break;
case DELKEY:
- if(but->pos>=0 && but->pos<strlen(str)) {
+ if (SELWIDTH > 0) {
+ len -= ui_delete_selection_edittext(but);
+
+ if (len < 0) len = 0;
+ dodraw=1;
+ }
+ else if(but->pos>=0 && but->pos<strlen(str)) {
for(x=but->pos; x<=strlen(str); x++)
str[x]= str[x+1];
str[--len]='\0';
@@ -1598,7 +1782,13 @@
case BACKSPACEKEY:
if(len!=0) {
- if(get_qual() & LR_SHIFTKEY) {
+ if (SELWIDTH > 0) {
+ len -= ui_delete_selection_edittext(but);
+
+ if (len < 0) len = 0;
+ dodraw=1;
+ }
+ else if(get_qual() & LR_SHIFTKEY) {
str[0]= 0;
but->pos= 0;
len= 0;
@@ -1613,6 +1803,7 @@
}
}
break;
+
case TABKEY:
if(but->autocomplete_func) {
but->autocomplete_func(str, but->autofunc_arg);
@@ -5448,7 +5639,7 @@
}
}
- uiBoundsBlock(block, 2);
+ uiBoundsBlock(block, 1);
event= uiDoBlocks(&listb, 0);
@@ -5596,7 +5787,7 @@
//uiDefButI(block, BUTM, B_NOP, md->items[a].str, x1, y1, (short)(width-(rows>1)), (short)(boxh-1), &val, (float)md->items[a].retval, 0.0, 0, 0, "");
}
- uiBoundsBlock(block, 3);
+ uiBoundsBlock(block, 1);
event= uiDoBlocks(&listb, 0);
Index: source/blender//src/interface_draw.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/interface_draw.c,v
retrieving revision 1.47
diff -u -r1.47 interface_draw.c
--- source/blender//src/interface_draw.c 28 Oct 2005 15:36:09 -0000 1.47
+++ source/blender//src/interface_draw.c 19 Nov 2005 21:38:22 -0000
@@ -1452,6 +1452,8 @@
float x;
int len;
char *cpoin;
+ short t, pos, ch;
+ short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw;
/* check for button text label */
if (but->type == ICONTEXTROW) {
@@ -1459,25 +1461,53 @@
}
else {
- // text button cursor
+ /* text button selection and cursor */
if(but->pos != -1) {
- short t, pos, ch;
-
- pos= but->pos+strlen(but->str);
- if(pos >= but->ofs) {
- if(but->drawstr[0]!=0) {
- ch= but->drawstr[pos];
- but->drawstr[pos]= 0;
-
- t= but->aspect*BIF_GetStringWidth(but->font, but->drawstr+but->ofs, (U.transopts & USER_TR_BUTTONS)) + 3;
- but->drawstr[pos]= ch;
+ if (SELWIDTH > 0) {
+ /* text button selection */
+ selsta_tmp = but->selsta + strlen(but->str);
+ selend_tmp = but->selend + strlen(but->str);
+ if (but->ofs >= strlen(but->str))
+ selsta_tmp += (but->ofs - strlen(but->str));
+
+ if(but->drawstr[0]!=0) {
+ ch= but->drawstr[selsta_tmp];
+ but->drawstr[selsta_tmp]= 0;
+
+ selsta_draw = but->aspect*BIF_GetStringWidth(but->font, but->drawstr+but->ofs, (U.transopts & USER_TR_BUTTONS)) + 3;
+
+ but->drawstr[selsta_tmp]= ch;
+
+
+ ch= but->drawstr[selend_tmp];
+ but->drawstr[selend_tmp]= 0;
+
+ selwidth_draw = but->aspect*BIF_GetStringWidth(but->font, but->drawstr+but->ofs, (U.transopts & USER_TR_BUTTONS)) + 3;
+
+ but->drawstr[selend_tmp]= ch;
+
+ BIF_ThemeColor(TH_BUT_TEXTFIELD_HI);
+ glRects(but->x1+selsta_draw+1, but->y1+2, but->x1+selwidth_draw+1, but->y2-2);
+ }
+ } else {
+ /* text cursor */
+ pos= but->pos+strlen(but->str);
+ if(pos >= but->ofs) {
+ if(but->drawstr[0]!=0) {
+ ch= but->drawstr[pos];
+ but->drawstr[pos]= 0;
+
+ t= but->aspect*BIF_GetStringWidth(but->font, but->drawstr+but->ofs, (U.transopts & USER_TR_BUTTONS)) + 3;
+
+ but->drawstr[pos]= ch;
+ }
+ else t= 3;
+
+ glColor3ub(255,0,0);
+ glRects(but->x1+t, but->y1+2, but->x1+t+2, but->y2-2);
}
- else t= 3;
-
- glColor3ub(255,0,0);
- glRects(but->x1+t, but->y1+2, but->x1+t+3, but->y2-2);
- }
+ }
}
if(but->drawstr[0]!=0) {
int transopts;
Index: source/blender//src/resources.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/resources.c,v
retrieving revision 1.51
diff -u -r1.51 resources.c
--- source/blender//src/resources.c 19 Nov 2005 11:06:29 -0000 1.51
+++ source/blender//src/resources.c 19 Nov 2005 21:38:23 -0000
@@ -674,6 +674,8 @@
cp= btheme->tui.num; break;
case TH_BUT_TEXTFIELD:
cp= btheme->tui.textfield; break;
+ case TH_BUT_TEXTFIELD_HI:
+ cp= btheme->tui.textfield_hi; break;
case TH_BUT_POPUP:
cp= btheme->tui.popup; break;
case TH_BUT_TEXT:
@@ -872,6 +874,7 @@
SETCOL(btheme->tui.setting2, 0xA1,0x99,0xA7, 255);
SETCOL(btheme->tui.num, 0x90,0x90,0x90, 255);
SETCOL(btheme->tui.textfield, 0x90,0x90,0x90, 255);
+ SETCOL(btheme->tui.textfield_hi,0xc6,0x77,0x77, 255);
SETCOL(btheme->tui.popup, 0xA0,0xA0,0xA0, 255);
SETCOL(btheme->tui.text, 0,0,0, 255);
@@ -1038,6 +1041,7 @@
sprintf(str, "Special Setting 2 %%x%d|", TH_BUT_SETTING2); strcat(cp, str);
sprintf(str, "Number Input %%x%d|", TH_BUT_NUM); strcat(cp, str);
sprintf(str, "Text Input %%x%d|", TH_BUT_TEXTFIELD); strcat(cp, str);
+ sprintf(str, "Text Input Highlight %%x%d|", TH_BUT_TEXTFIELD_HI); strcat(cp, str);
sprintf(str, "Popup %%x%d|", TH_BUT_POPUP); strcat(cp, str);
sprintf(str, "Text %%x%d|", TH_BUT_TEXT); strcat(cp, str);
sprintf(str, "Text Highlight %%x%d|", TH_BUT_TEXT_HI); strcat(cp, str);
Index: source/blender//src/usiblender.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/usiblender.c,v
retrieving revision 1.94
diff -u -r1.94 usiblender.c
--- source/blender//src/usiblender.c 19 Nov 2005 15:16:34 -0000 1.94
+++ source/blender//src/usiblender.c 19 Nov 2005 21:38:24 -0000
@@ -259,7 +259,17 @@
/* TEMPORAL, remove me! (ton) */
U.uiflag |= USER_PLAINMENUS;
}
+
+ /* check for text field selection highlight, set it to text editor highlight by default */
+ if(btheme->tui.textfield_hi[3]==0) {
+ SETCOL(btheme->tui.textfield_hi,
+ btheme->text.shade2[0],
+ btheme->text.shade2[1],
+ btheme->text.shade2[2],
+ 255);
+ }
}
+
if(U.obcenter_dia==0) U.obcenter_dia= 6;
}

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
45/6c/4527e4c2055dde06ab7f5014cb94

Event Timeline