diff --git a/src/game/boe.dlgutil.cpp b/src/game/boe.dlgutil.cpp index cb87c10b..a2eb7387 100644 --- a/src/game/boe.dlgutil.cpp +++ b/src/game/boe.dlgutil.cpp @@ -682,7 +682,10 @@ void handle_talk_event(location p) { int which_talk_entry = TALK_DUNNO; for(word_rect_t& word : talk_words) { if(word.node == -1) continue; - if(!p.in(word.rect)) continue; + rectangle wordRect(word.rect); + wordRect.offset(talk_area_rect.topLeft()); + wordRect.offset(-1, -10); // TODO: This corrects for the byzantine offsets that win_draw_string applies for some reason... + if(!p.in(wordRect)) continue; click_talk_rect(word); which_talk_entry = word.node; break; diff --git a/src/game/boe.newgraph.cpp b/src/game/boe.newgraph.cpp index b700f337..c564c3cf 100644 --- a/src/game/boe.newgraph.cpp +++ b/src/game/boe.newgraph.cpp @@ -828,7 +828,7 @@ void click_talk_rect(word_rect_t word) { style.pointSize = 18; style.lineHeight = 18; style.colour = word.on; - win_draw_string(mainPtr, wordRect, word.word, eTextMode::LEFT_TOP, style); + win_draw_string(mainPtr, wordRect, word.word, eTextMode::WRAP, style); place_talk_face(); mainPtr.display(); play_sound(37, time_in_ticks(5)); @@ -972,7 +972,6 @@ void place_talk_str(std::string str_to_place,std::string str_to_place2,short col } } - dest_rect = word_place_rect; style.colour = Colours::NAVY; // First determine the offsets of clickable words. // The added spaces ensure that end-of-word boundaries are found @@ -994,7 +993,7 @@ void place_talk_str(std::string str_to_place,std::string str_to_place2,short col } } - std::vector word_rects = draw_string_hilite(talk_gworld, dest_rect, str, style, hilites, color ? Colours::DARK_BLUE : Colours::DARK_RED); + std::vector word_rects = draw_string_hilite(talk_gworld, word_place_rect, str, style, hilites, color ? Colours::DARK_BLUE : Colours::DARK_RED); if(!talk_end_forced) { // Now build the list of word rects diff --git a/src/gfx/render_text.cpp b/src/gfx/render_text.cpp index a3f7a982..fcffbecb 100644 --- a/src/gfx/render_text.cpp +++ b/src/gfx/render_text.cpp @@ -8,6 +8,7 @@ #include "render_text.hpp" +#include #include "res_font.hpp" #include "render_shapes.hpp" @@ -76,7 +77,8 @@ static void push_snippets(size_t start, size_t end, text_params_t& options, size } size_t amount = end - start; snippets.push_back({str.substr(start,amount), loc, hilited}); - loc.x += string_length(snippets[snippets.size()-1].text, options.style); + if(hilited) std::cout << "Hiliting passage : \"" << snippets.back().text << '"' << std::endl; + loc.x += string_length(snippets.back().text, options.style); start = end; end = upper_bound; if(iHilite < hilites.size() && start >= hilites[iHilite].second) @@ -92,9 +94,10 @@ static void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,st short str_len; unsigned short last_line_break = 0,last_word_break = 0; short total_width = 0; - short adjust_x = 0,adjust_y = 0; + short adjust_x = 1, adjust_y = 10; str_to_draw.setString("fj"); // Something that has both an ascender and a descender + // TODO: Why the heck are we drawing a whole line higher than requested!? adjust_y -= str_to_draw.getLocalBounds().height; str_to_draw.setString(str); @@ -121,7 +124,7 @@ static void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,st line_height -= 2; // TODO: ...why are we arbitrarily reducing the line height from the requested value? if(mode == eTextMode::WRAP) { - moveTo = location(dest_rect.left + 1 + adjust_x, dest_rect.top + 1 + adjust_y + 9); + moveTo = location(dest_rect.left + adjust_x, dest_rect.top + adjust_y); short i; for(i = 0; text_len(i) != text_len(i + 1) && i < str_len; i++) { if(((text_len(i) - text_len(last_line_break) > (dest_rect.width() - 6)) @@ -146,15 +149,20 @@ static void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,st } } else { switch(mode) { + // TODO: CENTRE and LEFT_BOTTOM don't work with text rect calculation... + // Low priority, since the API doesn't even offer a way to do this. case eTextMode::CENTRE: - moveTo = location((dest_rect.right + dest_rect.left) / 2 - (4 * total_width) / 9 + adjust_x, - (dest_rect.bottom + dest_rect.top - line_height) / 2 + 9 + adjust_y); + // TODO: Calculate adjust_x/y directly instead... + moveTo = location((dest_rect.right + dest_rect.left) / 2 - (4 * total_width) / 9, + (dest_rect.bottom + dest_rect.top - line_height) / 2 + adjust_y - 1); + adjust_x = moveTo.x - dest_rect.left; + adjust_y = moveTo.y - dest_rect.top; break; case eTextMode::LEFT_TOP: - moveTo = location(dest_rect.left + 1 + adjust_x, dest_rect.top + 1 + adjust_y + 9); + moveTo = location(dest_rect.left + adjust_x, dest_rect.top + adjust_y); break; case eTextMode::LEFT_BOTTOM: - moveTo = location(dest_rect.left + 1 + adjust_x, dest_rect.top + 1 + adjust_y + 9 + dest_rect.height() / 6); + moveTo = location(dest_rect.left + adjust_x, dest_rect.top + adjust_y + dest_rect.height() / 6); break; case eTextMode::WRAP: break; // Never happens, but put this here to silence warning @@ -169,8 +177,8 @@ static void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,st rectangle bounds = str_to_draw.getGlobalBounds(); // Adjust so that drawing the same text to // the same rect is positioned exactly right - bounds.left = snippet.at.x - 1; - bounds.top = snippet.at.y + 5; + bounds.move_to(snippet.at); + bounds.offset(-adjust_x, -adjust_y); if(options.returnType == text_params_t::RECTS) options.returnRects.push_back(bounds); str_to_draw.setColor(options.hilite_fg); diff --git a/src/location.cpp b/src/location.cpp index ef1dd8b0..af45518a 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -195,6 +195,14 @@ void rectangle::offset(location diff) { offset(diff.x, diff.y); } +void rectangle::move_to(int x, int y) { + offset(x - left, y - top); +} + +void rectangle::move_to(location loc) { + move_to(loc.x, loc.y); +} + void rectangle::inset(int dh, int dv) { left += dh; right -= dh; top += dv; bottom -= dv; diff --git a/src/location.hpp b/src/location.hpp index 97d94990..61928395 100644 --- a/src/location.hpp +++ b/src/location.hpp @@ -90,6 +90,8 @@ struct rectangle { bool contains(int x, int y); void offset(int h, int v); void offset(location diff); + void move_to(int x, int y); + void move_to(location loc); template void offset(sf::Vector2 diff) {offset(diff.x,diff.y);} void inset(int dh, int dv);