diff --git a/desktop_version/src/Editor.cpp b/desktop_version/src/Editor.cpp index 51ae16b7..7ba601e4 100644 --- a/desktop_version/src/Editor.cpp +++ b/desktop_version/src/Editor.cpp @@ -99,6 +99,7 @@ void editorclass::reset(void) sbx=0; sby=0; pagey=0; + lines_visible = 25; scripteditmod=false; sbscript="null"; scripthelppage=0; @@ -755,9 +756,9 @@ void editorrender(void) } fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),16,24,graphics.getRGB(255, 255, 164)); short labelcol = ed.entframe<2 ? 255 : 196; - short startlen = graphics.len(loc::gettext("START")); - graphics.bprint( - (customentities[i].x*8) - (ed.levx*40*8) + 8 - startlen/2, + font::print( + PR_BOR | PR_CEN | PR_CJK_HIGH, + (customentities[i].x*8) - (ed.levx*40*8) + 8, (customentities[i].y*8) - (ed.levy*30*8) - 8, loc::gettext("START"), labelcol,labelcol,labelcol @@ -767,14 +768,13 @@ void editorrender(void) case 17: //Roomtext if(customentities[i].scriptname.length()<1) { - fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),8,8,graphics.getRGB(96,96,96)); + fillboxabs((customentities[i].x*8)-(ed.levx*40*8), (customentities[i].y*8)-(ed.levy*30*8), 8, 8, graphics.getRGB(96,96,96)); } else { - int length = utf8::unchecked::distance(customentities[i].scriptname.begin(), customentities[i].scriptname.end()); - fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),length*8,8,graphics.getRGB(96,96,96)); + fillboxabs((customentities[i].x*8)-(ed.levx*40*8), (customentities[i].y*8)-(ed.levy*30*8), font::len(PR_FONT_LEVEL, customentities[i].scriptname), font::height(PR_FONT_LEVEL), graphics.getRGB(96,96,96)); } - graphics.Print((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8), customentities[i].scriptname, 196, 196, 255 - help.glow); + font::print(PR_FONT_LEVEL | PR_CJK_LOW, (customentities[i].x*8)-(ed.levx*40*8), (customentities[i].y*8)-(ed.levy*30*8), customentities[i].scriptname, 196, 196, 255 - help.glow); break; case 18: //Terminals { @@ -1214,17 +1214,18 @@ void editorrender(void) ); graphics.Print(16,228, namebuffer, 123, 111, 218, true); //Draw text - for(int i=0; i<25; i++) + int font_height = font::height(PR_FONT_LEVEL); + for(int i=0; iroomname, 196, 196, 255 - help.glow, true); - graphics.bprint(4, 222, loc::gettext("SPACE ^ SHIFT ^"), 196, 196, 255 - help.glow, false); - graphics.bprint(268,222, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")",196, 196, 255 - help.glow, false); + font::print(PR_CEN | PR_BOR | PR_FONT_LEVEL | PR_CJK_LOW, -1, 231+ed.roomnamehide, room->roomname, 196, 196, 255 - help.glow); + font::print(PR_BOR | PR_CJK_HIGH, 4, 222, loc::gettext("SPACE ^ SHIFT ^"), 196, 196, 255 - help.glow); + font::print(PR_BOR | PR_CJK_HIGH | PR_RIGHT, 316, 222, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")", 196, 196, 255 - help.glow); } else { - graphics.bprint(4, 232, loc::gettext("SPACE ^ SHIFT ^"), 196, 196, 255 - help.glow, false); - graphics.bprint(268,232, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")",196, 196, 255 - help.glow, false); + font::print(PR_BOR | PR_CJK_HIGH, 4, 232, loc::gettext("SPACE ^ SHIFT ^"), 196, 196, 255 - help.glow); + font::print(PR_BOR | PR_CJK_HIGH | PR_RIGHT, 316, 232, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")", 196, 196, 255 - help.glow); } } @@ -1856,6 +1855,7 @@ static void editormenuactionpress(void) ed.scripthelppagedelay=0; ed.sby=0; ed.sbx=0, ed.pagey=0; + ed.lines_visible = 200/font::height(PR_FONT_LEVEL); break; case 2: music.playef(11); @@ -2191,7 +2191,7 @@ void editorinput(void) ed.sby=ed.sb.size()-1; ed.pagey=0; - while(ed.sby>=20) + while(ed.sby>=ed.lines_visible-5) { ed.pagey++; ed.sby--; @@ -2240,7 +2240,7 @@ void editorinput(void) if(ed.sby+ed.pagey<(int)ed.sb.size()-1) { ed.sby++; - if(ed.sby>=20) + if(ed.sby>=ed.lines_visible-5) { ed.pagey++; ed.sby--; @@ -2299,7 +2299,7 @@ void editorinput(void) if(ed.sby+ed.pagey>=(int)ed.sb.size()) //we're on the last line { ed.sby++; - if(ed.sby>=20) + if(ed.sby>=ed.lines_visible-5) { ed.pagey++; ed.sby--; @@ -2311,7 +2311,7 @@ void editorinput(void) { //We're not, insert a line instead ed.sby++; - if(ed.sby>=20) + if(ed.sby>=ed.lines_visible-5) { ed.pagey++; ed.sby--; diff --git a/desktop_version/src/Editor.h b/desktop_version/src/Editor.h index 9bbdad31..ba1317c2 100644 --- a/desktop_version/src/Editor.h +++ b/desktop_version/src/Editor.h @@ -147,6 +147,7 @@ public: std::string sbscript; int sbx, sby; int pagey; + int lines_visible; //Functions for interfacing with the script: void addhook(const std::string& t); diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index a56fcb54..a9caaae3 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -118,6 +118,11 @@ static GlyphInfo* find_glyphinfo(const Font* f, const uint32_t codepoint) int get_advance(const Font* f, const uint32_t codepoint) { // Get the width of a single character in a font + if (f == NULL) + { + return 8; + } + GlyphInfo* glyph = find_glyphinfo(f, codepoint); if (glyph == NULL) { @@ -341,7 +346,8 @@ static bool find_font_by_name(FontContainer* container, const char* name, size_t static void set_custom_font(const char* name) { - /* Apply the choice for a certain level-specific font */ + /* Apply the choice for a certain level-specific font. */ + if (find_font_by_name(&fonts_custom, name, &font_idx_custom)) { font_idx_custom_is_custom = true; @@ -693,11 +699,59 @@ static int print_char( return glyph->advance * scale; } +static Font* container_get(FontContainer* container, size_t idx) +{ + /* Get a certain font from the given container (with bounds checking). + * Does its best to return at least something, + * but if there are no fonts whatsoever, can return NULL. */ + + if (idx < container->count) + { + return &container->fonts[idx]; + } + if (font_idx_8x8 < fonts_main.count) + { + return &fonts_main.fonts[font_idx_8x8]; + } + if (fonts_main.count > 0) + { + return &fonts_main.fonts[0]; + } + return NULL; +} + static Font* fontsel_to_font(int sel) { - /* Take font selection integer (0-31) and turn it into the correct Font */ - // TODO handle all these cases here like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 etc - return &fonts_main.fonts[font_idx_8x8]; + /* Take font selection integer (0-31) and turn it into the correct Font + * 0: PR_FONT_INTERFACE - use interface font + * 1: PR_FONT_LEVEL - use level font + * 2: PR_FONT_8X8 - use 8x8 font no matter what + * 3-31: - use (main) font index 0-28 */ + + if (sel < 0) + { + /* Shouldn't happen but better safe than sorry... */ + return NULL; + } + + switch (sel) + { + case 0: + return container_get(&fonts_main, font_idx_interface); + case 1: + if (font_idx_custom_is_custom) + { + return container_get(&fonts_custom, font_idx_custom); + } + else + { + return container_get(&fonts_main, font_idx_custom); + } + case 2: + return container_get(&fonts_main, font_idx_8x8); + } + + return container_get(&fonts_main, sel-3); } #define FLAG_PART(start, count) ((flags >> start) % (1 << count)) @@ -742,6 +796,17 @@ int len(const uint32_t flags, const std::string& t) return text_len * pf.scale; } +int height(const uint32_t flags) +{ + PrintFlags pf = decode_print_flags(flags); + if (pf.font_sel == NULL) + { + return 8; + } + + return pf.font_sel->glyph_h * pf.scale; +} + void print( const uint32_t flags, int x, @@ -753,6 +818,10 @@ void print( ) { PrintFlags pf = decode_print_flags(flags); + if (pf.font_sel == NULL) + { + return; + } if (pf.align_cen || pf.align_right) { diff --git a/desktop_version/src/Font.h b/desktop_version/src/Font.h index ff0d5690..c79397f6 100644 --- a/desktop_version/src/Font.h +++ b/desktop_version/src/Font.h @@ -115,6 +115,7 @@ std::string string_wordwrap_balanced(const std::string& s, int maxwidth); std::string string_unwordwrap(const std::string& s); int len(uint32_t flags, const std::string& t); +int height(const uint32_t flags); void print( uint32_t flags, diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 70366458..905529f0 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -873,11 +873,17 @@ void Graphics::drawgui(void) const int b = textboxes[i].b * tl_lerp; size_t j; - drawtextbox(textboxes[i].xp, yp, textboxes[i].w/8, textboxes[i].h/8, r, g, b); + drawpixeltextbox(textboxes[i].xp, yp, textboxes[i].w, textboxes[i].h, r, g, b); for (j = 0; j < textboxes[i].lines.size(); j++) { - font::print(PR_COLORGLYPH_BRI(tl_lerp*255), textboxes[i].xp + 8, yp + text_yoff + text_sign * (j * 8), textboxes[i].lines[j], r, g, b); + font::print( + PR_COLORGLYPH_BRI(tl_lerp*255) | PR_CJK_LOW, + textboxes[i].xp + 8, + yp + text_yoff + text_sign * (j * font::height(PR_FONT_LEVEL)), + textboxes[i].lines[j], + r, g, b + ); } } @@ -1336,7 +1342,7 @@ void Graphics::drawtextbox( const int g, const int b ) { - return drawpixeltextbox(x, y, w*8, h*8, r, g, b); + return drawpixeltextbox(x, y, w*8, 16 + (h-2)*font::height(PR_FONT_LEVEL), r, g, b); } void Graphics::textboxactive(void) @@ -3476,10 +3482,19 @@ SDL_Color Graphics::crewcolourreal(int t) void Graphics::render_roomname(const char* roomname, int r, int g, int b) { - footerrect.y = 230; + int font_height = font::height(PR_FONT_LEVEL); + if (font_height <= 8) + { + footerrect.h = font_height + 2; + } + else + { + footerrect.h = font_height + 1; + } + footerrect.y = 240 - footerrect.h; set_blendmode(SDL_BLENDMODE_BLEND); fill_rect(&footerrect, getRGBA(0, 0, 0, translucentroomname ? 127 : 255)); - bprint(5, 231, roomname, r, g, b, true); + font::print(PR_CEN | PR_BOR | PR_FONT_LEVEL | PR_CJK_LOW, -1, footerrect.y+1, roomname, r, g, b); set_blendmode(SDL_BLENDMODE_NONE); } diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index b193ecb0..0eff172a 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -1945,7 +1945,7 @@ void gamerender(void) //Draw room text! for (size_t i = 0; i < map.roomtext.size(); i++) { - graphics.Print(map.roomtext[i].x*8, (map.roomtext[i].y*8), map.roomtext[i].text, 196, 196, 255 - help.glow); + font::print(PR_FONT_LEVEL | PR_CJK_LOW, map.roomtext[i].x*8, (map.roomtext[i].y*8), map.roomtext[i].text, 196, 196, 255 - help.glow); } } @@ -2233,7 +2233,7 @@ void gamerender(void) game.activity_b*act_alpha ); font::print( - PR_COLORGLYPH_BRI(act_alpha*255), + PR_COLORGLYPH_BRI(act_alpha*255) | PR_CJK_LOW, centered_x + game.activity_x, game.activity_y + 12, final_string, diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index b852580a..292dc643 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -577,12 +577,12 @@ void scriptclass::run(void) if (j == 1) //left { textx = obj.entities[i].xp -10000; //tells the box to be oriented correctly later - texty = obj.entities[i].yp - 16 - (txt.size()*8); + texty = obj.entities[i].yp - 16 - (txt.size() * font::height(PR_FONT_LEVEL)); } else if (j == 0) //Right { textx = obj.entities[i].xp - 16; - texty = obj.entities[i].yp - 18 - (txt.size() * 8); + texty = obj.entities[i].yp - 18 - (txt.size() * font::height(PR_FONT_LEVEL)); } } else if (INBOUNDS_VEC(i, obj.entities)) @@ -674,12 +674,12 @@ void scriptclass::run(void) if (j == 1) //left { textx = obj.entities[i].xp -10000; //tells the box to be oriented correctly later - texty = obj.entities[i].yp - 16 - (txt.size()*8); + texty = obj.entities[i].yp - 16 - (txt.size() * font::height(PR_FONT_LEVEL)); } else if (j == 0) //Right { textx = obj.entities[i].xp - 16; - texty = obj.entities[i].yp - 18 - (txt.size() * 8); + texty = obj.entities[i].yp - 18 - (txt.size() * font::height(PR_FONT_LEVEL)); } } else if (INBOUNDS_VEC(i, obj.entities)) diff --git a/desktop_version/src/Textbox.cpp b/desktop_version/src/Textbox.cpp index b4577e7d..14dc98f2 100644 --- a/desktop_version/src/Textbox.cpp +++ b/desktop_version/src/Textbox.cpp @@ -3,6 +3,8 @@ #include #include +#include "Font.h" + textboxclass::textboxclass(void) { w = 0; @@ -100,13 +102,13 @@ void textboxclass::resize(void) int max = 0; for (size_t iter = 0; iter < lines.size(); iter++) { - unsigned int len = utf8::unchecked::distance(lines[iter].begin(), lines[iter].end()); + int len = font::len(PR_FONT_LEVEL, lines[iter]); if (len > (unsigned int)max) max = len; } // 16 for the borders - w = max*8 + 16; - h = lines.size()*8 + 16; + w = max + 16; + h = lines.size()*font::height(PR_FONT_LEVEL) + 16; } void textboxclass::addline(const std::string& t)