Fix graphics.c
This commit is contained in:
parent
e3a7b626ab
commit
60de1cf575
437
src/graphics.c
437
src/graphics.c
@ -1023,16 +1023,16 @@ inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a)
|
|||||||
ba >>= 2;
|
ba >>= 2;
|
||||||
bn -= 2;
|
bn -= 2;
|
||||||
}
|
}
|
||||||
return x + w;
|
return x + w;
|
||||||
}
|
}
|
||||||
|
|
||||||
int drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a)
|
int drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
#ifdef OpenGL
|
#ifdef OpenGL
|
||||||
#else
|
#else
|
||||||
int sx = x;
|
int sx = x;
|
||||||
for (; *s; s++)
|
for (; *s; s++)
|
||||||
{
|
{
|
||||||
if (*s == '\n')
|
if (*s == '\n')
|
||||||
{
|
{
|
||||||
x = sx;
|
x = sx;
|
||||||
@ -1057,6 +1057,10 @@ for (; *s; s++)
|
|||||||
r = 255;
|
r = 255;
|
||||||
g = b = 0;
|
g = b = 0;
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
r = 255;
|
||||||
|
g = b = 75;
|
||||||
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
r = g = 0;
|
r = g = 0;
|
||||||
b = 255;
|
b = 255;
|
||||||
@ -1071,34 +1075,34 @@ for (; *s; s++)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
|
x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Draw text with an outline
|
//Draw text with an outline
|
||||||
int drawtext_outline(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a, int or, int og, int ob, int oa)
|
int drawtext_outline(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a, int or, int og, int ob, int oa)
|
||||||
{
|
{
|
||||||
drawtext(vid, x-1, y-1, s, or, og, ob, oa);
|
drawtext(vid, x-1, y-1, s, or, og, ob, oa);
|
||||||
drawtext(vid, x+1, y+1, s, or, og, ob, oa);
|
drawtext(vid, x+1, y+1, s, or, og, ob, oa);
|
||||||
|
|
||||||
drawtext(vid, x-1, y+1, s, or, og, ob, oa);
|
drawtext(vid, x-1, y+1, s, or, og, ob, oa);
|
||||||
drawtext(vid, x+1, y-1, s, or, og, ob, oa);
|
drawtext(vid, x+1, y-1, s, or, og, ob, oa);
|
||||||
|
|
||||||
return drawtext(vid, x, y, s, r, g, b, a);
|
return drawtext(vid, x, y, s, r, g, b, a);
|
||||||
}
|
}
|
||||||
int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, int b, int a)
|
int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
#ifdef OpenGL
|
#ifdef OpenGL
|
||||||
#else
|
#else
|
||||||
int sx = x;
|
int sx = x;
|
||||||
int rh = 12;
|
int rh = 12;
|
||||||
int rw = 0;
|
int rw = 0;
|
||||||
int cw = x;
|
int cw = x;
|
||||||
int wordlen;
|
int wordlen;
|
||||||
int charspace;
|
int charspace;
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
wordlen = strcspn(s," .,!?\n");
|
wordlen = strcspn(s," .,!?\n");
|
||||||
charspace = textwidthx((char *)s, w-(x-cw));
|
charspace = textwidthx((char *)s, w-(x-cw));
|
||||||
if (charspace<wordlen && wordlen && w-(x-cw)<w/3)
|
if (charspace<wordlen && wordlen && w-(x-cw)<w/3)
|
||||||
@ -1117,45 +1121,6 @@ while (*s)
|
|||||||
y += FONT_H+2;
|
y += FONT_H+2;
|
||||||
}
|
}
|
||||||
else if (*s == '\b')
|
else if (*s == '\b')
|
||||||
{
|
|
||||||
switch (s[1])
|
|
||||||
{
|
|
||||||
case 'w':
|
|
||||||
r = g = b = 255;
|
|
||||||
break;
|
|
||||||
case 'g':
|
|
||||||
r = g = b = 192;
|
|
||||||
break;
|
|
||||||
case 'o':
|
|
||||||
r = 255;
|
|
||||||
g = 216;
|
|
||||||
b = 32;
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
r = 255;
|
|
||||||
g = b = 0;
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
r = 255;
|
|
||||||
g = b = 75;
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
r = g = 0;
|
|
||||||
b = 255;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
if (x-cw>=w)
|
|
||||||
{
|
|
||||||
x = sx;
|
|
||||||
rw = 0;
|
|
||||||
y += FONT_H+2;
|
|
||||||
}
|
|
||||||
else if (*s == '\b')
|
|
||||||
{
|
{
|
||||||
switch (s[1])
|
switch (s[1])
|
||||||
{
|
{
|
||||||
@ -1202,38 +1167,36 @@ while (*s)
|
|||||||
}
|
}
|
||||||
x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
|
x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
|
||||||
}
|
}
|
||||||
x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return rh;
|
return rh;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//draws a rectange, (x,y) are the top left coords.
|
//draws a rectange, (x,y) are the top left coords.
|
||||||
void drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a)
|
void drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
#ifdef OpenGL
|
#ifdef OpenGL
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_LINE_LOOP);
|
||||||
glColor4ub(r, g, b, a);
|
glColor4ub(r, g, b, a);
|
||||||
glVertex2i(x, y);
|
glVertex2i(x, y);
|
||||||
glVertex2i(x+w, y);
|
glVertex2i(x+w, y);
|
||||||
glVertex2i(x+w, y+h);
|
glVertex2i(x+w, y+h);
|
||||||
glVertex2i(x, y+h);
|
glVertex2i(x, y+h);
|
||||||
glEnd();
|
glEnd();
|
||||||
#else
|
#else
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<=w; i++)
|
for (i=0; i<=w; i++)
|
||||||
{
|
{
|
||||||
drawpixel(vid, x+i, y, r, g, b, a);
|
drawpixel(vid, x+i, y, r, g, b, a);
|
||||||
drawpixel(vid, x+i, y+h, r, g, b, a);
|
drawpixel(vid, x+i, y+h, r, g, b, a);
|
||||||
}
|
}
|
||||||
for (i=1; i<h; i++)
|
for (i=1; i<h; i++)
|
||||||
{
|
{
|
||||||
drawpixel(vid, x, y+i, r, g, b, a);
|
drawpixel(vid, x, y+i, r, g, b, a);
|
||||||
drawpixel(vid, x+w, y+i, r, g, b, a);
|
drawpixel(vid, x+w, y+i, r, g, b, a);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1241,16 +1204,16 @@ for (i=1; i<h; i++)
|
|||||||
void fillrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a)
|
void fillrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
#ifdef OpenGL
|
#ifdef OpenGL
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor4ub(r, g, b, a);
|
glColor4ub(r, g, b, a);
|
||||||
glVertex2i(x, y);
|
glVertex2i(x, y);
|
||||||
glVertex2i(x+w, y);
|
glVertex2i(x+w, y);
|
||||||
glVertex2i(x+w, y+h);
|
glVertex2i(x+w, y+h);
|
||||||
glVertex2i(x, y+h);
|
glVertex2i(x, y+h);
|
||||||
glEnd();
|
glEnd();
|
||||||
#else
|
#else
|
||||||
int i,j;
|
int i,j;
|
||||||
for (j=1; j<h; j++)
|
for (j=1; j<h; j++)
|
||||||
for (i=1; i<w; i++)
|
for (i=1; i<w; i++)
|
||||||
drawpixel(vid, x+i, y+j, r, g, b, a);
|
drawpixel(vid, x+i, y+j, r, g, b, a);
|
||||||
#endif // OpenGL
|
#endif // OpenGL
|
||||||
@ -1258,70 +1221,70 @@ for (j=1; j<h; j++)
|
|||||||
|
|
||||||
void clearrect(pixel *vid, int x, int y, int w, int h)
|
void clearrect(pixel *vid, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i=1; i<h; i++)
|
for (i=1; i<h; i++)
|
||||||
memset(vid+(x+1+(XRES+BARSIZE)*(y+i)), 0, PIXELSIZE*(w-1));
|
memset(vid+(x+1+(XRES+BARSIZE)*(y+i)), 0, PIXELSIZE*(w-1));
|
||||||
}
|
}
|
||||||
//draws a line of dots, where h is the height. (why is this even here)
|
//draws a line of dots, where h is the height. (why is this even here)
|
||||||
void drawdots(pixel *vid, int x, int y, int h, int r, int g, int b, int a)
|
void drawdots(pixel *vid, int x, int y, int h, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
#ifdef OpenGL
|
#ifdef OpenGL
|
||||||
int i;
|
int i;
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor4ub(r, g, b, a);
|
glColor4ub(r, g, b, a);
|
||||||
for (i = 0; i <= h; i +=2)
|
for (i = 0; i <= h; i +=2)
|
||||||
glVertex2i(x, y+i);
|
glVertex2i(x, y+i);
|
||||||
glEnd();
|
glEnd();
|
||||||
#else
|
#else
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<=h; i+=2)
|
for (i=0; i<=h; i+=2)
|
||||||
drawpixel(vid, x, y+i, r, g, b, a);
|
drawpixel(vid, x, y+i, r, g, b, a);
|
||||||
#endif //OpenGL
|
#endif //OpenGL
|
||||||
}
|
}
|
||||||
|
|
||||||
int textwidth(char *s)
|
int textwidth(char *s)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
for (; *s; s++)
|
for (; *s; s++)
|
||||||
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||||
return x-1;
|
return x-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int drawtextmax(pixel *vid, int x, int y, int w, char *s, int r, int g, int b, int a)
|
int drawtextmax(pixel *vid, int x, int y, int w, char *s, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
w += x-5;
|
w += x-5;
|
||||||
for (; *s; s++)
|
for (; *s; s++)
|
||||||
{
|
{
|
||||||
if (x+font_data[font_ptrs[(int)(*(unsigned char *)s)]]>=w && x+textwidth(s)>=w+5)
|
if (x+font_data[font_ptrs[(int)(*(unsigned char *)s)]]>=w && x+textwidth(s)>=w+5)
|
||||||
break;
|
break;
|
||||||
x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
|
x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
|
||||||
}
|
}
|
||||||
if (*s)
|
if (*s)
|
||||||
for (i=0; i<3; i++)
|
for (i=0; i<3; i++)
|
||||||
x = drawchar(vid, x, y, '.', r, g, b, a);
|
x = drawchar(vid, x, y, '.', r, g, b, a);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
int textnwidth(char *s, int n)
|
int textnwidth(char *s, int n)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
for (; *s; s++)
|
for (; *s; s++)
|
||||||
{
|
{
|
||||||
if (!n)
|
if (!n)
|
||||||
break;
|
break;
|
||||||
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
return x-1;
|
return x-1;
|
||||||
}
|
}
|
||||||
void textnpos(char *s, int n, int w, int *cx, int *cy)
|
void textnpos(char *s, int n, int w, int *cx, int *cy)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int wordlen, charspace;
|
int wordlen, charspace;
|
||||||
while (*s&&n)
|
while (*s&&n)
|
||||||
{
|
{
|
||||||
wordlen = strcspn(s," .,!?\n");
|
wordlen = strcspn(s," .,!?\n");
|
||||||
charspace = textwidthx(s, w-x);
|
charspace = textwidthx(s, w-x);
|
||||||
if (charspace<wordlen && wordlen && w-x<w/3)
|
if (charspace<wordlen && wordlen && w-x<w/3)
|
||||||
@ -1342,29 +1305,29 @@ while (*s&&n)
|
|||||||
}
|
}
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*cx = x-1;
|
*cx = x-1;
|
||||||
*cy = y;
|
*cy = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int textwidthx(char *s, int w)
|
int textwidthx(char *s, int w)
|
||||||
{
|
{
|
||||||
int x=0,n=0,cw;
|
int x=0,n=0,cw;
|
||||||
for (; *s; s++)
|
for (; *s; s++)
|
||||||
{
|
{
|
||||||
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||||
if (x+(cw/2) >= w)
|
if (x+(cw/2) >= w)
|
||||||
break;
|
break;
|
||||||
x += cw;
|
x += cw;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
int textposxy(char *s, int width, int w, int h)
|
int textposxy(char *s, int width, int w, int h)
|
||||||
{
|
{
|
||||||
int x=0,y=0,n=0,cw, wordlen, charspace;
|
int x=0,y=0,n=0,cw, wordlen, charspace;
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
wordlen = strcspn(s," .,!?\n");
|
wordlen = strcspn(s," .,!?\n");
|
||||||
charspace = textwidthx(s, width-x);
|
charspace = textwidthx(s, width-x);
|
||||||
if (charspace<wordlen && wordlen && width-x<width/3)
|
if (charspace<wordlen && wordlen && width-x<width/3)
|
||||||
@ -1384,16 +1347,16 @@ while (*s)
|
|||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
int textwrapheight(char *s, int width)
|
int textwrapheight(char *s, int width)
|
||||||
{
|
{
|
||||||
int x=0, height=FONT_H+2, cw;
|
int x=0, height=FONT_H+2, cw;
|
||||||
int wordlen;
|
int wordlen;
|
||||||
int charspace;
|
int charspace;
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
wordlen = strcspn(s," .,!?\n");
|
wordlen = strcspn(s," .,!?\n");
|
||||||
charspace = textwidthx(s, width-x);
|
charspace = textwidthx(s, width-x);
|
||||||
if (charspace<wordlen && wordlen && width-x<width/3)
|
if (charspace<wordlen && wordlen && width-x<width/3)
|
||||||
@ -1423,8 +1386,8 @@ while (*s)
|
|||||||
x += cw;
|
x += cw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
//the most used function for drawing a pixel, because it has OpenGL support, which is not fully implemented.
|
//the most used function for drawing a pixel, because it has OpenGL support, which is not fully implemented.
|
||||||
@ -1461,30 +1424,30 @@ inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
|
|||||||
|
|
||||||
void draw_icon(pixel *vid_buf, int x, int y, char ch, int flag)
|
void draw_icon(pixel *vid_buf, int x, int y, char ch, int flag)
|
||||||
{
|
{
|
||||||
char t[2];
|
char t[2];
|
||||||
t[0] = ch;
|
t[0] = ch;
|
||||||
t[1] = 0;
|
t[1] = 0;
|
||||||
if (flag)
|
if (flag)
|
||||||
{
|
{
|
||||||
fillrect(vid_buf, x-1, y-1, 17, 17, 255, 255, 255, 255);
|
fillrect(vid_buf, x-1, y-1, 17, 17, 255, 255, 255, 255);
|
||||||
drawtext(vid_buf, x+3, y+2, t, 0, 0, 0, 255);
|
drawtext(vid_buf, x+3, y+2, t, 0, 0, 0, 255);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
drawrect(vid_buf, x, y, 15, 15, 255, 255, 255, 255);
|
drawrect(vid_buf, x, y, 15, 15, 255, 255, 255, 255);
|
||||||
drawtext(vid_buf, x+3, y+2, t, 255, 255, 255, 255);
|
drawtext(vid_buf, x+3, y+2, t, 255, 255, 255, 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_air(pixel *vid)
|
void draw_air(pixel *vid)
|
||||||
{
|
{
|
||||||
int x, y, i, j;
|
int x, y, i, j;
|
||||||
pixel c;
|
pixel c;
|
||||||
|
|
||||||
if (cmode == CM_PERS)//this should never happen anyway
|
if (cmode == CM_PERS)//this should never happen anyway
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (y=0; y<YRES/CELL; y++)
|
for (y=0; y<YRES/CELL; y++)
|
||||||
for (x=0; x<XRES/CELL; x++)
|
for (x=0; x<XRES/CELL; x++)
|
||||||
{
|
{
|
||||||
if (cmode == CM_PRESS)
|
if (cmode == CM_PRESS)
|
||||||
@ -1549,9 +1512,9 @@ for (y=0; y<YRES/CELL; y++)
|
|||||||
|
|
||||||
void draw_grav_zones(pixel * vid)
|
void draw_grav_zones(pixel * vid)
|
||||||
{
|
{
|
||||||
int x, y, i, j;
|
int x, y, i, j;
|
||||||
for (y=0; y<YRES/CELL; y++)
|
for (y=0; y<YRES/CELL; y++)
|
||||||
{
|
{
|
||||||
for (x=0; x<XRES/CELL; x++)
|
for (x=0; x<XRES/CELL; x++)
|
||||||
{
|
{
|
||||||
if(gravmask[y][x])
|
if(gravmask[y][x])
|
||||||
@ -1564,7 +1527,7 @@ for (y=0; y<YRES/CELL; y++)
|
|||||||
drawpixel(vid, x*CELL+i, y*CELL+j, 32, 32, 32, 120);
|
drawpixel(vid, x*CELL+i, y*CELL+j, 32, 32, 32, 120);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_grav(pixel *vid)
|
void draw_grav(pixel *vid)
|
||||||
@ -1572,16 +1535,9 @@ void draw_grav(pixel *vid)
|
|||||||
int x, y, i, ca;
|
int x, y, i, ca;
|
||||||
float nx, ny, dist;
|
float nx, ny, dist;
|
||||||
|
|
||||||
for (y=0; y<YRES/CELL; y++)
|
for (y=0; y<YRES/CELL; y++)
|
||||||
{
|
|
||||||
for (x=0; x<XRES/CELL; x++)
|
|
||||||
{
|
{
|
||||||
if(fabsf(gravx[y][x]) <= 0.001f && fabsf(gravy[y][x]) <= 0.001f)
|
for (x=0; x<XRES/CELL; x++)
|
||||||
continue;
|
|
||||||
nx = x*CELL;
|
|
||||||
ny = y*CELL;
|
|
||||||
dist = fabsf(gravx[y][x])+fabsf(gravy[y][x]);
|
|
||||||
for(i = 0; i < 4; i++)
|
|
||||||
{
|
{
|
||||||
ca = ((y*CELL)*XRES)+(x*CELL);
|
ca = ((y*CELL)*XRES)+(x*CELL);
|
||||||
if(fabsf(gravpf[ca]) <= 0.001f && fabsf(gravyf[ca]) <= 0.001f)
|
if(fabsf(gravpf[ca]) <= 0.001f && fabsf(gravyf[ca]) <= 0.001f)
|
||||||
@ -1598,31 +1554,30 @@ for (y=0; y<YRES/CELL; y++)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void draw_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a) //Draws a line
|
void draw_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a) //Draws a line
|
||||||
{
|
{
|
||||||
int dx, dy, i, sx, sy, check, e, x, y;
|
int dx, dy, i, sx, sy, check, e, x, y;
|
||||||
|
|
||||||
dx = abs(x1-x2);
|
dx = abs(x1-x2);
|
||||||
dy = abs(y1-y2);
|
dy = abs(y1-y2);
|
||||||
sx = isign(x2-x1);
|
sx = isign(x2-x1);
|
||||||
sy = isign(y2-y1);
|
sy = isign(y2-y1);
|
||||||
x = x1;
|
x = x1;
|
||||||
y = y1;
|
y = y1;
|
||||||
check = 0;
|
check = 0;
|
||||||
|
|
||||||
if (dy>dx)
|
if (dy>dx)
|
||||||
{
|
{
|
||||||
dx = dx+dy;
|
dx = dx+dy;
|
||||||
dy = dx-dy;
|
dy = dx-dy;
|
||||||
dx = dx-dy;
|
dx = dx-dy;
|
||||||
check = 1;
|
check = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
e = (dy<<2)-dx;
|
e = (dy<<2)-dx;
|
||||||
for (i=0; i<=dx; i++)
|
for (i=0; i<=dx; i++)
|
||||||
{
|
{
|
||||||
if (x>=0 && y>=0 && x<a && y<YRES+MENUSIZE)
|
if (x>=0 && y>=0 && x<a && y<YRES+MENUSIZE)
|
||||||
vid[x+y*a] =PIXRGB(r, g, b);
|
vid[x+y*a] =PIXRGB(r, g, b);
|
||||||
if (e>=0)
|
if (e>=0)
|
||||||
@ -1638,76 +1593,76 @@ for (i=0; i<=dx; i++)
|
|||||||
else
|
else
|
||||||
x = x+sx;
|
x = x+sx;
|
||||||
e = e+(dy<<2);
|
e = e+(dy<<2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//adds color to a pixel, does not overwrite.
|
//adds color to a pixel, does not overwrite.
|
||||||
void addpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
|
void addpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
pixel t;
|
pixel t;
|
||||||
if (x<0 || y<0 || x>=XRES || y>=YRES)
|
if (x<0 || y<0 || x>=XRES || y>=YRES)
|
||||||
return;
|
return;
|
||||||
t = vid[y*(XRES+BARSIZE)+x];
|
t = vid[y*(XRES+BARSIZE)+x];
|
||||||
r = (a*r + 255*PIXR(t)) >> 8;
|
r = (a*r + 255*PIXR(t)) >> 8;
|
||||||
g = (a*g + 255*PIXG(t)) >> 8;
|
g = (a*g + 255*PIXG(t)) >> 8;
|
||||||
b = (a*b + 255*PIXB(t)) >> 8;
|
b = (a*b + 255*PIXB(t)) >> 8;
|
||||||
if (r>255)
|
if (r>255)
|
||||||
r = 255;
|
r = 255;
|
||||||
if (g>255)
|
if (g>255)
|
||||||
g = 255;
|
g = 255;
|
||||||
if (b>255)
|
if (b>255)
|
||||||
b = 255;
|
b = 255;
|
||||||
vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b);
|
vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
//draws one of two colors, so that it is always clearly visible
|
//draws one of two colors, so that it is always clearly visible
|
||||||
void xor_pixel(int x, int y, pixel *vid)
|
void xor_pixel(int x, int y, pixel *vid)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
if (x<0 || y<0 || x>=XRES || y>=YRES)
|
if (x<0 || y<0 || x>=XRES || y>=YRES)
|
||||||
return;
|
return;
|
||||||
c = vid[y*(XRES+BARSIZE)+x];
|
c = vid[y*(XRES+BARSIZE)+x];
|
||||||
c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c);
|
c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c);
|
||||||
if (c<512)
|
if (c<512)
|
||||||
vid[y*(XRES+BARSIZE)+x] = PIXPACK(0xC0C0C0);
|
vid[y*(XRES+BARSIZE)+x] = PIXPACK(0xC0C0C0);
|
||||||
else
|
else
|
||||||
vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040);
|
vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040);
|
||||||
}
|
}
|
||||||
|
|
||||||
//same as xor_pixel, but draws a line of it
|
//same as xor_pixel, but draws a line of it
|
||||||
void xor_line(int x1, int y1, int x2, int y2, pixel *vid)
|
void xor_line(int x1, int y1, int x2, int y2, pixel *vid)
|
||||||
{
|
{
|
||||||
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
|
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
|
||||||
float e, de;
|
float e, de;
|
||||||
if (cp)
|
if (cp)
|
||||||
{
|
{
|
||||||
y = x1;
|
y = x1;
|
||||||
x1 = y1;
|
x1 = y1;
|
||||||
y1 = y;
|
y1 = y;
|
||||||
y = x2;
|
y = x2;
|
||||||
x2 = y2;
|
x2 = y2;
|
||||||
y2 = y;
|
y2 = y;
|
||||||
}
|
}
|
||||||
if (x1 > x2)
|
if (x1 > x2)
|
||||||
{
|
{
|
||||||
y = x1;
|
y = x1;
|
||||||
x1 = x2;
|
x1 = x2;
|
||||||
x2 = y;
|
x2 = y;
|
||||||
y = y1;
|
y = y1;
|
||||||
y1 = y2;
|
y1 = y2;
|
||||||
y2 = y;
|
y2 = y;
|
||||||
}
|
}
|
||||||
dx = x2 - x1;
|
dx = x2 - x1;
|
||||||
dy = abs(y2 - y1);
|
dy = abs(y2 - y1);
|
||||||
e = 0.0f;
|
e = 0.0f;
|
||||||
if (dx)
|
if (dx)
|
||||||
de = dy/(float)dx;
|
de = dy/(float)dx;
|
||||||
else
|
else
|
||||||
de = 0.0f;
|
de = 0.0f;
|
||||||
y = y1;
|
y = y1;
|
||||||
sy = (y1<y2) ? 1 : -1;
|
sy = (y1<y2) ? 1 : -1;
|
||||||
for (x=x1; x<=x2; x++)
|
for (x=x1; x<=x2; x++)
|
||||||
{
|
{
|
||||||
if (cp)
|
if (cp)
|
||||||
xor_pixel(y, x, vid);
|
xor_pixel(y, x, vid);
|
||||||
else
|
else
|
||||||
@ -1718,43 +1673,43 @@ for (x=x1; x<=x2; x++)
|
|||||||
y += sy;
|
y += sy;
|
||||||
e -= 1.0f;
|
e -= 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//same as blend_pixel, but draws a line of it
|
//same as blend_pixel, but draws a line of it
|
||||||
void blend_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a)
|
void blend_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
|
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
|
||||||
float e, de;
|
float e, de;
|
||||||
if (cp)
|
if (cp)
|
||||||
{
|
{
|
||||||
y = x1;
|
y = x1;
|
||||||
x1 = y1;
|
x1 = y1;
|
||||||
y1 = y;
|
y1 = y;
|
||||||
y = x2;
|
y = x2;
|
||||||
x2 = y2;
|
x2 = y2;
|
||||||
y2 = y;
|
y2 = y;
|
||||||
}
|
}
|
||||||
if (x1 > x2)
|
if (x1 > x2)
|
||||||
{
|
{
|
||||||
y = x1;
|
y = x1;
|
||||||
x1 = x2;
|
x1 = x2;
|
||||||
x2 = y;
|
x2 = y;
|
||||||
y = y1;
|
y = y1;
|
||||||
y1 = y2;
|
y1 = y2;
|
||||||
y2 = y;
|
y2 = y;
|
||||||
}
|
}
|
||||||
dx = x2 - x1;
|
dx = x2 - x1;
|
||||||
dy = abs(y2 - y1);
|
dy = abs(y2 - y1);
|
||||||
e = 0.0f;
|
e = 0.0f;
|
||||||
if (dx)
|
if (dx)
|
||||||
de = dy/(float)dx;
|
de = dy/(float)dx;
|
||||||
else
|
else
|
||||||
de = 0.0f;
|
de = 0.0f;
|
||||||
y = y1;
|
y = y1;
|
||||||
sy = (y1<y2) ? 1 : -1;
|
sy = (y1<y2) ? 1 : -1;
|
||||||
for (x=x1; x<=x2; x++)
|
for (x=x1; x<=x2; x++)
|
||||||
{
|
{
|
||||||
if (cp)
|
if (cp)
|
||||||
blendpixel(vid, y, x, r, g, b, a);
|
blendpixel(vid, y, x, r, g, b, a);
|
||||||
else
|
else
|
||||||
@ -1765,23 +1720,23 @@ for (x=x1; x<=x2; x++)
|
|||||||
y += sy;
|
y += sy;
|
||||||
e -= 1.0f;
|
e -= 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//same as xor_pixel, but draws a rectangle
|
//same as xor_pixel, but draws a rectangle
|
||||||
void xor_rect(pixel *vid, int x, int y, int w, int h)
|
void xor_rect(pixel *vid, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<w; i+=2)
|
for (i=0; i<w; i+=2)
|
||||||
{
|
{
|
||||||
xor_pixel(x+i, y, vid);
|
xor_pixel(x+i, y, vid);
|
||||||
xor_pixel(x+i, y+h-1, vid);
|
xor_pixel(x+i, y+h-1, vid);
|
||||||
}
|
}
|
||||||
for (i=2; i<h; i+=2)
|
for (i=2; i<h; i+=2)
|
||||||
{
|
{
|
||||||
xor_pixel(x, y+i, vid);
|
xor_pixel(x, y+i, vid);
|
||||||
xor_pixel(x+w-1, y+i, vid);
|
xor_pixel(x+w-1, y+i, vid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_other(pixel *vid) // EMP effect
|
void draw_other(pixel *vid) // EMP effect
|
||||||
@ -1829,16 +1784,6 @@ void draw_parts(pixel *vid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i<=parts_lastActiveIndex; i++) {
|
for (i = 0; i<=parts_lastActiveIndex; i++) {
|
||||||
#ifdef OpenGL
|
|
||||||
if (cmode == CM_FANCY) //If fancy mode
|
|
||||||
{
|
|
||||||
if (ny%(4*GRID_MODE)==0)
|
|
||||||
blendpixel(vid, nx, ny, 100, 100, 100, 80);
|
|
||||||
if (nx%(4*GRID_MODE)==0)
|
|
||||||
blendpixel(vid, nx, ny, 100, 100, 100, 80);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i = 0; i<=parts_lastActiveIndex; i++) {
|
|
||||||
#ifdef OpenGL
|
#ifdef OpenGL
|
||||||
if (cmode == CM_FANCY) //If fancy mode
|
if (cmode == CM_FANCY) //If fancy mode
|
||||||
{
|
{
|
||||||
@ -1997,7 +1942,7 @@ for (i = 0; i<=parts_lastActiveIndex; i++) {
|
|||||||
draw_line(vid , nx, ny+3, figh->legs[8], figh->legs[9], 255, 255, 255, s);
|
draw_line(vid , nx, ny+3, figh->legs[8], figh->legs[9], 255, 255, 255, s);
|
||||||
draw_line(vid , figh->legs[8], figh->legs[9], figh->legs[12], figh->legs[13], 255, 255, 255, s);
|
draw_line(vid , figh->legs[8], figh->legs[9], figh->legs[12], figh->legs[13], 255, 255, 255, s);
|
||||||
}
|
}
|
||||||
if (cmode==CM_NOTHING && t!=PT_PIPE && t!=PT_SWCH && t!=PT_LCRY && t!=PT_PUMP && t!=PT_GPMP && t!=PT_PBCN && t!=PT_FILT && t!=PT_HSWC && t!=PT_PCLN && t!=PT_DEUT && t!=PT_WIFI && t!=PT_LIFE)//nothing display but show needed color changes
|
if (cmode==CM_NOTHING && t!=PT_PIPE && t!=PT_SWCH && t!=PT_LCRY && t!=PT_PUMP && t!=PT_GPMP && t!=PT_PBCN && t!=PT_FILT && t!=PT_HSWC && t!=PT_PCLN && t!=PT_DEUT && t!=PT_WIFI && t!=PT_LIFE && t!=PT_PVOD)//nothing display but show needed color changes
|
||||||
{
|
{
|
||||||
if (t==PT_PHOT)
|
if (t==PT_PHOT)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user