summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcracker64 <cracker642@gmail.com>2011-09-19 21:02:04 (GMT)
committer cracker64 <cracker642@gmail.com>2011-09-19 21:02:04 (GMT)
commitf0379c5418fd97632004027aa311c4f9b3fb9ab0 (patch)
tree92cf624eeb08a6cd317b2b5c40fab3332cb004d7 /src
parentfb1a522cca4d3f065d9d2af525bc872c73798a4d (diff)
downloadpowder-f0379c5418fd97632004027aa311c4f9b3fb9ab0.zip
powder-f0379c5418fd97632004027aa311c4f9b3fb9ab0.tar.gz
Tool menu in deco editor, Lighten/Darken tools.
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c78
-rw-r--r--src/interface.c104
2 files changed, 142 insertions, 40 deletions
diff --git a/src/graphics.c b/src/graphics.c
index 3d51cb6..8b63dc5 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -959,6 +959,20 @@ void draw_menu(pixel *vid_buf, int i, int hover)
}
}
+void draw_color_menu(pixel *vid_buf, int i, int hover)
+{
+ drawrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+YRES+MENUSIZE-16-(DECO_SECTIONS*16), 14, 14, 255, 255, 255, 255);
+ if (hover==i)
+ {
+ fillrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+YRES+MENUSIZE-16-(DECO_SECTIONS*16), 14, 14, 255, 255, 255, 255);
+ drawtext(vid_buf, (XRES+BARSIZE)-13, (i*16)+YRES+MENUSIZE-14-(DECO_SECTIONS*16), colorsections[i].icon, 0, 0, 0, 255);
+ }
+ else
+ {
+ drawtext(vid_buf, (XRES+BARSIZE)-13, (i*16)+YRES+MENUSIZE-14-(DECO_SECTIONS*16), colorsections[i].icon, 255, 255, 255, 255);
+ }
+}
+
//draws a pixel, identical to blendpixel(), except blendpixel has OpenGL support
#if defined(WIN32) && !defined(__GNUC__)
_inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
@@ -3922,34 +3936,54 @@ void draw_walls(pixel *vid)
}
}
-void create_decorations(int x, int y, int rx, int ry, int r, int g, int b, int click)
+void create_decorations(int x, int y, int rx, int ry, int r, int g, int b, int click, int tool)
{
int i,j,rp;
if (rx==0 && ry==0)
{
- rp = pmap[y][x];
- if (!rp)
- return;
- if (click == 4)
- parts[rp>>8].dcolour = 0;
- else
- parts[rp>>8].dcolour = ((255<<24)|(r<<16)|(g<<8)|b);
+ create_decoration(x,y,r,g,b,click,tool);
return;
}
for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++)
if(y+j>=0 && x+i>=0 && x+i<XRES && y+j<YRES)
if (InCurrentBrush(i, j, rx, ry)){
- rp = pmap[y+j][x+i];
- if (!rp)
- continue;
- if (click == 4)
- parts[rp>>8].dcolour = 0;
- else
- parts[rp>>8].dcolour = ((255<<24)|(r<<16)|(g<<8)|b);
+ create_decoration(x+i,y+j,r,g,b,click,tool);
}
}
-void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int g, int b, int click)
+void create_decoration(int x, int y, int r, int g, int b, int click, int tool)
+{
+ int rp, tr,tg,tb;
+ rp = pmap[y][x];
+ if (!rp)
+ return;
+ if (tool == DECO_DRAW)
+ {
+ if (click == 4)
+ parts[rp>>8].dcolour = 0;
+ else
+ parts[rp>>8].dcolour = ((255<<24)|(r<<16)|(g<<8)|b);
+ }
+ else if (tool == DECO_LIGHTEN)
+ {//maybe get a better lighten/darken?
+ if (parts[rp>>8].dcolour == 0)
+ return;
+ tr = PIXR(parts[rp>>8].dcolour)&0xFF;
+ tg = PIXG(parts[rp>>8].dcolour);
+ tb = PIXB(parts[rp>>8].dcolour);
+ parts[rp>>8].dcolour = ((255<<24)|(clamp_flt(tr+(255-tr)*0.02+1, 0,255)<<16)|(clamp_flt(tg+(255-tg)*0.02+1, 0,255)<<8)|clamp_flt(tb+(255-tb)*0.02+1, 0,255));
+ }
+ else if (tool == DECO_DARKEN)
+ {
+ if (parts[rp>>8].dcolour == 0)
+ return;
+ tr = PIXR(parts[rp>>8].dcolour)&0xFF;
+ tg = PIXG(parts[rp>>8].dcolour);
+ tb = PIXB(parts[rp>>8].dcolour);
+ parts[rp>>8].dcolour = ((255<<24)|(clamp_flt(tr-(tr)*0.02, 0,255)<<16)|(clamp_flt(tg-(tg)*0.02, 0,255)<<8)|clamp_flt(tb-(tb)*0.02, 0,255));
+ }
+}
+void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int g, int b, int click, int tool)
{
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
float e, de;
@@ -3983,9 +4017,9 @@ void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int
for (x=x1; x<=x2; x++)
{
if (cp)
- create_decorations(y, x, rx, ry, r, g, b, click);
+ create_decorations(y, x, rx, ry, r, g, b, click, tool);
else
- create_decorations(x, y, rx, ry, r, g, b, click);
+ create_decorations(x, y, rx, ry, r, g, b, click, tool);
e += de;
if (e >= 0.5f)
{
@@ -3993,15 +4027,15 @@ void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int
if (!(rx+ry))
{
if (cp)
- create_decorations(y, x, rx, ry, r, g, b, click);
+ create_decorations(y, x, rx, ry, r, g, b, click, tool);
else
- create_decorations(x, y, rx, ry, r, g, b, click);
+ create_decorations(x, y, rx, ry, r, g, b, click, tool);
}
e -= 1.0f;
}
}
}
-void box_decorations(int x1, int y1, int x2, int y2, int r, int g, int b, int click)
+void box_decorations(int x1, int y1, int x2, int y2, int r, int g, int b, int click, int tool)
{
int i, j;
if (x1>x2)
@@ -4018,7 +4052,7 @@ void box_decorations(int x1, int y1, int x2, int y2, int r, int g, int b, int cl
}
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
- create_decorations(i, j, 0, 0, r, g, b, click);
+ create_decorations(i, j, 0, 0, r, g, b, click, tool);
}
//draws the photon colors in the HUD
diff --git a/src/interface.c b/src/interface.c
index b140a60..9fe5877 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -2158,7 +2158,7 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *dae, int b, int bq
}
}
}
-int color_menu_ui(pixel *vid_buf, int i, int *cr, int *cg, int *cb, int b, int bq, int mx, int my)
+int color_menu_ui(pixel *vid_buf, int i, int *cr, int *cg, int *cb, int b, int bq, int mx, int my, int *tool)
{
int h,x,y,n=0,height,width,sy,rows=0,xoff=0,fwidth,a,c;
fwidth = colorsections[i].itemcount*31;
@@ -2166,7 +2166,7 @@ int color_menu_ui(pixel *vid_buf, int i, int *cr, int *cg, int *cb, int b, int b
x = XRES-BARSIZE-18;
y = YRES+5;
sy = y;
- if(i==1) //color menu
+ if(i==0) //color menu
{
if (fwidth > XRES-BARSIZE) { //fancy scrolling
float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE)));
@@ -2188,20 +2188,74 @@ int color_menu_ui(pixel *vid_buf, int i, int *cr, int *cg, int *cb, int b, int b
h = n;
}
}
+ if(h!=-1)
+ {
+ drawtext(vid_buf, XRES-textwidth((char *)colorlist[h].descs)-BARSIZE, sy+20, (char *)colorlist[h].descs, 255, 255, 255, 255);
+ }
+ else
+ {
+ drawtext(vid_buf, XRES-textwidth((char *)colorsections[i].name)-BARSIZE, sy+20, (char *)colorsections[i].name, 255, 255, 255, 255);
+ }
+ //these are click events, b=1 is left click, b=4 is right
+ //h has the value of the element it is over, and -1 if not over an element
+ if (b==1 && h!=-1)
+ {
+ *cr = PIXR(colorlist[h].colour);
+ *cg = PIXG(colorlist[h].colour);
+ *cb = PIXB(colorlist[h].colour);
+ return 1;
+ }
}
- if(h!=-1)
- {
- drawtext(vid_buf, XRES-textwidth((char *)colorlist[h].descs)-BARSIZE, sy-14, (char *)colorlist[h].descs, 255, 255, 255, 255);
- }
- //these are click events, b=1 is left click, b=4 is right
- //h has the value of the element it is over, and -1 if not over an element
- if (b==1 && h!=-1)
+ if(i==1) //deco tool menu
{
- *cr = PIXR(colorlist[h].colour);
- *cg = PIXG(colorlist[h].colour);
- *cb = PIXB(colorlist[h].colour);
- return 1;
+ if (fwidth > XRES-BARSIZE) { //fancy scrolling
+ float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE)));
+ xoff = (int)(overflow / location);
+ }
+ for (n = 0; n<3; n++)
+ {
+ for (a=1; a<15; a++)
+ {
+ for (c=1; c<27; c++)
+ {
+ if (n == DECO_LIGHTEN)
+ vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = toollist[n].colour - a*0x0A0A0A;
+ else if (n == DECO_DARKEN)
+ vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = toollist[n].colour + a*0x0A0A0A;
+ else if (n == DECO_DRAW)
+ vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = PIXRGB(*cr,*cg,*cb);
+ else
+ vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = toollist[n].colour;
+ }
+ }
+ x -= 26+5;
+ if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15)
+ {
+ drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
+ h = n;
+ }
+ else if (n==*tool)
+ {
+ drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
+ }
+ }
+ if(h!=-1)
+ {
+ drawtext(vid_buf, XRES-textwidth((char *)toollist[h].descs)-BARSIZE, sy+20, (char *)toollist[h].descs, 255, 255, 255, 255);
+ }
+ else
+ {
+ drawtext(vid_buf, XRES-textwidth((char *)colorsections[i].name)-BARSIZE, sy+20, (char *)colorsections[i].name, 255, 255, 255, 255);
+ }
+ //these are click events, b=1 is left click, b=4 is right
+ //h has the value of the element it is over, and -1 if not over an element
+ if (b==1 && h!=-1)
+ {
+ *tool = h;
+ return 0;
+ }
}
+
return 0;
}
@@ -4779,6 +4833,8 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
int currH = 0, currS = 255, currV = 127;
int currR = PIXR(savedColor), currG = PIXG(savedColor), currB = PIXB(savedColor);
int th = currH, ts = currS, tv = currV;
+ int tool = DECO_DRAW;
+ int active_color_menu= 0;
pixel *old_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
ui_edit box_R;
ui_edit box_G;
@@ -4907,7 +4963,19 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
fillrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, currR, currG, currB, 255);
}
- if( color_menu_ui(vid_buf, 1, &currR, &currG, &currB, b, bq, mx, my) )
+ for (i=0; i<2; i++)//draw all the menu sections
+ {
+ draw_color_menu(vid_buf, i, active_color_menu);
+ }
+
+ for (i=0; i<2; i++)//check mouse position to see if it is on a menu section
+ {
+ if (!b&&mx>=XRES-2 && mx<XRES+BARSIZE-1 &&my>= (i*16)+YRES+MENUSIZE-16-(DECO_SECTIONS*16) && my<(i*16)+YRES+MENUSIZE-16-(DECO_SECTIONS*16)+15)
+ {
+ active_color_menu = i;
+ }
+ }
+ if( color_menu_ui(vid_buf, active_color_menu, &currR, &currG, &currB, b, bq, mx, my, &tool) )
RGB_to_HSV(currR,currG,currB,&currH,&currS,&currV);
if(!box_R.focus)//prevent text update if it is being edited
@@ -5060,7 +5128,7 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
}
else if(lb!=3)//while mouse is held down, it draws lines between previous and current positions
{
- line_decorations(lx, ly, mx, my, *bsx, *bsy, currR, currG, currB, b);
+ line_decorations(lx, ly, mx, my, *bsx, *bsy, currR, currG, currB, b, tool);
lx = mx;
ly = my;
}
@@ -5105,7 +5173,7 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
}
else //normal click, draw deco
{
- create_decorations(mx,my,*bsx,*bsy,currR,currG,currB,b);
+ create_decorations(mx,my,*bsx,*bsy,currR,currG,currB,b, tool);
lx = mx;
ly = my;
lb = b;
@@ -5118,9 +5186,9 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
if (lb && lm) //lm is box/line tool
{
if (lm == 1)//line
- line_decorations(lx, ly, mx, my, *bsx, *bsy, currR, currG, currB, lb);
+ line_decorations(lx, ly, mx, my, *bsx, *bsy, currR, currG, currB, lb, tool);
else//box
- box_decorations(lx, ly, mx, my, currR, currG, currB, lb);
+ box_decorations(lx, ly, mx, my, currR, currG, currB, lb, tool);
lm = 0;
}
lb = 0;