From 9d20d6af82a3216c673dc5a8c0a3f03ff4326c4f Mon Sep 17 00:00:00 2001 From: Cracker64 Date: Tue, 10 May 2011 15:32:00 -0400 Subject: [PATCH] Decoration has a color menu. GoL uses less memory(17MB less), and probably a bit faster. --- includes/defines.h | 4 ++-- includes/interface.h | 21 ++++++++++++++++- src/elements/neut.c | 8 +++---- src/graphics.c | 7 +++++- src/interface.c | 56 +++++++++++++++++++++++++++++++++++++++++++- src/misc.c | 48 ++++++++++++++++++------------------- 6 files changed, 110 insertions(+), 34 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index dc29b4cdd..b756869c6 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -159,8 +159,8 @@ int ISWIRE; int GSPEED; int love[XRES/9][YRES/9]; int lolz[XRES/9][YRES/9]; -int gol[XRES][YRES]; -int gol2[XRES][YRES][NGOL+1]; +unsigned char gol[XRES][YRES]; +unsigned char gol2[XRES][YRES][NGOL+1]; int SEC; int SEC2; int console_mode; diff --git a/includes/interface.h b/includes/interface.h index cadffd930..aa5b0b259 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -26,7 +26,7 @@ typedef struct menu_section menu_section; #define SC_CRACKER2 13 #define SC_TOTAL 10 -static menu_section msections[] = //itemcount and doshow do not do anything currently. +static menu_section msections[] = //doshow does not do anything currently. { {"\xC1", "Walls", 0, 1}, {"\xC2", "Electronics", 0, 1}, @@ -44,6 +44,23 @@ static menu_section msections[] = //itemcount and doshow do not do anything curr {"\xC8", "Cracker!", 0, 0}, }; +static menu_section colorsections[] = //doshow does not do anything currently. +{ + {"\xD1", "Colors", 7, 1}, + {"\xC5", "Tools", 0, 1}, +}; + +static menu_wall colorlist[] = +{ + {PIXPACK(0xFF0000), "Red"}, + {PIXPACK(0x00FF00), "Green"}, + {PIXPACK(0x0000FF), "Blue"}, + {PIXPACK(0xFFFF00), "Yellow"}, + {PIXPACK(0xFF00FF), "Pink"}, + {PIXPACK(0x00FFFF), "Cyan"}, + {PIXPACK(0xFFFFFF), "White"}, +}; + struct ui_edit { int x, y, w, nx, h; @@ -177,6 +194,8 @@ void menu_ui(pixel *vid_buf, int i, int *sl, int *sr); void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *dae, 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 sdl_poll(void); void set_cmode(int cm); diff --git a/src/elements/neut.c b/src/elements/neut.c index 3207534b1..436a9dc76 100644 --- a/src/elements/neut.c +++ b/src/elements/neut.c @@ -1,10 +1,8 @@ #include -#if defined(WIN32) && !defined(__GNUC__) -_inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) -#else + inline int create_n_parts(int n, int x, int y, float vx, float vy, int t)//testing a new deut create part -#endif + { int i, c; n = (n/50); @@ -82,7 +80,7 @@ int update_NEUT(UPDATE_FUNC_ARGS) { #ifdef SDEUT else if ((r&0xFF)==PT_DEUT && (pressureFactor+1+(parts[i].life/100))>(rand()%1000)) { - create_n_parts(parts[r>>8].life, x+rx, y+ry, parts[i].vx, parts[i].vy, PT_NEUT); + //create_n_parts(parts[r>>8].life, x+rx, y+ry, parts[i].vx, parts[i].vy, PT_NEUT); kill_part(r>>8); } #else diff --git a/src/graphics.c b/src/graphics.c index 66c4c8149..fdaa6d315 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -448,7 +448,7 @@ void draw_tool(pixel *vid_buf, int b, int sl, int sr, unsigned pc, unsigned iswa } } */ -//draw walls +//draws walls and elements for menu int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc) { int i, j, c; @@ -3139,6 +3139,11 @@ void draw_decorations(pixel *vid_buf,pixel *decorations) void create_decorations(pixel *decorations,int x, int y, int rx, int ry, int r, int g, int b) { int i,j; + if (rx==0 && ry==0) + { + decorations[(y)*(XRES+BARSIZE)+(x)] = PIXRGB(r, g, b); + return; + } for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) if(y+j>=0 && x+i>=0 && x+i 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<7; n++) + { + for (a=1; a<15; a++) + { + for (c=1; c<27; c++) + { + vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = colorlist[n].colour; + } + } + x -= 26+5; + if (!bq && mx>=x+32-xoff && mx=y && my< y+15) + { + drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255); + h = n; + } + } + } + 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) + { + *cr = PIXR(colorlist[h].colour); + *cg = PIXG(colorlist[h].colour); + *cb = PIXB(colorlist[h].colour); + return 1; + } + return 0; +} int sdl_poll(void) { @@ -4304,7 +4350,7 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) 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) \nThis space should be used for basic color swatches to click on, and maybe some other tool buttons.\nPro tip: click the current color to move the selector to the other side. ", 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. Left 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); @@ -4327,7 +4373,11 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) 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( 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); @@ -4374,6 +4424,10 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) 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); } + else if (mx > XRES || my > YRES) + { + //click outside normal drawing area + } else if (b)//there is a click, outside window { if (!(b&1)) diff --git a/src/misc.c b/src/misc.c index 63289491d..dcf2f88d5 100644 --- a/src/misc.c +++ b/src/misc.c @@ -556,53 +556,53 @@ void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b)//convert 0-255 HSV value { float hh, ss, vv, c, x; int m; - hh = h/42.667f;//normalize values - ss = s/256.0f; - vv = v/256.0f; + hh = h/42.66667f;//normalize values + ss = s/255.0f; + vv = v/255.0f; c = vv * ss; x = c * ( 1 - fabsf(fmod(hh,2.0) -1) ); if(hh<1){ - *r = (int)(c*256.0); - *g = (int)(x*256.0); + *r = (int)(c*255.0); + *g = (int)(x*255.0); *b = 0; } else if(hh<2){ - *r = (int)(x*256.0); - *g = (int)(c*256.0); + *r = (int)(x*255.0); + *g = (int)(c*255.0); *b = 0; } else if(hh<3){ *r = 0; - *g = (int)(c*256.0); - *b = (int)(x*256.0); + *g = (int)(c*255.0); + *b = (int)(x*255.0); } else if(hh<4){ *r = 0; - *g = (int)(x*256.0); - *b = (int)(c*256.0); + *g = (int)(x*255.0); + *b = (int)(c*255.0); } else if(hh<5){ - *r = (int)(x*256.0); + *r = (int)(x*255.0); *g = 0; - *b = (int)(c*256.0); + *b = (int)(c*255.0); } else if(hh<6){ - *r = (int)(c*256.0); + *r = (int)(c*255.0); *g = 0; - *b = (int)(x*256.0); + *b = (int)(x*255.0); } - m = (int)((vv-c)*256.0); + m = (int)((vv-c)*255.0); *r += m; *g += m; *b += m; } -void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 HSV values to 0-255 RGB +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 { float rr, gg, bb, a,x,c,d; - rr = r/256.0f;//normalize values - gg = g/256.0f; - bb = b/256.0f; + rr = r/255.0f;//normalize values + gg = g/255.0f; + bb = b/255.0f; a = fmin(rr,gg); a = fmin(a,bb); x = fmax(rr,gg); @@ -611,15 +611,15 @@ void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 HSV value { *h = 0; *s = 0; - *v = a; + *v = (int)(a*255.0); } else { c = (rr==a) ? gg-bb : ((bb==a) ? rr-gg : bb-rr); d = (rr==a) ? 3 : ((bb==a) ? 1 : 5); - *h = (int)(42.667*(d - c/(x - a))); - *s = (int)(256.0*((x - a)/x)); - *v = (int)(256.0*x); + *h = (int)(42.66667*(d - c/(x - a))); + *s = (int)(255.0*((x - a)/x)); + *v = (int)(255.0*x); } } vector2d v2d_zero = {0,0};