TBX provides classes derived from tbx::Graphics
to make it easy to draw graphics, text and images to the screen. In
particular the tbx::OffsetGraphics
makes it
easy to paint your window in a redraw loop.
Example 9.1. Redrawing a screen using OffsetGraphics
First you need to attach a redraw listener after you have a window to attach it to.
// this is a class derived from tbx::RedrawListener window.add_redraw_listener(this);
Then you can easily draw graphics and text in the redraw method.
void GraphicsWnd::redraw(const tbx::RedrawEvent &e) { tbx::OffsetGraphics g(e.visible_area()); g.text_colours(tbx::Colour::black, tbx::Colour::white); g.text(0,-32, "This shows some of the facilities of the graphics object"); g.text(0,-160,"A line"); g.line(160,-160, 256, -160); g.text(0,-288, "A filled circle"); g.foreground(tbx::Colour(0,255, 0)); g.fill_circle(232, -280, 32); g.foreground(tbx::Colour::black); g.text(0,-668, "Fonts"); tbx::Font corpus("Corpus.Medium", tbx::os_to_points_16th(48)); g.text(160,-668, "This text is in Corpus Medium font", corpus); // Get and show user sprite from sprites loaded with application tbx::UserSprite us = app()->sprite_area()->get_sprite("example"); g.image(320, -752, us); }