Page MenuHome

context_menus.patch

File Metadata

Author
Matthias Derer (georgeblunt)
Created
Nov 13 2013, 1:00 PM

context_menus.patch

Index: source/blender/src/interface.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/interface.c,v
retrieving revision 1.227
diff -u -r1.227 interface.c
--- source/blender/src/interface.c 13 Mar 2006 02:22:48 -0000 1.227
+++ source/blender/src/interface.c 27 Mar 2006 22:19:04 -0000
@@ -4442,6 +4442,258 @@
}
}
if(but->flag & UI_ACTIVE) active= 1;
+
+ /* Context Menus: */
+
+ if(uevent->event==RIGHTMOUSE){
+ /* ContextMenu for NUM and NUMSLI */
+ if(but->type == NUM || but->type == NUMSLI){
+
+ /* create menu */
+ char menu[400]; /* 400 should be plenty */
+ char line[100]; /* same here */
+
+ /* title */
+ strcpy(menu, "BUTTON MENU%t");
+
+ /* min */
+ if(but->min != 0){
+ sprintf(line, "|Min%%x%d", 1);
+ strcat(menu, line);
+ }
+
+ /* zero */
+ if(but->min <= 0){
+ sprintf(line, "|Zero%%x%d", 6);
+ strcat(menu, line);
+ }
+
+ /* percentages for sliders */
+ if(but->type == NUMSLI){
+ sprintf(line, "|25%c %%x%d|50%c %%x%d|75%c %%x%d", '%', 7, '%', 8, '%', 9);
+ strcat(menu, line);
+ }
+
+ /* max */
+ sprintf(line, "|Max%%x%d", 2);
+ strcat(menu, line);
+
+ /* 'flip to negative' for values, that can be below zero */
+ if(but->min < 0){
+ sprintf(line, "|Flip to Negative%%x%d", 3);
+ strcat(menu, line);
+ }
+
+ /* copy/paste */
+ sprintf(line, "|Copy%%x%d|Paste%%x%d", 4, 5);
+ strcat(menu, line);
+
+ int chosenVar = pupmenu(menu);
+ if(chosenVar > 0){
+ double newVal; /* stores new value that is going to be written when setNewVal == 1 */
+ int setNewVal = 0; /* set to 1 when a new Value has to be written */
+
+ /* set to min */
+ if(chosenVar == 1){
+ newVal = but->min;
+ setNewVal = 1;
+ }
+
+ /* set to zero */
+ if(chosenVar == 6){
+ newVal = 0;
+ setNewVal = 1;
+ }
+
+ /* 25% */
+ if(chosenVar == 7){
+ newVal = (but->max - but->min) * 0.25 + but->min;
+ setNewVal = 1;
+ }
+
+ /* 50% */
+ if(chosenVar == 8){
+ newVal = (but->max - but->min) * 0.5 + but->min;
+ setNewVal = 1;
+ }
+
+ /* 75% */
+ if(chosenVar == 9){
+ newVal = (but->max - but->min) * 0.75 + but->min;
+ setNewVal = 1;
+ }
+
+ /* set to max */
+ if(chosenVar == 2){
+ newVal = but->max;
+ setNewVal = 1;
+ }
+
+ /* Flip to Negative */
+ if(chosenVar == 3){
+ newVal = -(ui_get_but_val(but));
+ setNewVal = 1;
+ }
+
+ /* copy */
+ if(chosenVar == 4){
+ ui_but_copy_paste(but, 'c');
+ return UI_RETURN;
+ }
+
+ /* paste */
+ if(chosenVar == 5){
+ ui_but_copy_paste(but, 'v');
+ ui_check_but(but);
+ ui_draw_but(but);
+ scrarea_queue_winredraw(curarea);
+ return UI_RETURN;
+ }
+
+ /* set new Value and redraw button: */
+ if(setNewVal == 1){
+ ui_set_but_val(but, newVal);
+ ui_check_but(but);
+ ui_draw_but(but);
+ BIF_preview_changed(ID_MA);
+ scrarea_queue_winredraw(curarea);
+ return UI_RETURN;
+ }
+
+ }
+ else{
+ return UI_RETURN;
+ }
+ }
+
+ /* ContextMenu for COL */
+ else if(but->type == COL){
+ void *poin;
+ float storedhsv[3]; /* stores the current hsv values of the color button (used when calculating new saturation */
+ float storedrgb[3]; /* stores current rgb values (used when calculating white/black/invert */
+ int colorChanged = 0; /* indicates a changed color so it can be written */
+ float changeFactor[3]; /* used in black/white/invert */
+
+ /* write storedrgb */
+ poin = but->poin;
+ if(but->pointype==FLO){
+ float *fp= (float *) poin;
+ storedrgb[0] = fp[0];
+ storedrgb[1] = fp[1];
+ storedrgb[2] = fp[2];
+ }
+ else if(but->pointype==CHA){
+ char *cp= (char *) poin;
+ storedrgb[0] = (float)cp[0];
+ storedrgb[1] = (float)cp[1];
+ storedrgb[2] = (float)cp[2];
+ }
+
+ /* write storedhsv */
+ rgb_to_hsv(storedrgb[0], storedrgb[1], storedrgb[2], &storedhsv[0], &storedhsv[1], &storedhsv[2]);
+
+ short chosenVar = pupmenu("COLOR MENU%t|White|Black|Invert|Saturate(step)|Saturate(full)|Desaturate(step)|Desaturate(full)|Copy|Paste");
+ if(chosenVar > 0){
+
+ /* set to white */
+ if(chosenVar == 1){
+ changeFactor[0] = 1;
+ changeFactor[1] = 1;
+ changeFactor[2] = 1;
+ colorChanged = 1;
+ }
+
+ /* set to black */
+ if(chosenVar == 2){
+ changeFactor[0] = 0;
+ changeFactor[1] = 0;
+ changeFactor[2] = 0;
+ colorChanged = 1;
+ }
+
+ /* invert */
+ if(chosenVar == 3){
+ changeFactor[0] = 1 - storedrgb[0];
+ changeFactor[1] = 1 - storedrgb[1];
+ changeFactor[2] = 1 - storedrgb[2];
+ colorChanged = 1;
+ }
+
+ /* saturate(step) */
+ if(chosenVar == 4){
+ storedhsv[1] = storedhsv[1] + 0.1;
+ if(storedhsv[1] > 1) storedhsv[1] = 1; /* make sure saturation isn't larger than 1 */
+ hsv_to_rgb(storedhsv[0], storedhsv[1], storedhsv[2], &changeFactor[0], &changeFactor[1], &changeFactor[2]);
+ colorChanged = 1;
+ }
+
+ /* saturate(full) */
+ if(chosenVar == 5){
+ storedhsv[1] = 1;
+ hsv_to_rgb(storedhsv[0], storedhsv[1], storedhsv[2], &changeFactor[0], &changeFactor[1], &changeFactor[2]);
+ colorChanged = 1;
+ }
+
+ /* desaturate(step) */
+ if(chosenVar == 6){
+ storedhsv[1] = storedhsv[1] - 0.1;
+ if(storedhsv[1] < 0) storedhsv[1] = 0; /* make sure saturation isn't less than 0 */
+ hsv_to_rgb(storedhsv[0], storedhsv[1], storedhsv[2], &changeFactor[0], &changeFactor[1], &changeFactor[2]);
+ colorChanged = 1;
+ }
+
+ /* desaturate(full) */
+ if(chosenVar == 7){
+ storedhsv[1] = 0;
+ hsv_to_rgb(storedhsv[0], storedhsv[1], storedhsv[2], &changeFactor[0], &changeFactor[1], &changeFactor[2]);
+ colorChanged = 1;
+ }
+
+ /* copy */
+ if(chosenVar == 8){
+ ui_but_copy_paste(but, 'c');
+ return UI_RETURN;
+ }
+
+ /* paste */
+ if(chosenVar == 9){
+ ui_but_copy_paste(but, 'v');
+ ui_check_but(but);
+ ui_draw_but(but);
+ scrarea_queue_winredraw(curarea);
+ return UI_RETURN;
+ }
+
+
+ /* set new Color and redraw */
+ if(colorChanged == 1){
+ if(but->pointype==FLO) {
+ float *fp= (float *) poin;
+ fp[0] = changeFactor[0];
+ fp[1] = changeFactor[1];
+ fp[2] = changeFactor[2];
+ }
+ else if (but->pointype==CHA) {
+ char *cp= (char *) poin;
+ cp[0] = (char)(changeFactor[0]*255.0);
+ cp[1] = (char)(changeFactor[1]*255.0);
+ cp[2] = (char)(changeFactor[2]*255.0);
+ }
+ ui_check_but(but);
+ ui_draw_but(but);
+ BIF_preview_changed(ID_MA);
+ scrarea_queue_winredraw(curarea);
+ return UI_RETURN;
+ }
+
+ }
+ else{
+ return UI_RETURN;
+ }
+ }
+
+ }
+
}
}

Event Timeline