some more deco editor changes. Right click deletes decoration again.

This commit is contained in:
Cracker64 2011-05-29 22:18:47 -04:00 committed by Simon Robertshaw
parent 469de0cae0
commit e3ef7f05f0
4 changed files with 42 additions and 29 deletions

View File

@ -122,6 +122,12 @@ void draw_parts(pixel *vid);
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 line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, 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);
void draw_wavelengths(pixel *vid, int x, int y, int h, int wl);
void render_signs(pixel *vid_buf);

View File

@ -3271,7 +3271,7 @@ void draw_walls(pixel *vid)
}
}
void create_decorations(int x, int y, int rx, int ry, int r, int g, int b)
void create_decorations(int x, int y, int rx, int ry, int r, int g, int b, int click)
{
int i,j,rp;
if (rx==0 && ry==0)
@ -3279,7 +3279,10 @@ void create_decorations(int x, int y, int rx, int ry, int r, int g, int b)
rp = pmap[y][x];
if ((rp>>8)>=NPART || !rp)
return;
parts[rp>>8].dcolour = ((255<<24)|(r<<16)|(g<<8)|b);
if (click == 4)
parts[rp>>8].dcolour = 0;
else
parts[rp>>8].dcolour = ((255<<24)|(r<<16)|(g<<8)|b);
return;
}
for (j=-ry; j<=ry; j++)
@ -3289,10 +3292,13 @@ void create_decorations(int x, int y, int rx, int ry, int r, int g, int b)
rp = pmap[y+j][x+i];
if ((rp>>8)>=NPART || !rp)
continue;
parts[rp>>8].dcolour = ((255<<24)|(r<<16)|(g<<8)|b);
if (click == 4)
parts[rp>>8].dcolour = 0;
else
parts[rp>>8].dcolour = ((255<<24)|(r<<16)|(g<<8)|b);
}
}
void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int g, int b)
void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int g, int b, int click)
{
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
float e, de;
@ -3326,9 +3332,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);
create_decorations(y, x, rx, ry, r, g, b, click);
else
create_decorations(x, y, rx, ry, r, g, b);
create_decorations(x, y, rx, ry, r, g, b, click);
e += de;
if (e >= 0.5f)
{
@ -3336,15 +3342,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);
create_decorations(y, x, rx, ry, r, g, b, click);
else
create_decorations(x, y, rx, ry, r, g, b);
create_decorations(x, y, rx, ry, r, g, b, click);
}
e -= 1.0f;
}
}
}
void box_decorations(int x1, int y1, int x2, int y2, int r, int g, int b)
void box_decorations(int x1, int y1, int x2, int y2, int r, int g, int b, int click)
{
int i, j;
if (x1>x2)
@ -3361,7 +3367,7 @@ void box_decorations(int x1, int y1, int x2, int y2, int r, int g, int b)
}
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
create_decorations(i, j, 0, 0, r, g, b);
create_decorations(i, j, 0, 0, r, g, b, click);
}
//draws the photon colors in the HUD

View File

