... | ... |
@@ -17,7 +17,6 @@ |
17 | 17 |
#include "re_ui.h" |
18 | 18 |
#include "hack_regular.h" |
19 | 19 |
|
20 |
-#define DEFAULTFONTSIZE 16 |
|
21 | 20 |
#define DEFAULTTITLEPREFIX "re - " |
22 | 21 |
#define DEFAULTWINDOWWIDTH 80 |
23 | 22 |
#define DEFAULTWINDOWHEIGHT 66 |
... | ... |
@@ -42,10 +41,12 @@ static int reui_triangle(SDL_Surface *dst, int x, int y, int w, int h, char dire |
42 | 41 |
|
43 | 42 |
|
44 | 43 |
reui_t * |
45 |
-reui_init() |
|
44 |
+reui_init(int fontheight) |
|
46 | 45 |
{ |
47 | 46 |
reui_t *ui; |
48 | 47 |
SDL_Rect screenrect; |
48 |
+ if(fontheight<=0) |
|
49 |
+ return(NULL); /* sanity check failed */ |
|
49 | 50 |
if((ui=malloc(sizeof(reui_t)))==NULL) |
50 | 51 |
return(NULL); |
51 | 52 |
memset(ui,0,sizeof(reui_t)); |
... | ... |
@@ -58,7 +59,7 @@ reui_init() |
58 | 59 |
ui->screenw=screenrect.w; |
59 | 60 |
ui->screenh=screenrect.h; |
60 | 61 |
/* font */ |
61 |
- ui->fontheight=DEFAULTFONTSIZE; |
|
62 |
+ ui->fontheight=fontheight; |
|
62 | 63 |
ui->fontdata=SDL_RWFromConstMem(hack_regular,SIZE_HACK_REGULAR); |
63 | 64 |
SDL_RWseek(ui->fontdata,0,RW_SEEK_SET); |
64 | 65 |
if(ui->fontdata==NULL |
... | ... |
@@ -153,6 +154,31 @@ reui_resize(reui_t *ui, int w, int h) |
153 | 154 |
return(0); |
154 | 155 |
} |
155 | 156 |
|
157 |
+int |
|
158 |
+reui_setfontheight(reui_t *ui, int fontheight) |
|
159 |
+{ |
|
160 |
+ TTF_Font *newfont; |
|
161 |
+ SDL_Surface *s; |
|
162 |
+ SDL_Color c={0,0,0,0}; |
|
163 |
+ if(ui==NULL || fontheight<=0) |
|
164 |
+ return(-1); /* sanity check failed */ |
|
165 |
+ SDL_RWseek(ui->fontdata,0,RW_SEEK_SET); |
|
166 |
+ if((newfont=TTF_OpenFontRW(ui->fontdata,0,fontheight))==NULL) |
|
167 |
+ return(-1); /* couln't setup new font */ |
|
168 |
+ if((s=TTF_RenderUTF8_Blended(newfont,"m",c))==NULL) { |
|
169 |
+ TTF_CloseFont(newfont),newfont=NULL; |
|
170 |
+ return(-1); /* couldn't use new font */ |
|
171 |
+ } |
|
172 |
+ if(ui->font!=NULL) |
|
173 |
+ TTF_CloseFont(ui->font),ui->font=NULL; |
|
174 |
+ ui->font=newfont; |
|
175 |
+ ui->fontheight=fontheight; |
|
176 |
+ ui->fontwidth=s->w; |
|
177 |
+ SDL_FreeSurface(s),s=NULL; |
|
178 |
+ return(0); |
|
179 |
+} |
|
180 |
+ |
|
181 |
+ |
|
156 | 182 |
int |
157 | 183 |
reui_fill(reui_t *ui, int x, int y, int w, int h, char *rgba) |
158 | 184 |
{ |
... | ... |
@@ -31,11 +31,12 @@ typedef struct reui_t { |
31 | 31 |
int rendererdirty; |
32 | 32 |
} reui_t; |
33 | 33 |
|
34 |
-reui_t *reui_init(); |
|
34 |
+reui_t *reui_init(int fontheight); |
|
35 | 35 |
void reui_free(reui_t *ui); |
36 | 36 |
|
37 | 37 |
int reui_title(reui_t *ui, char *titlefilename); |
38 | 38 |
int reui_resize(reui_t *ui, int w, int h); |
39 |
+int reui_setfontheight(reui_t *ui, int fontheight); |
|
39 | 40 |
int reui_fill(reui_t *ui, int x, int y, int w, int h, char *rgba); |
40 | 41 |
int reui_scr2renderer(reui_t *ui, int x, int y, int w, int h); |
41 | 42 |
int reui_present(reui_t *ui); |
... | ... |
@@ -28,6 +28,7 @@ |
28 | 28 |
#define IDLETIMEOUTSECONDS 10 |
29 | 29 |
|
30 | 30 |
#define COMMANDBUFSIZE 1024 |
31 |
+#define DEFAULTFONTHEIGHT 16 |
|
31 | 32 |
|
32 | 33 |
#define COMMAND_WARNING "(!)" |
33 | 34 |
#define COMMAND_GOTOLINE "Go to line:" |
... | ... |
@@ -54,6 +55,7 @@ typedef struct re_t { |
54 | 55 |
int flag_newfile; |
55 | 56 |
char filename[PATH_MAX]; |
56 | 57 |
int x, y, w, h; // contents rect |
58 |
+ int fontheightpercent; |
|
57 | 59 |
long cursorpos; |
58 | 60 |
int originline,origincol; |
59 | 61 |
int curline,curcol; |
... | ... |
@@ -91,6 +93,7 @@ int re_processkey_commanddata(re_t *re, SDL_Event *event); |
91 | 93 |
int re_processcommand(re_t *re); |
92 | 94 |
int re_moveupdown(re_t *re, int totalinc); |
93 | 95 |
int re_moveleftright(re_t *re, int totalinc); |
96 |
+int re_changefontsize(re_t *re, int direction); |
|
94 | 97 |
int re_rtrim(re_t *re, long curpos, int *trimmed); |
95 | 98 |
long re_getmatchingbracket(re_t *re,long posini, char originalchar, char *matchingchar); |
96 | 99 |
int re_drawheader_editing(re_t *re); |
... | ... |
@@ -320,7 +323,8 @@ re_init(void) |
320 | 323 |
re_free(re),re=NULL; |
321 | 324 |
return(NULL); /* insuf. mem. */ |
322 | 325 |
} |
323 |
- if((re->ui=reui_init())==NULL) { |
|
326 |
+ re->fontheightpercent=100; |
|
327 |
+ if((re->ui=reui_init(DEFAULTFONTHEIGHT*re->fontheightpercent/100))==NULL) { |
|
324 | 328 |
re_free(re),re=NULL; |
325 | 329 |
return(NULL); /* video init error */ |
326 | 330 |
} |
... | ... |
@@ -645,6 +649,18 @@ fprintf(stderr,"re_processkey(): received Control+l\n"); |
645 | 649 |
re_fixorigin_center(re); |
646 | 650 |
re->headerdirty=1; |
647 | 651 |
re->contentsdirty=1; |
652 |
+ } else if(event->key.keysym.sym==SDLK_PLUS && (SDL_GetModState()&KMOD_CTRL)!=0) { |
|
653 |
+fprintf(stderr,"re_processkey(): received Control+'+'\n"); |
|
654 |
+ re_changefontsize(re, 1); |
|
655 |
+ re->ignorenkeys++; |
|
656 |
+ } else if(event->key.keysym.sym==SDLK_MINUS && (SDL_GetModState()&KMOD_CTRL)!=0) { |
|
657 |
+fprintf(stderr,"re_processkey(): received Control+'-'\n"); |
|
658 |
+ re_changefontsize(re, -1); |
|
659 |
+ re->ignorenkeys++; |
|
660 |
+ } else if(event->key.keysym.sym==SDLK_0 && (SDL_GetModState()&KMOD_CTRL)!=0) { |
|
661 |
+fprintf(stderr,"re_processkey(): received Control+'0'\n"); |
|
662 |
+ re_changefontsize(re, 0); |
|
663 |
+ re->ignorenkeys++; |
|
648 | 664 |
} |
649 | 665 |
return(0); |
650 | 666 |
} |
... | ... |
@@ -915,6 +931,44 @@ re_moveleftright(re_t *re, int totalinc) |
915 | 931 |
return(0); |
916 | 932 |
} |
917 | 933 |
|
934 |
+int |
|
935 |
+re_changefontsize(re_t *re, int direction) |
|
936 |
+{ |
|
937 |
+ int validpercent[]={30,50,67,80,90,100,110,120,133,150,170,200,240,300}; |
|
938 |
+ int newpercent; |
|
939 |
+ int i; |
|
940 |
+ if(re==NULL) |
|
941 |
+ return(-1); /* sanity check failed */ |
|
942 |
+ if(direction<0) { |
|
943 |
+ newpercent=validpercent[0]; |
|
944 |
+ for(i=0;i<(sizeof(validpercent)/sizeof(validpercent[0]));i++) { |
|
945 |
+ if(validpercent[i]<re->fontheightpercent) |
|
946 |
+ newpercent=validpercent[i]; |
|
947 |
+ else |
|
948 |
+ break; |
|
949 |
+ } |
|
950 |
+ } else if(direction>0) { |
|
951 |
+ newpercent=validpercent[(sizeof(validpercent)/sizeof(validpercent[0]))-1]; |
|
952 |
+ for(i=(sizeof(validpercent)/sizeof(validpercent[0]))-1;i>=0;i--) { |
|
953 |
+ if(validpercent[i]>re->fontheightpercent) |
|
954 |
+ newpercent=validpercent[i]; |
|
955 |
+ else |
|
956 |
+ break; |
|
957 |
+ } |
|
958 |
+ } else { |
|
959 |
+ newpercent=100; |
|
960 |
+ } |
|
961 |
+ if(reui_setfontheight(re->ui,DEFAULTFONTHEIGHT*newpercent/100)==-1) |
|
962 |
+ return(-1); /* couldn't setup new font size */ |
|
963 |
+ re->fontheightpercent=newpercent; |
|
964 |
+ re_setuidata(re); |
|
965 |
+ re_fixorigin(re); |
|
966 |
+ re->contentsdirty=1; |
|
967 |
+ re->headerdirty=1; |
|
968 |
+ return(0); |
|
969 |
+} |
|
970 |
+ |
|
971 |
+ |
|
918 | 972 |
int |
919 | 973 |
re_rtrim(re_t *re, long curpos, int *trimmed) |
920 | 974 |
{ |