Add font editor from my mod, add two new icons for favorites menu
This commit is contained in:
parent
443c81e67a
commit
4ec4b32021
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,6 +18,7 @@ Saves/*
|
||||
scripts/*
|
||||
generated/*
|
||||
includes/*
|
||||
font/*
|
||||
generate
|
||||
Makefile.me
|
||||
*.xcodeproj
|
||||
|
11
data/font.h
11
data/font.h
@ -234,11 +234,11 @@ unsigned char font_data[] = {
|
||||
0x0C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x1E, 0x00, 0x80, 0x07, 0x00, 0xE0, 0x01, 0x00, 0x78, 0x60, 0x00, 0x24, 0x98, 0x01, 0x80, 0x42, 0x06, 0x00, 0x00, 0x19, 0x00, 0x00, 0x04,
|
||||
0x0A, 0x00, 0x00, 0x40, 0x7F, 0x00, 0x5C, 0x0D, 0xC0, 0xC1, 0x00, 0x1C, 0x0C, 0x40, 0xFF, 0x01, 0x00, 0x74, 0x00, 0x00, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0A, 0x00, 0x00, 0x01, 0x00, 0x68, 0x00, 0xA2, 0x02, 0x80, 0x0A, 0x00, 0x25, 0x00, 0x44, 0x08, 0x10, 0x01, 0x40, 0x04, 0x00, 0x14, 0x00, 0x10, 0x00, 0x00,
|
||||
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x03, 0x08, 0x00, 0x00,
|
||||
0x0A, 0xF0, 0xFF, 0x00, 0xFF, 0x0F, 0xF0, 0xFF, 0x00, 0xFF, 0x0F, 0xF0, 0xFF, 0x00, 0xFF, 0x0F, 0xF0, 0xFA, 0x00, 0x5B, 0x0E, 0x60, 0x90, 0x00, 0x01, 0x04,
|
||||
0x06, 0xCD, 0xF1, 0x3F, 0xFD, 0x41, 0x06, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x05, 0x74, 0x30, 0xC3, 0x0D, 0x33, 0xDC, 0x30, 0x93, 0xD9, 0xC0, 0x89, 0xD1, 0x01,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
@ -260,6 +260,7 @@ unsigned char font_data[] = {
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07,
|
||||
};
|
||||
|
||||
short font_ptrs[] = {
|
||||
0x0000, 0x000E, 0x001C, 0x002A, 0x0038, 0x0046, 0x0054, 0x0062,
|
||||
0x0070, 0x007E, 0x008C, 0x009A, 0x00A8, 0x00B6, 0x00C4, 0x00D2,
|
||||
@ -290,9 +291,9 @@ short font_ptrs[] = {
|
||||
0x0E48, 0x0E62, 0x0E7C, 0x0E96, 0x0EB0, 0x0ECA, 0x0EE4, 0x0EFE,
|
||||
0x0F18, 0x0F26, 0x0F3B, 0x0F53, 0x0F6D, 0x0F87, 0x0FA1, 0x0FBB,
|
||||
0x0FD5, 0x0FF2, 0x100C, 0x1026, 0x1040, 0x105F, 0x1079, 0x1093,
|
||||
0x10A3, 0x10B3, 0x10C3, 0x10D3, 0x10E1, 0x10F1, 0x1101, 0x1111,
|
||||
0x1121, 0x1131, 0x1141, 0x1151, 0x1161, 0x1171, 0x1181, 0x1191,
|
||||
0x11A1, 0x11B1, 0x11C1, 0x11D1, 0x11E1, 0x11F1, 0x1201, 0x1211,
|
||||
0x10AD, 0x10BD, 0x10CD, 0x10DD, 0x10ED, 0x10FD, 0x110D, 0x111D,
|
||||
0x112D, 0x113D, 0x114D, 0x115D, 0x116D, 0x117D, 0x118D, 0x119D,
|
||||
0x11AD, 0x11BD, 0x11CD, 0x11DD, 0x11ED, 0x11FD, 0x120D, 0x121D,
|
||||
};
|
||||
#else
|
||||
extern unsigned char font_data[];
|
||||
|
21
font/Makefile
Normal file
21
font/Makefile
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
editor: editor.c
|
||||
gcc -oeditor -DSCALE=1 -DFONTEDITOR editor.c -lSDL -lm -O3 -ffast-math -march=k8
|
||||
|
||||
editor.exe: editor.c
|
||||
i686-w64-mingw32-gcc -oeditor.exe -DSCALE=1 -DFONTEDITOR editor.c -lmingw32 -lm -lSDLmain -lSDL -O3 -ffast-math -march=k8 -mwindows
|
||||
|
||||
packer: packer.c
|
||||
gcc -opacker -DFONTEDITOR packer.c -lm -O3 -ffast-math -march=k8
|
||||
|
||||
packer.exe: packer.c
|
||||
i686-w64-mingw32-gcc -opacker.exe -DFONTEDITOR packer.c -lm -O3 -ffast-math -march=k8
|
||||
|
||||
unpacker: unpacker.c
|
||||
gcc -ounpacker -DFONTEDITOR unpacker.c -lm -O3 -ffast-math -march=k8
|
||||
|
||||
unpacker.exe: unpacker.c
|
||||
i686-w64-mingw32-gcc -ounpacker.exe -DFONTEDITOR unpacker.c -lm -O3 -ffast-math -march=k8
|
||||
|
||||
clean:
|
||||
rm -f editor packer unpacker editor.exe packer.exe unpacker.exe
|
404
font/editor.c
Normal file
404
font/editor.c
Normal file
@ -0,0 +1,404 @@
|
||||
#ifdef FONTEDITOR
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#define CELLW 12
|
||||
#define CELLH 10
|
||||
|
||||
#define XRES 800
|
||||
#define YRES 600
|
||||
//#define SCALE 1
|
||||
//#define EXTENDED_FONT 1
|
||||
|
||||
char font[256][CELLH][CELLW];
|
||||
char width[256];
|
||||
unsigned char flags[256];
|
||||
unsigned int color[256];
|
||||
signed char top[256];
|
||||
signed char left[256];
|
||||
|
||||
void blendpixel(unsigned *vid, int x, int y, int r, int g, int b, int a)
|
||||
{
|
||||
if (x<0 || y<0 || x>=XRES || y>=YRES)
|
||||
return;
|
||||
if (a != 255)
|
||||
{
|
||||
int t = vid[y*XRES+x];
|
||||
r = (a*r + (255-a)*((t>>16)&255)) >> 8;
|
||||
g = (a*g + (255-a)*((t>>8)&255)) >> 8;
|
||||
b = (a*b + (255-a)*(t&255)) >> 8;
|
||||
}
|
||||
vid[y*XRES+x] = (r<<16)|(g<<8)|b;
|
||||
}
|
||||
|
||||
int drawchar(unsigned *vid, int x, int y, int c, int r, int g, int b)
|
||||
{
|
||||
int i, j;
|
||||
if (color[c])
|
||||
{
|
||||
r = (color[c] >> 16) & 0xFF;
|
||||
g = (color[c] >> 8) & 0xFF;
|
||||
b = color[c] & 0xFF;
|
||||
}
|
||||
for (j = 0; j < CELLH; j++)
|
||||
for (i = 0; i < width[c] && i < CELLW; i++)
|
||||
blendpixel(vid, x+i+left[c], y+j+top[c], r, g, b, (font[c][j][i]*255)/3);
|
||||
return x + width[c];
|
||||
}
|
||||
|
||||
int drawtext(unsigned *vid, int x, int y, char *s, int r, int g, int b)
|
||||
{
|
||||
for (; *s; s++)
|
||||
x = drawchar(vid, x, y, *s, r, g, b);
|
||||
return x;
|
||||
}
|
||||
|
||||
void drawline(unsigned *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;
|
||||
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;
|
||||
de = dy/(float)dx;
|
||||
y = y1;
|
||||
sy = (y1<y2) ? 1 : -1;
|
||||
for (x=x1; x<=x2; x++)
|
||||
{
|
||||
if (cp)
|
||||
blendpixel(vid, y, x, r, g, b, a);
|
||||
else
|
||||
blendpixel(vid, x, y, r, g, b, a);
|
||||
e += de;
|
||||
if (e >= 0.5f)
|
||||
{
|
||||
y += sy;
|
||||
e -= 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawcell(unsigned *vid, int i, int j, int c, int m)
|
||||
{
|
||||
int x, y, x0=i*32+64, y0=j*32+64;
|
||||
for (y = 1;y < 32;y++)
|
||||
for (x = 1; x < 32; x++)
|
||||
blendpixel(vid, x0+x, y0+y, 127*m, 127*m, 127*m, c);
|
||||
for (x = 0; x <32; x+=2)
|
||||
{
|
||||
if (!j)
|
||||
blendpixel(vid, x0+x, y0, 64*m, 64*m, 64*m, 255);
|
||||
if (!i)
|
||||
blendpixel(vid, x0, y0+x, 64*m, 64*m, 64*m, 255);
|
||||
blendpixel(vid, x0+x, y0+32, 64*m, 64*m, 64*m, 255);
|
||||
blendpixel(vid, x0+32, y0+x, 64*m, 64*m, 64*m, 255);
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* SDL OUTPUT *
|
||||
***********************************************************/
|
||||
|
||||
SDL_Surface *sdl_scrn;
|
||||
int sdl_key;
|
||||
void sdl_open(void)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO)<0)
|
||||
{
|
||||
fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
atexit(SDL_Quit);
|
||||
sdl_scrn = SDL_SetVideoMode(XRES*SCALE, YRES*SCALE + 40*SCALE, 32, SDL_SWSURFACE);
|
||||
if (!sdl_scrn)
|
||||
{
|
||||
fprintf(stderr, "Creating window: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void sdl_blit(int x, int y, int w, int h, unsigned int *src, int pitch)
|
||||
{
|
||||
unsigned *dst,i,j,k;
|
||||
if (SDL_MUSTLOCK(sdl_scrn))
|
||||
if (SDL_LockSurface(sdl_scrn)<0)
|
||||
return;
|
||||
dst = (unsigned *)sdl_scrn->pixels+y*sdl_scrn->pitch/4+x;
|
||||
for (j = 0;j < h; j++)
|
||||
{
|
||||
for (k = 0; k < SCALE; k++)
|
||||
{
|
||||
for (i = 0; i < w*SCALE; i++)
|
||||
dst[i] = src[i/SCALE];
|
||||
dst += sdl_scrn->pitch/4;
|
||||
}
|
||||
src += pitch/4;
|
||||
}
|
||||
if (SDL_MUSTLOCK(sdl_scrn))
|
||||
SDL_UnlockSurface(sdl_scrn);
|
||||
SDL_UpdateRect(sdl_scrn,0,0,0,0);
|
||||
}
|
||||
|
||||
int frame_idx = 0;
|
||||
void dump_frame(unsigned int *src, int w, int h, int pitch)
|
||||
{
|
||||
char frame_name[32];
|
||||
unsigned j,i,c;
|
||||
FILE *f;
|
||||
sprintf(frame_name,"frame%04d.ppm",frame_idx);
|
||||
f=fopen(frame_name,"w");
|
||||
fprintf(f,"P6\n%d %d\n255\n",w,h);
|
||||
for (j = 0; j < h; j++)
|
||||
{
|
||||
for (i = 0; i < w; i++)
|
||||
{
|
||||
c = ((src[i]&0xFF0000)>>16) | (src[i]&0x00FF00) | ((src[i]&0x0000FF)<<16);
|
||||
fwrite(&c,3,1,f);
|
||||
}
|
||||
src += pitch/4;
|
||||
}
|
||||
fclose(f);
|
||||
frame_idx++;
|
||||
}
|
||||
|
||||
int sdl_poll()
|
||||
{
|
||||
SDL_Event event;
|
||||
sdl_key=0;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
sdl_key = event.key.keysym.sym;
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* MAIN PROGRAM *
|
||||
***********************************************************/
|
||||
|
||||
char *tag = "(c) 2008 Stanislaw Skowronek";
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned *vid_buf = calloc(XRES*YRES, sizeof(unsigned));
|
||||
int x, y, b = 0, lb, c = 0xA0, i, j, dc = 0;
|
||||
int mode = 0;
|
||||
char hex[18] = "";
|
||||
char inputColor = 0;
|
||||
FILE *f;
|
||||
|
||||
f = fopen("font.bin", "rb");
|
||||
if(f)
|
||||
{
|
||||
fread(width, 1, 256, f);
|
||||
#ifdef EXTENDED_FONT
|
||||
fread(flags, 1, 256, f);
|
||||
fread(color, 4, 256, f);
|
||||
fread(top, 1, 256, f);
|
||||
fread(left, 1, 256, f);
|
||||
#endif
|
||||
fread(font, CELLW*CELLH, 256, f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
sdl_open();
|
||||
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
while (!sdl_poll())
|
||||
{
|
||||
if (sdl_key=='q' || sdl_key==SDLK_ESCAPE)
|
||||
break;
|
||||
else if ((sdl_key==' ' || sdl_key=='=') && c < 255)
|
||||
{
|
||||
if (inputColor)
|
||||
{
|
||||
inputColor = 0;
|
||||
color[c] = 0;
|
||||
flags[c] &= ~0x2;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
else if ((sdl_key=='\b' || sdl_key=='-') && c > 0)
|
||||
{
|
||||
if (inputColor)
|
||||
{
|
||||
inputColor = 0;
|
||||
color[c] = 0;
|
||||
flags[c] &= ~0x2;
|
||||
}
|
||||
c--;
|
||||
}
|
||||
#ifdef EXTENDED_FONT
|
||||
else if (sdl_key == 'w')
|
||||
flags[c] ^= 0x1;
|
||||
else if (sdl_key == 'c')
|
||||
{
|
||||
if (!(flags[c] & 0x2))
|
||||
{
|
||||
flags[c] |= 0x2;
|
||||
color[c] = 255<<24;
|
||||
inputColor = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags[c] &= ~0x2;
|
||||
color[c] = 0;
|
||||
inputColor = 0;
|
||||
}
|
||||
}
|
||||
else if (sdl_key == SDLK_RETURN)
|
||||
{
|
||||
int val = (x > 255) ? 255 : x;
|
||||
switch (inputColor)
|
||||
{
|
||||
case 1:
|
||||
color[c] |= (val<<16);
|
||||
inputColor = 2;
|
||||
break;
|
||||
case 2:
|
||||
color[c] |= (val<<8);
|
||||
inputColor = 3;
|
||||
break;
|
||||
case 3:
|
||||
color[c] |= (val<<0);
|
||||
inputColor = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
lb = b;
|
||||
b = SDL_GetMouseState(&x, &y);
|
||||
if (b)
|
||||
{
|
||||
x /= SCALE;
|
||||
y /= SCALE;
|
||||
}
|
||||
|
||||
i = x/32-2;
|
||||
j = y/32-2;
|
||||
if (!lb && b && (j<0 || j>=CELLH || i<0 || i>=CELLW))
|
||||
{
|
||||
int leftDistance = abs(i-left[c]);
|
||||
int widthDistance = abs(i-width[c]);
|
||||
int topDistance = abs(j-top[c]);
|
||||
if (widthDistance <= leftDistance && widthDistance <= topDistance)
|
||||
mode = 3; // WIDTH
|
||||
else if (leftDistance <= topDistance)
|
||||
mode = 4; // LEFT
|
||||
else
|
||||
mode = 2; // TOP
|
||||
}
|
||||
else if (!lb && b)
|
||||
{
|
||||
mode = 1; // DRAW
|
||||
if (b == 1)
|
||||
dc = (font[c][j][i]+3)%4;
|
||||
else
|
||||
dc = (font[c][j][i]+1)%4;
|
||||
}
|
||||
|
||||
if (b)
|
||||
switch(mode)
|
||||
{
|
||||
case 1:
|
||||
if (i>=0 && j>=0 && i<CELLW && j<CELLH)
|
||||
font[c][j][i] = dc;
|
||||
break;
|
||||
#ifdef EXTENDED_FONT
|
||||
case 2:
|
||||
top[c] = j;
|
||||
break;
|
||||
#endif
|
||||
case 3:
|
||||
width[c] = i;
|
||||
break;
|
||||
#ifdef EXTENDED_FONT
|
||||
case 4:
|
||||
left[c] = i;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
memset(vid_buf, 0, XRES*YRES*4);
|
||||
for (j = 0; j < CELLH; j++)
|
||||
for (i = 0; i < CELLW; i++)
|
||||
drawcell(vid_buf, i, j, (font[c][j][i]*255)/3, i>=width[c]?1:2);
|
||||
drawline(vid_buf, 32, 64+top[c]*32, 128+32*CELLW, 64+top[c]*32, 128, 128, 255, 255);
|
||||
drawline(vid_buf, 64+width[c]*32, 32, 64+width[c]*32, 128+32*CELLH, 255, 128, 128, 255);
|
||||
drawline(vid_buf, 64+left[c]*32, 32, 64+left[c]*32, 128+32*CELLH, 128, 255, 128, 255);
|
||||
|
||||
drawtext(vid_buf, 64, 192+32*CELLH, "A quick brown fox jumps over the lazy dog.", 255, 255, 255);
|
||||
drawtext(vid_buf, 64, 192+33*CELLH, "A QUICK BROWN FOX JUMPS OVER THE LAZY DOG.", 255, 255, 255);
|
||||
drawtext(vid_buf, 64, 192+34*CELLH, "0123456789 ~`!@#$%^&*()-=_+[]{}\\|;:'\",./<>?", 255, 255, 255);
|
||||
|
||||
drawtext(vid_buf, 64, 192+37*CELLH, "Use '+' (= key) and '-' to switch between characters", 255, 255, 255);
|
||||
#ifdef EXTENDED_FONT
|
||||
drawtext(vid_buf, 64, 192+38*CELLH, "Click near a line to modify top/left offset, or character width", 255, 255, 255);
|
||||
drawtext(vid_buf, 64, 192+39*CELLH, "Use 'w' to toggle ignore width & auto draw next character flag, and 'c' to add / turn off font color", 255, 255, 255);
|
||||
if (inputColor)
|
||||
{
|
||||
char temptext[64];
|
||||
//drawtext(vid_buf, 64, 192+40*CELLH, "Due to extreme laziness, you must move the mouse and press enter to set the color of this icon", 255, 255, 255);
|
||||
sprintf(temptext, "Press enter to set %s color to: %i", inputColor == 1 ? "red" : (inputColor == 2 ? "green" : "blue"), (x > 255) ? 255 : x);
|
||||
drawtext(vid_buf, 64, 192+40*CELLH, temptext, 255, 255, 255);
|
||||
}
|
||||
#endif
|
||||
|
||||
drawchar(vid_buf, 32, 192+32*CELLH, c, 255, 255, 255);
|
||||
|
||||
sprintf(hex, "%02X", c);
|
||||
drawtext(vid_buf, 32, 192+34*CELLH, hex, 255, 255, 255);
|
||||
#ifdef EXTENDED_FONT
|
||||
sprintf(hex, "flags: 0x%02X", flags[c]);
|
||||
drawtext(vid_buf, 32, 192+35*CELLH, hex, 255, 255, 255);
|
||||
sprintf(hex, "color: 0x%08X", color[c]);
|
||||
drawtext(vid_buf, 32, 192+36*CELLH, hex, 255, 255, 255);
|
||||
#endif
|
||||
|
||||
sdl_blit(0, 0, XRES, YRES, vid_buf, XRES*4);
|
||||
}
|
||||
|
||||
f = fopen("font.bin", "wb");
|
||||
fwrite(width, 1, 256, f);
|
||||
#ifdef EXTENDED_FONT
|
||||
fwrite(flags, 1, 256, f);
|
||||
fwrite(color, 4, 256, f);
|
||||
fwrite(top, 1, 256, f);
|
||||
fwrite(left, 1, 256, f);
|
||||
#endif
|
||||
fwrite(font, CELLW*CELLH, 256, f);
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
127
font/packer.c
Normal file
127
font/packer.c
Normal file
@ -0,0 +1,127 @@
|
||||
#ifdef FONTEDITOR
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define CELLW 12
|
||||
#define CELLH 10
|
||||
//#define EXTENDED_FONT 1
|
||||
|
||||
char font[256][CELLH][CELLW];
|
||||
char width[256];
|
||||
unsigned char flags[256];
|
||||
unsigned int color[256];
|
||||
signed char top[256];
|
||||
signed char left[256];
|
||||
|
||||
int bits_n = 0, bits_a = 0;
|
||||
int flush_bits(void)
|
||||
{
|
||||
if (bits_n)
|
||||
{
|
||||
bits_a >>= 8-bits_n;
|
||||
printf("0x%02X, ", bits_a);
|
||||
bits_a = 0;
|
||||
bits_n = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int stock_bits(int b, int nb)
|
||||
{
|
||||
bits_a >>= nb;
|
||||
bits_a |= b << (8-nb);
|
||||
bits_n += nb;
|
||||
if (bits_n >= 8)
|
||||
{
|
||||
printf("0x%02X, ", bits_a);
|
||||
bits_a = 0;
|
||||
bits_n = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int save_char(int c)
|
||||
{
|
||||
int nb = 1;
|
||||
int x, y;
|
||||
|
||||
if (!width[c])
|
||||
return 0;
|
||||
|
||||
printf(" 0x%02hhX, ", width[c]);
|
||||
#ifdef EXTENDED_FONT
|
||||
nb += stock_bits(abs(top[c])&3, 2);
|
||||
nb += stock_bits(top[c] < 0 ? 1 : 0, 1);
|
||||
nb += stock_bits(abs(left[c])&3, 2);
|
||||
nb += stock_bits(left[c] < 0 ? 1 : 0, 1);
|
||||
nb += stock_bits(flags[c]&3, 2);
|
||||
if (flags[c]&0x2)
|
||||
{
|
||||
nb += 4;
|
||||
printf("0x%02X, ", color[c]>>24);
|
||||
printf("0x%02X, ", (color[c]>>16)&0xFF);
|
||||
printf("0x%02X, ", (color[c]>>8)&0xFF);
|
||||
printf("0x%02X, ", color[c]&0xFF);
|
||||
}
|
||||
#endif
|
||||
printf(" ");
|
||||
|
||||
for (y = 0; y < CELLH; y++)
|
||||
for (x = 0; x < width[c] && x < CELLW; x++)
|
||||
nb += stock_bits(font[c][y][x]&3, 2);
|
||||
nb += flush_bits();
|
||||
|
||||
printf("\n");
|
||||
|
||||
return nb;
|
||||
}
|
||||
|
||||
char *tag = "(c) 2008 Stanislaw Skowronek";
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
int c, p[256], n = 0;
|
||||
|
||||
memset(p, 0, 256*4);
|
||||
|
||||
f = fopen("font.bin", "rb");
|
||||
fread(width, 1, 256, f);
|
||||
#ifdef EXTENDED_FONT
|
||||
fread(flags, 1, 256, f);
|
||||
fread(color, 4, 256, f);
|
||||
fread(top, 1, 256, f);
|
||||
fread(left, 1, 256, f);
|
||||
#endif
|
||||
fread(font, CELLW*CELLH, 256, f);
|
||||
fclose(f);
|
||||
|
||||
printf("unsigned char font_data[] = {\n");
|
||||
for (c = 0; c < 256; c++)
|
||||
{
|
||||
p[c] = n;
|
||||
n += save_char(c);
|
||||
}
|
||||
printf("};\n");
|
||||
|
||||
printf("\nshort font_ptrs[] = {\n");
|
||||
for (c = 0; c < 256; c++)
|
||||
{
|
||||
if( !(c%8))
|
||||
printf(" ");
|
||||
printf("0x%04X,", p[c]);
|
||||
if ((c%8)==7)
|
||||
printf("\n");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
printf("};\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
97
font/unpacker.c
Normal file
97
font/unpacker.c
Normal file
@ -0,0 +1,97 @@
|
||||
#ifdef FONTEDITOR
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define INCLUDE_FONTDATA
|
||||
//#define EXTENDED_FONT 1
|
||||
|
||||
#include "font.h"
|
||||
|
||||
#define CELLW 12
|
||||
#define CELLH 10
|
||||
|
||||
char font[256][CELLH][CELLW];
|
||||
char width[256];
|
||||
unsigned char flags[256];
|
||||
unsigned int color[256];
|
||||
signed char top[256];
|
||||
signed char left[256];
|
||||
|
||||
void load_char(int c)
|
||||
{
|
||||
unsigned char *start = font_data + font_ptrs[c];
|
||||
unsigned char alpha, red, green, blue;
|
||||
int x, y, b;
|
||||
|
||||
int w = *(start++);
|
||||
#ifdef EXTENDED_FONT
|
||||
unsigned char flag = *(start++);
|
||||
signed char t = (flag&0x4) ? -(flag&0x3) : flag&0x3;
|
||||
signed char l = (flag&0x20) ? -((flag>>3)&0x3) : (flag>>3)&0x3;
|
||||
flag >>= 6;
|
||||
if (flag&0x2)
|
||||
{
|
||||
alpha = *(start++);
|
||||
red = *(start++);
|
||||
green = *(start++);
|
||||
blue = *(start++);
|
||||
color[c] = (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!w)
|
||||
return;
|
||||
|
||||
b = 0;
|
||||
for (y = 0; y < CELLH; y++)
|
||||
for (x = 0; x < w && x < CELLW; x++)
|
||||
{
|
||||
font[c][y][x] = ((*start) >> b) & 3;
|
||||
b += 2;
|
||||
if (b >= 8)
|
||||
{
|
||||
start++;
|
||||
b = 0;
|
||||
}
|
||||
}
|
||||
|
||||
width[c] = w;
|
||||
#ifdef EXTENDED_FONT
|
||||
flags[c] = flag;
|
||||
top[c] = t;
|
||||
left[c] = l;
|
||||
printf("%02X: %d %d %d %d\t0x%08X\n", c, w, t, l, flag, color[c]);
|
||||
#else
|
||||
printf("%02X: %d\n", c, w);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *tag = "(c) 2011 Stanislaw Skowronek";
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
int i;
|
||||
|
||||
memset(color, 0, sizeof(color));
|
||||
for (i = 0; i < 256; i++)
|
||||
load_char(i);
|
||||
|
||||
f = fopen("font.bin", "wb");
|
||||
fwrite(width, 1, 256, f);
|
||||
#ifdef EXTENDED_FONT
|
||||
fwrite(flags, 1, 256, f);
|
||||
fwrite(color, 4, 256, f);
|
||||
fwrite(top, 1, 256, f);
|
||||
fwrite(left, 1, 256, f);
|
||||
#endif
|
||||
fwrite(font, CELLW*CELLH, 256, f);
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
@ -59,14 +59,14 @@ void ToolButton::Draw(const ui::Point& screenPos)
|
||||
{
|
||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderActive.Red, Appearance.BorderActive.Green, Appearance.BorderActive.Blue, Appearance.BorderActive.Alpha);
|
||||
}
|
||||
else if (Favorite::Ref().IsFavorite(toolIdentifier) && currentSelection == -1)
|
||||
{
|
||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderFavorite.Red, Appearance.BorderFavorite.Green, Appearance.BorderFavorite.Blue, Appearance.BorderFavorite.Alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderInactive.Red, Appearance.BorderInactive.Green, Appearance.BorderInactive.Blue, Appearance.BorderInactive.Alpha);
|
||||
}
|
||||
if (Favorite::Ref().IsFavorite(toolIdentifier) && currentSelection == -1)
|
||||
{
|
||||
g->drawtext(screenPos.X, screenPos.Y, "\xE8", Appearance.BorderFavorite.Red, Appearance.BorderFavorite.Green, Appearance.BorderFavorite.Blue, Appearance.BorderFavorite.Alpha);
|
||||
}
|
||||
|
||||
if (totalColour<544)
|
||||
{
|
||||
|
@ -157,8 +157,8 @@ menu_section * LoadMenus(int & menuCount)
|
||||
{"\xCC", "Special", 0, 1},
|
||||
{"\xD2", "Game Of Life", 0, 1},
|
||||
{"\xD7", "Tools", 0, 1},
|
||||
{"\xE7", "Favorites", 0, 1},
|
||||
{"\xE4", "Decoration tools", 0, 1},
|
||||
{"\xCC", "Favorites", 0, 1},
|
||||
{"\xC8", "Cracker", 0, 0},
|
||||
{"\xC8", "Cracker!", 0, 0},
|
||||
};
|
||||
|
@ -14,8 +14,8 @@
|
||||
#define SC_SPECIAL 11
|
||||
#define SC_LIFE 12
|
||||
#define SC_TOOL 13
|
||||
#define SC_DECO 14
|
||||
#define SC_FAVORITES 15
|
||||
#define SC_FAVORITES 14
|
||||
#define SC_DECO 15
|
||||
#define SC_CRACKER 16
|
||||
#define SC_CRACKER2 17
|
||||
#define SC_TOTAL 16
|
||||
|
Loading…
Reference in New Issue
Block a user