diff --git a/src/PowderToy.cpp b/src/PowderToy.cpp index 39b663858..858102b4b 100644 --- a/src/PowderToy.cpp +++ b/src/PowderToy.cpp @@ -440,7 +440,7 @@ int main(int argc, char * argv[]) engine.g->Clear(); engine.g->DrawRect(RectSized(engine.g->Size() / 2 - Vec2(100, 25), Vec2(200, 50)), 0xB4B4B4_rgb); String loadingText = "Loading save..."; - engine.g->BlendText(engine.g->Size() / 2 - Vec2(Graphics::textwidth(loadingText) / 2, 5), loadingText, style::Colour::InformationTitle); + engine.g->BlendText(engine.g->Size() / 2 - Vec2((Graphics::TextSize(loadingText).X - 1) / 2, 5), loadingText, style::Colour::InformationTitle); blit(engine.g->Data()); try diff --git a/src/PowderToyRenderer.cpp b/src/PowderToyRenderer.cpp index 18f911bca..6f8b063b5 100644 --- a/src/PowderToyRenderer.cpp +++ b/src/PowderToyRenderer.cpp @@ -61,9 +61,9 @@ int main(int argc, char *argv[]) } else { - int w = Graphics::textwidth("Save file invalid")+16, x = (XRES-w)/2, y = (YRES-24)/2; + int w = Graphics::TextSize("Save file invalid").X + 15, x = (XRES-w)/2, y = (YRES-24)/2; ren->drawrect(x, y, w, 24, 192, 192, 192, 255); - ren->drawtext(x+8, y+8, "Save file invalid", 192, 192, 240, 255); + ren->BlendText({ x+8, y+8 }, "Save file invalid", RGBA(192, 192, 240, 255)); } ren->RenderBegin(); diff --git a/src/debug/DebugLines.cpp b/src/debug/DebugLines.cpp index 9ae004f0e..c5b921de2 100644 --- a/src/debug/DebugLines.cpp +++ b/src/debug/DebugLines.cpp @@ -31,16 +31,16 @@ void DebugLines::Draw() String info; info = String::Build(drawPoint2.X, " x ", drawPoint2.Y); - g->drawtext_outline(drawPoint2.X+(drawPoint2.X>drawPoint1.X?3:-g->textwidth(info)-3), drawPoint2.Y+(drawPoint2.YBlendTextOutline({ drawPoint2.X+(drawPoint2.X>drawPoint1.X?3:-(g->TextSize(info).X-1)-3), drawPoint2.Y+(drawPoint2.Y(255, 255, 255, 200)); info = String::Build(drawPoint1.X, " x ", drawPoint1.Y); - g->drawtext_outline(drawPoint1.X+(drawPoint2.Xtextwidth(info)-2), drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info, 255, 255, 255, 200); + g->BlendTextOutline({ drawPoint1.X+(drawPoint2.XTextSize(info).X-1)-2), drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3) }, info, RGBA(255, 255, 255, 200)); info = String::Build(std::abs(drawPoint2.X-drawPoint1.X)); - g->drawtext_outline((drawPoint1.X+drawPoint2.X)/2-g->textwidth(info)/2, drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info, 255, 255, 255, 200); + g->BlendTextOutline({ (drawPoint1.X+drawPoint2.X)/2-(g->TextSize(info).X-1)/2, drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3) }, info, RGBA(255, 255, 255, 200)); info = String::Build(std::abs(drawPoint2.Y-drawPoint1.Y)); - g->drawtext_outline(drawPoint1.X+(drawPoint2.Xtextwidth(info)-2), (drawPoint1.Y+drawPoint2.Y)/2-3, info, 255, 255, 255, 200); + g->BlendTextOutline({ drawPoint1.X+(drawPoint2.XTextSize(info).X-1)-2), (drawPoint1.Y+drawPoint2.Y)/2-3 }, info, RGBA(255, 255, 255, 200)); } } diff --git a/src/debug/DebugParts.cpp b/src/debug/DebugParts.cpp index 8587b8a33..f6b9bb262 100644 --- a/src/debug/DebugParts.cpp +++ b/src/debug/DebugParts.cpp @@ -47,8 +47,8 @@ void DebugParts::Draw() g->addpixel(lpx, lpy+1, 255, 50, 50, 120); g->addpixel(lpx, lpy-1, 255, 50, 50, 120); - g->fillrect(7, YRES-26, g->textwidth(info)+5, 14, 0, 0, 0, 180); - g->drawtext(10, YRES-22, info, 255, 255, 255, 255); + g->fillrect(7, YRES-26, g->TextSize(info).X + 4, 14, 0, 0, 0, 180); + g->BlendText({ 10, YRES-22 }, info, RGBA(255, 255, 255, 255)); } DebugParts::~DebugParts() diff --git a/src/debug/ElementPopulation.cpp b/src/debug/ElementPopulation.cpp index ecfe30aee..b93ba9b19 100644 --- a/src/debug/ElementPopulation.cpp +++ b/src/debug/ElementPopulation.cpp @@ -44,7 +44,7 @@ void ElementPopulationDebug::Draw() halfValString = String::Build(maxAverage/2); - g->fillrect(xStart-5, yBottom - 263, bars+10+Graphics::textwidth(maxValString)+10, 255 + 13, 0, 0, 0, 180); + g->fillrect(xStart-5, yBottom - 263, bars+10+Graphics::TextSize(maxValString).X+9, 255 + 13, 0, 0, 0, 180); bars = 0; for(int i = 0; i < PT_NUM; i++) @@ -76,9 +76,9 @@ void ElementPopulationDebug::Draw() } } - g->drawtext(xStart + bars + 5, yBottom-5, "0", 255, 255, 255, 255); - g->drawtext(xStart + bars + 5, yBottom-132, halfValString, 255, 255, 255, 255); - g->drawtext(xStart + bars + 5, yBottom-260, maxValString, 255, 255, 255, 255); + g->BlendText({ xStart + bars + 5, yBottom-5 }, "0", RGBA(255, 255, 255, 255)); + g->BlendText({ xStart + bars + 5, yBottom-132 }, halfValString, RGBA(255, 255, 255, 255)); + g->BlendText({ xStart + bars + 5, yBottom-260 }, maxValString, RGBA(255, 255, 255, 255)); } ElementPopulationDebug::~ElementPopulationDebug() diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index c6152e501..b9aa22c2c 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -167,11 +167,6 @@ template class RasterDrawMethods; Graphics::Graphics() {} -int Graphics::textwidth(const String &str) -{ - return TextSize(str).X - 1; -} - void Graphics::draw_icon(int x, int y, Icon icon, unsigned char alpha, bool invert) { y--; @@ -199,12 +194,12 @@ void Graphics::draw_icon(int x, int y, Icon icon, unsigned char alpha, bool inve if(invert) { drawchar(x-11, y+1, 0xE04B, 0, 100, 0, alpha); - drawtext(x+2, y+1, "Vote", 0, 100, 0, alpha); + BlendText({ x+2, y+1 }, "Vote", RGBA(0, 100, 0, alpha)); } else { drawchar(x-11, y+1, 0xE04B, 0, 187, 18, alpha); - drawtext(x+2, y+1, "Vote", 0, 187, 18, alpha); + BlendText({ x+2, y+1 }, "Vote", RGBA(0, 187, 18, alpha)); } break; case IconVoteDown: diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index 2090b0a59..bbc7eb0ce 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -91,10 +91,6 @@ public: }; static std::vector> Gradient(std::vector stops, int resolution); - //Font/text metrics - [[deprecated("Use TextSize().X - 1 (yes this is very bad code eww)")]] - static int textwidth(const String &s); - VideoBuffer DumpFrame(); void draw_icon(int x, int y, Icon icon, unsigned char alpha = 255, bool invert = false); diff --git a/src/graphics/RasterDrawMethods.h b/src/graphics/RasterDrawMethods.h index 83add64d3..53a93e042 100644 --- a/src/graphics/RasterDrawMethods.h +++ b/src/graphics/RasterDrawMethods.h @@ -60,10 +60,6 @@ struct RasterDrawMethods void Clear(); - [[deprecated("Use BlendTextOutline")]] - int drawtext_outline(int x, int y, const String &, int r, int g, int b, int a); - [[deprecated("Use BlendText")]] - int drawtext(int x, int y, const String &, int r, int g, int b, int a); [[deprecated("Use BlendChar")]] int drawchar(int x, int y, String::value_type, int r, int g, int b, int a); [[deprecated("Use AddChar")]] @@ -92,8 +88,4 @@ struct RasterDrawMethods void fillcircle(int x, int y, int rx, int ry, int r, int g, int b, int a); [[deprecated("Use DrawFilledRect (beware off by 1)")]] void clearrect(int x, int y, int w, int h); - [[deprecated("Use BlendImage")]] - void draw_image(pixel const *, int x, int y, int w, int h, int a); - [[deprecated("Use BlendImage")]] - void draw_image(VideoBuffer const *, int x, int y, int a); }; diff --git a/src/graphics/RasterDrawMethodsImpl.h b/src/graphics/RasterDrawMethodsImpl.h index 1c1742e2d..42d6d43d7 100644 --- a/src/graphics/RasterDrawMethodsImpl.h +++ b/src/graphics/RasterDrawMethodsImpl.h @@ -401,18 +401,6 @@ String::const_iterator RasterDrawMethods::TextFit(String const &str, in return str.end(); } -template -int RasterDrawMethods::drawtext_outline(int x, int y, const String &s, int r, int g, int b, int a) -{ - return x + BlendTextOutline(Vec2(x, y), s, RGBA(r, g, b, a)).X; -} - -template -int RasterDrawMethods::drawtext(int x, int y, const String &str, int r, int g, int b, int a) -{ - return x + BlendText(Vec2(x, y), str, RGBA(r, g, b, a)).X; -} - template int RasterDrawMethods::drawchar(int x, int y, String::value_type c, int r, int g, int b, int a) { @@ -513,17 +501,5 @@ void RasterDrawMethods::clearrect(int x, int y, int w, int h) DrawFilledRect(RectSized(Vec2(x + 1, y + 1), Vec2(w - 1, h - 1)), 0x000000_rgb); } -template -void RasterDrawMethods::draw_image(const pixel *img, int x, int y, int w, int h, int a) -{ - BlendImage(img, a, RectSized(Vec2(x, y), Vec2(w, h))); -} - -template -void RasterDrawMethods::draw_image(const VideoBuffer * vidBuf, int x, int y, int a) -{ - BlendImage(vidBuf->Data(), a, RectSized(Vec2(x, y), vidBuf->Size())); -} - #undef video #undef clipRect diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 477db8f5a..34134290d 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -152,7 +152,7 @@ void Renderer::DrawSigns() String text = currentSign.getDisplayText(sim, x, y, w, h); clearrect(x, y, w+1, h); drawrect(x, y, w+1, h, 192, 192, 192, 255); - drawtext(x+3, y+4, text, 255, 255, 255, 255); + BlendText({ x+3, y+4 }, text, RGBA(255, 255, 255, 255)); if (currentSign.ju != sign::None) { @@ -417,7 +417,7 @@ void Renderer::render_parts() if (mousePos.X>(nx-3) && mousePos.X<(nx+3) && mousePos.Y<(ny+3) && mousePos.Y>(ny-3)) //If mouse is in the head { String hp = String::Build(Format::Width(sim->parts[i].life, 3)); - drawtext(mousePos.X-8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), mousePos.Y-12, hp, 255, 255, 255, 255); + BlendText(mousePos + Vec2{ -8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), -12 }, hp, RGBA(255, 255, 255, 255)); } if (findingElement == t) @@ -980,7 +980,7 @@ void Renderer::DrawWalls() // there is no velocity here, draw a streamline and continue if (!xVel && !yVel) { - drawtext(x*CELL, y*CELL-2, 0xE00D, 255, 255, 255, 128); + BlendText({ x*CELL, y*CELL-2 }, 0xE00D, RGBA(255, 255, 255, 128)); addpixel(oldX, oldY, 255, 255, 255, 255); continue; } @@ -1011,7 +1011,7 @@ void Renderer::DrawWalls() xf += xVel; yf += yVel; } - drawtext(x*CELL, y*CELL-2, 0xE00D, 255, 255, 255, 128); + BlendText({ x*CELL, y*CELL-2 }, 0xE00D, RGBA(255, 255, 255, 128)); } break; case 1: diff --git a/src/gui/dialogues/SaveIDMessage.cpp b/src/gui/dialogues/SaveIDMessage.cpp index 188d407df..ff70727b3 100644 --- a/src/gui/dialogues/SaveIDMessage.cpp +++ b/src/gui/dialogues/SaveIDMessage.cpp @@ -10,26 +10,26 @@ SaveIDMessage::SaveIDMessage(int id): ui::Window(ui::Point((XRES-244)/2, (YRES-90)/2), ui::Point(244, 90)) { - int textWidth = Graphics::textwidth("Save ID"); + int textWidth = Graphics::TextSize("Save ID").X - 1; ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(textWidth+20, 16), "Save ID"); titleLabel->SetTextColour(style::Colour::InformationTitle); titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; AddComponent(titleLabel); - textWidth = Graphics::textwidth("Saved Successfully!"); + textWidth = Graphics::TextSize("Saved Successfully!").X - 1; ui::Label * messageLabel = new ui::Label(ui::Point(4, 24), ui::Point(textWidth+20, 16), "Saved Successfully!"); messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop; AddComponent(messageLabel); - textWidth = Graphics::textwidth("Click the box below to copy the save ID"); + textWidth = Graphics::TextSize("Click the box below to copy the save ID").X - 1; ui::Label * copyTextLabel = new ui::Label(ui::Point((Size.X-textWidth-20)/2, 35), ui::Point(textWidth+20, 16), "Click the box below to copy the save id"); copyTextLabel->SetTextColour(ui::Colour(150, 150, 150)); copyTextLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; AddComponent(copyTextLabel); - textWidth = Graphics::textwidth(String::Build(id)); + textWidth = Graphics::TextSize(String::Build(id)).X - 1; ui::CopyTextButton * copyTextButton = new ui::CopyTextButton(ui::Point((Size.X-textWidth-10)/2, 50), ui::Point(textWidth+10, 18), String::Build(id), copyTextLabel); AddComponent(copyTextButton); diff --git a/src/gui/elementsearch/ElementSearchActivity.cpp b/src/gui/elementsearch/ElementSearchActivity.cpp index 1946ad68a..687553563 100644 --- a/src/gui/elementsearch/ElementSearchActivity.cpp +++ b/src/gui/elementsearch/ElementSearchActivity.cpp @@ -218,7 +218,7 @@ void ElementSearchActivity::OnDraw() g->drawrect(Position.X+searchField->Position.X, Position.Y+searchField->Position.Y+searchField->Size.Y+8, searchField->Size.X, Size.Y-(searchField->Position.Y+searchField->Size.Y+8)-23, 255, 255, 255, 180); if (toolTipPresence && toolTip.length()) { - g->drawtext(10, Size.Y+70, toolTip, 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5); + g->BlendText({ 10, Size.Y+70 }, toolTip, RGBA(255, 255, 255, toolTipPresence>51?255:toolTipPresence*5)); } } diff --git a/src/gui/font/FontEditor.cpp b/src/gui/font/FontEditor.cpp index 2172f1c5d..78f65d079 100644 --- a/src/gui/font/FontEditor.cpp +++ b/src/gui/font/FontEditor.cpp @@ -503,7 +503,7 @@ void FontEditor::OnDraw() } else { - g->drawtext(8, 8, "No character", 255, 0, 0, 255); + g->BlendText({ 8, 8 }, "No character", RGBA(255, 0, 0, 255)); } } diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 101e425e8..2a2ec165e 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1278,16 +1278,16 @@ void GameView::ToolTip(ui::Point senderPosition, String toolTip) else if(senderPosition.X > Size.X-BARSIZE)// < Size.Y-(quickOptionButtons.size()+1)*16) { this->toolTip = toolTip; - toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth(toolTip), senderPosition.Y+3); + toolTipPosition = ui::Point(Size.X-27-(Graphics::TextSize(toolTip).X - 1), senderPosition.Y+3); if(toolTipPosition.Y+10 > Size.Y-MENUSIZE) - toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth(toolTip), Size.Y-MENUSIZE-10); + toolTipPosition = ui::Point(Size.X-27-(Graphics::TextSize(toolTip).X - 1), Size.Y-MENUSIZE-10); isToolTipFadingIn = true; } // element tooltips else { this->toolTip = toolTip; - toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth(toolTip), Size.Y-MENUSIZE-10); + toolTipPosition = ui::Point(Size.X-27-(Graphics::TextSize(toolTip).X - 1), Size.Y-MENUSIZE-10); isToolTipFadingIn = true; } } @@ -1864,7 +1864,7 @@ void GameView::NotifyNotificationsChanged(GameModel * sender) int currentY = YRES-23; for (auto *notification : notifications) { - int width = (Graphics::textwidth(notification->Message))+8; + int width = Graphics::TextSize(notification->Message).X + 7; ui::Button * tempButton = new ui::Button(ui::Point(XRES-width-22, currentY), ui::Point(width, 15), notification->Message); tempButton->SetActionCallback({ [notification] { notification->Action(); @@ -2197,8 +2197,8 @@ void GameView::OnDraw() break; } startY -= 14; - g->fillrect(startX-3, startY-3, Graphics::textwidth(message)+6, 14, 0, 0, 0, std::min(100, alpha)); - g->drawtext(startX, startY, message, 255, 255, 255, alpha); + g->fillrect(startX-3, startY-3, Graphics::TextSize(message).X + 5, 14, 0, 0, 0, std::min(100, alpha)); + g->BlendText({ startX, startY }, message, RGBA(255, 255, 255, alpha)); (*iter).second -= 3; } } @@ -2208,9 +2208,9 @@ void GameView::OnDraw() { String sampleInfo = String::Build("#", screenshotIndex, " ", String(0xE00E), " REC"); - int textWidth = Graphics::textwidth(sampleInfo); + int textWidth = Graphics::TextSize(sampleInfo).X - 1; g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 127); - g->drawtext(XRES-16-textWidth, 16, sampleInfo, 255, 50, 20, 255); + g->BlendText({ XRES-16-textWidth, 16 }, sampleInfo, RGBA(255, 50, 20, 255)); } else if(showHud) { @@ -2329,9 +2329,9 @@ void GameView::OnDraw() sampleInfo << "Empty"; } - int textWidth = Graphics::textwidth(sampleInfo.Build()); + int textWidth = Graphics::TextSize(sampleInfo.Build()).X - 1; g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, int(alpha*0.5f)); - g->drawtext(XRES-16-textWidth, 16, sampleInfo.Build(), 255, 255, 255, int(alpha*0.75f)); + g->BlendText({ XRES-16-textWidth, 16 }, sampleInfo.Build(), RGBA(255, 255, 255, int(alpha*0.75f))); if (wavelengthGfx) { @@ -2387,9 +2387,9 @@ void GameView::OnDraw() format::RenderTemperature(sampleInfo, sample.AirTemperature, c->GetTemperatureScale()); } - textWidth = Graphics::textwidth(sampleInfo.Build()); + auto textWidth = Graphics::TextSize(sampleInfo.Build()).X - 1; g->fillrect(XRES-20-textWidth, 27, textWidth+8, 14, 0, 0, 0, int(alpha*0.5f)); - g->drawtext(XRES-16-textWidth, 30, sampleInfo.Build(), 255, 255, 255, int(alpha*0.75f)); + g->BlendText({ XRES-16-textWidth, 30 }, sampleInfo.Build(), RGBA(255, 255, 255, int(alpha*0.75f))); } } @@ -2415,37 +2415,37 @@ void GameView::OnDraw() if (ren && ren->findingElement) fpsInfo << " [FIND]"; - int textWidth = Graphics::textwidth(fpsInfo.Build()); + int textWidth = Graphics::TextSize(fpsInfo.Build()).X - 1; int alpha = 255-introText*5; g->fillrect(12, 12, textWidth+8, 15, 0, 0, 0, int(alpha*0.5)); - g->drawtext(16, 16, fpsInfo.Build(), 32, 216, 255, int(alpha*0.75)); + g->BlendText({ 16, 16 }, fpsInfo.Build(), RGBA(32, 216, 255, int(alpha*0.75))); } //Tooltips if(infoTipPresence) { int infoTipAlpha = (infoTipPresence>50?50:infoTipPresence)*5; - g->drawtext_outline((XRES-Graphics::textwidth(infoTip))/2, (YRES/2)-2, infoTip, 255, 255, 255, infoTipAlpha); + g->BlendTextOutline({ (XRES - (Graphics::TextSize(infoTip).X - 1)) / 2, YRES / 2 - 2 }, infoTip, RGBA(255, 255, 255, infoTipAlpha)); } if(toolTipPresence && toolTipPosition.X!=-1 && toolTipPosition.Y!=-1 && toolTip.length()) { if (toolTipPosition.Y == Size.Y-MENUSIZE-10) - g->drawtext_outline(toolTipPosition.X, toolTipPosition.Y, toolTip, 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5); + g->BlendTextOutline(toolTipPosition, toolTip, RGBA(255, 255, 255, toolTipPresence>51?255:toolTipPresence*5)); else - g->drawtext(toolTipPosition.X, toolTipPosition.Y, toolTip, 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5); + g->BlendText(toolTipPosition, toolTip, RGBA(255, 255, 255, toolTipPresence>51?255:toolTipPresence*5)); } if(buttonTipShow > 0) { - g->drawtext(16, Size.Y-MENUSIZE-24, buttonTip, 255, 255, 255, buttonTipShow>51?255:buttonTipShow*5); + g->BlendText({ 16, Size.Y-MENUSIZE-24 }, buttonTip, RGBA(255, 255, 255, buttonTipShow>51?255:buttonTipShow*5)); } //Introduction text if(introText && showHud) { g->fillrect(0, 0, WINDOWW, WINDOWH, 0, 0, 0, introText>51?102:introText*2); - g->drawtext(16, 16, introTextMessage, 255, 255, 255, introText>51?255:introText*5); + g->BlendText({ 16, 16 }, introTextMessage, RGBA(255, 255, 255, introText>51?255:introText*5)); } } diff --git a/src/gui/game/SignTool.cpp b/src/gui/game/SignTool.cpp index f3c035e9f..8f16f7ad9 100644 --- a/src/gui/game/SignTool.cpp +++ b/src/gui/game/SignTool.cpp @@ -170,7 +170,7 @@ void SignWindow::DoDraw() String text = currentSign.getDisplayText(sim, x, y, w, h); g->clearrect(x, y, w+1, h); g->drawrect(x, y, w+1, h, 192, 192, 192, 255); - g->drawtext(x+3, y+4, text, 255, 255, 255, 255); + g->BlendText({ x+3, y+4 }, text, RGBA(255, 255, 255, 255)); if (currentSign.ju != sign::None) { diff --git a/src/gui/game/ToolButton.cpp b/src/gui/game/ToolButton.cpp index 3354e0011..d01b7c7d4 100644 --- a/src/gui/game/ToolButton.cpp +++ b/src/gui/game/ToolButton.cpp @@ -53,7 +53,8 @@ void ToolButton::Draw(const ui::Point& screenPos) if (Appearance.GetTexture()) { - g->draw_image(Appearance.GetTexture(), screenPos.X+2, screenPos.Y+2, 255); + auto *tex = Appearance.GetTexture(); + g->BlendImage(tex->Data(), 255, RectSized(screenPos + Vec2{ 2, 2 }, tex->Size())); } else { @@ -70,16 +71,16 @@ void ToolButton::Draw(const ui::Point& screenPos) } if (Favorite::Ref().IsFavorite(toolIdentifier)) { - g->drawtext(screenPos.X, screenPos.Y, 0xE068, Appearance.BorderFavorite.Red, Appearance.BorderFavorite.Green, Appearance.BorderFavorite.Blue, Appearance.BorderFavorite.Alpha); + g->BlendText(screenPos, 0xE068, Appearance.BorderFavorite); } if (totalColour<544) { - g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText, 255, 255, 255, 255); + g->BlendText(screenPos + textPosition, buttonDisplayText, RGBA(255, 255, 255, 255)); } else { - g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText, 0, 0, 0, 255); + g->BlendText(screenPos + textPosition, buttonDisplayText, RGBA(0, 0, 0, 255)); } if (ClipRect.Size().X && ClipRect.Size().Y) diff --git a/src/gui/interface/AvatarButton.cpp b/src/gui/interface/AvatarButton.cpp index 6b47b25ac..34db88bed 100644 --- a/src/gui/interface/AvatarButton.cpp +++ b/src/gui/interface/AvatarButton.cpp @@ -39,7 +39,8 @@ void AvatarButton::Draw(const Point& screenPos) if(avatar) { - g->draw_image(avatar.get(), screenPos.X, screenPos.Y, 255); + auto *tex = avatar.get(); + g->BlendImage(tex->Data(), 255, RectSized(screenPos, tex->Size())); } } diff --git a/src/gui/interface/Button.cpp b/src/gui/interface/Button.cpp index 1cd851c8f..23492eaf8 100644 --- a/src/gui/interface/Button.cpp +++ b/src/gui/interface/Button.cpp @@ -127,7 +127,7 @@ void Button::Draw(const Point& screenPos) if(Appearance.Border.Right) g->draw_line(Position.X+Size.X-1, Position.Y, Position.X+Size.X-1, Position.Y+Size.Y-1, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha); } - g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, buttonDisplayText, textColour.Red, textColour.Green, textColour.Blue, textColour.Alpha); + g->BlendText(Position + textPosition, buttonDisplayText, textColour); bool iconInvert = (backgroundColour.Blue + (3*backgroundColour.Green) + (2*backgroundColour.Red))>544?true:false; diff --git a/src/gui/interface/Checkbox.cpp b/src/gui/interface/Checkbox.cpp index 42e23d14e..19924e455 100644 --- a/src/gui/interface/Checkbox.cpp +++ b/src/gui/interface/Checkbox.cpp @@ -83,7 +83,7 @@ void Checkbox::Draw(const Point& screenPos) g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 255); g->fillrect(screenPos.X+5, screenPos.Y+5, 6, 6, 255, 255, 255, 170); if (!Appearance.icon) - g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 255); + g->BlendText(screenPos + Vec2{ 18, 4 }, text, RGBA(255, 255, 255, 255)); else g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon, 255); } @@ -91,7 +91,7 @@ void Checkbox::Draw(const Point& screenPos) { g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 200); if (!Appearance.icon) - g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 200); + g->BlendText(screenPos + Vec2{ 18, 4 }, text, RGBA(255, 255, 255, 200)); else g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon, 200); } diff --git a/src/gui/interface/DropDown.cpp b/src/gui/interface/DropDown.cpp index 9c40964ea..8e7fcf5af 100644 --- a/src/gui/interface/DropDown.cpp +++ b/src/gui/interface/DropDown.cpp @@ -101,7 +101,7 @@ void DropDown::Draw(const Point& screenPos) g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, backgroundColour.Red, backgroundColour.Green, backgroundColour.Blue, backgroundColour.Alpha); g->drawrect(Position.X, Position.Y, Size.X, Size.Y, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha); if(optionIndex!=-1) - g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, textColour.Red, textColour.Green, textColour.Blue, textColour.Alpha); + g->BlendText(Position + textPosition, options[optionIndex].first, textColour); } void DropDown::OnMouseEnter(int x, int y) diff --git a/src/gui/interface/Label.cpp b/src/gui/interface/Label.cpp index 01d55a5d9..3a9604f62 100644 --- a/src/gui/interface/Label.cpp +++ b/src/gui/interface/Label.cpp @@ -285,11 +285,10 @@ void Label::Draw(const Point& screenPos) } } - g->drawtext( - screenPos.X + textPosition.X, - screenPos.Y + textPosition.Y, + g->BlendText( + screenPos + textPosition, displayTextWithSelection, - textColour.Red, textColour.Green, textColour.Blue, 255 + RGBA(textColour.Red, textColour.Green, textColour.Blue, 255) ); } diff --git a/src/gui/interface/ProgressBar.cpp b/src/gui/interface/ProgressBar.cpp index 45617a39c..b9ce973cd 100644 --- a/src/gui/interface/ProgressBar.cpp +++ b/src/gui/interface/ProgressBar.cpp @@ -72,10 +72,7 @@ void ProgressBar::Draw(const Point & screenPos) g->fillrect(screenPos.X + 2, screenPos.Y + 2, rsize, Size.Y-4, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); } } - if(progress<50) - g->drawtext(screenPos.X + ((Size.X-Graphics::textwidth(progressStatus))/2), screenPos.Y + (Size.Y-8)/2, progressStatus, 255, 255, 255, 255); - else - g->drawtext(screenPos.X + ((Size.X-Graphics::textwidth(progressStatus))/2), screenPos.Y + (Size.Y-8)/2, progressStatus, 0, 0, 0, 255); + g->BlendText(screenPos + Vec2{ ((Size.X-(Graphics::TextSize(progressStatus).X - 1))/2), (Size.Y-8)/2 }, progressStatus, progress<50 ? RGBA(255, 255, 255, 255) : RGBA(0, 0, 0, 255)); } void ProgressBar::Tick(float dt) diff --git a/src/gui/interface/RichLabel.cpp b/src/gui/interface/RichLabel.cpp index 04dc48e43..22c9e80dc 100644 --- a/src/gui/interface/RichLabel.cpp +++ b/src/gui/interface/RichLabel.cpp @@ -179,7 +179,7 @@ void RichLabel::Draw(const Point& screenPos) { Graphics * g = GetGraphics(); ui::Colour textColour = Appearance.TextInactive; - g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, displayText, textColour.Red, textColour.Green, textColour.Blue, 255); + g->BlendText(screenPos + textPosition, displayText, RGBA(textColour.Red, textColour.Green, textColour.Blue, 255)); } void RichLabel::OnMouseClick(int x, int y, unsigned button) diff --git a/src/gui/interface/SaveButton.cpp b/src/gui/interface/SaveButton.cpp index ab2d8ab83..088c2a1be 100644 --- a/src/gui/interface/SaveButton.cpp +++ b/src/gui/interface/SaveButton.cpp @@ -194,13 +194,12 @@ void SaveButton::Draw(const Point& screenPos) if (thumbnail) { //thumbBoxSize = ui::Point(thumbnail->Width, thumbnail->Height); - if (save && save->id) - g->draw_image(thumbnail.get(), screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, 255); - else - g->draw_image(thumbnail.get(), screenPos.X+(Size.X-thumbSize.X)/2, screenPos.Y+(Size.Y-21-thumbSize.Y)/2, 255); + auto *tex = thumbnail.get(); + auto space = Size - Vec2{ 0, 21 }; + g->BlendImage(tex->Data(), 255, RectSized(screenPos + ((save && save->id) ? ((space - thumbBoxSize) / 2 - Vec2{ 3, 0 }) : (space - thumbSize) / 2), tex->Size())); } else if (file && !file->GetGameSave()) - g->drawtext(screenPos.X+(Size.X-Graphics::textwidth("Error loading save"))/2, screenPos.Y+(Size.Y-28)/2, "Error loading save", 180, 180, 180, 255); + g->BlendText(screenPos + Vec2{ (Size.X-(Graphics::TextSize("Error loading save").X - 1))/2, (Size.Y-28)/2 }, "Error loading save", RGBA(180, 180, 180, 255)); if(save) { if(save->id) @@ -230,38 +229,27 @@ void SaveButton::Draw(const Point& screenPos) g->drawrect(screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 180, 180, 180, 255); } - if(isMouseInside && !isMouseInsideAuthor) - g->drawtext(screenPos.X+(Size.X-Graphics::textwidth(name))/2, screenPos.Y+Size.Y - 21, name, 255, 255, 255, 255); - else - g->drawtext(screenPos.X+(Size.X-Graphics::textwidth(name))/2, screenPos.Y+Size.Y - 21, name, 180, 180, 180, 255); - - if(isMouseInsideAuthor) - g->drawtext(screenPos.X+(Size.X-Graphics::textwidth(save->userName.FromUtf8()))/2, screenPos.Y+Size.Y - 10, save->userName.FromUtf8(), 200, 230, 255, 255); - else - g->drawtext(screenPos.X+(Size.X-Graphics::textwidth(save->userName.FromUtf8()))/2, screenPos.Y+Size.Y - 10, save->userName.FromUtf8(), 100, 130, 160, 255); + g->BlendText(screenPos + Vec2{ (Size.X-(Graphics::TextSize(name).X - 1))/2, Size.Y - 21 }, name, (isMouseInside && !isMouseInsideAuthor) ? RGBA(255, 255, 255, 255) : RGBA(180, 180, 180, 255)); + g->BlendText(screenPos + Vec2{ (Size.X-(Graphics::TextSize(save->userName.FromUtf8()).X - 1))/2, Size.Y - 10 }, save->userName.FromUtf8(), isMouseInsideAuthor ? RGBA(200, 230, 255, 255) : RGBA(100, 130, 160, 255)); if (showVotes)// && !isMouseInside) { - int x = screenPos.X-7+(Size.X-thumbBoxSize.X)/2+thumbBoxSize.X-Graphics::textwidth(votesBackground); + int x = screenPos.X-7+(Size.X-thumbBoxSize.X)/2+thumbBoxSize.X-(Graphics::TextSize(votesBackground).X - 1); int y = screenPos.Y-23+(Size.Y-thumbBoxSize.Y)/2+thumbBoxSize.Y; - g->drawtext(x, y, votesBackground, 16, 72, 16, 255); - g->drawtext(x, y, votesBackground2, 192, 192, 192, 255); - g->drawtext(x+3, y, votesString, 255, 255, 255, 255); + g->BlendText({ x, y }, votesBackground, RGBA(16, 72, 16, 255)); + g->BlendText({ x, y }, votesBackground2, RGBA(192, 192, 192, 255)); + g->BlendText({ x+3, y }, votesString, RGBA(255, 255, 255, 255)); } if (isMouseInsideHistory && showVotes) { int x = screenPos.X; int y = screenPos.Y-15+(Size.Y-thumbBoxSize.Y)/2+thumbBoxSize.Y; g->fillrect(x+1, y+1, 7, 8, 255, 255, 255, 255); - if (isMouseInsideHistory) { - g->drawtext(x, y, 0xE026, 200, 100, 80, 255); - } else { - g->drawtext(x, y, 0xE026, 160, 70, 50, 255); - } + g->BlendText({ x, y }, 0xE026, isMouseInsideHistory ? RGBA(200, 100, 80, 255) : RGBA(160, 70, 50, 255)); } if (!save->GetPublished()) { - g->drawtext(screenPos.X, screenPos.Y-2, 0xE04D, 255, 255, 255, 255); - g->drawtext(screenPos.X, screenPos.Y-2, 0xE04E, 212, 151, 81, 255); + g->BlendText(screenPos - Vec2{ 0, 2 }, 0xE04D, RGBA(255, 255, 255, 255)); + g->BlendText(screenPos - Vec2{ 0, 2 }, 0xE04E, RGBA(212, 151, 81, 255)); } } else if (file) @@ -273,14 +261,7 @@ void SaveButton::Draw(const Point& screenPos) if (thumbSize.X) g->xor_rect(screenPos.X+(Size.X-thumbSize.X)/2, screenPos.Y+(Size.Y-21-thumbSize.Y)/2, thumbSize.X, thumbSize.Y); - if (isMouseInside) - { - g->drawtext(screenPos.X+(Size.X-Graphics::textwidth(name))/2, screenPos.Y+Size.Y - 21, name, 255, 255, 255, 255); - } - else - { - g->drawtext(screenPos.X+(Size.X-Graphics::textwidth(name))/2, screenPos.Y+Size.Y - 21, name, 180, 180, 180, 255); - } + g->BlendText(screenPos + Vec2{ (Size.X-(Graphics::TextSize(name).X - 1))/2, Size.Y - 21 }, name, isMouseInside ? RGBA(255, 255, 255, 255) : RGBA(180, 180, 180, 255)); } if(isMouseInside && selectable) diff --git a/src/gui/interface/Textbox.cpp b/src/gui/interface/Textbox.cpp index ae8421db8..f0ee0af08 100644 --- a/src/gui/interface/Textbox.cpp +++ b/src/gui/interface/Textbox.cpp @@ -200,9 +200,9 @@ void Textbox::pasteIntoSelection() { newText = newText.Substr(0, limit-backingText.length()); } - if (!multiline && Graphics::textwidth(backingText + newText) > regionWidth) + if (!multiline && Graphics::TextSize(backingText + newText).X - 1 > regionWidth) { - int pLimit = regionWidth - Graphics::textwidth(backingText); + int pLimit = regionWidth - (Graphics::TextSize(backingText).X - 1); int pWidth = 0; auto it = newText.begin(); while (it != newText.end()) @@ -488,7 +488,7 @@ void Textbox::InsertText(String text) regionWidth -= 13; regionWidth -= Appearance.Margin.Left; regionWidth -= Appearance.Margin.Right; - if ((limit==String::npos || backingText.length() < limit) && (Graphics::textwidth(backingText + text) <= regionWidth || multiline)) + if ((limit==String::npos || backingText.length() < limit) && (Graphics::TextSize(backingText + text).X - 1 <= regionWidth || multiline)) { if (cursor == (int)backingText.length()) { @@ -620,7 +620,7 @@ void Textbox::Draw(const Point& screenPos) { if(!text.length()) { - g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, placeHolder, textColour.Red, textColour.Green, textColour.Blue, 170); + g->BlendText(screenPos + textPosition, placeHolder, RGBA(textColour.Red, textColour.Green, textColour.Blue, 170)); } if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 160, 160, 160, 255); } diff --git a/src/gui/interface/Window.cpp b/src/gui/interface/Window.cpp index b6db0099a..d63ccf0d5 100644 --- a/src/gui/interface/Window.cpp +++ b/src/gui/interface/Window.cpp @@ -218,8 +218,8 @@ void Window::DoDraw() ); auto pos = focusedComponent_->Position + Position + Vec2(focusedComponent_->Size.X + 5, 0); - pos.X = std::min(pos.X, g->Size().X - Graphics::textwidth(posText) - 5); - pos.X = std::min(pos.X, g->Size().X - Graphics::textwidth(sizeText) - 5); + pos.X = std::min(pos.X, g->Size().X - (Graphics::TextSize(posText).X - 1) - 5); + pos.X = std::min(pos.X, g->Size().X - (Graphics::TextSize(sizeText).X - 1) - 5); g->BlendText(pos + Vec2(0, 1), posText, 0x000000_rgb .WithAlpha(0xC8)); g->BlendText(pos + Vec2(0, 0), posText, 0xFFFFFF_rgb .WithAlpha(0xFF)); diff --git a/src/gui/localbrowser/LocalBrowserView.cpp b/src/gui/localbrowser/LocalBrowserView.cpp index cbbced5e8..cb8d73b6d 100644 --- a/src/gui/localbrowser/LocalBrowserView.cpp +++ b/src/gui/localbrowser/LocalBrowserView.cpp @@ -83,7 +83,7 @@ void LocalBrowserView::NotifyPageChanged(LocalBrowserModel * sender) { String pageInfo = String::Build("of ", pageCount); pageCountLabel->SetText(pageInfo); - int width = Graphics::textwidth(pageInfo); + int width = Graphics::TextSize(pageInfo).X - 1; pageLabel->Position.X = WINDOWW/2-width-20; pageTextbox->Position.X = WINDOWW/2-width+11; diff --git a/src/gui/options/OptionsView.cpp b/src/gui/options/OptionsView.cpp index 21ac709ce..4aa4b27fe 100644 --- a/src/gui/options/OptionsView.cpp +++ b/src/gui/options/OptionsView.cpp @@ -281,7 +281,7 @@ OptionsView::OptionsView(): resizable = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Resizable", ""); autowidth(resizable); resizable->SetActionCallback({ [this] { c->SetResizable(resizable->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(resizable->Position.X+Graphics::textwidth(resizable->GetText())+20, currentY), ui::Point(1, 16), "\bg- Allow resizing and maximizing window"); + tempLabel = new ui::Label(ui::Point(resizable->Position.X+Graphics::TextSize(resizable->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- Allow resizing and maximizing window"); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -292,7 +292,7 @@ OptionsView::OptionsView(): fullscreen = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Fullscreen", ""); autowidth(fullscreen); fullscreen->SetActionCallback({ [this] { c->SetFullscreen(fullscreen->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(fullscreen->Position.X+Graphics::textwidth(fullscreen->GetText())+20, currentY), ui::Point(1, 16), "\bg- Fill the entire screen"); + tempLabel = new ui::Label(ui::Point(fullscreen->Position.X+Graphics::TextSize(fullscreen->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- Fill the entire screen"); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -303,7 +303,7 @@ OptionsView::OptionsView(): altFullscreen = new ui::Checkbox(ui::Point(23, currentY), ui::Point(1, 16), "Change Resolution", ""); autowidth(altFullscreen); altFullscreen->SetActionCallback({ [this] { c->SetAltFullscreen(altFullscreen->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(altFullscreen->Position.X+Graphics::textwidth(altFullscreen->GetText())+20, currentY), ui::Point(1, 16), "\bg- Set optimal screen resolution"); + tempLabel = new ui::Label(ui::Point(altFullscreen->Position.X+Graphics::TextSize(altFullscreen->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- Set optimal screen resolution"); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -314,7 +314,7 @@ OptionsView::OptionsView(): forceIntegerScaling = new ui::Checkbox(ui::Point(23, currentY), ui::Point(1, 16), "Force Integer Scaling", ""); autowidth(forceIntegerScaling); forceIntegerScaling->SetActionCallback({ [this] { c->SetForceIntegerScaling(forceIntegerScaling->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(altFullscreen->Position.X+Graphics::textwidth(forceIntegerScaling->GetText())+20, currentY), ui::Point(1, 16), "\bg- Less blurry"); + tempLabel = new ui::Label(ui::Point(altFullscreen->Position.X+Graphics::TextSize(forceIntegerScaling->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- Less blurry"); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -325,7 +325,7 @@ OptionsView::OptionsView(): fastquit = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Fast Quit", ""); autowidth(fastquit); fastquit->SetActionCallback({ [this] { c->SetFastQuit(fastquit->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(fastquit->Position.X+Graphics::textwidth(fastquit->GetText())+20, currentY), ui::Point(1, 16), "\bg- Always exit completely when hitting close"); + tempLabel = new ui::Label(ui::Point(fastquit->Position.X+Graphics::TextSize(fastquit->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- Always exit completely when hitting close"); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -336,7 +336,7 @@ OptionsView::OptionsView(): showAvatars = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Show Avatars", ""); autowidth(showAvatars); showAvatars->SetActionCallback({ [this] { c->SetShowAvatars(showAvatars->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(showAvatars->Position.X+Graphics::textwidth(showAvatars->GetText())+20, currentY), ui::Point(1, 16), "\bg- Disable if you have a slow connection"); + tempLabel = new ui::Label(ui::Point(showAvatars->Position.X+Graphics::TextSize(showAvatars->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- Disable if you have a slow connection"); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -347,7 +347,7 @@ OptionsView::OptionsView(): momentumScroll = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Momentum/Old Scrolling", ""); autowidth(momentumScroll); momentumScroll->SetActionCallback({ [this] { c->SetMomentumScroll(momentumScroll->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(momentumScroll->Position.X + Graphics::textwidth(momentumScroll->GetText()) + 20, currentY), ui::Point(1, 16), "\bg- Accelerating instead of step scroll"); + tempLabel = new ui::Label(ui::Point(momentumScroll->Position.X + Graphics::TextSize(momentumScroll->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- Accelerating instead of step scroll"); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -358,7 +358,7 @@ OptionsView::OptionsView(): mouseClickRequired = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Sticky Categories", ""); autowidth(mouseClickRequired); mouseClickRequired->SetActionCallback({ [this] { c->SetMouseClickrequired(mouseClickRequired->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(mouseClickRequired->Position.X+Graphics::textwidth(mouseClickRequired->GetText())+20, currentY), ui::Point(1, 16), "\bg- Switch between categories by clicking"); + tempLabel = new ui::Label(ui::Point(mouseClickRequired->Position.X+Graphics::TextSize(mouseClickRequired->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- Switch between categories by clicking"); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -369,7 +369,7 @@ OptionsView::OptionsView(): includePressure = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Include Pressure", ""); autowidth(includePressure); includePressure->SetActionCallback({ [this] { c->SetIncludePressure(includePressure->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(includePressure->Position.X+Graphics::textwidth(includePressure->GetText())+20, currentY), ui::Point(1, 16), "\bg- When saving, copying, stamping, etc."); + tempLabel = new ui::Label(ui::Point(includePressure->Position.X+Graphics::TextSize(includePressure->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- When saving, copying, stamping, etc."); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -380,7 +380,7 @@ OptionsView::OptionsView(): perfectCirclePressure = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Perfect Circle", ""); autowidth(perfectCirclePressure); perfectCirclePressure->SetActionCallback({ [this] { c->SetPerfectCircle(perfectCirclePressure->GetChecked()); } }); - tempLabel = new ui::Label(ui::Point(perfectCirclePressure->Position.X+Graphics::textwidth(perfectCirclePressure->GetText())+20, currentY), ui::Point(1, 16), "\bg- Better circle brush, without incorrect points on edges"); + tempLabel = new ui::Label(ui::Point(perfectCirclePressure->Position.X+Graphics::TextSize(perfectCirclePressure->GetText()).X+19, currentY), ui::Point(1, 16), "\bg- Better circle brush, without incorrect points on edges"); autowidth(tempLabel); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index c517c07b1..6501b2a19 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -149,13 +149,13 @@ void PreviewView::AttachController(PreviewController * controller) { c = controller; - int textWidth = Graphics::textwidth("Click the box below to copy the save ID"); + int textWidth = Graphics::TextSize("Click the box below to copy the save ID").X - 1; saveIDLabel = new ui::Label(ui::Point((Size.X-textWidth-20)/2, Size.Y+5), ui::Point(textWidth+20, 16), "Click the box below to copy the save ID"); saveIDLabel->SetTextColour(ui::Colour(150, 150, 150)); saveIDLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; AddComponent(saveIDLabel); - textWidth = Graphics::textwidth(String::Build(c->SaveID())); + textWidth = Graphics::TextSize(String::Build(c->SaveID())).X - 1; saveIDLabel2 = new ui::Label(ui::Point((Size.X-textWidth-20)/2-37, Size.Y+22), ui::Point(40, 16), "Save ID:"); AddComponent(saveIDLabel2); @@ -167,7 +167,7 @@ void PreviewView::commentBoxAutoHeight() { if(!addCommentBox) return; - int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str()); + int textWidth = Graphics::TextSize(addCommentBox->GetText().c_str()).X - 1; if (commentHelpText || textWidth+15 > Size.X-(XRES/2)-48) { addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop; @@ -271,7 +271,7 @@ void PreviewView::DoDraw() { g->fillrect(Position.X+(Size.X/2)-101, Position.Y+(Size.Y/2)-26, 202, 52, 0, 0, 0, 210); g->drawrect(Position.X+(Size.X/2)-100, Position.Y+(Size.Y/2)-25, 200, 50, 255, 255, 255, 180); - g->drawtext(Position.X+(Size.X/2)-(Graphics::textwidth("Loading save...")/2), Position.Y+(Size.Y/2)-5, "Loading save...", style::Colour::InformationTitle.Red, style::Colour::InformationTitle.Green, style::Colour::InformationTitle.Blue, 255); + g->BlendText(Position + Vec2{(Size.X/2)-((Graphics::TextSize("Loading save...").X - 1)/2), (Size.Y/2)-5}, "Loading save...", RGBA(style::Colour::InformationTitle.Red, style::Colour::InformationTitle.Green, style::Colour::InformationTitle.Blue, 255)); } g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255); diff --git a/src/gui/render/RenderView.cpp b/src/gui/render/RenderView.cpp index bdc22928f..b81367307 100644 --- a/src/gui/render/RenderView.cpp +++ b/src/gui/render/RenderView.cpp @@ -170,7 +170,7 @@ void RenderView::OnDraw() g->draw_line(XRES, 0, XRES, WINDOWH, 255, 255, 255, 255); if(toolTipPresence && toolTip.length()) { - g->drawtext(6, Size.Y-MENUSIZE-12, toolTip, 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5); + g->BlendText({ 6, Size.Y-MENUSIZE-12 }, toolTip, RGBA(255, 255, 255, toolTipPresence>51?255:toolTipPresence*5)); } } diff --git a/src/gui/search/SearchView.cpp b/src/gui/search/SearchView.cpp index 232eb3b78..95f3237a1 100644 --- a/src/gui/search/SearchView.cpp +++ b/src/gui/search/SearchView.cpp @@ -271,7 +271,7 @@ void SearchView::NotifyPageChanged(SearchModel * sender) { String pageInfo = String::Build("of ", pageCount); pageCountLabel->SetText(pageInfo); - int width = Graphics::textwidth(pageInfo); + int width = Graphics::TextSize(pageInfo).X - 1; pageLabel->Position.X = WINDOWW/2-width-20; pageTextbox->Position.X = WINDOWW/2-width+11; diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index 7cc1e552b..54173269e 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -332,7 +332,7 @@ int luatpt_drawtext(lua_State* l) if (textalpha<0) textalpha = 0; if (textalpha>255) textalpha = 255; - luacon_g->drawtext(textx, texty, string, textred, textgreen, textblue, textalpha); + luacon_g->BlendText({ textx, texty }, string, RGBA(textred, textgreen, textblue, textalpha)); return 0; } @@ -983,7 +983,7 @@ int luatpt_drawline(lua_State* l) int luatpt_textwidth(lua_State* l) { auto string = tpt_lua_optString(l, 1, ""); - int strwidth = Graphics::textwidth(string); + int strwidth = Graphics::TextSize(string).X - 1; lua_pushinteger(l, strwidth); return 1; } diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 22ee18379..ea4c1613c 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -3812,7 +3812,7 @@ int LuaScriptInterface::graphics_drawText(lua_State * l) if (a<0) a = 0; else if (a>255) a = 255; - luacon_g->drawtext(x, y, text, r, g, b, a); + luacon_g->BlendText({ x, y }, text, RGBA(r, g, b, a)); return 0; } diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp index 735e2dd86..e885fcc65 100644 --- a/src/simulation/Sign.cpp +++ b/src/simulation/Sign.cpp @@ -134,7 +134,7 @@ String sign::getDisplayText(Simulation *sim, int &x0, int &y0, int &w, int &h, b } } - w = Graphics::textwidth(drawable_text.c_str()) + 5; + w = Graphics::TextSize(drawable_text.c_str()).X + 4; h = 15; x0 = (ju == Right) ? x - w : (ju == Left) ? x : x - w/2; y0 = (y > 18) ? y - 18 : y + 4; diff --git a/src/tasks/TaskWindow.cpp b/src/tasks/TaskWindow.cpp index 12d941c97..7f22e201b 100644 --- a/src/tasks/TaskWindow.cpp +++ b/src/tasks/TaskWindow.cpp @@ -117,10 +117,7 @@ void TaskWindow::OnDraw() g->fillrect(Position.X + 2, Position.Y + Size.Y-15, rsize, 13, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); } } - if(progress<50) - g->drawtext(Position.X + ((Size.X-Graphics::textwidth(progressStatus))/2), Position.Y + Size.Y-13, progressStatus, 255, 255, 255, 255); - else - g->drawtext(Position.X + ((Size.X-Graphics::textwidth(progressStatus))/2), Position.Y + Size.Y-13, progressStatus, 0, 0, 0, 255); + g->BlendText(Position + Vec2{ ((Size.X-(Graphics::TextSize(progressStatus).X - 1))/2), Size.Y-13 }, progressStatus, progress<50 ? RGBA(255, 255, 255, 255) : RGBA(0, 0, 0, 255)); } TaskWindow::~TaskWindow() {