Skip to content

Commit

Permalink
GRAPHICS: Implemented basic rendering for MacText
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 14, 2016
1 parent aecc17e commit 6329f73
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
27 changes: 25 additions & 2 deletions graphics/macgui/mactext.cpp
Expand Up @@ -24,15 +24,20 @@

namespace Graphics {

MacText::MacText(Common::String s, Graphics::Font *font, int maxWidth) {
MacText::MacText(Common::String s, Graphics::Font *font, int fgcolor, int bgcolor, int maxWidth) {
_str = s;
_font = font;
_fgcolor = fgcolor;
_bgcolor = bgcolor;
_maxWidth = maxWidth;
_interLinear = 2; // 2 pixels by default

_interLinear = 0; // 0 pixels between the lines by default

_textMaxWidth = -1;

splitString();

_fullRefresh = true;
}

void MacText::splitString() {
Expand Down Expand Up @@ -62,6 +67,9 @@ void MacText::splitString() {
tmp += *s;
}

if (_text.size())
_text.push_back(tmp);

calcMaxWidth();
}

Expand All @@ -76,6 +84,21 @@ void MacText::calcMaxWidth() {
}

void MacText::render() {
if (_fullRefresh) {
_surface.create(_textMaxWidth, _text.size() * (_font->getFontHeight() + _interLinear));

_surface.clear(_bgcolor);

int y = 0;

for (uint i = 0; i < _text.size(); i++) {
_font->drawString(&_surface, _text[i], 0, y, _textMaxWidth, _fgcolor);

y += _font->getFontHeight() + _interLinear;
}

_fullRefresh = false;
}
}

} // End of namespace Graphics
8 changes: 7 additions & 1 deletion graphics/macgui/mactext.h
Expand Up @@ -24,12 +24,13 @@
#define GRAPHICS_MACGUI_MACTEXT_H

#include "graphics/fontman.h"
#include "graphics/managed_surface.h"

namespace Graphics {

class MacText {
public:
MacText(Common::String s, Graphics::Font *font, int maxWidth = -1);
MacText(Common::String s, Graphics::Font *font, int fgcolor, int bgcolor, int maxWidth = -1);

void setInterLinear(int interLinear) { _interLinear = interLinear; }

Expand All @@ -41,13 +42,18 @@ class MacText {
private:
Common::String _str;
Graphics::Font *_font;
int _fgcolor, _bgcolor;

int _maxWidth;
int _interLinear;

Common::Array<Common::String> _text;
Common::Array<int> _widths;

int _textMaxWidth;

Graphics::ManagedSurface _surface;
bool _fullRefresh;
};

} // End of namespace Graphics
Expand Down

0 comments on commit 6329f73

Please sign in to comment.