Add text-color to Label widget.

This commit is contained in:
David Capello 2011-02-19 23:08:15 -03:00
parent 96095159bb
commit d1baef1555
3 changed files with 31 additions and 7 deletions

View File

@ -13,9 +13,21 @@
Label::Label(const char *text)
: Widget(JI_LABEL)
{
this->setAlign(JI_LEFT | JI_MIDDLE);
this->setText(text);
setAlign(JI_LEFT | JI_MIDDLE);
setText(text);
initTheme();
m_textColor = ji_color_foreground();
}
int Label::getTextColor() const
{
return m_textColor;
}
void Label::setTextColor(int color)
{
m_textColor = color;
}
bool Label::onProcessMessage(JMessage msg)

View File

@ -14,10 +14,15 @@ class Label : public Widget
public:
Label(const char *text);
int getTextColor() const;
void setTextColor(int color);
protected:
bool onProcessMessage(JMessage msg);
void onPaint(PaintEvent& ev);
private:
int m_textColor;
};
#endif

View File

@ -27,8 +27,6 @@
#include "gfx/point.h"
#include "gfx/rect.h"
#include "gfx/size.h"
#include "gui/paint_event.h"
#include "gui/graphics.h"
#include "gui/gui.h"
#include "gui/intern.h"
#include "loadpng.h"
@ -842,12 +840,21 @@ void SkinTheme::paintEntry(PaintEvent& ev)
void SkinTheme::paintLabel(PaintEvent& ev)
{
Widget* widget = static_cast<Widget*>(ev.getSource());
Graphics* g = ev.getGraphics();
Label* widget = static_cast<Label*>(ev.getSource());
struct jrect text;
int bg = BGCOLOR;
int fg = widget->getTextColor();
gfx::Rect rc = widget->getClientBounds();
jdraw_rectfill(widget->rc, bg);
g->fillRect(bg, rc);
rc.shrink(widget->getBorder());
draw_textstring(NULL, -1, bg, false, widget, widget->rc, 0);
jwidget_get_texticon_info(widget, NULL, &text, NULL, 0, 0, 0);
g->drawString(widget->getText(), fg, bg, false,
// TODO "text" coordinates are absolute and we are drawing on client area
gfx::Point(text.x1, text.y1) - gfx::Point(widget->rc->x1, widget->rc->y1));
}
void SkinTheme::paintLinkLabel(PaintEvent& ev)