From a48c3dd573157b581f522325bc6dd9c5259c2ad3 Mon Sep 17 00:00:00 2001 From: Bilgin COSKUN Date: Mon, 10 Aug 2020 12:47:39 +0300 Subject: [PATCH] Add Option to Blend Full Tiles --- README.md | 7 ++++- app/jni/src/main.c | 44 ++++++++++++++++++++++++-------- app/src/main/assets/default.ttf | Bin 93680 -> 93712 bytes 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4033b8a..803c9c3 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ You can see the supported configurations below: | filter_mode | Integer | 2 | Selects the algorithm for anti-aliasing: 0 uses nearest pixel sampling, 1 uses linear filtering and 2 uses anistropic filtering. If you get graphical glitches or performance issues, try to lower the value | | tiles_by_default | Boolean | 0 | When enabled, the tiles will be shown by default | | tiles_animation | Boolean | 1 | Enables tiles animation. Disabling will lower the power consumption | +| blend_full_tiles | Boolean | 1 | Tries to blend full tiles like walls with adjacent ones. May result in blurrier tiles | | double_tap_lock | Boolean | 1 | When enabled it will ignore the missclicks within **double_tap_interval** range | | double_tap_interval | Integer | 500 | Milliseconds.The maximum time between two taps to acknowledge it as a double tap. Value is between 100 and 100000 | | dpad_enabled | Boolean | 1 | Enable on-screen d-pad | @@ -136,4 +137,8 @@ However fonts must be: * Monospace -* Animated tiles must be placed such that the offset between the first frame and the second one must be 256 +Additionally: + +* If the font have animated tiles then the offset between the first frame and the second one should be 256 + +* the font should define a boundary box in glyph 139 for full tiles diff --git a/app/jni/src/main.c b/app/jni/src/main.c index 31467e2..0bc028a 100644 --- a/app/jni/src/main.c +++ b/app/jni/src/main.c @@ -32,11 +32,13 @@ #define MAX_GLYPH_NO (TILES_LEN * 3) #define TILES_FLIP_TIME 900 #define MIN_TILE G_UP_ARROW +#define FONT_BOUND_CHAR 139 typedef struct { double width, height, offset_x, offset_y; SDL_Texture *c; boolean animated; + boolean full_tile; } glyph_cache; typedef enum{ @@ -84,6 +86,8 @@ static boolean screen_changed = false; static _Atomic boolean resumed = false; static TTF_Font *font; static glyph_cache font_cache[MAX_GLYPH_NO]; +static int font_width; +static int font_height; static SDL_Texture * dpad_image_select; static SDL_Texture * dpad_image_move; static SDL_Rect dpad_area; @@ -137,6 +141,7 @@ static int check_update_interval; static boolean ask_for_update_check; static boolean tiles_by_default; static boolean tiles_animation; +static boolean blend_full_tiles; boolean hasGraphics = true; boolean graphicsEnabled = true; @@ -332,6 +337,7 @@ void set_conf(const char * name,const char * value){ set_and_parse_bool_conf(dynamic_colors,true,false); set_and_parse_bool_conf(tiles_by_default, false, false); set_and_parse_bool_conf(tiles_animation, true, false); + set_and_parse_bool_conf(blend_full_tiles, true, false); set_and_parse_conf(filter_mode,2,0,2,true); add_section("Input Settings"); set_and_parse_bool_conf(double_tap_lock,true,false); @@ -593,25 +599,39 @@ void draw_glyph(enum displayGlyph c, SDL_FRect rect, uint8_t r, uint8_t g, uint8 SDL_Color fc = {COLOR_MAX, COLOR_MAX, COLOR_MAX}; SDL_Surface *text; if((key >= 2*TILES_LEN) && !TTF_GlyphIsProvided(font,key)){ - text = TTF_RenderGlyph_Blended(font, key - TILES_LEN, fc); + key = key - TILES_LEN; }else{ - text = TTF_RenderGlyph_Blended(font, key, fc); font_cache[c].animated = true; } - lc->width = text->w; - lc->height = text->h; + text = TTF_RenderGlyph_Blended(font, key, fc); + int minx,maxx,miny,maxy,fw,fh; + TTF_GlyphMetrics(font,key,&minx,&maxx,&miny,&maxy,NULL); + fw = maxx - minx; + fh = maxy - miny; + if((fw >= font_width) && (fh >= font_height)){ + lc->full_tile = true; + } lc->offset_x = (rect.w - text->w) / 2; lc->offset_y = (rect.h - text->h) / 2; + lc->width = text->w; + lc->height = text->h; lc->c = SDL_CreateTextureFromSurface(renderer, text); SDL_FreeSurface(text); } - SDL_Rect font_rect; - font_rect.x = rect.x + lc->offset_x; - font_rect.y = rect.y + lc->offset_y; - font_rect.w = lc->width; - font_rect.h = lc->height; + SDL_SetTextureColorMod(lc->c, r, g, b); - SDL_RenderCopy(renderer, lc->c, NULL, &font_rect); + if(blend_full_tiles && (lc->full_tile)){ + SDL_Rect src = {.x = 0,.y=0,.w=font_width,.h=font_height}; + SDL_RenderCopyF(renderer, lc->c, &src, &rect); + }else{ + SDL_Rect font_rect; + font_rect.x = rect.x + lc->offset_x; + font_rect.y = rect.y + lc->offset_y; + font_rect.w = lc->width; + font_rect.h = lc->height; + SDL_RenderCopy(renderer, lc->c, NULL, &font_rect); + } + } TTF_Font *init_font_size(char *font_path, int size) { @@ -644,6 +664,10 @@ boolean init_font() { TTF_CloseFont(font); font = new_size; } else { + int minx,maxx,miny,maxy; + TTF_GlyphMetrics(font,FONT_BOUND_CHAR,&minx,&maxx,&miny,&maxy,NULL); + font_width = maxx - minx; + font_height = maxy - miny; return true; } } diff --git a/app/src/main/assets/default.ttf b/app/src/main/assets/default.ttf index bba27ed4decc8123e4b00c5d5c6ec599a33355ca..8254308fcd0f113e5a55e5158efa4eb15505fcbd 100644 GIT binary patch delta 1104 zcmexxn{~n+Ru2Y71_lNpAi=_*;N}+M+qvP-b_T}WFF;WlcNbST26e_`42(HTfP6Lg z0RLdqbAB6u@>_s>2lwDmr=XP$*+BU-6FvN8X8;9x(sL@)wyisQpMgOXXt<6+MrvY; z{N5>M6SwGC%%2mg2egfafq~g6H?g9C{U2*R0|R3RP@h6xVs7fqQv2HsjE)ry42t#z z`Nbt~itSf3FedGoEWs!vQxfN#6whz-l|h~ZsGfo0@*zzD5Pdsr{nE_=j1vXx>tr^_ z9Fe&r^F@|VRz=oIHcxh$>@nFpvTtO+$bONNk*kwCAs-^YPyUHQnZgW3HN_cL=Ch|V;f3%VS-F1k&+3v?go z1?k1H-gYh2|H-t4>3Prk!P{RQqS^L61Ew(J$5#Bf9yl-&p2o~9CPGx+~6eQl;m{IS;hIDOPWb=9H5N5B zwe>8ui|X9!w$&Tdx77b=Sk>^UaZyuJ)2?Qt=8hJ%mSe3NtyQhB+FaV+wKue%>agip z)XCM^)Wy(ss@tx+qQ|UfQLjnwp5A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