From a52344f399857f49abecaa49d76489adb2366999 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 24 May 2011 15:01:18 +0100 Subject: [PATCH] Decorations improvements --- includes/interface.h | 2 +- src/interface.c | 288 +++++++++++++++++++++++++++++-------------- src/main.c | 19 +-- 3 files changed, 202 insertions(+), 107 deletions(-) diff --git a/includes/interface.h b/includes/interface.h index e1e45ea0f..dd45fb7de 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -240,6 +240,6 @@ char *console_ui(pixel *vid_buf, char error[255],char console_more); void simulation_ui(pixel *vid_buf); -void decorations_ui(pixel *vid_buf, pixel *decorations, int *bsx, int *bsy); +unsigned int decorations_ui(pixel *vid_buf, pixel *decorations, int *bsx, int *bsy, unsigned int savedColor); #endif diff --git a/src/interface.c b/src/interface.c index 35fac84b4..9d1020794 100644 --- a/src/interface.c +++ b/src/interface.c @@ -4259,9 +4259,9 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { return NULL; } -void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) -{ - 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; +unsigned int decorations_ui(pixel *vid_buf,pixel *decorations,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) + 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; int window_offset_y = 2; @@ -4274,13 +4274,15 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) int grid_offset_x; int window_offset_x; int onleft_button_offset_x; - int h = 0, s = 255, v = 127; - int th = 0, ts =255, tv=127; + int h = PIXR(savedColor), s = PIXG(savedColor), v = PIXB(savedColor); + int th = h, ts = s, tv=v; pixel *old_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); ui_edit box_R; ui_edit box_G; ui_edit box_B; + zoom_en = 0; + box_R.x = 5; box_R.y = 5+255+4; box_R.w = 30; @@ -4349,51 +4351,77 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) box_G.x = XRES - 254 + 40; box_B.x = XRES - 254 + 75; } - render_cursor(vid_buf, mx, my, PT_DUST, *bsx, *bsy); + if (zoom_en && mx>=zoom_wx && my>=zoom_wy //change mouse position while it is in a zoom window + && mx<(zoom_wx+ZFACTOR*ZSIZE) + && my<(zoom_wy+ZFACTOR*ZSIZE)) + { + mx = (((mx-zoom_wx)/ZFACTOR)+zoom_x); + my = (((my-zoom_wy)/ZFACTOR)+zoom_y); + } 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); - clearrect(vid_buf, window_offset_x, window_offset_y, 2+255+4+10+5, 2+255+20); - drawrect(vid_buf, window_offset_x, window_offset_y, 2+255+4+10+5, 2+255+20, 255, 255, 255, 255);//window around whole thing + if(!hidden) + { + clearrect(vid_buf, window_offset_x, window_offset_y, 2+255+4+10+5, 2+255+20); + drawrect(vid_buf, window_offset_x, window_offset_y, 2+255+4+10+5, 2+255+20, 255, 255, 255, 255);//window around whole thing - drawrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, 255, 255, 255, 255); - drawrect(vid_buf, window_offset_x + 230, window_offset_y +255+6, 26, 12, 255, 255, 255, 255); - drawtext(vid_buf, window_offset_x + 232, window_offset_y +255+9, "Clear", 255, 255, 255, 255); - drawtext(vid_buf, 2, 388, "Welcome to the decoration editor v.1 (by cracker64) \n\nPro tip: click the current color to move the selector to the other side. Right click is eraser. ", 255, 255, 255, 255); - ui_edit_draw(vid_buf, &box_R); - ui_edit_draw(vid_buf, &box_G); - ui_edit_draw(vid_buf, &box_B); + drawrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, 255, 255, 255, 255); + drawrect(vid_buf, window_offset_x + 230, window_offset_y +255+6, 26, 12, 255, 255, 255, 255); + drawtext(vid_buf, window_offset_x + 232, window_offset_y +255+9, "Clear", 255, 255, 255, 255); + ui_edit_draw(vid_buf, &box_R); + ui_edit_draw(vid_buf, &box_G); + ui_edit_draw(vid_buf, &box_B); - for(ss=0; ss<=255; ss++) - for(hh=0;hh<=255;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); - } - for(vv=0; vv<=255; vv++) - for( i=0; i<10; i++) - { - cr = 0; - cg = 0; - cb = 0; - HSV_to_RGB(0,0,vv,&cr,&cg,&cb); - vid_buf[(vv+grid_offset_y)*(XRES+BARSIZE)+(i+grid_offset_x+255+4)] = PIXRGB(cr, cg, cb); - } + for(ss=0; ss<=255; ss++) + for(hh=0;hh<=255;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); + } + for(vv=0; vv<=255; vv++) + for( i=0; i<10; i++) + { + cr = 0; + cg = 0; + cb = 0; + HSV_to_RGB(0,0,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 -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 -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); + addpixel(vid_buf,grid_offset_x + 255 +3,grid_offset_y +v,255,255,255,255); + + HSV_to_RGB(h,s,v,&cr,&cg,&cb); + fillrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, cr, cg, cb, 255); + } if( color_menu_ui(vid_buf, 1, &cr, &cg, &cb, b, bq, mx, my) ) RGB_to_HSV(cr,cg,cb,&h,&s,&v); HSV_to_RGB(h,s,v,&cr,&cg,&cb); - fillrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, cr, cg, cb, 255); sprintf(box_R.str,"%d",cr); sprintf(box_G.str,"%d",cg); sprintf(box_B.str,"%d",cb); + fillrect(vid_buf, 250, YRES+4, 40, 15, cr, cg, cb, 255); - if(!lb && mx >= window_offset_x && my >= window_offset_y && mx <= window_offset_x+255+4+10+5 && my <= window_offset_y+255+20)//in the main window + drawrect(vid_buf, 295, YRES+5, 25, 12, 255, 255, 255, 255); + if(hidden) + drawtext(vid_buf, 297, YRES+5 +3, "Show", 255, 255, 255, 255); + else + drawtext(vid_buf, 297, YRES+5 +3, "Hide", 255, 255, 255, 255); + + if(!lb && !hidden && mx >= window_offset_x && my >= window_offset_y && mx <= window_offset_x+255+4+10+5 && my <= window_offset_y+255+20)//in the main window { if(mx >= grid_offset_x +255+4 && my >= grid_offset_y && mx <= grid_offset_x+255+4+10 && my <= grid_offset_y+255) { @@ -4426,19 +4454,39 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) sprintf(box_G.str,"%d",cg); sprintf(box_B.str,"%d",cb); } - if(b && mx >= window_offset_x + onleft_button_offset_x +1 && my >= window_offset_y +255+6 && mx <= window_offset_x + onleft_button_offset_x +13 && my <= window_offset_y +255+5 +13) + if(b && !bq && mx >= window_offset_x + onleft_button_offset_x +1 && my >= window_offset_y +255+6 && mx <= window_offset_x + onleft_button_offset_x +13 && my <= window_offset_y +255+5 +13) { on_left = !on_left; lb = 3;//prevent immediate drawing after clicking } - if(b && mx >= window_offset_x + 230 && my >= window_offset_y +255+6 && mx <= window_offset_x + 230 +26 && my <= window_offset_y +255+5 +13) - memset(decorations, 0,(XRES+BARSIZE)*YRES*PIXELSIZE); + if(b && !bq && mx >= window_offset_x + 230 && my >= window_offset_y +255+6 && mx <= window_offset_x + 230 +26 && my <= window_offset_y +255+5 +13) + if (confirm_ui(vid_buf, "Reset Decoration Layer", "Do you really want to erase everything?", "Erase") ) + memset(decorations, 0,(XRES+BARSIZE)*YRES*PIXELSIZE); } else if (mx > XRES || my > YRES) { //click outside normal drawing area + if (!zoom_en && b && !bq && mx >= 295 && mx <= 295+25 && my >= YRES+5 && my<= YRES+5+12) + hidden = !hidden; } - else if (b)//there is a click, outside window + else if (sdl_zoom_trig && zoom_en<2) + { + mx -= ZSIZE/2; + my -= ZSIZE/2; + if (mx<0) mx=0; + if (my<0) my=0; + if (mx>XRES-ZSIZE) mx=XRES-ZSIZE; + if (my>YRES-ZSIZE) my=YRES-ZSIZE; + zoom_x = mx; + zoom_y = my; + zoom_wx = (mx