@ -4451,7 +4451,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
}
unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int savedColor)
{//TODO: have the text boxes be editable and update the color. Maybe use 0-360 for H in hsv to fix minor inaccuracies (rgb of 0,0,255 , comes back as 0,3,255)
{//TODO: have the text boxes be editable and update the color.
int i,ss,hh,vv,cr=127,cg=0,cb=0,b = 0,mx,my,bq = 0,j, lb=0,lx=0,ly=0,lm=0,hidden=0;
int window_offset_x_left = 2;
int window_offset_x_right = XRES - 279;
@ -4552,7 +4552,7 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
drawrect(vid_buf, -1, -1, XRES+1, YRES+1, 220, 220, 220, 255);
drawrect(vid_buf, -1, -1, XRES+2, YRES+2, 70, 70, 70, 255);
drawtext(vid_buf, 2, 388, "Welcome to the decoration editor v.2 (by cracker64) \n\nClicking the current color on the window will move it to the other side. Right click is eraser. ", 255, 255, 255, 255);
drawtext(vid_buf, 2, 388, "Welcome to the decoration editor v.3 (by cracker64) \n\nClicking the current color on the window will move it to the other side. Right click is eraser. ", 255, 255, 255, 255);
if(!hidden)
{
@ -4567,13 +4567,13 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
ui_edit_draw(vid_buf, &box_B);
for(ss=0; ss<=255; ss++)
for(hh=0;hh<=255;hh++)
for(hh=0;hh<=359;hh++)
{
cr = 0;
cg = 0;
cb = 0;
HSV_to_RGB(hh,255-ss,255,&cr,&cg,&cb);
vid_buf[(ss+grid_offset_y)*(XRES+BARSIZE)+(hh+grid_offset_x)] = PIXRGB(cr, cg, cb);
HSV_to_RGB(hh,255-ss,255-ss,&cr,&cg,&cb);
vid_buf[(ss+grid_offset_y)*(XRES+BARSIZE)+(clamp_flt(hh, 0, 359)+grid_offset_x)] = PIXRGB(cr, cg, cb);
}
for(vv=0; vv<=255; vv++)
for( i=0; i<10; i++)
@ -4581,13 +4581,13 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
cr = 0;
cg = 0;
cb = 0;
HSV_to_RGB(0,0,vv,&cr,&cg,&cb);
HSV_to_RGB(h,s,vv,&cr,&cg,&cb);
vid_buf[(vv+grid_offset_y)*(XRES+BARSIZE)+(i+grid_offset_x+255+4)] = PIXRGB(cr, cg, cb);
}
addpixel(vid_buf,grid_offset_x + h,grid_offset_y-1,255,255,255,255);
addpixel(vid_buf,grid_offset_x + clamp_flt(h, 0, 359),grid_offset_y-1,255,255,255,255);
addpixel(vid_buf,grid_offset_x -1,grid_offset_y+(255-s),255,255,255,255);
addpixel(vid_buf,grid_offset_x + th,grid_offset_y-1,100,100,100,255);
addpixel(vid_buf,grid_offset_x + clamp_flt(th, 0, 359),grid_offset_y-1,100,100,100,255);
addpixel(vid_buf,grid_offset_x -1,grid_offset_y+(255-ts),100,100,100,255);
addpixel(vid_buf,grid_offset_x + 255 +3,grid_offset_y+tv,100,100,100,255);
@ -4631,11 +4631,12 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
if(mx >= grid_offset_x && my >= grid_offset_y && mx <= grid_offset_x+255 && my <= grid_offset_y+255)
{
th = mx - grid_offset_x;
th = (int)( th*359/255 );
ts = 255 - (my - grid_offset_y);
if(b)
{
h = mx - grid_offset_x;
s = 255 - (my - grid_offset_y);
h = th;
s = ts;
}
HSV_to_RGB(th,ts,v,&cr,&cg,&cb);
//clearrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6,12,12);
@ -4704,7 +4705,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, cr, cg, cb);
line_decorations(lx, ly, mx, my, *bsx, *bsy, cr, cg, cb, b);
lx = mx;
ly = my;
}
@ -4745,7 +4746,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,cr,cg,cb);
create_decorations(mx,my,*bsx,*bsy,cr,cg,cb,b);
lx = mx;
ly = my;
lb = b;
@ -4764,9 +4765,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, cr, cg, cb);
line_decorations(lx, ly, mx, my, *bsx, *bsy, cr, cg, cb, b);
else//box
box_decorations(lx, ly, mx, my, cr, cg, cb);
box_decorations(lx, ly, mx, my, cr, cg, cb, b);
lm = 0;
}
lb = 0;

View File

@ -552,15 +552,15 @@ int register_extension()
#endif
}
void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b)//convert 0-255 HSV values to 0-255 RGB
void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b)//convert 0-255(0-360 for H) HSV values to 0-255 RGB
{
float hh, ss, vv, c, x;
int m;
hh = h/42.66667f;//normalize values
hh = h/60.0f;//normalize values
ss = s/255.0f;
vv = v/255.0f;
c = vv * ss;
x = c * ( 1 - fabsf(fmod(hh,2.0) -1) );
x = c * ( 1 - fabs(fmod(hh,2.0) -1) );
if(hh<1){
*r = (int)(c*255.0);
*g = (int)(x*255.0);
@ -597,7 +597,7 @@ void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b)//convert 0-255 HSV value
*b += m;
}
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 RGB values to 0-255 HSV
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 RGB values to 0-255(0-360 for H) HSV
{
float rr, gg, bb, a,x,c,d;
rr = r/255.0f;//normalize values
@ -617,7 +617,7 @@ void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 RGB value
{
c = (rr==a) ? gg-bb : ((bb==a) ? rr-gg : bb-rr);
d = (rr==a) ? 3 : ((bb==a) ? 1 : 5);
*h = (int)(42.66667*(d - c/(x - a)));
*h = (int)(60.0*(d - c/(x - a)));
*s = (int)(255.0*((x - a)/x));
*v = (int)(255.0*x);
}