Decoration has a color menu. GoL uses less memory(17MB less), and probably a bit faster.
This commit is contained in:
parent
e675fb3cc1
commit
9d20d6af82
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
48
src/misc.c
48
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};
|
||||
|
Loading…
Reference in New Issue
Block a user