From bd8de4c8420b7b6dc782d12a0eef1ea3fe6f5883 Mon Sep 17 00:00:00 2001 From: Cracker64 Date: Fri, 22 Apr 2011 23:11:05 -0400 Subject: [PATCH] Decorations! ,still messing with it. It does not save currently. TODO: fix typing in boxes to update the color. Line/box tools. Some basic color selections like an element menu. --- includes/graphics.h | 2 + includes/interface.h | 1 + includes/misc.h | 3 + src/graphics.c | 12 +++ src/interface.c | 220 +++++++++++++++++++++++++++++++++++++++++++ src/main.c | 5 +- src/misc.c | 68 +++++++++++++ 7 files changed, 310 insertions(+), 1 deletion(-) diff --git a/includes/graphics.h b/includes/graphics.h index f17e3f3d3..d028e9bfa 100644 --- a/includes/graphics.h +++ b/includes/graphics.h @@ -114,6 +114,8 @@ void xor_rect(pixel *vid, int x, int y, int w, int h); void draw_parts(pixel *vid); +void draw_decorations(pixel *vid_buf,pixel *decorations); + void draw_wavelengths(pixel *vid, int x, int y, int h, int wl); void render_signs(pixel *vid_buf); diff --git a/includes/interface.h b/includes/interface.h index fec1a60c0..1a092af64 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -244,5 +244,6 @@ int console_parse_coords(char *txt, int *x, int *y, char *err); int console_parse_type(char *txt, int *element, char *err); int console_parse_partref(char *txt, int *which, char *err); +void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy); #endif diff --git a/includes/misc.h b/includes/misc.h index ef23b1e2a..f504a7b82 100644 --- a/includes/misc.h +++ b/includes/misc.h @@ -66,6 +66,9 @@ int register_extension(); int cpu_check(void); +void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b); + +void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v); // a b // c d struct matrix2d { diff --git a/src/graphics.c b/src/graphics.c index 703e97244..0b9ffe7a4 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -3056,6 +3056,18 @@ void draw_parts(pixel *vid) #endif } +void draw_decorations(pixel *vid_buf,pixel *decorations) +{ + int i,r,g,b; + for (i=0; i<(XRES+BARSIZE)*YRES; i++) + { + r = PIXR(decorations[i]); + g = PIXG(decorations[i]); + b = PIXB(decorations[i]); + if (r>0 || g>0 || b>0) + vid_buf[i] = PIXRGB(r,g,b); + } +} //draws the photon colors in the HUD void draw_wavelengths(pixel *vid, int x, int y, int h, int wl) diff --git a/src/interface.c b/src/interface.c index 86d389b94..312e33833 100644 --- a/src/interface.c +++ b/src/interface.c @@ -4275,3 +4275,223 @@ int console_parse_partref(char *txt, int *which, char *err) if (strcmp(err,"")==0) strcpy(err,"Particle does not exist"); return 0; } + +void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) +{ + int i,cr=127,cg=0,cb=0,b = 0,mx,my,bq = 0,j; + int window_offset_x_left = 2; + int window_offset_x_right = XRES - 279; + int window_offset_y = 2; + int grid_offset_x_left = 5; + int grid_offset_x_right = XRES - 274; + int grid_offset_y = 5; + int onleft_button_offset_x_left = 259; + int onleft_button_offset_x_right = 4; + int on_left = 1; + 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; + ui_edit box_R; + ui_edit box_G; + ui_edit box_B; + + box_R.x = 5; + box_R.y = 5+255+4; + box_R.w = 30; + box_R.nx = 1; + box_R.def = ""; + strcpy(box_R.str, "127"); + box_R.focus = 0; + box_R.hide = 0; + box_R.multiline = 0; + box_R.cursor = 0; + + box_G.x = 40; + box_G.y = 5+255+4; + box_G.w = 30; + box_G.nx = 1; + box_G.def = ""; + strcpy(box_G.str, ""); + box_G.focus = 0; + box_G.hide = 0; + box_G.multiline = 0; + box_G.cursor = 0; + + box_B.x = 75; + box_B.y = 5+255+4; + box_B.w = 30; + box_B.nx = 1; + box_B.def = ""; + strcpy(box_B.str, ""); + box_B.focus = 0; + box_B.hide = 0; + box_B.multiline = 0; + box_B.cursor = 0; + + pixel *old_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); + memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); + while (!sdl_poll()) + { + bq = b; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + + memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); + draw_decorations(vid_buf,decorations); + ui_edit_draw(vid_buf, &box_R); + ui_edit_draw(vid_buf, &box_G); + ui_edit_draw(vid_buf, &box_B); + ui_edit_process(mx, my, b, &box_R); + ui_edit_process(mx, my, b, &box_G); + ui_edit_process(mx, my, b, &box_B); + //HSV_to_RGB(h,s,v,&cr,&cg,&cb); + //if(cr != atoi(box_R.str)) + //RGB_to_HSV(atoi(box_R.str),cg,cb,&h,&s,&v); + if(on_left==1) + { + grid_offset_x = grid_offset_x_left; + window_offset_x = window_offset_x_left; + onleft_button_offset_x = onleft_button_offset_x_left; + box_R.x = 5; + box_G.x = 40; + box_B.x = 75; + } + else + { + grid_offset_x = grid_offset_x_right; + window_offset_x = window_offset_x_right; + onleft_button_offset_x = onleft_button_offset_x_right; + box_R.x = XRES - 254 + 5; + box_G.x = XRES - 254 + 40; + box_B.x = XRES - 254 + 75; + } + 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); + 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); + for(int ss=0; ss<=255; ss++) + for(int 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(int 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); + } + if(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) + { + tv = my - grid_offset_y; + if(b) + { + v =my - grid_offset_y; + } + HSV_to_RGB(h,s,tv,&cr,&cg,&cb); + //clearrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6,12,12); + 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); + } + if(mx >= grid_offset_x && my >= grid_offset_y && mx <= grid_offset_x+255 && my <= grid_offset_y+255) + { + th = mx - grid_offset_x; + ts = 255 - (my - grid_offset_y); + if(b) + { + h = mx - grid_offset_x; + s = 255 - (my - grid_offset_y); + } + 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); + 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.def,"%d",cr); + sprintf(box_R.str,"%d",cr); + sprintf(box_G.str,"%d",cg); + sprintf(box_B.str,"%d",cb); + } + } + else + { + render_cursor(vid_buf, mx, my, PT_DUST, *bsx, *bsy); + HSV_to_RGB(h,s,v,&cr,&cg,&cb); + if (b) + { + for (j=-*bsy; j<=*bsy; j++) + for (i=-*bsx; i<=*bsx; i++) + if(my+j>=0 && mx+i>=0 && mx+i= window_offset_x + onleft_button_offset_x && my >= window_offset_y +255+4 && mx <= window_offset_x + onleft_button_offset_x +13 && my <= window_offset_y +255+4 +13) + on_left = !on_left; + if (sdl_wheel) + { + //change brush size + { + if (!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL))) + { + *bsx += sdl_wheel; + *bsy += sdl_wheel; + } + else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL))) + { + *bsx += sdl_wheel; + } + else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT))) + { + *bsy += sdl_wheel; + } + if (*bsx>1180) + *bsx = 1180; + if (*bsx<0) + *bsx = 0; + if (*bsy>1180) + *bsy = 1180; + if (*bsy<0) + *bsy = 0; + sdl_wheel = 0; + /*if(su >= PT_NUM) { + if(sl < PT_NUM) + su = sl; + if(sr < PT_NUM) + su = sr; + }*/ + } + } + if(sdl_key=='b') + { + free(old_buf); + return; + } + } + free(old_buf); +} diff --git a/src/main.c b/src/main.c index a235131ca..f98e98cb1 100644 --- a/src/main.c +++ b/src/main.c @@ -2658,6 +2658,7 @@ int main(int argc, char *argv[]) PyObject *pname,*pmodule,*pfunc,*pvalue,*pargs,*pstep,*pkey; PyObject *tpt_console_obj; #endif + pixel *decorations = calloc((XRES+BARSIZE)*YRES, PIXELSIZE); vid_buf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE); GSPEED = 1; @@ -3243,6 +3244,8 @@ int main(int argc, char *argv[]) console_mode = !console_mode; //hud_enable = !console_mode; } + if (sdl_key=='b') + decorations_ui(vid_buf,decorations,&bsx,&bsy);//decoration_mode = !decoration_mode; if (sdl_key=='g') { if (sdl_mod & (KMOD_SHIFT)) @@ -3535,7 +3538,7 @@ int main(int argc, char *argv[]) } } menu_ui_v3(vid_buf, active_menu, &sl, &sr, &dae, b, bq, x, y); //draw the elements in the current menu - + draw_decorations(vid_buf,decorations); if (zoom_en && x>=sdl_scale*zoom_wx && y>=sdl_scale*zoom_wy //change mouse position while it is in a zoom window && x