More painting code from ji_screen to ui::Graphics

We planned to migrate everything to ui::Graphics to port the program to
other back-end (e.g. SDL or Allegro5). This is one step forward to that
direction.

Changes:
- Delete a lot of deprecated functions from src/ui/draw.h/cpp and SkinTheme
  that used BITMAP/ji_screen.
- Rename ui::ji_move_region to ui::_move_region
- Move ui::jwidget_get_texticon_info to ui::Widget::getTextIconInfo.
  Now the member function returns client coordinate instead of absolute
  ones.
- ui::drawTextBox() now receives a ui::Graphics instead of a BITMAP
- Add ui::Graphics::drawChar/measureChar() member functions.
- Replace ui::jrectexclude() with with ui::Graphics::fillAreaBetweenRects()
This commit is contained in:
David Capello 2014-04-19 15:18:16 -03:00
parent 4beff46e02
commit af4e714360
17 changed files with 263 additions and 627 deletions

View File

@ -166,7 +166,7 @@ bool ColorButton::onProcessMessage(Message* msg)
void ColorButton::onPreferredSize(PreferredSizeEvent& ev)
{
gfx::Rect box;
jwidget_get_texticon_info(this, &box, NULL, NULL, 0, 0, 0);
getTextIconInfo(&box);
box.w = 64;
ev.setPreferredSize(box.w + border_width.l + border_width.r,
@ -177,10 +177,7 @@ void ColorButton::onPaint(PaintEvent& ev)
{
Graphics* g = ev.getGraphics();
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
gfx::Rect rc = getClientBounds();
gfx::Rect text;
jwidget_get_texticon_info(this, NULL, &text, NULL, 0, 0, 0);
ui::Color bg = getBgColor();
if (is_transparent(bg))
@ -211,14 +208,14 @@ void ColorButton::onPaint(PaintEvent& ev)
app::Color::ShortHumanReadableString);
setTextQuiet(str.c_str());
jwidget_get_texticon_info(this, NULL, &text, NULL, 0, 0, 0);
ui::Color textcolor = ui::rgba(255, 255, 255);
if (color.isValid())
textcolor = color_utils::blackandwhite_neg(ui::rgba(color.getRed(), color.getGreen(), color.getBlue()));
g->drawString(getText(), textcolor, ColorNone, false,
text.getOrigin() - getBounds().getOrigin());
gfx::Rect text;
getTextIconInfo(NULL, &text);
g->drawString(getText(), textcolor, ColorNone, false, text.getOrigin());
}
void ColorButton::onClick(Event& ev)

View File

@ -1,5 +1,5 @@
/* Aseprite
* Copyright (C) 2001-2013 David Capello
* Copyright (C) 2001-2014 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,9 +20,6 @@
#include "config.h"
#endif
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include "app/modules/gui.h"
#include "app/resource_finder.h"
#include "app/ui/skin/button_icon_impl.h"
@ -41,14 +38,14 @@
#include "gfx/point.h"
#include "gfx/rect.h"
#include "gfx/size.h"
#include "loadpng.h"
#include "she/system.h"
#include "ui/intern.h"
#include "ui/ui.h"
#include "tinyxml.h"
#define CHARACTER_LENGTH(f, c) ((f)->vtable->char_length((f), (c)))
#include <allegro.h>
#include <allegro/internal/aintern.h>
#define BGCOLOR (getWidgetBgColor(widget))
@ -386,7 +383,7 @@ void SkinTheme::reload_skin()
set_color_conversion(COLORCONV_NONE);
PALETTE pal;
m_sheet_bmp = load_png(rf.filename().c_str(), pal);
m_sheet_bmp = load_bitmap(rf.filename().c_str(), pal);
if (!m_sheet_bmp)
throw base::Exception("Error loading %s file", sheet_filename.c_str());
@ -928,10 +925,10 @@ void SkinTheme::paintButton(PaintEvent& ev)
ui::Color fg, bg;
int part_nw;
jwidget_get_texticon_info(widget, &box, &text, &icon,
iconInterface ? iconInterface->getIconAlign(): 0,
iconInterface ? iconInterface->getWidth() : 0,
iconInterface ? iconInterface->getHeight() : 0);
widget->getTextIconInfo(&box, &text, &icon,
iconInterface ? iconInterface->getIconAlign(): 0,
iconInterface ? iconInterface->getWidth() : 0,
iconInterface ? iconInterface->getHeight() : 0);
// Tool buttons are smaller
LookType look = NormalLook;
@ -990,23 +987,23 @@ void SkinTheme::paintButton(PaintEvent& ev)
icon.offset(get_button_selected_offset(),
get_button_selected_offset());
paintIcon(widget, ev.getGraphics(), iconInterface,
icon.x-widget->getBounds().x,
icon.y-widget->getBounds().y);
paintIcon(widget, ev.getGraphics(), iconInterface, icon.x, icon.y);
}
}
void SkinTheme::paintCheckBox(PaintEvent& ev)
{
Graphics* g = ev.getGraphics();
ButtonBase* widget = static_cast<ButtonBase*>(ev.getSource());
gfx::Rect bounds = widget->getClientBounds();
IButtonIcon* iconInterface = widget->getIconInterface();
gfx::Rect box, text, icon;
ui::Color bg;
jwidget_get_texticon_info(widget, &box, &text, &icon,
iconInterface ? iconInterface->getIconAlign(): 0,
iconInterface ? iconInterface->getWidth() : 0,
iconInterface ? iconInterface->getHeight() : 0);
widget->getTextIconInfo(&box, &text, &icon,
iconInterface ? iconInterface->getIconAlign(): 0,
iconInterface ? iconInterface->getWidth() : 0,
iconInterface ? iconInterface->getHeight() : 0);
// Check box look
LookType look = NormalLook;
@ -1015,31 +1012,26 @@ void SkinTheme::paintCheckBox(PaintEvent& ev)
look = skinPropery->getLook();
// Background
jdraw_rectfill(widget->getBounds(), bg = BGCOLOR);
g->fillRect(bg = BGCOLOR, bounds);
// Mouse
if (widget->isEnabled()) {
if (widget->hasMouseOver())
jdraw_rectfill(widget->getBounds(), bg = getColor(ThemeColor::CheckHotFace));
g->fillRect(bg = getColor(ThemeColor::CheckHotFace), bounds);
else if (widget->hasFocus())
jdraw_rectfill(widget->getBounds(), bg = getColor(ThemeColor::CheckFocusFace));
g->fillRect(bg = getColor(ThemeColor::CheckFocusFace), bounds);
}
// Text
drawTextStringDeprecated(NULL, ColorNone, bg, false, widget, text, 0);
drawTextString(g, NULL, ColorNone, bg, false, widget, text, 0);
// Paint the icon
if (iconInterface)
paintIcon(widget, ev.getGraphics(), iconInterface, icon.x-widget->getBounds().x, icon.y-widget->getBounds().y);
paintIcon(widget, g, iconInterface, icon.x, icon.y);
// draw focus
if (look != WithoutBordersLook && widget->hasFocus()) {
draw_bounds_nw(ji_screen,
widget->getBounds().x,
widget->getBounds().y,
widget->getBounds().x2()-1,
widget->getBounds().y2()-1, PART_CHECK_FOCUS_NW, ui::ColorNone);
}
if (look != WithoutBordersLook && widget->hasFocus())
draw_bounds_nw(g, bounds, PART_CHECK_FOCUS_NW, ui::ColorNone);
}
void SkinTheme::paintGrid(PaintEvent& ev)
@ -1052,26 +1044,21 @@ void SkinTheme::paintGrid(PaintEvent& ev)
void SkinTheme::paintEntry(PaintEvent& ev)
{
Graphics* g = ev.getGraphics();
Entry* widget = static_cast<Entry*>(ev.getSource());
gfx::Rect bounds = widget->getClientBounds();
bool password = widget->isPassword();
int scroll, caret, state, selbeg, selend;
std::string textString = widget->getText() + widget->getSuffix();
int suffixIndex = widget->getTextLength();
const char* text = textString.c_str();
int c, ch, x, y, w;
int x1, y1, x2, y2;
int caret_x;
widget->getEntryThemeInfo(&scroll, &caret, &state, &selbeg, &selend);
// Outside borders
jdraw_rectfill(widget->getBounds(), BGCOLOR);
// Main pos
x1 = widget->getBounds().x;
y1 = widget->getBounds().y;
x2 = widget->getBounds().x2()-1;
y2 = widget->getBounds().y2()-1;
g->fillRect(BGCOLOR, bounds);
bool isMiniLook = false;
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
@ -1079,16 +1066,15 @@ void SkinTheme::paintEntry(PaintEvent& ev)
isMiniLook = (skinPropery->getLook() == MiniLook);
ui::Color bg = getColor(ThemeColor::Background);
draw_bounds_nw(ji_screen,
x1, y1, x2, y2,
(widget->hasFocus() ?
(isMiniLook ? PART_SUNKEN_MINI_FOCUSED_NW: PART_SUNKEN_FOCUSED_NW):
(isMiniLook ? PART_SUNKEN_MINI_NORMAL_NW : PART_SUNKEN_NORMAL_NW)),
bg);
draw_bounds_nw(g, bounds,
(widget->hasFocus() ?
(isMiniLook ? PART_SUNKEN_MINI_FOCUSED_NW: PART_SUNKEN_FOCUSED_NW):
(isMiniLook ? PART_SUNKEN_MINI_NORMAL_NW : PART_SUNKEN_NORMAL_NW)),
bg);
// Draw the text
x = widget->getBounds().x + widget->border_width.l;
y = widget->getBounds().y + widget->getBounds().h/2 - widget->getTextHeight()/2;
x = bounds.x + widget->border_width.l;
y = bounds.y + bounds.h/2 - widget->getTextHeight()/2;
for (c=scroll; ugetat(text, c); c++) {
ch = password ? '*': ugetat(text, c);
@ -1121,29 +1107,24 @@ void SkinTheme::paintEntry(PaintEvent& ev)
fg = getColor(ThemeColor::EntrySuffix);
}
w = CHARACTER_LENGTH(widget->getFont(), ch);
if (x+w > widget->getBounds().x2()-3)
w = g->measureChar(ch).w;
if (x+w > bounds.x2()-3)
return;
caret_x = x;
ji_font_set_aa_mode(widget->getFont(),
to_system(is_transparent(bg) ? getColor(ThemeColor::Background):
bg));
widget->getFont()->vtable->render_char(widget->getFont(), ch,
to_system(fg),
to_system(bg), ji_screen, x, y);
g->drawChar(ch, fg, bg, x, y);
x += w;
// Caret
if ((c == caret) && (state) && (widget->hasFocus()))
draw_entry_caret(widget, caret_x, y);
drawEntryCaret(g, widget, caret_x, y);
}
// Draw the caret if it is next of the last character
if ((c == caret) && (state) &&
(widget->hasFocus()) &&
(widget->isEnabled())) {
draw_entry_caret(widget, x, y);
drawEntryCaret(g, widget, x, y);
}
}
@ -1158,30 +1139,26 @@ void SkinTheme::paintLabel(PaintEvent& ev)
g->fillRect(bg, rc);
rc.shrink(widget->getBorder());
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
Point(text.x, text.y) - widget->getOrigin());
widget->getTextIconInfo(NULL, &text);
g->drawString(widget->getText(), fg, bg, false, text.getOrigin());
}
void SkinTheme::paintLinkLabel(PaintEvent& ev)
{
Graphics* g = ev.getGraphics();
Widget* widget = static_cast<Widget*>(ev.getSource());
gfx::Rect bounds = widget->getClientBounds();
ui::Color fg = getColor(ThemeColor::LinkText);
ui::Color bg = BGCOLOR;
jdraw_rectfill(widget->getBounds(), bg);
drawTextStringDeprecated(NULL, getColor(ThemeColor::LinkText), bg, false, widget,
widget->getBounds(), 0);
g->fillRect(bg, bounds);
drawTextString(g, NULL, fg, bg, false, widget, bounds, 0);
// Underline style
if (widget->hasMouseOver()) {
int w = widget->getTextWidth();
hline(ji_screen,
widget->getBounds().x,
widget->getBounds().y2()-1,
widget->getBounds().x+w-1,
to_system(getColor(ThemeColor::LinkText)));
for (int v=0; v<jguiscale(); ++v)
g->drawHLine(fg, bounds.x, bounds.y2()-1-v, w);
}
}
@ -1196,9 +1173,9 @@ void SkinTheme::paintListBox(PaintEvent& ev)
void SkinTheme::paintListItem(ui::PaintEvent& ev)
{
Widget* widget = static_cast<Widget*>(ev.getSource());
gfx::Rect bounds = widget->getClientBounds();
Graphics* g = ev.getGraphics();
ui::Color fg, bg;
int x, y;
if (!widget->isEnabled()) {
bg = getColor(ThemeColor::Face);
@ -1213,26 +1190,11 @@ void SkinTheme::paintListItem(ui::PaintEvent& ev)
bg = getColor(ThemeColor::ListItemNormalFace);
}
x = widget->getBounds().x+widget->border_width.l;
y = widget->getBounds().y+widget->border_width.t;
g->fillRect(bg, bounds);
if (widget->hasText()) {
// Text
jdraw_text(ji_screen, widget->getFont(), widget->getText().c_str(), x, y,
fg, bg, true, jguiscale());
// Background
jrectexclude
(ji_screen,
widget->getBounds().x, widget->getBounds().y,
widget->getBounds().x2()-1, widget->getBounds().y2()-1,
x, y,
x+widget->getTextWidth()-1,
y+widget->getTextHeight()-1, bg);
}
// Background
else {
jdraw_rectfill(widget->getBounds(), bg);
bounds.shrink(widget->getBorder());
drawTextString(g, NULL, fg, bg, true, widget, bounds, 0);
}
}
@ -1246,10 +1208,10 @@ void SkinTheme::paintMenu(PaintEvent& ev)
void SkinTheme::paintMenuItem(ui::PaintEvent& ev)
{
MenuItem* widget = static_cast<MenuItem*>(ev.getSource());
Graphics* g = ev.getGraphics();
MenuItem* widget = static_cast<MenuItem*>(ev.getSource());
gfx::Rect bounds = widget->getClientBounds();
ui::Color fg, bg;
int x1, y1, x2, y2;
int c, bar;
// TODO ASSERT?
@ -1278,34 +1240,26 @@ void SkinTheme::paintMenuItem(ui::PaintEvent& ev)
}
}
/* widget position */
x1 = widget->getBounds().x;
y1 = widget->getBounds().y;
x2 = widget->getBounds().x2()-1;
y2 = widget->getBounds().y2()-1;
// Background
g->fillRect(bg, bounds);
/* background */
rectfill(ji_screen, x1, y1, x2, y2, to_system(bg));
/* draw an indicator for selected items */
// Draw an indicator for selected items
if (widget->isSelected()) {
BITMAP* icon = m_part[widget->isEnabled() ? PART_CHECK_SELECTED:
PART_CHECK_DISABLED];
int x = widget->getBounds().x+4-icon->w/2;
int y = widget->getBounds().y+widget->getBounds().h/2-icon->h/2;
set_alpha_blender();
draw_trans_sprite(ji_screen, icon, x, y);
int x = bounds.x+4-icon->w/2;
int y = bounds.y+bounds.h/2-icon->h/2;
g->drawAlphaBitmap(icon, x, y);
}
/* text */
// Text
if (bar)
widget->setAlign(JI_CENTER | JI_MIDDLE);
else
widget->setAlign(JI_LEFT | JI_MIDDLE);
Rect pos = widget->getClientBounds();
Rect pos = bounds;
if (!bar)
pos.offset(widget->child_spacing/2, 0);
drawTextString(g, NULL, fg, bg, false, widget, pos, 0);
@ -1319,32 +1273,28 @@ void SkinTheme::paintMenuItem(ui::PaintEvent& ev)
// Enabled
if (widget->isEnabled()) {
for (c=0; c<3*scale; c++)
vline(ji_screen,
widget->getBounds().x2()-3*scale-c,
widget->getBounds().y+widget->getBounds().h/2-c,
widget->getBounds().y+widget->getBounds().h/2+c, to_system(fg));
g->drawVLine(fg,
bounds.x2()-3*scale-c,
bounds.y+bounds.h/2-c, 2*c+1);
}
// Disabled
else {
for (c=0; c<3*scale; c++)
vline(ji_screen,
widget->getBounds().x2()-3*scale-c+1,
widget->getBounds().y+widget->getBounds().h/2-c+1,
widget->getBounds().y+widget->getBounds().h/2+c+1,
to_system(getColor(ThemeColor::Background)));
g->drawVLine(getColor(ThemeColor::Background),
bounds.x2()-3*scale-c+1,
bounds.y+bounds.h/2-c+1, 2*c+1);
for (c=0; c<3*scale; c++)
vline(ji_screen,
widget->getBounds().x2()-3*scale-c,
widget->getBounds().y+widget->getBounds().h/2-c,
widget->getBounds().y+widget->getBounds().h/2+c,
to_system(getColor(ThemeColor::Disabled)));
g->drawVLine(getColor(ThemeColor::Disabled),
bounds.x2()-3*scale-c,
bounds.y+bounds.h/2-c, 2*c+1);
}
}
// Draw the keyboard shortcut
else if (widget->getAccel()) {
int old_align = widget->getAlign();
pos = widget->getClientBounds();
pos = bounds;
pos.w -= widget->child_spacing/4;
std::string buf = widget->getAccel()->toString();
@ -1366,16 +1316,17 @@ void SkinTheme::paintSplitter(PaintEvent& ev)
void SkinTheme::paintRadioButton(PaintEvent& ev)
{
ButtonBase* widget = static_cast<ButtonBase*>(ev.getSource());
Graphics* g = ev.getGraphics();
ButtonBase* widget = static_cast<ButtonBase*>(ev.getSource());
gfx::Rect bounds = widget->getClientBounds();
IButtonIcon* iconInterface = widget->getIconInterface();
ui::Color bg = BGCOLOR;
gfx::Rect box, text, icon;
jwidget_get_texticon_info(widget, &box, &text, &icon,
iconInterface ? iconInterface->getIconAlign(): 0,
iconInterface ? iconInterface->getWidth() : 0,
iconInterface ? iconInterface->getHeight() : 0);
widget->getTextIconInfo(&box, &text, &icon,
iconInterface ? iconInterface->getIconAlign(): 0,
iconInterface ? iconInterface->getWidth() : 0,
iconInterface ? iconInterface->getHeight() : 0);
// Background
g->fillRect(bg, g->getClipBounds());
@ -1383,63 +1334,52 @@ void SkinTheme::paintRadioButton(PaintEvent& ev)
// Mouse
if (widget->isEnabled()) {
if (widget->hasMouseOver())
jdraw_rectfill(widget->getBounds(), bg = getColor(ThemeColor::RadioHotFace));
g->fillRect(bg = getColor(ThemeColor::RadioHotFace), bounds);
else if (widget->hasFocus())
jdraw_rectfill(widget->getBounds(), bg = getColor(ThemeColor::RadioFocusFace));
g->fillRect(bg = getColor(ThemeColor::RadioFocusFace), bounds);
}
// Text
drawTextStringDeprecated(NULL, ColorNone, bg, false, widget, text, 0);
drawTextString(g, NULL, ColorNone, bg, false, widget, text, 0);
// Paint the icon
// Icon
if (iconInterface)
paintIcon(widget, g, iconInterface, icon.x-widget->getBounds().x, icon.y-widget->getBounds().y);
paintIcon(widget, g, iconInterface, icon.x, icon.y);
// draw focus
if (widget->hasFocus()) {
draw_bounds_nw(ji_screen,
widget->getBounds(), PART_RADIO_FOCUS_NW, ui::ColorNone);
}
// Focus
if (widget->hasFocus())
draw_bounds_nw(g, bounds, PART_RADIO_FOCUS_NW, ui::ColorNone);
}
void SkinTheme::paintSeparator(ui::PaintEvent& ev)
{
Widget* widget = static_cast<Widget*>(ev.getSource());
Graphics* g = ev.getGraphics();
int x1, y1, x2, y2;
// position
x1 = widget->getBounds().x + widget->border_width.l/2;
y1 = widget->getBounds().y + widget->border_width.t/2;
x2 = widget->getBounds().x2() - 1 - widget->border_width.r/2;
y2 = widget->getBounds().y2() - 1 - widget->border_width.b/2;
Widget* widget = static_cast<Widget*>(ev.getSource());
gfx::Rect bounds = widget->getClientBounds();
// background
jdraw_rectfill(widget->getBounds(), BGCOLOR);
g->fillRect(BGCOLOR, bounds);
if (widget->getAlign() & JI_HORIZONTAL) {
draw_part_as_hline(ji_screen,
widget->getBounds().x,
widget->getBounds().y,
widget->getBounds().x2()-1,
widget->getBounds().y2()-1, PART_SEPARATOR_HORZ);
}
if (widget->getAlign() & JI_HORIZONTAL)
draw_part_as_hline(g, bounds, PART_SEPARATOR_HORZ);
if (widget->getAlign() & JI_VERTICAL) {
draw_part_as_vline(ji_screen,
widget->getBounds().x,
widget->getBounds().y,
widget->getBounds().x2()-1,
widget->getBounds().y2()-1, PART_SEPARATOR_VERT);
}
if (widget->getAlign() & JI_VERTICAL)
draw_part_as_vline(g, bounds, PART_SEPARATOR_VERT);
// text
if (widget->hasText()) {
int h = widget->getTextHeight();
Rect r(Point(x1+h/2, y1-h/2),
Point(x2+1-h, y2+1+h));
Rect r(
Point(
bounds.x + widget->border_width.l/2 + h/2,
bounds.y + widget->border_width.t/2 - h/2),
Point(
bounds.x2() - widget->border_width.r/2 - h,
bounds.y2() - widget->border_width.b/2 + h));
drawTextString(g, NULL, getColor(ThemeColor::Selected), BGCOLOR, false, widget, r, 0);
drawTextString(g, NULL,
getColor(ThemeColor::Selected), BGCOLOR, false,
widget, r, 0);
}
}
@ -1460,19 +1400,20 @@ static bool my_add_clip_rect(BITMAP *bitmap, int x1, int y1, int x2, int y2)
void SkinTheme::paintSlider(PaintEvent& ev)
{
Slider* widget = static_cast<Slider*>(ev.getSource());
Graphics* g = ev.getGraphics();
Slider* widget = static_cast<Slider*>(ev.getSource());
Rect bounds = widget->getClientBounds();
int min, max, value;
char buf[256];
// Outside borders
ui::Color bgcolor = widget->getBgColor();
if (!is_transparent(bgcolor))
jdraw_rectfill(widget->getBounds(), bgcolor);
g->fillRect(bgcolor, bounds);
widget->getSliderThemeInfo(&min, &max, &value);
Rect rc(widget->getClientBounds().shrink(widget->getBorder()));
Rect rc(Rect(bounds).shrink(widget->getBorder()));
int x;
if (min != max)
x = rc.x + rc.w * (value-min) / (max-min);
@ -1574,35 +1515,30 @@ void SkinTheme::paintSlider(PaintEvent& ev)
void SkinTheme::paintComboBoxEntry(ui::PaintEvent& ev)
{
Graphics* g = ev.getGraphics();
Entry* widget = static_cast<Entry*>(ev.getSource());
gfx::Rect bounds = widget->getClientBounds();
bool password = widget->isPassword();
int scroll, caret, state, selbeg, selend;
const char *text = widget->getText().c_str();
int c, ch, x, y, w;
int x1, y1, x2, y2;
int caret_x;
widget->getEntryThemeInfo(&scroll, &caret, &state, &selbeg, &selend);
// Outside borders
jdraw_rectfill(widget->getBounds(), BGCOLOR);
// Main pos
x1 = widget->getBounds().x;
y1 = widget->getBounds().y;
x2 = widget->getBounds().x2()-1;
y2 = widget->getBounds().y2()-1;
g->fillRect(BGCOLOR, bounds);
ui::Color fg, bg = getColor(ThemeColor::Background);
draw_bounds_nw(ji_screen,
x1, y1, x2, y2,
widget->hasFocus() ? PART_SUNKEN2_FOCUSED_NW:
PART_SUNKEN2_NORMAL_NW, bg);
draw_bounds_nw(g, bounds,
widget->hasFocus() ?
PART_SUNKEN2_FOCUSED_NW:
PART_SUNKEN2_NORMAL_NW, bg);
// Draw the text
x = widget->getBounds().x + widget->border_width.l;
y = widget->getBounds().y + widget->getBounds().h/2 - widget->getTextHeight()/2;
x = bounds.x + widget->border_width.l;
y = bounds.y + bounds.h/2 - widget->getTextHeight()/2;
for (c=scroll; ugetat(text, c); c++) {
ch = password ? '*': ugetat(text, c);
@ -1626,29 +1562,24 @@ void SkinTheme::paintComboBoxEntry(ui::PaintEvent& ev)
fg = getColor(ThemeColor::Disabled);
}
w = CHARACTER_LENGTH(widget->getFont(), ch);
if (x+w > widget->getBounds().x2()-3)
w = g->measureChar(ch).w;
if (x+w > bounds.x2()-3)
return;
caret_x = x;
ji_font_set_aa_mode(widget->getFont(),
to_system(is_transparent(bg) ? getColor(ThemeColor::Background):
bg));
widget->getFont()->vtable->render_char(widget->getFont(), ch,
to_system(fg),
to_system(bg), ji_screen, x, y);
g->drawChar(ch, fg, bg, x, y);
x += w;
// Caret
if ((c == caret) && (state) && (widget->hasFocus()))
draw_entry_caret(widget, caret_x, y);
drawEntryCaret(g, widget, caret_x, y);
}
// Draw the caret if it is next of the last character
if ((c == caret) && (state) &&
(widget->hasFocus()) &&
(widget->isEnabled())) {
draw_entry_caret(widget, x, y);
drawEntryCaret(g, widget, x, y);
}
}
@ -1695,23 +1626,27 @@ void SkinTheme::paintComboBoxButton(PaintEvent& ev)
void SkinTheme::paintTextBox(ui::PaintEvent& ev)
{
Graphics* g = ev.getGraphics();
Widget* widget = static_cast<Widget*>(ev.getSource());
drawTextBox(ji_screen, widget, NULL, NULL,
getColor(ThemeColor::TextBoxFace),
getColor(ThemeColor::TextBoxText));
drawTextBox(g, widget, NULL, NULL,
getColor(ThemeColor::TextBoxFace),
getColor(ThemeColor::TextBoxText));
}
void SkinTheme::paintView(PaintEvent& ev)
{
Graphics* g = ev.getGraphics();
View* widget = static_cast<View*>(ev.getSource());
gfx::Rect bounds = widget->getClientBounds();
g->fillRect(BGCOLOR, widget->getClientBounds());
g->fillRect(BGCOLOR, bounds);
draw_bounds_nw(g, widget->getClientBounds(),
widget->hasFocus() ? PART_SUNKEN_FOCUSED_NW:
PART_SUNKEN_NORMAL_NW,
getColor(ThemeColor::Background));
draw_bounds_nw(g, bounds,
(widget->hasFocus() ?
PART_SUNKEN_FOCUSED_NW:
PART_SUNKEN_NORMAL_NW),
getColor(ThemeColor::Background));
}
void SkinTheme::paintViewScrollbar(PaintEvent& ev)
@ -1886,74 +1821,6 @@ ui::Color SkinTheme::getWidgetBgColor(Widget* widget)
getColor(ThemeColor::Face)));
}
void SkinTheme::drawTextStringDeprecated(const char* t, ui::Color fg_color, ui::Color bg_color,
bool fill_bg, Widget* widget, const Rect& rect,
int selected_offset)
{
if (t || widget->hasText()) {
int x, y, w, h;
if (!t) {
t = widget->getText().c_str();
w = widget->getTextWidth();
}
else {
w = ji_font_text_len(widget->getFont(), t);
}
h = widget->getTextHeight();
/* horizontally text alignment */
if (widget->getAlign() & JI_RIGHT)
x = rect.x2() - w;
else if (widget->getAlign() & JI_CENTER)
x = rect.x + rect.w/2 - w/2;
else
x = rect.x;
/* vertically text alignment */
if (widget->getAlign() & JI_BOTTOM)
y = rect.y2() - h;
else if (widget->getAlign() & JI_MIDDLE)
y = rect.y + rect.h/2 - h/2;
else
y = rect.y;
if (widget->isSelected()) {
x += selected_offset;
y += selected_offset;
}
/* background */
if (ui::geta(bg_color) > 0) {
if (!widget->isEnabled())
rectfill(ji_screen, x, y, x+w-1+jguiscale(), y+h-1+jguiscale(), to_system(bg_color));
else
rectfill(ji_screen, x, y, x+w-1, y+h-1, to_system(bg_color));
}
/* text */
if (!widget->isEnabled()) {
// TODO avoid this
if (fill_bg) // Only to draw the background
jdraw_text(ji_screen, widget->getFont(), t, x, y, ColorNone, bg_color, fill_bg, jguiscale());
// Draw white part
jdraw_text(ji_screen, widget->getFont(), t, x+jguiscale(), y+jguiscale(),
getColor(ThemeColor::Background), bg_color, fill_bg, jguiscale());
if (fill_bg)
fill_bg = false;
}
jdraw_text(ji_screen, widget->getFont(), t, x, y,
(!widget->isEnabled() ? getColor(ThemeColor::Disabled):
(is_transparent(fg_color) ? getColor(ThemeColor::Text): fg_color)),
bg_color, fill_bg, jguiscale());
}
}
void SkinTheme::drawTextString(Graphics* g, const char *t, ui::Color fg_color, ui::Color bg_color,
bool fill_bg, Widget* widget, const Rect& rc,
int selected_offset)
@ -2001,7 +1868,9 @@ void SkinTheme::drawTextString(Graphics* g, const char *t, ui::Color fg_color, u
// Text
Rect textWrap = textrc.createIntersect(
Rect(widget->getClientBounds()).shrink(widget->getBorder()));
// TODO add ui::Widget::getPadding() property
// Rect(widget->getClientBounds()).shrink(widget->getBorder()));
widget->getClientBounds());
if (IntersectClip clip = IntersectClip(g, textWrap)) {
if (!widget->isEnabled()) {
@ -2027,12 +1896,13 @@ void SkinTheme::drawTextString(Graphics* g, const char *t, ui::Color fg_color, u
}
}
void SkinTheme::draw_entry_caret(Entry* widget, int x, int y)
void SkinTheme::drawEntryCaret(ui::Graphics* g, Entry* widget, int x, int y)
{
ui::Color color = getColor(ThemeColor::Text);
int h = widget->getTextHeight();
vline(ji_screen, x, y-1, y+h, to_system(getColor(ThemeColor::Text)));
vline(ji_screen, x+1, y-1, y+h, to_system(getColor(ThemeColor::Text)));
for (int u=x; u<x+2*jguiscale(); ++u)
g->drawVLine(color, u, y-1, h+2);
}
BITMAP* SkinTheme::get_toolicon(const char* tool_id) const
@ -2044,67 +1914,6 @@ BITMAP* SkinTheme::get_toolicon(const char* tool_id) const
return NULL;
}
void SkinTheme::draw_bounds_template(BITMAP* bmp, int x1, int y1, int x2, int y2,
int nw, int n, int ne, int e, int se, int s, int sw, int w)
{
int x, y;
int cx1, cy1, cx2, cy2;
get_clip_rect(bmp, &cx1, &cy1, &cx2, &cy2);
/* top */
draw_trans_sprite(bmp, m_part[nw], x1, y1);
if (my_add_clip_rect(bmp,
x1+m_part[nw]->w, y1,
x2-m_part[ne]->w, y2)) {
for (x = x1+m_part[nw]->w;
x <= x2-m_part[ne]->w;
x += m_part[n]->w) {
draw_trans_sprite(bmp, m_part[n], x, y1);
}
}
set_clip_rect(bmp, cx1, cy1, cx2, cy2);
draw_trans_sprite(bmp, m_part[ne], x2-m_part[ne]->w+1, y1);
/* bottom */
draw_trans_sprite(bmp, m_part[sw], x1, y2-m_part[sw]->h+1);
if (my_add_clip_rect(bmp,
x1+m_part[sw]->w, y1,
x2-m_part[se]->w, y2)) {
for (x = x1+m_part[sw]->w;
x <= x2-m_part[se]->w;
x += m_part[s]->w) {
draw_trans_sprite(bmp, m_part[s], x, y2-m_part[s]->h+1);
}
}
set_clip_rect(bmp, cx1, cy1, cx2, cy2);
draw_trans_sprite(bmp, m_part[se], x2-m_part[se]->w+1, y2-m_part[se]->h+1);
if (my_add_clip_rect(bmp,
x1, y1+m_part[nw]->h,
x2, y2-m_part[sw]->h)) {
/* left */
for (y = y1+m_part[nw]->h;
y <= y2-m_part[sw]->h;
y += m_part[w]->h) {
draw_trans_sprite(bmp, m_part[w], x1, y);
}
/* right */
for (y = y1+m_part[ne]->h;
y <= y2-m_part[se]->h;
y += m_part[e]->h) {
draw_trans_sprite(bmp, m_part[e], x2-m_part[e]->w+1, y);
}
}
set_clip_rect(bmp, cx1, cy1, cx2, cy2);
}
void SkinTheme::draw_bounds_template(Graphics* g, const Rect& rc,
int nw, int n, int ne, int e, int se, int s, int sw, int w)
{
@ -2204,24 +2013,6 @@ void SkinTheme::draw_bounds_array(ui::Graphics* g, const gfx::Rect& rc, int part
se, s, sw, w);
}
void SkinTheme::draw_bounds_nw(BITMAP* bmp, int x1, int y1, int x2, int y2, int nw, ui::Color bg)
{
set_alpha_blender();
draw_bounds_template(bmp, x1, y1, x2, y2,
nw+0, nw+1, nw+2, nw+3,
nw+4, nw+5, nw+6, nw+7);
// Center
if (!is_transparent(bg)) {
x1 += m_part[nw+7]->w;
y1 += m_part[nw+1]->h;
x2 -= m_part[nw+3]->w;
y2 -= m_part[nw+5]->h;
rectfill(bmp, x1, y1, x2, y2, to_system(bg));
}
}
void SkinTheme::draw_bounds_nw(Graphics* g, const Rect& rc, int nw, ui::Color bg)
{
draw_bounds_template(g, rc,
@ -2269,58 +2060,10 @@ void SkinTheme::draw_bounds_nw2(Graphics* g, const Rect& rc, int x_mid, int nw1,
draw_bounds_nw(g, rc, nw2, bg2);
}
void SkinTheme::draw_part_as_hline(BITMAP* bmp, int x1, int y1, int x2, int y2, int part)
{
int x;
set_alpha_blender();
for (x = x1;
x <= x2-m_part[part]->w;
x += m_part[part]->w) {
draw_trans_sprite(bmp, m_part[part], x, y1);
}
if (x <= x2) {
int cx1, cy1, cx2, cy2;
get_clip_rect(bmp, &cx1, &cy1, &cx2, &cy2);
if (my_add_clip_rect(bmp, x, y1, x2, y1+m_part[part]->h-1))
draw_trans_sprite(bmp, m_part[part], x, y1);
set_clip_rect(bmp, cx1, cy1, cx2, cy2);
}
}
void SkinTheme::draw_part_as_vline(BITMAP* bmp, int x1, int y1, int x2, int y2, int part)
{
int y;
set_alpha_blender();
for (y = y1;
y <= y2-m_part[part]->h;
y += m_part[part]->h) {
draw_trans_sprite(bmp, m_part[part], x1, y);
}
if (y <= y2) {
int cx1, cy1, cx2, cy2;
get_clip_rect(bmp, &cx1, &cy1, &cx2, &cy2);
if (my_add_clip_rect(bmp, x1, y, x1+m_part[part]->w-1, y2))
draw_trans_sprite(bmp, m_part[part], x1, y);
set_clip_rect(bmp, cx1, cy1, cx2, cy2);
}
}
void SkinTheme::draw_part_as_hline(ui::Graphics* g, const gfx::Rect& rc, int part)
{
int x;
set_alpha_blender();
for (x = rc.x;
x < rc.x2()-m_part[part]->w;
x += m_part[part]->w) {
@ -2351,23 +2094,6 @@ void SkinTheme::draw_part_as_vline(ui::Graphics* g, const gfx::Rect& rc, int par
}
}
void SkinTheme::drawProgressBar(BITMAP* bmp, int x1, int y1, int x2, int y2, float progress)
{
int w = x2 - x1 + 1;
int u = (int)((float)(w-2)*progress);
u = MID(0, u, w-2);
rect(bmp, x1, y1, x2, y2, ui::to_system(getColor(ThemeColor::Text)));
if (u > 0)
rectfill(bmp, x1+1, y1+1, x1+u, y2-1,
ui::to_system(getColor(ThemeColor::Selected)));
if (1+u < w-2)
rectfill(bmp, x1+u+1, y1+1, x2-1, y2-1,
ui::to_system(getColor(ThemeColor::Background)));
}
void SkinTheme::paintProgressBar(ui::Graphics* g, const gfx::Rect& rc0, float progress)
{
g->drawRect(getColor(ThemeColor::Text), rc0);

View File

@ -163,23 +163,13 @@ namespace app {
BITMAP* get_toolicon(const char* tool_id) const;
gfx::Size get_part_size(int part_i) const;
// helper functions to draw bounds/hlines with sheet parts
// Helper functions to draw bounds/hlines with sheet parts
void draw_bounds_array(ui::Graphics* g, const gfx::Rect& rc, int parts[8]);
void draw_bounds_nw(BITMAP* bmp, int x1, int y1, int x2, int y2, int nw, ui::Color bg = ui::ColorNone);
void draw_bounds_nw(ui::Graphics* g, const gfx::Rect& rc, int nw, ui::Color bg = ui::ColorNone);
void draw_bounds_nw(ui::Graphics* g, const gfx::Rect& rc, const SkinPartPtr skinPart, ui::Color bg = ui::ColorNone);
void draw_bounds_nw2(ui::Graphics* g, const gfx::Rect& rc, int x_mid, int nw1, int nw2, ui::Color bg1, ui::Color bg2);
void draw_part_as_hline(BITMAP* bmp, int x1, int y1, int x2, int y2, int part);
void draw_part_as_vline(BITMAP* bmp, int x1, int y1, int x2, int y2, int part);
void draw_part_as_hline(ui::Graphics* g, const gfx::Rect& rc, int part);
void draw_part_as_vline(ui::Graphics* g, const gfx::Rect& rc, int part);
// Wrapper to use the new "Rect" class (x, y, w, h)
void draw_bounds_nw(BITMAP* bmp, const gfx::Rect& rc, int nw, ui::Color bg) {
draw_bounds_nw(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, nw, bg);
}
void drawProgressBar(BITMAP* bmp, int x1, int y1, int x2, int y2, float progress);
void paintProgressBar(ui::Graphics* g, const gfx::Rect& rc, float progress);
Style* getStyle(const std::string& id) {
@ -198,8 +188,6 @@ namespace app {
void onRegenerate() OVERRIDE;
private:
void draw_bounds_template(BITMAP* bmp, int x1, int y1, int x2, int y2,
int nw, int n, int ne, int e, int se, int s, int sw, int w);
void draw_bounds_template(ui::Graphics* g, const gfx::Rect& rc,
int nw, int n, int ne, int e, int se, int s, int sw, int w);
void draw_bounds_template(ui::Graphics* g, const gfx::Rect& rc, const SkinPartPtr& skinPart);
@ -210,13 +198,10 @@ namespace app {
BITMAP* cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h);
ui::Color getWidgetBgColor(ui::Widget* widget);
void drawTextStringDeprecated(const char* t, ui::Color fg_color, ui::Color bg_color,
bool fill_bg, ui::Widget* widget, const gfx::Rect& rect,
int selected_offset);
void drawTextString(ui::Graphics* g, const char *t, ui::Color fg_color, ui::Color bg_color,
bool fill_bg, ui::Widget* widget, const gfx::Rect& rc,
int selected_offset);
void draw_entry_caret(ui::Entry* widget, int x, int y);
void drawEntryCaret(ui::Graphics* g, ui::Entry* widget, int x, int y);
void paintIcon(ui::Widget* widget, ui::Graphics* g, ui::IButtonIcon* iconInterface, int x, int y);

View File

@ -275,10 +275,10 @@ bool ButtonBase::onProcessMessage(Message* msg)
void ButtonBase::onPreferredSize(PreferredSizeEvent& ev)
{
gfx::Rect box;
jwidget_get_texticon_info(this, &box, NULL, NULL,
m_iconInterface ? m_iconInterface->getIconAlign(): 0,
m_iconInterface ? m_iconInterface->getWidth(): 0,
m_iconInterface ? m_iconInterface->getHeight(): 0);
getTextIconInfo(&box, NULL, NULL,
m_iconInterface ? m_iconInterface->getIconAlign(): 0,
m_iconInterface ? m_iconInterface->getWidth(): 0,
m_iconInterface ? m_iconInterface->getHeight(): 0);
ev.setPreferredSize(border_width.l + box.w + border_width.r,
border_width.t + box.h + border_width.b);

View File

@ -27,79 +27,8 @@ namespace ui {
using namespace gfx;
void jrectedge(BITMAP *bmp, int x1, int y1, int x2, int y2,
ui::Color c1, ui::Color c2)
{
hline(bmp, x1, y1, x2-1, to_system(c1));
hline(bmp, x1+1, y2, x2, to_system(c2));
vline(bmp, x1, y1+1, y2, to_system(c1));
vline(bmp, x2, y1, y2-1, to_system(c2));
}
void jrectexclude(BITMAP *bmp, int x1, int y1, int x2, int y2,
int ex1, int ey1, int ex2, int ey2, ui::Color color)
{
if ((ex1 > x2) || (ex2 < x1) ||
(ey1 > y2) || (ey2 < y1))
rectfill(bmp, x1, y1, x2, y2, to_system(color));
else {
int my1, my2;
my1 = MAX(y1, ey1);
my2 = MIN(y2, ey2);
// top
if (y1 < ey1)
rectfill(bmp, x1, y1, x2, ey1-1, to_system(color));
// left
if (x1 < ex1)
rectfill(bmp, x1, my1, ex1-1, my2, to_system(color));
// right
if (x2 > ex2)
rectfill(bmp, ex2+1, my1, x2, my2, to_system(color));
// bottom
if (y2 > ey2)
rectfill(bmp, x1, ey2+1, x2, y2, to_system(color));
}
}
void jdraw_rect(const Rect& rc, ui::Color color)
{
rect(ji_screen, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, to_system(color));
}
void jdraw_rectfill(const Rect& rc, ui::Color color)
{
rectfill(ji_screen, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, to_system(color));
}
void jdraw_rectedge(const Rect& rc, ui::Color c1, ui::Color c2)
{
jrectedge(ji_screen, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, c1, c2);
}
void jdraw_rectexclude(const Rect& rc, const Rect& exclude, ui::Color color)
{
jrectexclude(ji_screen,
rc.x, rc.y,
rc.x+rc.w-1, rc.y+rc.h-1,
exclude.x, exclude.y,
exclude.x+exclude.w-1, exclude.y+exclude.h-1, color);
}
void jdraw_char(FONT* f, int chr, int x, int y, ui::Color fg, ui::Color bg, bool fill_bg)
{
SETUP_ANTIALISING(f, bg, fill_bg);
f->vtable->render_char(f, chr, to_system(fg),
fill_bg ? to_system(bg): -1, ji_screen, x, y);
}
void jdraw_text(BITMAP* bmp, FONT* font, const char *s, int x, int y,
ui::Color fg_color, ui::Color bg_color, bool fill_bg, int underline_height)
void _draw_text(BITMAP* bmp, FONT* font, const char *s, int x, int y,
ui::Color fg_color, ui::Color bg_color, bool fill_bg, int underline_height)
{
// original code from allegro/src/guiproc.c
char tmp[1024];
@ -149,7 +78,7 @@ void jdraw_text(BITMAP* bmp, FONT* font, const char *s, int x, int y,
}
}
void ji_move_region(const Region& region, int dx, int dy)
void _move_region(const Region& region, int dx, int dy)
{
size_t nrects = region.size();

View File

@ -20,22 +20,8 @@ struct BITMAP;
namespace ui {
void jrectedge(struct BITMAP *bmp, int x1, int y1, int x2, int y2,
ui::Color c1, ui::Color c2);
void jrectexclude(struct BITMAP *bmp, int x1, int y1, int x2, int y2,
int ex1, int ey1, int ex2, int ey2, ui::Color color);
void jdraw_rect(const gfx::Rect& rect, ui::Color color);
void jdraw_rectfill(const gfx::Rect& rect, ui::Color color);
void jdraw_rectedge(const gfx::Rect& rect, ui::Color c1, ui::Color c2);
void jdraw_rectexclude(const gfx::Rect& rect, const gfx::Rect& exclude, ui::Color color);
void jdraw_char(FONT* f, int chr, int x, int y, ui::Color fg, ui::Color bg, bool fill_bg);
void jdraw_text(BITMAP* bmp, FONT* f, const char* text, int x, int y, ui::Color fg, ui::Color bg, bool fill_bg, int underline_height = 1);
void jdraw_inverted_sprite(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y);
void ji_move_region(const gfx::Region& region, int dx, int dy);
void _draw_text(BITMAP* bmp, FONT* f, const char* text, int x, int y, ui::Color fg, ui::Color bg, bool fill_bg, int underline_height = 1);
void _move_region(const gfx::Region& region, int dx, int dy);
} // namespace ui

View File

@ -576,7 +576,6 @@ int ji_font_char_len(FONT* f, int chr)
return f->vtable->char_length(f, chr);
}
// see jdraw_text
int ji_font_text_len(struct FONT* f, const char *s)
{
int in_pos = 0;
@ -980,7 +979,6 @@ int ji_font_char_len(FONT* f, int chr)
return f->vtable->char_length(f, chr);
}
// see jdraw_text
int ji_font_text_len(struct FONT* f, const char* s)
{
int in_pos = 0;

View File

@ -18,6 +18,7 @@
#include "ui/theme.h"
#include <allegro.h>
#include <allegro/internal/aintern.h>
namespace ui {
@ -110,6 +111,18 @@ void Graphics::fillRegion(ui::Color color, const gfx::Region& rgn)
fillRect(color, *it);
}
void Graphics::fillAreaBetweenRects(ui::Color color,
const gfx::Rect& outer, const gfx::Rect& inner)
{
if (!outer.intersects(inner))
fillRect(color, inner);
else {
gfx::Region rgn(outer);
rgn.createSubtraction(rgn, gfx::Region(inner));
fillRegion(color, rgn);
}
}
void Graphics::drawBitmap(BITMAP* sprite, int x, int y)
{
draw_sprite(m_bmp, sprite, m_dx+x, m_dy+y);
@ -131,15 +144,20 @@ void Graphics::setFont(FONT* font)
m_currentFont = font;
}
FONT* Graphics::getFont()
void Graphics::drawChar(int chr, Color fg, Color bg, int x, int y)
{
return m_currentFont;
// to_system(is_transparent(bg) ? getColor(ThemeColor::Background): bg));
ji_font_set_aa_mode(getFont(), bg);
getFont()->vtable->render_char(getFont(), chr,
to_system(fg),
to_system(bg),
m_bmp, m_dx+x, m_dy+y);
}
void Graphics::drawString(const std::string& str, Color fg, Color bg, bool fillbg, const gfx::Point& pt)
{
jdraw_text(m_bmp, m_currentFont, str.c_str(), m_dx+pt.x, m_dy+pt.y,
fg, bg, fillbg, 1 * jguiscale());
_draw_text(m_bmp, m_currentFont, str.c_str(), m_dx+pt.x, m_dy+pt.y,
fg, bg, fillbg, 1 * jguiscale());
}
void Graphics::drawString(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align)
@ -147,10 +165,18 @@ void Graphics::drawString(const std::string& str, Color fg, Color bg, const gfx:
drawStringAlgorithm(str, fg, bg, rc, align, true);
}
gfx::Size Graphics::measureChar(int chr)
{
return gfx::Size(
getFont()->vtable->char_length(getFont(), chr),
text_height(getFont()));
}
gfx::Size Graphics::measureString(const std::string& str)
{
return gfx::Size(ji_font_text_len(m_currentFont, str.c_str()),
text_height(m_currentFont));
return gfx::Size(
ji_font_text_len(getFont(), str.c_str()),
text_height(getFont()));
}
gfx::Size Graphics::fitString(const std::string& str, int maxWidth, int align)
@ -233,9 +259,9 @@ gfx::Size Graphics::drawStringAlgorithm(const std::string& str, Color fg, Color
textout_ex(m_bmp, m_currentFont, line.c_str(), m_dx+xout, m_dy+pt.y, to_system(fg), to_system(bg));
if (!is_transparent(bg))
jrectexclude(m_bmp,
m_dx+rc.x, m_dy+pt.y, m_dx+rc.x+rc.w-1, m_dy+pt.y+lineSize.h-1,
m_dx+xout, m_dy+pt.y, m_dx+xout+lineSize.w-1, m_dy+pt.y+lineSize.h-1, bg);
fillAreaBetweenRects(bg,
gfx::Rect(rc.x, pt.y, rc.w, lineSize.h),
gfx::Rect(xout, pt.y, lineSize.w, lineSize.h));
}
pt.y += lineSize.h;

View File

@ -43,6 +43,8 @@ namespace ui {
void drawRect(ui::Color color, const gfx::Rect& rc);
void fillRect(ui::Color color, const gfx::Rect& rc);
void fillRegion(ui::Color color, const gfx::Region& rgn);
void fillAreaBetweenRects(ui::Color color,
const gfx::Rect& outer, const gfx::Rect& inner);
void drawBitmap(BITMAP* sprite, int x, int y);
void drawAlphaBitmap(BITMAP* sprite, int x, int y);
@ -54,11 +56,15 @@ namespace ui {
// ======================================================================
void setFont(FONT* font);
FONT* getFont();
FONT* getFont() {
return m_currentFont;
}
void drawChar(int chr, Color fg, Color bg, int x, int y);
void drawString(const std::string& str, Color fg, Color bg, bool fillbg, const gfx::Point& pt);
void drawString(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align);
gfx::Size measureChar(int chr);
gfx::Size measureString(const std::string& str);
gfx::Size fitString(const std::string& str, int maxWidth, int align);

View File

@ -31,8 +31,8 @@ ImageView::ImageView(BITMAP* bmp, int align)
void ImageView::onPreferredSize(PreferredSizeEvent& ev)
{
gfx::Rect box;
jwidget_get_texticon_info(this, &box, NULL, NULL,
getAlign(), m_bmp->w, m_bmp->h);
getTextIconInfo(&box, NULL, NULL,
getAlign(), m_bmp->w, m_bmp->h);
ev.setPreferredSize(gfx::Size(border_width.l + box.w + border_width.r,
border_width.t + box.h + border_width.b));
@ -43,14 +43,9 @@ void ImageView::onPaint(PaintEvent& ev)
Graphics* g = ev.getGraphics();
gfx::Rect bounds = getClientBounds();
gfx::Rect icon;
jwidget_get_texticon_info(this, NULL, NULL, &icon,
getAlign(), m_bmp->w, m_bmp->h);
getTextIconInfo(NULL, NULL, &icon, getAlign(), m_bmp->w, m_bmp->h);
g->fillRect(getBgColor(), bounds);
icon.x -= getBounds().x;
icon.y -= getBounds().y;
g->blit(m_bmp, 0, 0, icon.x, icon.y, icon.w, icon.h);
}

View File

@ -16,6 +16,7 @@ struct BITMAP;
namespace ui {
class Graphics;
class Widget;
class Window;
@ -29,7 +30,7 @@ namespace ui {
// theme.cpp
void drawTextBox(BITMAP* bmp, Widget* textbox,
void drawTextBox(Graphics* g, Widget* textbox,
int* w, int* h, ui::Color bg, ui::Color fg);
// fontbmp.c

View File

@ -23,6 +23,7 @@ using namespace gfx;
ListItem::ListItem(const base::string& text)
: Widget(kListItemWidget)
{
setDoubleBuffered(true);
setAlign(JI_LEFT | JI_MIDDLE);
setText(text);
initTheme();

View File

@ -23,7 +23,9 @@ Separator::Separator(const base::string& text, int align)
: Widget(kSeparatorWidget)
{
setAlign(align);
setText(text);
if (!text.empty())
setText(text);
initTheme();
}

View File

@ -26,9 +26,6 @@ namespace ui {
static Theme* current_theme = NULL;
static void draw_text(BITMAP *bmp, FONT *f, const char* text, int x, int y,
Color fg_color, Color bg_color, bool fill_bg);
Theme::Theme()
{
this->name = "Theme";
@ -95,8 +92,8 @@ BITMAP* ji_apply_guiscale(BITMAP* original)
return original;
}
void drawTextBox(BITMAP* bmp, Widget* widget,
int* w, int* h, Color bg, Color fg)
void drawTextBox(Graphics* g, Widget* widget,
int* w, int* h, Color bg, Color fg)
{
View* view = View::getView(widget);
char* text = const_cast<char*>(widget->getText().c_str());
@ -111,7 +108,9 @@ void drawTextBox(BITMAP* bmp, Widget* widget,
int width;
if (view) {
gfx::Rect vp = view->getViewportBounds();
gfx::Rect vp = view->getViewportBounds()
.offset(-view->getViewport()->getBounds().getOrigin());
x1 = vp.x;
y1 = vp.y;
viewport_w = vp.w;
@ -119,22 +118,22 @@ void drawTextBox(BITMAP* bmp, Widget* widget,
scroll = view->getViewScroll();
}
else {
x1 = widget->getBounds().x + widget->border_width.l;
y1 = widget->getBounds().y + widget->border_width.t;
viewport_w = widget->getBounds().w - widget->border_width.l - widget->border_width.r;
viewport_h = widget->getBounds().h - widget->border_width.t - widget->border_width.b;
x1 = widget->getClientBounds().x + widget->border_width.l;
y1 = widget->getClientBounds().y + widget->border_width.t;
viewport_w = widget->getClientBounds().w - widget->border_width.l - widget->border_width.r;
viewport_h = widget->getClientBounds().h - widget->border_width.t - widget->border_width.b;
scroll.x = scroll.y = 0;
}
x2 = x1+viewport_w-1;
y2 = y1+viewport_h-1;
x2 = x1 + viewport_w;
y2 = y1 + viewport_h;
chr = 0;
/* without word-wrap */
// Without word-wrap
if (!(widget->getAlign() & JI_WORDWRAP)) {
width = widget->getBounds().w;
width = widget->getClientBounds().w;
}
/* with word-wrap */
// With word-wrap
else {
if (w) {
width = *w;
@ -158,7 +157,7 @@ void drawTextBox(BITMAP* bmp, Widget* widget,
}
}
/* draw line-by-line */
// Draw line-by-line
y = y1 - scroll.y;
for (beg=end=text; end; ) {
x = x1 - scroll.x;
@ -210,25 +209,23 @@ void drawTextBox(BITMAP* bmp, Widget* widget,
len = text_length(font, beg);
/* render the text in the "bmp" */
if (bmp) {
// Render the text
if (g) {
int xout;
if (widget->getAlign() & JI_CENTER)
xout = x + width/2 - len/2;
else if (widget->getAlign() & JI_RIGHT)
xout = x + width - len;
else /* left */
else // Left align
xout = x;
draw_text(bmp, font, beg, xout, y, fg, bg, true);
jrectexclude(bmp,
x1, y, x2, y+textheight-1,
xout, y, xout+len-1, y+textheight-1, bg);
g->drawString(beg, fg, bg, true, gfx::Point(xout, y));
g->fillAreaBetweenRects(bg,
gfx::Rect(x1, y, x2 - x1, textheight),
gfx::Rect(xout, y, len, textheight));
}
/* width */
if (w)
*w = MAX(*w, len);
@ -240,26 +237,15 @@ void drawTextBox(BITMAP* bmp, Widget* widget,
}
}
/* height */
if (h)
*h = (y-y1+scroll.y);
*h = (y - y1 + scroll.y);
if (w) *w += widget->border_width.l + widget->border_width.r;
if (h) *h += widget->border_width.t + widget->border_width.b;
// Fill bottom area
if (bmp) {
if (y <= y2)
rectfill(bmp, x1, y, x2, y2, to_system(bg));
}
}
static void draw_text(BITMAP *bmp, FONT *f, const char *text, int x, int y,
Color fg_color, Color bg_color, bool fill_bg)
{
// TODO Optional anti-aliased textout
ji_font_set_aa_mode(f, to_system(bg_color));
textout_ex(bmp, f, text, x, y, to_system(fg_color), (fill_bg ? to_system(bg_color): -1));
if (g && y < y2)
g->fillRect(bg, gfx::Rect(x1, y, x2 - x1, y2 - y));
}
} // namespace ui

View File

@ -742,11 +742,11 @@ int Widget::getTextHeight() const
return text_height(getFont());
}
void jwidget_get_texticon_info(Widget* widget,
gfx::Rect* box,
gfx::Rect* text,
gfx::Rect* icon,
int icon_align, int icon_w, int icon_h)
void Widget::getTextIconInfo(
gfx::Rect* box,
gfx::Rect* text,
gfx::Rect* icon,
int icon_align, int icon_w, int icon_h)
{
#define SETRECT(r) \
if (r) { \
@ -756,17 +756,16 @@ void jwidget_get_texticon_info(Widget* widget,
r->h = r##_h; \
}
gfx::Rect bounds = getClientBounds();
int box_x, box_y, box_w, box_h, icon_x, icon_y;
int text_x, text_y, text_w, text_h;
ASSERT_VALID_WIDGET(widget);
text_x = text_y = 0;
// Size of the text
if (widget->hasText()) {
text_w = widget->getTextWidth();
text_h = widget->getTextHeight();
if (hasText()) {
text_w = getTextWidth();
text_h = getTextHeight();
}
else {
text_w = text_h = 0;
@ -781,32 +780,32 @@ void jwidget_get_texticon_info(Widget* widget,
/* with the icon in the top or bottom */
else {
box_w = MAX(icon_w, text_w);
box_h = icon_h + (widget->hasText() ? widget->child_spacing: 0) + text_h;
box_h = icon_h + (hasText() ? child_spacing: 0) + text_h;
}
}
/* with the icon in left or right that doesn't care by now */
else {
box_w = icon_w + (widget->hasText() ? widget->child_spacing: 0) + text_w;
box_w = icon_w + (hasText() ? child_spacing: 0) + text_w;
box_h = MAX(icon_h, text_h);
}
/* box position */
if (widget->getAlign() & JI_RIGHT)
box_x = widget->getBounds().x2() - box_w - widget->border_width.r;
else if (widget->getAlign() & JI_CENTER)
box_x = (widget->getBounds().x+widget->getBounds().x2())/2 - box_w/2;
if (getAlign() & JI_RIGHT)
box_x = bounds.x2() - box_w - border_width.r;
else if (getAlign() & JI_CENTER)
box_x = (bounds.x+bounds.x2())/2 - box_w/2;
else
box_x = widget->getBounds().x + widget->border_width.l;
box_x = bounds.x + border_width.l;
if (widget->getAlign() & JI_BOTTOM)
box_y = widget->getBounds().y2() - box_h - widget->border_width.b;
else if (widget->getAlign() & JI_MIDDLE)
box_y = (widget->getBounds().y+widget->getBounds().y2())/2 - box_h/2;
if (getAlign() & JI_BOTTOM)
box_y = bounds.y2() - box_h - border_width.b;
else if (getAlign() & JI_MIDDLE)
box_y = (bounds.y+bounds.y2())/2 - box_h/2;
else
box_y = widget->getBounds().y + widget->border_width.t;
box_y = bounds.y + border_width.t;
// With text
if (widget->hasText()) {
if (hasText()) {
// Text/icon X position
if (icon_align & JI_RIGHT) {
text_x = box_x;
@ -962,7 +961,7 @@ void Widget::scrollRegion(const Region& region, int dx, int dy)
// Move screen pixels
jmouse_hide();
ji_move_region(reg2, dx, dy);
ui::_move_region(reg2, dx, dy);
jmouse_show();
reg2.offset(dx, dy);
@ -1004,7 +1003,6 @@ GraphicsPtr Widget::getGraphics(const gfx::Rect& clip)
graphics.reset(new Graphics(bmp, -clip.x, -clip.y),
DeleteGraphicsAndBitmap(clip, bmp));
}
// Paint directly on ji_screen (in this case "ji_screen" can be
// the screen or a memory bitmap).

View File

@ -45,12 +45,6 @@ namespace ui {
// Position and geometry
void jwidget_get_texticon_info(Widget* widget,
gfx::Rect* box,
gfx::Rect* text,
gfx::Rect* icon,
int icon_align, int icon_w, int icon_h);
void jwidget_set_min_size(Widget* widget, int w, int h);
void jwidget_set_max_size(Widget* widget, int w, int h);
@ -292,6 +286,12 @@ namespace ui {
return gfx::Rect(rc).offset(-m_bounds.x, -m_bounds.y);
}
void getTextIconInfo(
gfx::Rect* box,
gfx::Rect* text = NULL,
gfx::Rect* icon = NULL,
int icon_align = 0, int icon_w = 0, int icon_h = 0);
// ===============================================================
// REFRESH ISSUES
// ===============================================================

View File

@ -595,9 +595,9 @@ void Window::moveWindow(const gfx::Rect& rect, bool use_blit)
set_clip_rect(ji_screen,
man_pos.x, man_pos.y, man_pos.x2()-1, man_pos.y2()-1);
ji_move_region(moveable_region,
getBounds().x - old_pos.x,
getBounds().y - old_pos.y);
ui::_move_region(moveable_region,
getBounds().x - old_pos.x,
getBounds().y - old_pos.y);
set_clip_rect(ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1);
jmouse_show();
}