summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorSimon <simon@hardwired.org.uk>2010-08-28 10:40:49 (GMT)
committer Simon <simon@hardwired.org.uk>2010-08-28 10:40:49 (GMT)
commita23f3777314312f8dfb70b779258dbb2f948bd08 (patch)
treec682a4be53a38ef876aa0596b9f5a1039f10d6af /main.c
parent07ade7ed72face5ece3408e953198b5ebcf1170c (diff)
downloadpowder-a23f3777314312f8dfb70b779258dbb2f948bd08.zip
powder-a23f3777314312f8dfb70b779258dbb2f948bd08.tar.gz
Even more work, something broke though
Diffstat (limited to 'main.c')
-rw-r--r--main.c1250
1 files changed, 7 insertions, 1243 deletions
diff --git a/main.c b/main.c
index ce1d634..88b712c 100644
--- a/main.c
+++ b/main.c
@@ -927,50 +927,9 @@ corrupt:
return NULL;
}
-/* NO, I DON'T THINK SO
- #include "fbi.h"
-
- pixel *render_packed_rgb(void *image, int width, int height, int cmp_size)
- {
- unsigned char *tmp;
- pixel *res;
- int i;
-
- tmp = malloc(width*height*3);
- if(!tmp)
- return NULL;
- res = malloc(width*height*PIXELSIZE);
- if(!res) {
- free(tmp);
- return NULL;
- }
-
- i = width*height*3;
- if(BZ2_bzBuffToBuffDecompress((char *)tmp, (unsigned *)&i, (char *)image, cmp_size, 0, 0)) {
- free(res);
- free(tmp);
- return NULL;
- }
-
- for(i=0; i<width*height; i++)
- res[i] = PIXRGB(tmp[3*i], tmp[3*i+1], tmp[3*i+2]);
-
- free(tmp);
- return res;
- }
- */
// stamps library
-#define STAMP_X 4
-#define STAMP_Y 4
-#define STAMP_MAX 120
-
-struct stamp_info
-{
- char name[11];
- pixel *thumb;
- int thumb_w, thumb_h, dodelete;
-} stamps[STAMP_MAX];//[STAMP_X*STAMP_Y];
+stamp stamps[STAMP_MAX];//[STAMP_X*STAMP_Y];
int stamp_count = 0;
@@ -1011,12 +970,6 @@ void *file_load(char *fn, int *size)
return s;
}
-#ifdef WIN32
-#define PATH_SEP "\\"
-#else
-#define PATH_SEP "/"
-#endif
-
void stamp_update(void)
{
FILE *f;
@@ -1036,12 +989,6 @@ void stamp_update(void)
fclose(f);
}
-#define GRID_X 5
-#define GRID_Y 4
-#define GRID_P 3
-#define GRID_S 6
-#define GRID_Z 3
-
void stamp_gen_thumb(int i)
{
char fn[64];
@@ -1106,8 +1053,8 @@ void stamp_save(int x, int y, int w, int h)
if(stamps[STAMP_MAX-1].thumb)
free(stamps[STAMP_MAX-1].thumb);
- memmove(stamps+1, stamps, sizeof(struct stamp_info)*(STAMP_MAX-1));
- memset(stamps, 0, sizeof(struct stamp_info));
+ memmove(stamps+1, stamps, sizeof(struct stamp)*(STAMP_MAX-1));
+ memset(stamps, 0, sizeof(struct stamp));
if(stamp_count<STAMP_MAX)
stamp_count++;
@@ -1121,7 +1068,7 @@ void *stamp_load(int i, int *size)
{
void *data;
char fn[64];
- struct stamp_info tmp;
+ struct stamp tmp;
if(!stamps[i].thumb || !stamps[i].name[0])
return NULL;
@@ -1133,9 +1080,9 @@ void *stamp_load(int i, int *size)
if(i>0)
{
- memcpy(&tmp, stamps+i, sizeof(struct stamp_info));
- memmove(stamps+1, stamps, sizeof(struct stamp_info)*i);
- memcpy(stamps, &tmp, sizeof(struct stamp_info));
+ memcpy(&tmp, stamps+i, sizeof(struct stamp));
+ memmove(stamps+1, stamps, sizeof(struct stamp)*i);
+ memcpy(stamps, &tmp, sizeof(struct stamp));
stamp_update();
}
@@ -1172,637 +1119,6 @@ void del_stamp(int d)
stamp_init();
}
-void menu_ui(pixel *vid_buf, int i, int *sl, int *sr)
-{
- int b=1,bq,mx,my,h,x,y,n=0,height,width,sy,rows=0;
- pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- fillrect(vid_buf, -1, -1, XRES+1, YRES+MENUSIZE, 0, 0, 0, 192);
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
-
- while(!sdl_poll())
- {
- b = SDL_GetMouseState(&mx, &my);
- if(!b)
- break;
- }
- while(!sdl_poll())
- {
- bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
- rows = ceil((float)msections[i].itemcount/16.0f);
- height = (ceil((float)msections[i].itemcount/16.0f)*18);
- width = restrict_flt(msections[i].itemcount*31, 0, 16*31);
- //clearrect(vid_buf, -1, -1, XRES+1, YRES+MENUSIZE+1);
- h = -1;
- x = XRES-BARSIZE-26;
- y = (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-(height/2)+(FONT_H/2)+1;
- sy = y;
- //clearrect(vid_buf, (XRES-BARSIZE-width)+1, y-4, width+4, height+4+rows);
- fillrect(vid_buf, (XRES-BARSIZE-width)-7, y-10, width+16, height+16+rows, 0, 0, 0, 100);
- drawrect(vid_buf, (XRES-BARSIZE-width)-7, y-10, width+16, height+16+rows, 255, 255, 255, 255);
- fillrect(vid_buf, (XRES-BARSIZE)+11, (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-2, 15, FONT_H+3, 0, 0, 0, 100);
- drawrect(vid_buf, (XRES-BARSIZE)+10, (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-2, 16, FONT_H+3, 255, 255, 255, 255);
- drawrect(vid_buf, (XRES-BARSIZE)+9, (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-1, 1, FONT_H+1, 0, 0, 0, 255);
- if(i==SC_WALL)
- {
- for(n = 122; n<122+UI_WALLCOUNT; n++)
- {
- if(n!=SPC_AIR&&n!=SPC_HEAT&&n!=SPC_COOL&&n!=SPC_VACUUM)
- {
- if(x-26<=60)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, mwalls[n-122].colour)+5;
- if(mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if(n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if(n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- }
- else if(i==SC_SPECIAL)
- {
- for(n = 122; n<122+UI_WALLCOUNT; n++)
- {
- if(n==SPC_AIR||n==SPC_HEAT||n==SPC_COOL||n==SPC_VACUUM)
- {
- if(x-26<=60)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, mwalls[n-122].colour)+5;
- if(mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if(n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if(n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- for(n = 0; n<PT_NUM; n++)
- {
- if(ptypes[n].menusection==i&&ptypes[n].menu==1)
- {
- if(x-26<=60)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, ptypes[n].pcolors)+5;
- if(mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if(n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if(n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- }
- else
- {
- for(n = 0; n<PT_NUM; n++)
- {
- if(ptypes[n].menusection==i&&ptypes[n].menu==1)
- {
- if(x-26<=60)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, ptypes[n].pcolors)+5;
- if(mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if(n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if(n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- }
-
- if(h==-1)
- {
- drawtext(vid_buf, XRES-textwidth((char *)msections[i].name)-BARSIZE, sy+height+10, (char *)msections[i].name, 255, 255, 255, 255);
- }
- else if(i==SC_WALL||(i==SC_SPECIAL&&h>=122))
- {
- drawtext(vid_buf, XRES-textwidth((char *)mwalls[h-122].descs)-BARSIZE, sy+height+10, (char *)mwalls[h-122].descs, 255, 255, 255, 255);
- }
- else
- {
- drawtext(vid_buf, XRES-textwidth((char *)ptypes[h].descs)-BARSIZE, sy+height+10, (char *)ptypes[h].descs, 255, 255, 255, 255);
- }
-
-
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
- memcpy(vid_buf, old_vid, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
- if(!(mx>=(XRES-BARSIZE-width)-7 && my>=sy-10 && my<sy+height+9))
- {
- break;
- }
-
- if(b==1&&h!=-1)
- {
- *sl = h;
- break;
- }
- if(b==4&&h!=-1)
- {
- *sr = h;
- break;
- }
- //if(b==4&&h!=-1) {
- // h = -1;
- // break;
- //}
-
- if(sdl_key==SDLK_RETURN)
- break;
- if(sdl_key==SDLK_ESCAPE)
- break;
- }
-
- while(!sdl_poll())
- {
- b = SDL_GetMouseState(&mx, &my);
- if(!b)
- break;
- }
- //drawtext(vid_buf, XRES+2, (12*i)+2, msections[i].icon, 255, 255, 255, 255);
-}
-
-void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int b, int bq, int mx, int my)
-{
- int h,x,y,n=0,height,width,sy,rows=0;
- //bq = b;
- //b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
- rows = ceil((float)msections[i].itemcount/16.0f);
- height = (ceil((float)msections[i].itemcount/16.0f)*18);
- width = restrict_flt(msections[i].itemcount*31, 0, 16*31);
- //clearrect(vid_buf, -1, -1, XRES+1, YRES+MENUSIZE+1);
- h = -1;
- x = XRES-BARSIZE-26;
- y = YRES+1;//(((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-(height/2)+(FONT_H/2)+1;
- sy = y;
- //clearrect(vid_buf, (XRES-BARSIZE-width)+1, y-4, width+4, height+4+rows);
- //fillrect(vid_buf, (XRES-BARSIZE-width)-7, y-10, width+16, height+16+rows, 0, 0, 0, 100);
- //drawrect(vid_buf, (XRES-BARSIZE-width)-7, y-10, width+16, height+16+rows, 255, 255, 255, 255);
- //fillrect(vid_buf, (XRES-BARSIZE)+11, (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-2, 15, FONT_H+3, 0, 0, 0, 100);
- //drawrect(vid_buf, (XRES-BARSIZE)+10, (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-2, 16, FONT_H+3, 255, 255, 255, 255);
- //drawrect(vid_buf, (XRES-BARSIZE)+9, (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-1, 1, FONT_H+1, 0, 0, 0, 255);
- if(i==SC_WALL)
- {
- for(n = 122; n<122+UI_WALLCOUNT; n++)
- {
- if(n!=SPC_AIR&&n!=SPC_HEAT&&n!=SPC_COOL&&n!=SPC_VACUUM)
- {
- if(x-26<=20)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, mwalls[n-122].colour)+5;
- if(!bq && mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if(n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if(n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- }
- else if(i==SC_SPECIAL)
- {
- for(n = 122; n<122+UI_WALLCOUNT; n++)
- {
- if(n==SPC_AIR||n==SPC_HEAT||n==SPC_COOL||n==SPC_VACUUM)
- {
- if(x-26<=20)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, mwalls[n-122].colour)+5;
- if(!bq && mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if(n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if(n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- for(n = 0; n<PT_NUM; n++)
- {
- if(ptypes[n].menusection==i&&ptypes[n].menu==1)
- {
- if(x-26<=20)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, ptypes[n].pcolors)+5;
- if(!bq && mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if(n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if(n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- }
- else
- {
- for(n = 0; n<PT_NUM; n++)
- {
- if(ptypes[n].menusection==i&&ptypes[n].menu==1)
- {
- if(x-26<=20)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, ptypes[n].pcolors)+5;
- if(!bq && mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if(n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if(n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- }
-
- if(h==-1)
- {
- drawtext(vid_buf, XRES-textwidth((char *)msections[i].name)-BARSIZE, sy-10, (char *)msections[i].name, 255, 255, 255, 255);
- }
- else if(i==SC_WALL||(i==SC_SPECIAL&&h>=122))
- {
- drawtext(vid_buf, XRES-textwidth((char *)mwalls[h-122].descs)-BARSIZE, sy-10, (char *)mwalls[h-122].descs, 255, 255, 255, 255);
- }
- else
- {
- drawtext(vid_buf, XRES-textwidth((char *)ptypes[h].descs)-BARSIZE, sy-10, (char *)ptypes[h].descs, 255, 255, 255, 255);
- }
-
- if(b==1&&h!=-1)
- {
- *sl = h;
- }
- if(b==4&&h!=-1)
- {
- *sr = h;
- }
-}
-
-int create_parts(int x, int y, int r, int c)
-{
- int i, j, f = 0, u, v, oy, ox, b = 0, dw = 0; //n;
-
- if(c == 125)
- {
- i = x / CELL;
- j = y / CELL;
- for(v=-1; v<2; v++)
- for(u=-1; u<2; u++)
- if(i+u>=0 && i+u<XRES/CELL &&
- j+v>=0 && j+v<YRES/CELL &&
- bmap[j+v][i+u] == 5)
- return 1;
- bmap[j][i] = 5;
- return 1;
- }
- //LOLOLOLOLLOLOLOLO
- if(c == 127)
- {
- b = 4;
- dw = 1;
- }
- if(c == 122)
- {
- b = 8;
- dw = 1;
- }
- if(c == 123)
- {
- b = 7;
- dw = 1;
- }
- if(c == 124)
- {
- b = 6;
- dw = 1;
- }
- if(c == 128)
- {
- b = 3;
- dw = 1;
- }
- if(c == 129)
- {
- b = 2;
- dw = 1;
- }
- if(c == 130)
- {
- b = 0;
- dw = 1;
- }
- if(c == 131)
- {
- b = 1;
- dw = 1;
- }
- if(c == 132)
- {
- b = 9;
- dw = 1;
- }
- if(c == 133)
- {
- b = 10;
- dw = 1;
- }
- if(c == 134)
- {
- b = 11;
- dw = 1;
- }
- if(c == 135)
- {
- b = 12;
- dw = 1;
- }
- if(c == 140)
- {
- b = 13;
- dw = 1;
- }
- if(c == 255)
- {
- b = 255;
- dw = 1;
- }
- if(dw==1)
- {
- r = r/CELL;
- x = x/CELL;
- y = y/CELL;
- x -= r/2;
- y -= r/2;
- for (ox=x; ox<=x+r; ox++)
- {
- for (oy=y; oy<=y+r; oy++)
- {
- if(ox>=0&&ox<XRES/CELL&&oy>=0&&oy<YRES/CELL)
- {
- i = ox;
- j = oy;
- if(b==4)
- {
- fvx[j][i] = 0.0f;
- fvy[j][i] = 0.0f;
- }
- bmap[j][i] = b;
- }
- }
- }
- return 1;
- }
- if(c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM)
- {
- for(j=-r; j<=r; j++)
- for(i=-r; i<=r; i++)
- if(i*i+j*j<=r*r)
- create_part(-1, x+i, y+j, c);
- return 1;
- }
-
- if(c == 0)
- {
- for(j=-r; j<=r; j++)
- for(i=-r; i<=r; i++)
- if(i*i+j*j<=r*r)
- delete_part(x+i, y+j);
- return 1;
- }
-
- for(j=-r; j<=r; j++)
- for(i=-r; i<=r; i++)
- if(i*i+j*j<=r*r)
- if(create_part(-1, x+i, y+j, c)==-1)
- f = 1;
- return !f;
-}
-
-void create_line(int x1, int y1, int x2, int y2, int r, int c)
-{
- int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
- float e, de;
- if(cp)
- {
- y = x1;
- x1 = y1;
- y1 = y;
- y = x2;
- x2 = y2;
- y2 = y;
- }
- if(x1 > x2)
- {
- y = x1;
- x1 = x2;
- x2 = y;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- dx = x2 - x1;
- dy = abs(y2 - y1);
- e = 0.0f;
- if(dx)
- de = dy/(float)dx;
- else
- de = 0.0f;
- y = y1;
- sy = (y1<y2) ? 1 : -1;
- for(x=x1; x<=x2; x++)
- {
- if(cp)
- create_parts(y, x, r, c);
- else
- create_parts(x, y, r, c);
- e += de;
- if(e >= 0.5f)
- {
- y += sy;
- if(c==135 || c==140 || c==134 || c==133 || c==132 || c==131 || c==129 || c==128 || c==127 || c==125 || c==124 || c==123 || c==122 || !r)
- {
- if(cp)
- create_parts(y, x, r, c);
- else
- create_parts(x, y, r, c);
- }
- e -= 1.0f;
- }
- }
-}
-
-void create_box(int x1, int y1, int x2, int y2, int c)
-{
- int i, j;
- if(x1>x2)
- {
- i = x2;
- x2 = x1;
- x1 = i;
- }
- if(y1>y2)
- {
- j = y2;
- y2 = y1;
- y1 = j;
- }
- for(j=y1; j<=y2; j++)
- for(i=x1; i<=x2; i++)
- create_parts(i, j, 1, c);
-}
-
-int flood_parts(int x, int y, int c, int cm, int bm)
-{
- int x1, x2, dy = (c<PT_NUM)?1:CELL;
- int co = c;
- if(c>=122&&c<=122+UI_WALLCOUNT)
- {
- c = c-100;
- }
- if(cm==-1)
- {
- if(c==0)
- {
- cm = pmap[y][x]&0xFF;
- if(!cm)
- return 0;
- }
- else
- cm = 0;
- }
- if(bm==-1)
- {
- if(c==30)
- {
- bm = bmap[y/CELL][x/CELL];
- if(!bm)
- return 0;
- if(bm==1)
- cm = 0xFF;
- }
- else
- bm = 0;
- }
-
- if((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm)
- return 1;
-
- // go left as far as possible
- x1 = x2 = x;
- while(x1>=CELL)
- {
- if((pmap[y][x1-1]&0xFF)!=cm || bmap[y/CELL][(x1-1)/CELL]!=bm)
- break;
- x1--;
- }
- while(x2<XRES-CELL)
- {
- if((pmap[y][x2+1]&0xFF)!=cm || bmap[y/CELL][(x2+1)/CELL]!=bm)
- break;
- x2++;
- }
-
- // fill span
- for(x=x1; x<=x2; x++)
- if(!create_parts(x, y, 0, co))
- return 0;
-
- // fill children
- if(y>=CELL+dy)
- for(x=x1; x<=x2; x++)
- if((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm)
- if(!flood_parts(x, y-dy, co, cm, bm))
- return 0;
- if(y<YRES-CELL-dy)
- for(x=x1; x<=x2; x++)
- if((pmap[y+dy][x]&0xFF)==cm && bmap[(y+dy)/CELL][x/CELL]==bm)
- if(!flood_parts(x, y+dy, co, cm, bm))
- return 0;
- return 1;
-}
-
int execute_tagop(pixel *vid_buf, char *op, char *tag)
{
int status;
@@ -1885,262 +1201,6 @@ void strlist_free(struct strlist **list)
}
}
-void tag_list_ui(pixel *vid_buf)
-{
- int y,d,x0=(XRES-192)/2,y0=(YRES-256)/2,b=1,bq,mx,my,vp,vn;
- char *p,*q,s;
- char *tag=NULL, *op=NULL;
- ui_edit ed;
- struct strlist *vote=NULL,*down=NULL;
-
- ed.x = x0+25;
- ed.y = y0+221;
- ed.w = 158;
- ed.nx = 1;
- ed.def = "[new tag]";
- ed.focus = 0;
- ed.hide = 0;
- ed.cursor = 0;
- strcpy(ed.str, "");
-
- fillrect(vid_buf, -1, -1, XRES, YRES+MENUSIZE, 0, 0, 0, 192);
- while(!sdl_poll())
- {
- bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
-
- op = tag = NULL;
-
- drawrect(vid_buf, x0, y0, 192, 256, 192, 192, 192, 255);
- clearrect(vid_buf, x0, y0, 192, 256);
- drawtext(vid_buf, x0+8, y0+8, "Current tags:", 255, 255, 255, 255);
- p = svf_tags;
- s = svf_tags[0] ? ' ' : 0;
- y = 36 + y0;
- while(s)
- {
- q = strchr(p, ' ');
- if(!q)
- q = p+strlen(p);
- s = *q;
- *q = 0;
- if(svf_own || svf_admin || svf_mod)
- {
- drawtext(vid_buf, x0+20, y-1, "\x86", 160, 48, 32, 255);
- drawtext(vid_buf, x0+20, y-1, "\x85", 255, 255, 255, 255);
- d = 14;
- if(b && !bq && mx>=x0+18 && mx<x0+32 && my>=y-2 && my<y+12)
- {
- op = "delete";
- tag = mystrdup(p);
- }
- }
- else
- d = 0;
- vp = strlist_find(&vote, p);
- vn = strlist_find(&down, p);
- if((!vp && !vn && !svf_own) || svf_admin || svf_mod)
- {
- drawtext(vid_buf, x0+d+20, y-1, "\x88", 32, 144, 32, 255);
- drawtext(vid_buf, x0+d+20, y-1, "\x87", 255, 255, 255, 255);
- if(b && !bq && mx>=x0+d+18 && mx<x0+d+32 && my>=y-2 && my<y+12)
- {
- op = "vote";
- tag = mystrdup(p);
- strlist_add(&vote, p);
- }
- drawtext(vid_buf, x0+d+34, y-1, "\x88", 144, 48, 32, 255);
- drawtext(vid_buf, x0+d+34, y-1, "\xA2", 255, 255, 255, 255);
- if(b && !bq && mx>=x0+d+32 && mx<x0+d+46 && my>=y-2 && my<y+12)
- {
- op = "down";
- tag = mystrdup(p);
- strlist_add(&down, p);
- }
- }
- if(vp)
- drawtext(vid_buf, x0+d+48+textwidth(p), y, " - voted!", 48, 192, 48, 255);
- if(vn)
- drawtext(vid_buf, x0+d+48+textwidth(p), y, " - voted.", 192, 64, 32, 255);
- drawtext(vid_buf, x0+d+48, y, p, 192, 192, 192, 255);
- *q = s;
- p = q+1;
- y += 16;
- }
- drawtext(vid_buf, x0+11, y0+219, "\x86", 32, 144, 32, 255);
- drawtext(vid_buf, x0+11, y0+219, "\x89", 255, 255, 255, 255);
- drawrect(vid_buf, x0+8, y0+216, 176, 16, 192, 192, 192, 255);
- ui_edit_draw(vid_buf, &ed);
- drawtext(vid_buf, x0+5, y0+245, "Close", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+240, 192, 16, 192, 192, 192, 255);
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- ui_edit_process(mx, my, b, &ed);
-
- if(b && mx>=x0 && mx<=x0+192 && my>=y0+240 && my<y0+256)
- break;
-
- if(op)
- {
- d = execute_tagop(vid_buf, op, tag);
- free(tag);
- op = tag = NULL;
- if(d)
- goto finish;
- }
-
- if(b && !bq && mx>=x0+9 && mx<x0+23 && my>=y0+218 && my<y0+232)
- {
- d = execute_tagop(vid_buf, "add", ed.str);
- strcpy(ed.str, "");
- ed.cursor = 0;
- if(d)
- goto finish;
- }
-
- if(sdl_key==SDLK_RETURN)
- {
- if(!ed.focus)
- break;
- d = execute_tagop(vid_buf, "add", ed.str);
- strcpy(ed.str, "");
- ed.cursor = 0;
- if(d)
- goto finish;
- }
- if(sdl_key==SDLK_ESCAPE)
- {
- if(!ed.focus)
- break;
- strcpy(ed.str, "");
- ed.cursor = 0;
- ed.focus = 0;
- }
- }
- while(!sdl_poll())
- {
- b = SDL_GetMouseState(&mx, &my);
- if(!b)
- break;
- }
- sdl_key = 0;
-
-finish:
- strlist_free(&vote);
-}
-
-int save_name_ui(pixel *vid_buf)
-{
- int x0=(XRES-192)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,nd=0;
- void *th;
- ui_edit ed;
- ui_checkbox cb;
-
- th = build_thumb(&ths, 0);
-
- while(!sdl_poll())
- {
- b = SDL_GetMouseState(&mx, &my);
- if(!b)
- break;
- }
-
- ed.x = x0+25;
- ed.y = y0+25;
- ed.w = 158;
- ed.nx = 1;
- ed.def = "[simulation name]";
- ed.focus = 1;
- ed.hide = 0;
- ed.cursor = strlen(svf_name);
- strcpy(ed.str, svf_name);
-
- cb.x = x0+10;
- cb.y = y0+53+YRES/4;
- cb.focus = 0;
- cb.checked = svf_publish;
-
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- while(!sdl_poll())
- {
- bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
-
- drawrect(vid_buf, x0, y0, 192, 90+YRES/4, 192, 192, 192, 255);
- clearrect(vid_buf, x0, y0, 192, 90+YRES/4);
- drawtext(vid_buf, x0+8, y0+8, "New simulation name:", 255, 255, 255, 255);
- drawtext(vid_buf, x0+10, y0+23, "\x82", 192, 192, 192, 255);
- drawrect(vid_buf, x0+8, y0+20, 176, 16, 192, 192, 192, 255);
-
- ui_edit_draw(vid_buf, &ed);
-
- drawrect(vid_buf, x0+(192-XRES/4)/2-2, y0+42, XRES/4+3, YRES/4+3, 128, 128, 128, 255);
- render_thumb(th, ths, 0, vid_buf, x0+(192-XRES/4)/2, y0+44, 4);
-
- ui_checkbox_draw(vid_buf, &cb);
- drawtext(vid_buf, x0+34, y0+50+YRES/4, "Publish? (Do not publish others'\nworks without permission)", 192, 192, 192, 255);
-
- drawtext(vid_buf, x0+5, y0+79+YRES/4, "Save simulation", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+74+YRES/4, 192, 16, 192, 192, 192, 255);
-
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- ui_edit_process(mx, my, b, &ed);
- ui_checkbox_process(mx, my, b, bq, &cb);
-
- if(b && !bq && ((mx>=x0+9 && mx<x0+23 && my>=y0+22 && my<y0+36) ||
- (mx>=x0 && mx<x0+192 && my>=y0+74+YRES/4 && my<y0+90+YRES/4)))
- {
- free(th);
- if(!ed.str[0])
- return 0;
- nd = strcmp(svf_name, ed.str) || !svf_own;
- strncpy(svf_name, ed.str, 63);
- svf_name[63] = 0;
- if(nd)
- {
- strcpy(svf_id, "");
- strcpy(svf_tags, "");
- }
- svf_open = 1;
- svf_own = 1;
- svf_publish = cb.checked;
- return nd+1;
- }
-
- if(sdl_key==SDLK_RETURN)
- {
- free(th);
- if(!ed.str[0])
- return 0;
- nd = strcmp(svf_name, ed.str) || !svf_own;
- strncpy(svf_name, ed.str, 63);
- svf_name[63] = 0;
- if(nd)
- {
- strcpy(svf_id, "");
- strcpy(svf_tags, "");
- }
- svf_open = 1;
- svf_own = 1;
- svf_publish = cb.checked;
- return nd+1;
- }
- if(sdl_key==SDLK_ESCAPE)
- {
- if(!ed.focus)
- break;
- ed.focus = 0;
- }
- }
- free(th);
- return 0;
-}
-
void thumb_cache_inval(char *id);
void execute_save(pixel *vid_buf)
@@ -3289,205 +2349,10 @@ void draw_image(pixel *vid, pixel *img, int x, int y, int w, int h, int a)
}
}
-int stamp_ui(pixel *vid_buf)
-{
- int b=1,bq,mx,my,d=-1,i,j,k,x,gx,gy,y,w,h,r=-1,stamp_page=0,per_page=STAMP_X*STAMP_Y,page_count;
- char page_info[64];
- page_count = ceil((float)stamp_count/(float)per_page);
-
- while(!sdl_poll())
- {
- b = SDL_GetMouseState(&mx, &my);
- if(!b)
- break;
- }
-
- while(!sdl_poll())
- {
- bq = b;
- b = SDL_GetMouseState(&mx, &my);
- mx /= sdl_scale;
- my /= sdl_scale;
-
- clearrect(vid_buf, -1, -1, XRES+1, YRES+MENUSIZE+1);
- k = stamp_page*per_page;//0;
- r = -1;
- d = -1;
- for(j=0; j<GRID_Y; j++)
- for(i=0; i<GRID_X; i++)
- {
- if(stamps[k].name[0] && stamps[k].thumb)
- {
- gx = ((XRES/GRID_X)*i) + (XRES/GRID_X-XRES/GRID_S)/2;
- gy = ((((YRES-MENUSIZE+20)+15)/GRID_Y)*j) + ((YRES-MENUSIZE+20)/GRID_Y-(YRES-MENUSIZE+20)/GRID_S+10)/2 + 18;
- x = (XRES*i)/GRID_X + XRES/(GRID_X*2);
- y = (YRES*j)/GRID_Y + YRES/(GRID_Y*2);
- gy -= 20;
- w = stamps[k].thumb_w;
- h = stamps[k].thumb_h;
- x -= w/2;
- y -= h/2;
- draw_image(vid_buf, stamps[k].thumb, gx+(((XRES/GRID_S)/2)-(w/2)), gy+(((YRES/GRID_S)/2)-(h/2)), w, h, 255);
- xor_rect(vid_buf, gx+(((XRES/GRID_S)/2)-(w/2)), gy+(((YRES/GRID_S)/2)-(h/2)), w, h);
- if(mx>=gx+XRES/GRID_S-4 && mx<(gx+XRES/GRID_S)+6 && my>=gy-6 && my<gy+4)
- {
- d = k;
- drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 128, 128, 128, 255);
- drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x86", 255, 48, 32, 255);
- }
- else
- {
- if(mx>=gx && mx<gx+(XRES/GRID_S) && my>=gy && my<gy+(YRES/GRID_S))
- {
- r = k;
- drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 128, 128, 210, 255);
- }
- else
- {
- drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 128, 128, 128, 255);
- }
- drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x86", 150, 48, 32, 255);
- }
- drawtext(vid_buf, gx+XRES/(GRID_S*2)-textwidth(stamps[k].name)/2, gy+YRES/GRID_S+7, stamps[k].name, 192, 192, 192, 255);
- drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x85", 255, 255, 255, 255);
- }
- k++;
- }
-
- sprintf(page_info, "Page %d of %d", stamp_page+1, page_count);
-
- drawtext(vid_buf, (XRES/2)-(textwidth(page_info)/2), YRES+MENUSIZE-14, page_info, 255, 255, 255, 255);
-
- if(stamp_page)
- {
- drawtext(vid_buf, 4, YRES+MENUSIZE-14, "\x96", 255, 255, 255, 255);
- drawrect(vid_buf, 1, YRES+MENUSIZE-18, 16, 16, 255, 255, 255, 255);
- }
- if(stamp_page<page_count-1)
- {
- drawtext(vid_buf, XRES-15, YRES+MENUSIZE-14, "\x95", 255, 255, 255, 255);
- drawrect(vid_buf, XRES-18, YRES+MENUSIZE-18, 16, 16, 255, 255, 255, 255);
- }
-
- if(b==1&&d!=-1)
- {
- if(confirm_ui(vid_buf, "Do you want to delete?", stamps[d].name, "Delete"))
- {
- del_stamp(d);
- }
- }
-
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if(b==1&&r!=-1)
- break;
- if(b==4&&r!=-1)
- {
- r = -1;
- break;
- }
-
- if((b && !bq && mx>=1 && mx<=17 && my>=YRES+MENUSIZE-18 && my<YRES+MENUSIZE-2) || sdl_wheel>0)
- {
- if(stamp_page)
- {
- stamp_page --;
- }
- sdl_wheel = 0;
- }
- if((b && !bq && mx>=XRES-18 && mx<=XRES-1 && my>=YRES+MENUSIZE-18 && my<YRES+MENUSIZE-2) || sdl_wheel<0)
- {
- if(stamp_page<page_count-1)
- {
- stamp_page ++;
- }
- sdl_wheel = 0;
- }
-
- if(sdl_key==SDLK_RETURN)
- break;
- if(sdl_key==SDLK_ESCAPE)
- {
- r = -1;
- break;
- }
- }
-
- while(!sdl_poll())
- {
- b = SDL_GetMouseState(&mx, &my);
- if(!b)
- break;
- }
-
- return r;
-}
-
/***********************************************************
* MESSAGE SIGNS *
***********************************************************/
-void get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
-{
- //Changing width if sign have special content
- if(strcmp(signs[i].text, "{p}")==0)
- *w = textwidth("Pressure: -000.00");
-
- if(strcmp(signs[i].text, "{t}")==0)
- *w = textwidth("Temp: 0000.00");
-
- //Ususal width
- if(strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}"))
- *w = textwidth(signs[i].text) + 5;
- *h = 14;
- *x0 = (signs[i].ju == 2) ? signs[i].x - *w :
- (signs[i].ju == 1) ? signs[i].x - *w/2 : signs[i].x;
- *y0 = (signs[i].y > 18) ? signs[i].y - 18 : signs[i].y + 4;
-}
-
-void render_signs(pixel *vid_buf)
-{
- int i, j, x, y, w, h, dx, dy;
- char buff[30]; //Buffer
- for(i=0; i<MAXSIGNS; i++)
- if(signs[i].text[0])
- {
- get_sign_pos(i, &x, &y, &w, &h);
- clearrect(vid_buf, x, y, w, h);
- drawrect(vid_buf, x, y, w, h, 192, 192, 192, 255);
-
- //Displaying special information
- if(strcmp(signs[i].text, "{p}")==0)
- {
- sprintf(buff, "Pressure: %3.2f", pv[signs[i].y/CELL][signs[i].x/CELL]); //...pressure
- drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255);
- }
-
- if(strcmp(signs[i].text, "{t}")==0)
- {
- if((pmap[signs[i].y][signs[i].x]>>8)>0 && (pmap[signs[i].y][signs[i].x]>>8)<NPART)
- sprintf(buff, "Temp: %4.2f", parts[pmap[signs[i].y][signs[i].x]>>8].temp); //...tempirature
- else
- sprintf(buff, "Temp: 0.00"); //...tempirature
- drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255);
- }
-
- //Usual text
- if(strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}"))
- drawtext(vid_buf, x+3, y+3, signs[i].text, 255, 255, 255, 255);
- x = signs[i].x;
- y = signs[i].y;
- dx = 1 - signs[i].ju;
- dy = (signs[i].y > 18) ? -1 : 1;
- for(j=0; j<4; j++)
- {
- drawpixel(vid_buf, x, y, 192, 192, 192, 255);
- x+=dx;
- y+=dy;
- }
- }
-}
-
/***********************************************************
* CONFIG FILE *
***********************************************************/
@@ -3624,52 +2489,6 @@ void dim_copy(pixel *dst, pixel *src)
}
}
-unsigned int fire_alpha[CELL*3][CELL*3];
-void prepare_alpha(void)
-{
- int x,y,i,j;
- float temp[CELL*3][CELL*3];
- memset(temp, 0, sizeof(temp));
- for(x=0; x<CELL; x++)
- for(y=0; y<CELL; y++)
- for(i=-CELL; i<CELL; i++)
- for(j=-CELL; j<CELL; j++)
- temp[y+CELL+j][x+CELL+i] += expf(-0.1f*(i*i+j*j));
- for(x=0; x<CELL*3; x++)
- for(y=0; y<CELL*3; y++)
- fire_alpha[y][x] = (int)(255.0f*temp[y][x]/(CELL*CELL));
-}
-
-void render_fire(pixel *dst)
-{
- int i,j,x,y,r,g,b;
- for(j=0; j<YRES/CELL; j++)
- for(i=0; i<XRES/CELL; i++)
- {
- r = fire_r[j][i];
- g = fire_g[j][i];
- b = fire_b[j][i];
- if(r || g || b)
- for(y=-CELL+1; y<2*CELL; y++)
- for(x=-CELL+1; x<2*CELL; x++)
- addpixel(dst, i*CELL+x, j*CELL+y, r, g, b, fire_alpha[y+CELL][x+CELL]);
- for(y=-1; y<2; y++)
- for(x=-1; x<2; x++)
- if(i+x>=0 && j+y>=0 && i+x<XRES/CELL && j+y<YRES/CELL && (x || y))
- {
- r += fire_r[j+y][i+x] / 8;
- g += fire_g[j+y][i+x] / 8;
- b += fire_b[j+y][i+x] / 8;
- }
- r /= 2;
- g /= 2;
- b /= 2;
- fire_r[j][i] = r>4 ? r-4 : 0;
- fire_g[j][i] = g>4 ? g-4 : 0;
- fire_b[j][i] = b>4 ? b-4 : 0;
- }
-}
-
int zoom_en = 0;
int zoom_x=(XRES-ZSIZE_D)/2, zoom_y=(YRES-ZSIZE_D)/2;
int zoom_wx=0, zoom_wy=0;
@@ -3798,47 +2617,6 @@ char *tag = "(c) 2008-9 Stanislaw Skowronek";
int itc = 0;
char itc_msg[64] = "[?]";
-pixel *fire_bg;
-void set_cmode(int cm)
-{
- cmode = cm;
- itc = 51;
- if(cmode==4)
- {
- memset(fire_r, 0, sizeof(fire_r));
- memset(fire_g, 0, sizeof(fire_g));
- memset(fire_b, 0, sizeof(fire_b));
- strcpy(itc_msg, "Blob Display");
- }
- else if(cmode==5)
- {
- strcpy(itc_msg, "Heat Display");
- }
- else if(cmode==6)
- {
- memset(fire_r, 0, sizeof(fire_r));
- memset(fire_g, 0, sizeof(fire_g));
- memset(fire_b, 0, sizeof(fire_b));
- strcpy(itc_msg, "Fancy Display");
- }
- else if(cmode==3)
- {
- memset(fire_r, 0, sizeof(fire_r));
- memset(fire_g, 0, sizeof(fire_g));
- memset(fire_b, 0, sizeof(fire_b));
- strcpy(itc_msg, "Fire Display");
- }
- else if(cmode==2)
- {
- memset(fire_bg, 0, XRES*YRES*PIXELSIZE);
- strcpy(itc_msg, "Persistent Display");
- }
- else if(cmode==1)
- strcpy(itc_msg, "Pressure Display");
- else
- strcpy(itc_msg, "Velocity Display");
-}
-
char my_uri[] = "http://" SERVER "/Update.api?Action=Download&Architecture="
#if defined WIN32
"Windows32"
@@ -3955,20 +2733,6 @@ corrupt:
return NULL;
}
-void clear_area(int area_x, int area_y, int area_w, int area_h)
-{
- int cx = 0;
- int cy = 0;
- for(cy=0; cy<area_h; cy++)
- {
- for(cx=0; cx<area_w; cx++)
- {
- bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
- delete_part(cx+area_x, cy+area_y);
- }
- }
-}
-
int main(int argc, char *argv[])
{
int hud_enable = 1;