Sat, 22 May 2021 11:33:17 +0300
#320 Fantastical bugs are captured
--- a/Source/Gorgon/Graphics/AdvancedPrinter.cpp Fri May 21 14:18:22 2021 +0300 +++ b/Source/Gorgon/Graphics/AdvancedPrinter.cpp Sat May 22 11:33:17 2021 +0300 @@ -7,14 +7,14 @@ std::vector<AdvancedPrinter::Region> AdvancedPrinter::AdvancedPrint( TextureTarget &target, const std::string &text, - Geometry::Point location, int width, bool wrap, bool stopoffscreen + Geometry::Point &location, int width, bool wrap, bool stopoffscreen ) const { auto tsize = target.GetTargetSize(); return AdvancedOperation( [&target, tsize, stopoffscreen]( const GlyphRenderer &renderer, Glyph g, - const Geometry::Point &location, const RGBAf &color, int + const Geometry::Point &location, const RGBAf &color, long ) { if(g != 0xffff) renderer.Render(g, target, location, color); @@ -44,11 +44,12 @@ Geometry::Size AdvancedPrinter::GetSize(const std::string &text) const { Geometry::Size sz = {0, 0}; - + Geometry::Point l = {0, 0}; + AdvancedOperation( [&sz]( const GlyphRenderer &renderer, Glyph g, - const Geometry::Point &location, const RGBAf &, int + const Geometry::Point &location, const RGBAf &, long ) { if(g != 0xffff) { auto p = location + (Geometry::Point)renderer.GetSize(g) + renderer.GetOffset(g); @@ -69,7 +70,7 @@ }, [](Byte, const Geometry::Bounds &, const RGBAf &, bool) { }, - text, {0,0}, 0, false + text, l, 0, false ); return sz; @@ -77,11 +78,12 @@ Geometry::Size AdvancedPrinter::GetSize(const std::string &text, int width) const { Geometry::Size sz = {0, 0}; + Geometry::Point l = {0, 0}; AdvancedOperation( [&sz]( const GlyphRenderer &renderer, Glyph g, - const Geometry::Point &location, const RGBAf &, int + const Geometry::Point &location, const RGBAf &, long ) { if(g != 0xffff) { auto p = location + (Geometry::Point)renderer.GetSize(g) + renderer.GetOffset(g); @@ -101,7 +103,7 @@ }, [](Byte, const Geometry::Bounds &, const RGBAf &, bool) { }, - text, {0,0}, width, true + text, l, width, true ); return sz; @@ -109,95 +111,112 @@ int AdvancedPrinter::GetCharacterIndex(const std::string &text, Geometry::Point location) const { int maxdoney = -1; - int nearestind = -1; + int nearestind = 0; bool done = false; + bool xfound = false; //used to determine if the point is outside the width + + Geometry::Point l = {0, 0}; AdvancedOperation( [&]( const GlyphRenderer &renderer, Glyph g, - const Geometry::Point &l, const RGBAf &, int index - ) { - if(done) - return false; + const Geometry::Point &l, const RGBAf &, long index + ) { + if(done || index == std::numeric_limits<long>::max()) + return false; - if(l.Y >= location.Y) { - done = true; - return false; - } + if(l.Y >= location.Y) { + done = true; + return false; + } - if(maxdoney < l.Y) { - if(l.X >= location.X+renderer.GetCursorAdvance(g)/2) { - maxdoney = l.Y; - } - else { + if(maxdoney < l.Y) { + if(l.X >= location.X-renderer.GetCursorAdvance(g)/2) { + maxdoney = l.Y; + xfound = true; + } + else { + xfound = false; + } nearestind = index; } - } - return true; - }, + return true; + }, [](const Geometry::Bounds &, const RGBAf &, int, RGBAf) { - }, + }, [](int, int, int, int, RGBAf) { - }, + }, [](Byte, const Geometry::Bounds &, const RGBAf &, bool) { - }, - text, {0,0}, 0, false - ); + }, + text, l, 0, false + ); + + if(!done && !xfound) + return nearestind+1; return nearestind; } int AdvancedPrinter::GetCharacterIndex(const std::string &text, int w, Geometry::Point location, bool wrap) const { int maxdoney = -1; - int nearestind = -1; + int nearestind = 0; bool done = false; + bool xfound = false; //used to determine if the point is outside the width + + Geometry::Point l = {0, 0}; AdvancedOperation( [&]( const GlyphRenderer &renderer, Glyph g, - const Geometry::Point &l, const RGBAf &, int index - ) { - if(done) - return false; + const Geometry::Point &l, const RGBAf &, long index + ) { + if(done || index == std::numeric_limits<long>::max()) + return false; - if(l.Y >= location.Y) { - done = true; - return false; - } + if(l.Y >= location.Y) { + done = true; + return false; + } - if(maxdoney < l.Y) { - if(l.X >= location.X+renderer.GetCursorAdvance(g)/2) { - maxdoney = l.Y; - } - else { + if(maxdoney < l.Y) { + if(l.X >= location.X-renderer.GetCursorAdvance(g)/2) { + maxdoney = l.Y; + xfound = true; + } + else { + xfound = false; + } nearestind = index; } - } - return true; - }, + return true; + }, [](const Geometry::Bounds &, const RGBAf &, int, RGBAf) { - }, + }, [](int, int, int, int, RGBAf) { - }, + }, [](Byte, const Geometry::Bounds &, const RGBAf &, bool) { - }, - text, {0,0}, w, wrap - ); + }, + text, l, w, wrap + ); + + if(!done && !xfound) + return nearestind+1; return nearestind; } Geometry::Rectangle AdvancedPrinter::GetPosition(const std::string &text, int index) const { Geometry::Rectangle cur = {std::numeric_limits<int>::min(), std::numeric_limits<int>::min(), 0, 0}; + Geometry::Point location = {0, 0}; AdvancedOperation( [index, &cur]( const GlyphRenderer &renderer, Glyph g, const Geometry::Point &location, const RGBAf &, long ind ) { - if(index == ind) { + if(index <= ind) { cur.Move(location); cur.Resize(renderer.GetSize(g)); @@ -212,22 +231,26 @@ }, [](Byte, const Geometry::Bounds &, const RGBAf &, bool) { }, - text, {0,0}, 0, false + text, location, 0, false ); + + if(cur.X == std::numeric_limits<int>::min()) { + cur.Move(location); + } return cur; } Geometry::Rectangle AdvancedPrinter::GetPosition(const std::string &text, int w, int index, bool wrap) const { - Geometry::Rectangle cur = {std::numeric_limits<int>::min(), std::numeric_limits<int>::min(), 0, 0}; - + Geometry::Point location = {0, 0}; + AdvancedOperation( [index, &cur]( const GlyphRenderer &renderer, Glyph g, const Geometry::Point &location, const RGBAf &, long ind ) { - if(index == ind) { + if(index <= ind) { cur.Move(location + Geometry::Point(renderer.GetOffset(g).X, 0)); cur.Resize(renderer.GetSize(g).Width, renderer.GetHeight()); @@ -242,8 +265,12 @@ }, [](Byte, const Geometry::Bounds &, const RGBAf &, bool) { }, - text, {0,0}, w, wrap + text, location, w, wrap ); + + if(cur.X == std::numeric_limits<int>::min()) { + cur.Move(location); + } return cur; }
--- a/Source/Gorgon/Graphics/AdvancedPrinter.h Fri May 21 14:18:22 2021 +0300 +++ b/Source/Gorgon/Graphics/AdvancedPrinter.h Sat May 22 11:33:17 2021 +0300 @@ -163,7 +163,7 @@ template<class GF_, class BF_, class LF_, class IF_> std::vector<Region> AdvancedOperation( GF_ glyphr, BF_ boxr, LF_ liner, IF_ imgr, - const std::string &text, Geometry::Point location, int width, bool wrap = true + const std::string &text, Geometry::Point &location, int width, bool wrap = true ) const; /// Prints the given text. Unlike regular print function, this function returns the @@ -172,7 +172,19 @@ /// vertical offset. std::vector<Region> AdvancedPrint( TextureTarget &target, const std::string &text, - Geometry::Point location, int width, bool wrap = true, bool stopoffscreen = true + const Geometry::Point &location, int width, bool wrap = true, bool stopoffscreen = true + ) const { + auto l = location; + return AdvancedPrint(target, text, l, width, wrap, stopoffscreen); + } + + /// Prints the given text. Unlike regular print function, this function returns the + /// collected regions and has more options. If stopoffscreen is true, once the printing goes + /// out of screen, it will be stopped. This may cause issues in systems that use negative + /// vertical offset. + std::vector<Region> AdvancedPrint( + TextureTarget &target, const std::string &text, + Geometry::Point &location, int width, bool wrap = true, bool stopoffscreen = true ) const; bool IsReady() const override {
--- a/Source/Gorgon/Graphics/AdvancedPrinterImpl.h Fri May 21 14:18:22 2021 +0300 +++ b/Source/Gorgon/Graphics/AdvancedPrinterImpl.h Sat May 22 11:33:17 2021 +0300 @@ -10,7 +10,12 @@ namespace Gorgon { namespace Graphics { template<class GF_, class BF_, class LF_, class IF_> - std::vector<AdvancedPrinter::Region> AdvancedPrinter::AdvancedOperation(GF_ glyphr, BF_ boxr, LF_ liner, IF_ imgr, const std::string &text, Geometry::Point location, int width, bool wrap) const { + std::vector<AdvancedPrinter::Region> AdvancedPrinter::AdvancedOperation( + GF_ glyphr, BF_ boxr, LF_ liner, IF_ imgr, const std::string &text, Geometry::Point &location, + int width, bool wrap + ) const { + + bool done = false; struct linesettings { bool descenders = false; @@ -800,22 +805,35 @@ //render for(int i = 0; i<end; i++) { Translate(acc[i].location, xoff, maxb-acc[i].baseline+extralineoffset); - if(acc[i].g != '\t' && (!internal::isspace(acc[i].g) || renderer->Exists(acc[i].g))) - if(! - glyphr( - *acc[i].renderer, acc[i].g, - acc[i].location + acc[i].offset, - acc[i].color, acc[i].index - ) - ) { - acc.clear(); - return false; - } + auto g = acc[i].g; + + if(g == '\t' || (internal::isspace(g) && !renderer->Exists(g))) { + g = 0xffff; + } + + if(!glyphr( + *acc[i].renderer, g, + acc[i].location + acc[i].offset, + acc[i].color, acc[i].index + )) { + acc.clear(); + return false; + } } if(nl == 0) { //clean spaces at the start of the next line for(; end<acc.size(); end++) { + //send the index with do not draw glyph + if(!glyphr( + *acc[end].renderer, 0xffff, + acc[end].location + acc[end].offset, + acc[end].color, acc[end].index + )) { + acc.clear(); + return false; + } + if(!internal::isspace(acc[end].g) && acc[end].g != '\t') break; else { @@ -1173,8 +1191,17 @@ // **** Determine glyph size if(internal::isnewline(g)) { - if(!doline(g)) + auto newlineloc = cur; + + if(!doline(g)) { + done = true; break; + } + + if(!glyphr(*renderer, 0xffff, newlineloc, 0.f, curindex-1)) { + done = true; + break; + } continue; } @@ -1351,8 +1378,10 @@ auto blosave = baselineoffset; baselineoffset = baselineoffsetatlastspace; - if(!doline(0)) + if(!doline(0)) { + done = true; break; + } baselineoffset = blosave; if(baselineoffset == 0 && blosave != 0) { @@ -1367,9 +1396,16 @@ } - if(!acc.empty()) - doline(-1); - + location = cur; + if(!acc.empty()) { + if(!doline(-1)) { + done = true; + } + } + + if(!done) + glyphr(*renderer, 0xffff, location, 0.f, std::numeric_limits<long>::max()); + return regions; }
--- a/Source/Gorgon/Widgets/Textarea.cpp Fri May 21 14:18:22 2021 +0300 +++ b/Source/Gorgon/Widgets/Textarea.cpp Sat May 22 11:33:17 2021 +0300 @@ -273,7 +273,7 @@ return relevant; } - + bool Textarea::CharacterPressed(Char c) { if(c == Input::Keyboard::Keycodes::Enter) return false; @@ -304,6 +304,7 @@ } void Textarea::updateselection() { + std::cout << selstart.glyph << " : " << sellen.glyph << std::endl; updatecursor(); if(sellen.byte != 0) { @@ -380,7 +381,7 @@ location -= bounds.TopLeft(); - selstart.glyph = renderer.GetCharacterIndex(text, bounds.Width(), location, false); + selstart.glyph = renderer.GetCharacterIndex(text, bounds.Width(), location, true); selstart.byte = 0; int g = selstart.glyph; pglyph = g; @@ -427,7 +428,7 @@ location -= bounds.TopLeft(); - int glyph = renderer.GetCharacterIndex(text, bounds.Width(), location, false); + int glyph = renderer.GetCharacterIndex(text, bounds.Width(), location, true); if(glyph == pglyph) return; @@ -601,7 +602,7 @@ location = {0, 0}; } else { - location = renderer.GetPosition(text, stack.TagBounds(UI::ComponentTemplate::ContentsTag).Width(), pos, false).TopLeft() - scrolloffset; + location = renderer.GetPosition(text, stack.TagBounds(UI::ComponentTemplate::ContentsTag).Width(), pos, true).TopLeft() - scrolloffset; } if(text == "") {
--- a/Testing/Source/Manual/UI_WidgetTest.cpp Fri May 21 14:18:22 2021 +0300 +++ b/Testing/Source/Manual/UI_WidgetTest.cpp Sat May 22 11:33:17 2021 +0300 @@ -24,7 +24,7 @@ org << wgt1 ; - wgt1.SetText(wgt1.GetText() + "\nA lot more text is written in here..."); + wgt1.SetText(wgt1.GetText() + "A lot more text is written in here..."); app.wind.Run();