diff options
| author | Cracker64 <cracker642@gmail.com> | 2011-05-10 19:32:00 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-05-14 12:46:10 (GMT) |
| commit | 9d20d6af82a3216c673dc5a8c0a3f03ff4326c4f (patch) | |
| tree | 53567d991ce0efc03ab74393612dd75c5894b4f0 /src | |
| parent | e675fb3cc18117bee065719afd390995e8494e87 (diff) | |
| download | powder-9d20d6af82a3216c673dc5a8c0a3f03ff4326c4f.zip powder-9d20d6af82a3216c673dc5a8c0a3f03ff4326c4f.tar.gz | |
Decoration has a color menu. GoL uses less memory(17MB less), and probably a bit faster.
Diffstat (limited to 'src')
| -rw-r--r-- | src/elements/neut.c | 8 | ||||
| -rw-r--r-- | src/graphics.c | 7 | ||||
| -rw-r--r-- | src/interface.c | 56 | ||||
| -rw-r--r-- | src/misc.c | 48 |
4 files changed, 88 insertions, 31 deletions
diff --git a/src/elements/neut.c b/src/elements/neut.c index 3207534..436a9dc 100644 --- a/src/elements/neut.c +++ b/src/elements/neut.c @@ -1,10 +1,8 @@ #include <element.h> -#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 66c4c81..fdaa6d3 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 && y+j<YRES) diff --git a/src/interface.c b/src/interface.c index 2383782..8021763 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1918,6 +1918,52 @@ 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 h,x,y,n=0,height,width,sy,rows=0,xoff=0,fwidth,a,c; + fwidth = colorsections[i].itemcount*31; + h = -1; + x = XRES-BARSIZE-18; + y = YRES+5; + sy = y; + if(i==1) //color menu + { + 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<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<x+58-xoff && my>=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)) @@ -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}; |
