diff options
author | Gentoo <installgentoo@endianness.com> | 2021-03-27 10:39:17 +1100 |
---|---|---|
committer | Gentoo <installgentoo@endianness.com> | 2021-03-27 10:39:17 +1100 |
commit | f99cf64d9b9aae6cd3d68ec8842dbd85ef57f6fe (patch) | |
tree | b56cb7583f25a0b28cf21948022c0a8d5ca4d0ca /makefont | |
download | wii_jewels-master.tar.gz wii_jewels-master.tar.bz2 wii_jewels-master.zip |
Diffstat (limited to 'makefont')
-rw-r--r-- | makefont/Makefile | 11 | ||||
-rw-r--r-- | makefont/hockey.ttf | bin | 0 -> 46560 bytes | |||
-rw-r--r-- | makefont/makefont.c | 330 |
3 files changed, 341 insertions, 0 deletions
diff --git a/makefont/Makefile b/makefont/Makefile new file mode 100644 index 0000000..28b5601 --- /dev/null +++ b/makefont/Makefile @@ -0,0 +1,11 @@ +CC = gcc +#DFLG = -g +CFLAGS = $(DFLG) -O2 -Wall $(shell sdl-config --cflags) +LDFLAGS = $(DFLG) $(shell sdl-config --libs) -lSDL_ttf + +all: makefont +makefont: makefont.c +clean: + rm -f *.o makefont +test: all + ./makefont diff --git a/makefont/hockey.ttf b/makefont/hockey.ttf Binary files differnew file mode 100644 index 0000000..ce7da93 --- /dev/null +++ b/makefont/hockey.ttf diff --git a/makefont/makefont.c b/makefont/makefont.c new file mode 100644 index 0000000..5480fb6 --- /dev/null +++ b/makefont/makefont.c @@ -0,0 +1,330 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> +#include <stdarg.h> +#include <math.h> +#include <fcntl.h> + +#include <SDL.h> +#include <SDL/SDL_ttf.h> + +#define XSIZE 1200 +#define YSIZE 32 + +Uint32 gridcolor,xcolor,ocolor,white; + +int mousex,mousey; + +int bgr=0, bgg=00, bgb=0; +int fgr=255, fgg=255, fgb=255; + + +SDL_Surface *readppm(char *name) +{ +char line[1024*3], *p; +int width=0, height=0; +int len; +SDL_Surface *s; +int x; +unsigned char *put; +FILE *f; +void *res; + + f=fopen(name, "r"); + if(!f) + { + fprintf(stderr, "Couldn't open %s\n", name); + exit(-1); + } + p=fgets(line, sizeof(line), f); // P6 + if(!p || strncmp(p, "P6", 2)) + { + fclose(f); + fprintf(stderr, "Not ppm file %s\n", line); + exit(-1); + } + res=fgets(line, sizeof(line), f); // 480 270 + sscanf(line, "%d %d", &width, &height); + res=fgets(line, sizeof(line), f); // 255 + + s = SDL_AllocSurface(SDL_SWSURFACE, width, height, 24, + 0x0000ff, 0x00ff00, 0xff0000, 0x0); + + x=0; + put = s->pixels; + + while((len = fread(line, 1, sizeof(line), f)) > 0) + { + p=line; + while(len>0) + { + int r,g,b; + r=*p++; + g=*p++; + b=*p++; + put[x++] = r; + put[x++] = g; + put[x++] = b; + if(x==width*3) + { + x = 0; + put += s->pitch; + } + len-=3; + } + } + fclose(f); + return s; + +} + + + +SDL_Surface *thescreen; +void clear(SDL_Surface *s) +{ +int i,c; + c = SDL_MapRGB(s->format, bgr, bgg, bgb); + for(i=0;i<s->w;++i) + *(unsigned short *)(s->pixels+i*2) = c; + for(i=1;i<s->h;++i) + memcpy(s->pixels + i*s->pitch, s->pixels, s->w*2); + +} +inline void colordot(SDL_Surface *s, unsigned x,unsigned y,int c) +{ + if(x<s->w && y<s->h) + *((uint32_t *)s->pixels+y*thescreen->pitch/4+x)=c; +} + + +void scrlock(SDL_Surface *s) +{ + if(SDL_MUSTLOCK(s)) + { + if ( SDL_LockSurface(s) < 0 ) + { + fprintf(stderr, "Couldn't lock display surface: %s\n", + SDL_GetError()); + return; + } + } +} +void scrunlock(SDL_Surface *s) +{ + if(SDL_MUSTLOCK(s)) + SDL_UnlockSurface(s); +} +void copyup(SDL_Surface *s) +{ + SDL_UpdateRect(s, 0, 0, 0, 0); +} + +Uint32 maprgb(int r,int g,int b) +{ + return SDL_MapRGB(thescreen->format,r,g,b); +} + + +void circle(SDL_Surface *s, int cx,int cy,int radius,int c) +{ +int x,y,e; + + x=0; + y=radius; + e=3-(radius<<1); + while(x<=y) + { + colordot(s, cx+x,cy+y,c); + colordot(s, cx-x,cy+y,c); + colordot(s, cx+x,cy-y,c); + colordot(s, cx-x,cy-y,c); + colordot(s, cx+y,cy+x,c); + colordot(s, cx-y,cy+x,c); + colordot(s, cx+y,cy-x,c); + colordot(s, cx-y,cy-x,c); + if(e<0) + e+=(x<<2)+6; + else + { + e+=((x-y)<<2)+10; + --y; + } + ++x; + } +} + + +#define JUST_CENTER 0 +#define JUST_LEFT 1 +#define JUST_RIGHT 2 + +void text_to(SDL_Surface *dest, TTF_Font *font, int x, int y, int just, + char *fmt, ...) +{ +SDL_Surface *s; +SDL_Rect r; +char text[256]; +va_list ap; +SDL_Color tc = {fgr, fgg, fgb, 0}; + + + va_start(ap, fmt); + vsnprintf(text, sizeof(text), fmt, ap); + va_end(ap); + + s = TTF_RenderUTF8_Blended(font, text, tc); + r.x = x; + if(just == JUST_CENTER) + r.x -= s->w/2; + else if(just == JUST_RIGHT) + r.x -= s->w; + + r.y = y - s->h/2; + SDL_BlitSurface(s, 0, dest, &r); + SDL_FreeSurface(s); +} + +struct state { + SDL_Surface *surface; + SDL_Surface *pictures; + TTF_Font *bigfont, *smallfont; + int mousex, mousey; +}; + +int writeppm(SDL_Surface *thescreen, char *name) +{ +int ofile; +unsigned char text[8192],*p; +char temp[128]; + +uint32_t *take; +int i,j; +int res; + + ofile=open(name,O_WRONLY|O_CREAT|O_TRUNC,0644); + if(ofile<0) return -1; + sprintf(temp,"P6\n"); + res=write(ofile,temp,strlen(temp)); + sprintf(temp,"%d %d\n", thescreen->w, thescreen->h); + res=write(ofile,temp,strlen(temp)); + sprintf(temp,"255\n"); + res=write(ofile,temp,strlen(temp)); + take=(void *) thescreen->pixels; + j=thescreen->h; + while(j--) + { + p = text; + for(i=0;i<thescreen->w;++i) + { + SDL_GetRGB(take[i],thescreen->format,p,p+1,p+2); + p+=3; + } + res=write(ofile,text,p-text); + take+=thescreen->pitch / sizeof(*take); + } +//printf("%d\n", thescreen->format->BytesPerPixel); + return 0; +} + +void paint_all(struct state *st) +{ +SDL_Surface *s = st->surface; +int x, y; +char *p; +SDL_Surface *ts; +SDL_Color tc = {255, 255, 255, 0}; +SDL_Rect r; +int gap = maprgb(255,0,255); + + scrlock(s); + clear(s); + p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.!:>^@() + "; +// p="uvwxyz0123456789.!:>^@() + "; + +// text_to(s, st->bigfont, 0, 15, JUST_LEFT, "foo!"); + + x = 0; + while(*p) + { + char text[2]; + text[0] = *p++; + text[1] = 0; + ts = TTF_RenderUTF8_Blended(st->bigfont, text, tc); + r.x = x+1; + r.y = 15 - ts->h / 2; + SDL_BlitSurface(ts, 0, s, &r); + for(y=1;y<s->h-2;++y) + colordot(s, x, y, gap); + x += ts->w+1; + SDL_FreeSurface(ts); + } + + scrunlock(st->surface); + copyup(st->surface); + writeppm(s, "/tmp/font.ppm"); +exit(0); + +} + + + + +int main(int argc,char **argv) +{ +int first; +int code; +SDL_Event event; +Uint32 videoflags; +struct state st; + + if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) + { + fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); + exit(1); + } + videoflags = 0; + thescreen = SDL_SetVideoMode(XSIZE, YSIZE, 32, videoflags); + if ( thescreen == NULL ) + { + fprintf(stderr, "Couldn't set display mode: %s\n", + SDL_GetError()); + exit(5); + } + + TTF_Init(); + + memset(&st, 0, sizeof(st)); + st.surface = thescreen; +// st.pictures = readppm("animals.ppm"); + st.bigfont = TTF_OpenFont("hockey.ttf", 30); + st.smallfont = TTF_OpenFont("hockey.ttf", XSIZE/16); + + + first=0; + + for(;;) + { + usleep(50000); + paint_all(&st); + while(SDL_PollEvent(&event)) + { + switch(event.type) + { + case SDL_MOUSEMOTION: + mousex=event.motion.x; + mousey=event.motion.y; + break; + case SDL_MOUSEBUTTONDOWN: + break; + case SDL_KEYDOWN: + code=event.key.keysym.sym; + if(code==SDLK_ESCAPE) exit(0); + break; + } + } + } + return 0; +} |