Add she::Font class (wrapper of Allegro FONT)

This is an huge refactor to avoid handling Allegro FONT directly. Some
changes:
* Add she::System::defaultDisplay/Font, createRgbaSurface, loadSurface,
  and loadRgbaSurface.
* Rename she::CreateSystem/Instance to she::create_system/instance.
* Remove ui/font.cpp and move ui/fontbmp.cpp to she library.
* ui::IButtonIcon uses she::Surface instead of BITMAP.
* Rename she::LockedSurface::drawAlphaSurface -> drawRgbaSurface
* Rename ui::SetDisplay -> set_display
* Rename _ji_font_text_len -> ui::Graphics::measureUIStringLength
This commit is contained in:
David Capello 2014-06-22 18:53:14 -03:00
parent b7dca01532
commit dbad153698
69 changed files with 1537 additions and 2364 deletions

View File

@ -80,7 +80,6 @@ Aseprite uses libraries or parts of the original source code
of the following projects created by third-parties:
* [Allegro 4](http://alleg.sourceforge.net/) - [allegro4 license](https://github.com/dacap/aseprite/tree/master/docs/licenses/allegro4-LICENSE.txt)
* [AllegroFont](http://chernsha.sitesled.com/) - [FTL license](https://github.com/dacap/aseprite/tree/master/docs/licenses/FTL.txt)
* [curl](http://curl.haxx.se/) - [curl license](https://github.com/dacap/aseprite/tree/master/docs/licenses/curl-LICENSE.txt)
* [FreeType](http://www.freetype.org/) - [FTL license](https://github.com/dacap/aseprite/tree/master/docs/licenses/FTL.txt)
* [giflib](http://sourceforge.net/projects/giflib/) - [giflib license](https://github.com/dacap/aseprite/tree/master/docs/licenses/giflib-LICENSE.txt)

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
@ -169,13 +169,13 @@ int init_module_gui()
load_gui_config(w, h, maximized);
try {
main_display = she::Instance()->createDisplay(w, h, screen_scaling);
main_display = she::instance()->createDisplay(w, h, screen_scaling);
}
catch (const she::DisplayCreationException&) {
for (c=min_possible_dsk_res; try_resolutions[c].width; ++c) {
try {
main_display =
she::Instance()->createDisplay(try_resolutions[c].width,
she::instance()->createDisplay(try_resolutions[c].width,
try_resolutions[c].height,
try_resolutions[c].scale);
@ -193,7 +193,7 @@ int init_module_gui()
return -1;
}
main_clipboard = she::Instance()->createClipboard();
main_clipboard = she::instance()->createClipboard();
// Create the default-manager
manager = new CustomizedGuiManager();
@ -334,7 +334,7 @@ void gui_setup_screen(bool reload_font)
bool reinit = false;
main_display->setScale(screen_scaling);
ui::SetDisplay(main_display);
ui::set_display(main_display);
// Update guiscale factor
int old_guiscale = jguiscale();

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,25 +20,25 @@
#include "config.h"
#endif
#include <allegro.h>
#include <cstring>
#include "app/ui/color_bar.h"
#include "app/color.h"
#include "app/commands/commands.h"
#include "app/commands/params.h"
#include "app/ini_file.h"
#include "app/modules/gui.h"
#include "app/ui/color_bar.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h"
#include "app/ui_context.h"
#include "base/bind.h"
#include "raster/image.h"
#include "raster/palette.h"
#include "she/surface.h"
#include "ui/graphics.h"
#include "ui/menu.h"
#include "ui/paint_event.h"
#include "ui/menu.h"
#include <cstring>
namespace app {
@ -51,10 +51,10 @@ using namespace ui;
ColorBar::ScrollableView::ScrollableView()
{
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
int l = theme->get_part(PART_EDITOR_SELECTED_W)->w;
int t = theme->get_part(PART_EDITOR_SELECTED_N)->h;
int r = theme->get_part(PART_EDITOR_SELECTED_E)->w;
int b = theme->get_part(PART_EDITOR_SELECTED_S)->h;
int l = theme->get_part(PART_EDITOR_SELECTED_W)->width();
int t = theme->get_part(PART_EDITOR_SELECTED_N)->height();
int r = theme->get_part(PART_EDITOR_SELECTED_E)->width();
int b = theme->get_part(PART_EDITOR_SELECTED_S)->height();
setBorder(gfx::Border(l, t, r, b));
}

View File

@ -20,8 +20,6 @@
#include "config.h"
#endif
#include <allegro.h>
#include "app/app.h"
#include "app/color.h"
#include "app/color_picker.h"
@ -213,7 +211,7 @@ void ColorButton::onPaint(PaintEvent& ev)
gfx::Rect text;
getTextIconInfo(NULL, &text);
g->drawString(getText(), textcolor, ColorNone, false, text.getOrigin());
g->drawUIString(getText(), textcolor, ColorNone, false, text.getOrigin());
}
void ColorButton::onClick(Event& ev)

View File

@ -20,7 +20,6 @@
#include "config.h"
#endif
#include <allegro.h>
#include <vector>
#include "app/app.h"

View File

@ -20,8 +20,6 @@
#include "config.h"
#endif
#include <allegro.h>
#include "app/color_utils.h"
#include "app/ui/color_sliders.h"
#include "base/bind.h"

View File

@ -43,6 +43,9 @@
#include "raster/conversion_alleg.h"
#include "raster/image.h"
#include "raster/palette.h"
#include "she/scoped_surface_lock.h"
#include "she/surface.h"
#include "she/system.h"
#include "ui/button.h"
#include "ui/combobox.h"
#include "ui/int_entry.h"
@ -53,8 +56,6 @@
#include "ui/theme.h"
#include "ui/tooltips.h"
#include <allegro.h>
namespace app {
using namespace app::skin;
@ -63,8 +64,7 @@ using namespace ui;
using namespace tools;
class ContextBar::BrushTypeField : public Button
, public IButtonIcon
{
, public IButtonIcon {
public:
BrushTypeField()
: Button("")
@ -73,14 +73,16 @@ public:
setup_mini_look(this);
setIconInterface(this);
m_bitmap = create_bitmap_ex(32, 8, 8);
clear(m_bitmap);
m_bitmap = she::instance()->createRgbaSurface(8, 8);
she::ScopedSurfaceLock lock(m_bitmap);
lock->clear();
}
~BrushTypeField() {
closePopup();
setIconInterface(NULL);
destroy_bitmap(m_bitmap);
m_bitmap->dispose();
}
void setBrushSettings(IBrushSettings* brushSettings) {
@ -97,10 +99,16 @@ public:
Image* image = brush->get_image();
if (m_bitmap)
destroy_bitmap(m_bitmap);
m_bitmap = create_bitmap_ex(32, image->getWidth(), image->getHeight());
clear(m_bitmap);
convert_image_to_allegro(image, m_bitmap, 0, 0, palette);
m_bitmap->dispose();
m_bitmap = she::instance()->createRgbaSurface(image->getWidth(), image->getHeight());
{
she::ScopedSurfaceLock lock(m_bitmap);
lock->clear();
convert_image_to_allegro(image,
reinterpret_cast<BITMAP*>(m_bitmap->nativeHandle()),
0, 0, palette);
}
invalidate();
}
@ -113,22 +121,22 @@ public:
}
int getWidth() OVERRIDE {
return m_bitmap->w;
return m_bitmap->width();
}
int getHeight() OVERRIDE {
return m_bitmap->h;
return m_bitmap->height();
}
BITMAP* getNormalIcon() OVERRIDE {
she::Surface* getNormalIcon() OVERRIDE {
return m_bitmap;
}
BITMAP* getSelectedIcon() OVERRIDE {
she::Surface* getSelectedIcon() OVERRIDE {
return m_bitmap;
}
BITMAP* getDisabledIcon() OVERRIDE {
she::Surface* getDisabledIcon() OVERRIDE {
return m_bitmap;
}
@ -196,7 +204,7 @@ private:
setBrushSettings(brushSettings);
}
BITMAP* m_bitmap;
she::Surface* m_bitmap;
BrushType m_brushType;
PopupWindow* m_popupWindow;
ButtonSet* m_brushTypeButton;
@ -487,22 +495,22 @@ public:
}
int getWidth() OVERRIDE {
return m_bitmap->w;
return m_bitmap->width();
}
int getHeight() OVERRIDE {
return m_bitmap->h;
return m_bitmap->height();
}
BITMAP* getNormalIcon() OVERRIDE {
she::Surface* getNormalIcon() OVERRIDE {
return m_bitmap;
}
BITMAP* getSelectedIcon() OVERRIDE {
she::Surface* getSelectedIcon() OVERRIDE {
return m_bitmap;
}
BITMAP* getDisabledIcon() OVERRIDE {
she::Surface* getDisabledIcon() OVERRIDE {
return m_bitmap;
}
@ -573,7 +581,7 @@ private:
->setFreehandAlgorithm(m_freehandAlgo);
}
BITMAP* m_bitmap;
she::Surface* m_bitmap;
FreehandAlgorithm m_freehandAlgo;
PopupWindow* m_popupWindow;
ButtonSet* m_freehandAlgoButton;

View File

@ -28,11 +28,10 @@
#include "app/ui/editor/editor.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui_context.h"
#include "she/surface.h"
#include "ui/paint_event.h"
#include "ui/resize_event.h"
#include <allegro.h>
namespace app {
using namespace app::skin;
@ -43,10 +42,10 @@ EditorView::EditorView(EditorView::Type type)
, m_type(type)
{
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
int l = theme->get_part(PART_EDITOR_SELECTED_W)->w;
int t = theme->get_part(PART_EDITOR_SELECTED_N)->h;
int r = theme->get_part(PART_EDITOR_SELECTED_E)->w;
int b = theme->get_part(PART_EDITOR_SELECTED_S)->h;
int l = theme->get_part(PART_EDITOR_SELECTED_W)->width();
int t = theme->get_part(PART_EDITOR_SELECTED_N)->height();
int r = theme->get_part(PART_EDITOR_SELECTED_E)->width();
int b = theme->get_part(PART_EDITOR_SELECTED_S)->height();
setBorder(gfx::Border(l, t, r, b));
setBgColor(ui::rgba(0, 0, 0));

View File

@ -51,8 +51,6 @@
#include "ui/system.h"
#include "ui/view.h"
#include <allegro.h>
namespace app {
using namespace ui;

View File

@ -47,8 +47,6 @@
#include "raster/sprite.h"
#include "ui/ui.h"
#include <allegro.h>
namespace app {
using namespace ui;

View File

@ -24,6 +24,7 @@
#include "app/ui/editor/editor.h"
#include "app/ui/skin/skin_theme.h"
#include "she/surface.h"
#include <allegro.h>
@ -73,7 +74,7 @@ TransformHandles::~TransformHandles()
HandleType TransformHandles::getHandleAtPoint(Editor* editor, const gfx::Point& pt, const gfx::Transformation& transform)
{
SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get());
BITMAP* gfx = theme->get_part(PART_TRANSFORMATION_HANDLE);
she::Surface* gfx = theme->get_part(PART_TRANSFORMATION_HANDLE);
fixed angle = ftofix(128.0 * transform.angle() / PI);
gfx::Transformation::Corners corners;
@ -84,7 +85,7 @@ HandleType TransformHandles::getHandleAtPoint(Editor* editor, const gfx::Point&
for (size_t c=0; c<corners.size(); ++c)
editor->editorToScreen(corners[c].x, corners[c].y, &x[c], &y[c]);
int handle_rs[2] = { gfx->w*2, gfx->w*3 };
int handle_rs[2] = { gfx->width()*2, gfx->width()*3 };
for (int i=0; i<2; ++i) {
int handle_r = handle_rs[i];
for (size_t c=0; c<HANDLES; ++c) {
@ -107,7 +108,7 @@ HandleType TransformHandles::getHandleAtPoint(Editor* editor, const gfx::Point&
void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& transform)
{
BITMAP* bmp = ji_screen;
ScreenGraphics g;
fixed angle = ftofix(128.0 * transform.angle() / PI);
gfx::Transformation::Corners corners;
@ -118,6 +119,7 @@ void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& tr
for (size_t c=0; c<corners.size(); ++c)
editor->editorToScreen(corners[c].x, corners[c].y, &x[c], &y[c]);
// TODO DO NOT COMMIT
#if 0 // Uncomment this if you want to see the bounds in red (only for debugging purposes)
// -----------------------------------------------
{
@ -128,19 +130,19 @@ void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& tr
y2 = y1 + transform.bounds().h;
editor->editorToScreen(x1, y1, &x1, &y1);
editor->editorToScreen(x2, y2, &x2, &y2);
rect(bmp, x1, y1, x2, y2, makecol(255, 0, 0));
g.drawRect(ui::rgba(255, 0, 0), gfx::Rect(x1, y1, x2-x1+1, y2-y1+1));
x1 = transform.pivot().x;
y1 = transform.pivot().y;
editor->editorToScreen(x1, y1, &x1, &y1);
circle(bmp, x1, y1, 4, makecol(255, 0, 0));
g.drawRect(ui::rgba(255, 0, 0), gfx::Rect(x1-2, y1-2, 5, 5));
}
// -----------------------------------------------
#endif
// Draw corner handle
for (size_t c=0; c<HANDLES; ++c) {
drawHandle(bmp,
drawHandle(&g,
(x[handles_info[c].i1]+x[handles_info[c].i2])/2,
(y[handles_info[c].i1]+y[handles_info[c].i2])/2,
angle + handles_info[c].angle);
@ -150,13 +152,9 @@ void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& tr
if (angle != 0) {
gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners);
SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get());
BITMAP* gfx = theme->get_part(PART_PIVOT_HANDLE);
she::Surface* part = theme->get_part(PART_PIVOT_HANDLE);
#if ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION >= 4
draw_sprite_ex(bmp, gfx, pivotBounds.x, pivotBounds.y, DRAW_SPRITE_TRANS, DRAW_SPRITE_NO_FLIP);
#else
draw_trans_sprite(bmp, gfx, pivotBounds.x, pivotBounds.y);
#endif
g.drawRgbaSurface(part, pivotBounds.x, pivotBounds.y);
}
}
@ -175,23 +173,23 @@ void TransformHandles::invalidateHandles(Editor* editor, const gfx::Transformati
// Invalidate each corner handle.
for (size_t c=0; c<HANDLES; ++c) {
BITMAP* gfx = theme->get_part(PART_TRANSFORMATION_HANDLE);
she::Surface* part = theme->get_part(PART_TRANSFORMATION_HANDLE);
int u = (x[handles_info[c].i1]+x[handles_info[c].i2])/2;
int v = (y[handles_info[c].i1]+y[handles_info[c].i2])/2;
adjustHandle(u, v, gfx->w, gfx->h, angle + handles_info[c].angle);
adjustHandle(u, v, part->width(), part->height(), angle + handles_info[c].angle);
editor->invalidateRect(gfx::Rect(u, v, gfx->w, gfx->h));
editor->invalidateRect(gfx::Rect(u, v, part->width(), part->height()));
}
// Invalidate area where the pivot is.
if (angle != 0) {
gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners);
BITMAP* gfx = theme->get_part(PART_PIVOT_HANDLE);
she::Surface* part = theme->get_part(PART_PIVOT_HANDLE);
editor->invalidateRect(gfx::Rect(pivotBounds.x,
pivotBounds.y,
gfx->w, gfx->h));
editor->invalidateRect(
gfx::Rect(pivotBounds.x, pivotBounds.y,
part->width(), part->height()));
}
}
@ -200,7 +198,7 @@ gfx::Rect TransformHandles::getPivotHandleBounds(Editor* editor,
const gfx::Transformation::Corners& corners)
{
SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get());
BITMAP* gfx = theme->get_part(PART_PIVOT_HANDLE);
she::Surface* part = theme->get_part(PART_PIVOT_HANDLE);
int pvx, pvy;
editor->editorToScreen(transform.pivot().x, transform.pivot().y, &pvx, &pvy);
@ -208,13 +206,16 @@ gfx::Rect TransformHandles::getPivotHandleBounds(Editor* editor,
pvx += (1 << editor->getZoom()) / 2;
pvy += (1 << editor->getZoom()) / 2;
return gfx::Rect(pvx-gfx->w/2, pvy-gfx->h/2, gfx->w, gfx->h);
return gfx::Rect(
pvx-part->width()/2,
pvy-part->height()/2,
part->width(),
part->height());
}
bool TransformHandles::inHandle(const gfx::Point& pt, int x, int y, int gfx_w, int gfx_h, fixed angle)
{
SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get());
BITMAP* gfx = theme->get_part(PART_TRANSFORMATION_HANDLE);
adjustHandle(x, y, gfx_w, gfx_h, angle);
@ -222,18 +223,14 @@ bool TransformHandles::inHandle(const gfx::Point& pt, int x, int y, int gfx_w, i
pt.y >= y && pt.y < y+gfx_h);
}
void TransformHandles::drawHandle(BITMAP* bmp, int x, int y, fixed angle)
void TransformHandles::drawHandle(Graphics* g, int x, int y, fixed angle)
{
SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get());
BITMAP* gfx = theme->get_part(PART_TRANSFORMATION_HANDLE);
she::Surface* part = theme->get_part(PART_TRANSFORMATION_HANDLE);
adjustHandle(x, y, gfx->w, gfx->h, angle);
adjustHandle(x, y, part->width(), part->height(), angle);
#if ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION >= 4
draw_sprite_ex(bmp, gfx, x, y, DRAW_SPRITE_TRANS, DRAW_SPRITE_NO_FLIP);
#else
draw_trans_sprite(bmp, gfx, x, y);
#endif
g->drawRgbaSurface(part, x, y);
}
void TransformHandles::adjustHandle(int& x, int& y, int handle_w, int handle_h, fixed angle)

View File

@ -26,7 +26,9 @@
#include <allegro/fixed.h>
struct BITMAP;
namespace ui {
class Graphics;
}
namespace app {
class Editor;
@ -51,7 +53,7 @@ namespace app {
const gfx::Transformation::Corners& corners);
bool inHandle(const gfx::Point& pt, int x, int y, int gfx_w, int gfx_h, fixed angle);
void drawHandle(BITMAP* bmp, int x, int y, fixed angle);
void drawHandle(ui::Graphics* g, int x, int y, fixed angle);
void adjustHandle(int& x, int& y, int handle_w, int handle_h, fixed angle);
};

View File

@ -25,6 +25,7 @@
#include "app/modules/gfx.h"
#include "app/thumbnail_generator.h"
#include "app/ui/skin/skin_theme.h"
#include "she/font.h"
#include "ui/ui.h"
#include <algorithm>
@ -135,9 +136,9 @@ bool FileList::onProcessMessage(Message* msg)
gfx::Size itemSize = getFileItemSize(fi);
if (((mouseMsg->position().y >= y) &&
(mouseMsg->position().y < y+2+th+2)) ||
(mouseMsg->position().y < y+th+4*jguiscale())) ||
(it == m_list.begin() && mouseMsg->position().y < y) ||
(it == m_list.end()-1 && mouseMsg->position().y >= y+2+th+2)) {
(it == m_list.end()-1 && mouseMsg->position().y >= y+th+4*jguiscale())) {
m_selected = fi;
makeSelectedFileitemVisible();
break;
@ -197,7 +198,7 @@ bool FileList::onProcessMessage(Message* msg)
gfx::Rect vp = view->getViewportBounds();
if (select < 0)
select = 0;
select += sgn * vp.h / (2+getTextHeight()+2);
select += sgn * vp.h / (getTextHeight()+4*jguiscale());
break;
}
case kKeyLeft:
@ -273,7 +274,7 @@ bool FileList::onProcessMessage(Message* msg)
View* view = View::getView(this);
if (view) {
gfx::Point scroll = view->getViewScroll();
scroll += static_cast<MouseMessage*>(msg)->wheelDelta() * 3*(2+getTextHeight()+2);
scroll += static_cast<MouseMessage*>(msg)->wheelDelta() * 3*(getTextHeight()+4*jguiscale());
view->setViewScroll(scroll);
}
break;
@ -335,25 +336,22 @@ void FileList::onPaint(ui::PaintEvent& ev)
theme->getColor(ThemeColor::FileListOddRowText);
}
x = bounds.x+2;
x = bounds.x+2*jguiscale();
// Item background
g->fillRect(bgcolor, gfx::Rect(bounds.x, y, bounds.w, itemSize.h));
if (fi->isFolder()) {
int icon_w = ji_font_text_len(getFont(), "[+]");
int icon_h = ji_font_get_size(getFont());
int icon_w = getFont()->textLength("[+]");
g->drawString("[+]", fgcolor, bgcolor, true,
gfx::Point(x, y+2));
x += icon_w+2;
g->drawUIString("[+]", fgcolor, bgcolor, true, gfx::Point(x, y+2*jguiscale()));
x += icon_w+2*jguiscale();
}
// item name
g->drawString(
fi->getDisplayName().c_str(),
fgcolor, bgcolor, true, gfx::Point(x, y+2));
fgcolor, bgcolor, true, gfx::Point(x, y+2*jguiscale()));
// draw progress bars
double progress;
@ -451,14 +449,12 @@ gfx::Size FileList::getFileItemSize(IFileItem* fi) const
{
int len = 0;
if (fi->isFolder()) {
len += ji_font_text_len(getFont(), "[+]")+2;
}
if (fi->isFolder())
len += getFont()->textLength("[+]") + 2*jguiscale();
len += ji_font_text_len(getFont(), fi->getDisplayName().c_str());
len += getFont()->textLength(fi->getDisplayName().c_str());
return gfx::Size(2+len+2,
2+getTextHeight()+2);
return gfx::Size(len+4*jguiscale(), getTextHeight()+4*jguiscale());
}
void FileList::makeSelectedFileitemVisible()
@ -479,8 +475,8 @@ void FileList::makeSelectedFileitemVisible()
if (fi == m_selected) {
if (y < vp.y)
scroll.y = y - getBounds().y;
else if (y > vp.y + vp.h - (2+th+2))
scroll.y = y - getBounds().y - vp.h + (2+th+2);
else if (y > vp.y + vp.h - (th+4*jguiscale()))
scroll.y = y - getBounds().y - vp.h + (th+4*jguiscale());
view->setViewScroll(scroll);
break;

View File

@ -20,10 +20,6 @@
#include "config.h"
#endif
#include <allegro.h>
#include <stdlib.h>
#include <string.h>
#include "app/app.h"
#include "app/color.h"
#include "app/modules/gui.h"
@ -44,6 +40,9 @@
#include "ui/view.h"
#include "ui/widget.h"
#include <cstdlib>
#include <cstring>
namespace app {
using namespace ui;

View File

@ -83,7 +83,7 @@ void PalettesListBox::onPaintResource(Graphics* g, const gfx::Rect& bounds, Reso
// g->drawString(getText(), fgcolor, ui::ColorNone, false,
// gfx::Point(
// bounds.x + jguiscale()*2,
// bounds.y + bounds.h/2 - g->measureString(getText()).h/2));
// bounds.y + bounds.h/2 - g->measureUIString(getText()).h/2));
}
void PalettesListBox::onResourcePreferredSize(Resource* resource, gfx::Size& size)

View File

@ -30,7 +30,6 @@
#include "gfx/size.h"
#include "ui/ui.h"
#include <allegro.h>
#include <vector>
namespace app {

View File

@ -93,7 +93,7 @@ protected:
g->drawString(getText(), fgcolor, ui::ColorNone, false,
gfx::Point(
bounds.x + jguiscale()*2,
bounds.y + bounds.h/2 - g->measureString(getText()).h/2));
bounds.y + bounds.h/2 - g->measureUIString(getText()).h/2));
}
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE {

View File

@ -23,8 +23,7 @@
#include "app/ui/skin/button_icon_impl.h"
#include "app/ui/skin/skin_theme.h"
#include <allegro.h>
#include "she/surface.h"
namespace app {
@ -51,25 +50,25 @@ void ButtonIconImpl::destroy()
int ButtonIconImpl::getWidth()
{
return m_theme->get_part(m_normalIcon)->w;
return m_theme->get_part(m_normalIcon)->width();
}
int ButtonIconImpl::getHeight()
{
return m_theme->get_part(m_normalIcon)->h;
return m_theme->get_part(m_normalIcon)->height();
}
BITMAP* ButtonIconImpl::getNormalIcon()
she::Surface* ButtonIconImpl::getNormalIcon()
{
return m_theme->get_part(m_normalIcon);
}
BITMAP* ButtonIconImpl::getSelectedIcon()
she::Surface* ButtonIconImpl::getSelectedIcon()
{
return m_theme->get_part(m_selectedIcon);
}
BITMAP* ButtonIconImpl::getDisabledIcon()
she::Surface* ButtonIconImpl::getDisabledIcon()
{
return m_theme->get_part(m_disabledIcon);
}

View File

@ -39,9 +39,9 @@ namespace app {
void destroy();
int getWidth();
int getHeight();
BITMAP* getNormalIcon();
BITMAP* getSelectedIcon();
BITMAP* getDisabledIcon();
she::Surface* getNormalIcon();
she::Surface* getSelectedIcon();
she::Surface* getDisabledIcon();
int getIconAlign();
public:

View File

@ -65,7 +65,7 @@ namespace app {
else
part = m_partNormal;
g->drawAlphaBitmap(theme->get_part(part), bounds.x, bounds.y);
g->drawRgbaSurface(theme->get_part(part), bounds.x, bounds.y);
}
private:

View File

@ -22,7 +22,7 @@
#include "app/ui/skin/skin_part.h"
#include <allegro.h>
#include "she/surface.h"
namespace app {
namespace skin {
@ -42,12 +42,12 @@ void SkinPart::clear()
it != end; ++it) {
ASSERT(*it != NULL);
destroy_bitmap(*it);
(*it)->dispose();
*it = NULL;
}
}
void SkinPart::setBitmap(size_t index, BITMAP* bitmap)
void SkinPart::setBitmap(size_t index, she::Surface* bitmap)
{
if (index >= m_bitmaps.size())
m_bitmaps.resize(index+1, NULL);

View File

@ -23,14 +23,16 @@
#include <vector>
#include "base/shared_ptr.h"
struct BITMAP;
namespace she {
class Surface;
}
namespace app {
namespace skin {
class SkinPart {
public:
typedef std::vector<BITMAP*> Bitmaps;
typedef std::vector<she::Surface*> Bitmaps;
SkinPart();
~SkinPart();
@ -40,9 +42,9 @@ namespace app {
void clear();
// It doesn't destroy the previous bitmap in the given "index".
void setBitmap(size_t index, BITMAP* bitmap);
void setBitmap(size_t index, she::Surface* bitmap);
BITMAP* getBitmap(size_t index) const {
she::Surface* getBitmap(size_t index) const {
return (index < m_bitmaps.size() ? m_bitmaps[index]: NULL);
}

View File

@ -38,6 +38,9 @@
#include "gfx/point.h"
#include "gfx/rect.h"
#include "gfx/size.h"
#include "she/font.h"
#include "she/scoped_surface_lock.h"
#include "she/surface.h"
#include "she/system.h"
#include "ui/intern.h"
#include "ui/ui.h"
@ -45,7 +48,6 @@
#include "tinyxml.h"
#include <allegro.h>
#include <allegro/internal/aintern.h>
#define BGCOLOR (getWidgetBgColor(widget))
@ -145,10 +147,10 @@ SkinTheme::SkinTheme()
{
this->name = "Skin Theme";
m_selected_skin = get_config_string("Skin", "Selected", "default");
m_minifont = font;
m_minifont = she::instance()->defaultFont();
// Initialize all graphics in NULL (these bitmaps are loaded from the skin)
m_sheet_bmp = NULL;
m_sheet = NULL;
m_part.resize(PARTS, NULL);
sheet_mapping["radio_normal"] = PART_RADIO_NORMAL;
@ -359,12 +361,13 @@ SkinTheme::~SkinTheme()
for (size_t c=0; c<m_cursors.size(); ++c)
delete m_cursors[c];
for (std::map<std::string, BITMAP*>::iterator
for (std::map<std::string, she::Surface*>::iterator
it = m_toolicon.begin(); it != m_toolicon.end(); ++it) {
destroy_bitmap(it->second);
it->second->dispose();
}
destroy_bitmap(m_sheet_bmp);
if (m_sheet)
m_sheet->dispose();
m_part.clear();
m_parts_by_id.clear();
@ -372,16 +375,16 @@ SkinTheme::~SkinTheme()
color_mapping.clear();
// Destroy the minifont
if (m_minifont && m_minifont != font)
destroy_font(m_minifont);
if (m_minifont)
m_minifont->dispose();
}
// Call Theme::regenerate() after this.
void SkinTheme::reload_skin()
{
if (m_sheet_bmp) {
destroy_bitmap(m_sheet_bmp);
m_sheet_bmp = NULL;
if (m_sheet) {
m_sheet->dispose();
m_sheet = NULL;
}
// Load the skin sheet
@ -392,24 +395,21 @@ void SkinTheme::reload_skin()
if (!rf.findFirst())
throw base::Exception("File %s not found", sheet_filename.c_str());
int old_color_conv = _color_conv;
set_color_conversion(COLORCONV_NONE);
PALETTE pal;
m_sheet_bmp = load_bitmap(rf.filename().c_str(), pal);
if (!m_sheet_bmp)
try {
m_sheet = she::instance()->loadRgbaSurface(rf.filename().c_str());
}
catch (...) {
throw base::Exception("Error loading %s file", sheet_filename.c_str());
set_color_conversion(old_color_conv);
}
}
void SkinTheme::reload_fonts()
{
if (default_font && default_font != font)
destroy_font(default_font);
if (default_font)
default_font->dispose();
if (m_minifont && m_minifont != font)
destroy_font(m_minifont);
if (m_minifont)
m_minifont->dispose();
default_font = loadFont("UserFont", "skins/" + m_selected_skin + "/font.png");
m_minifont = loadFont("UserMiniFont", "skins/" + m_selected_skin + "/minifont.png");
@ -417,8 +417,9 @@ void SkinTheme::reload_fonts()
gfx::Size SkinTheme::get_part_size(int part_i) const
{
BITMAP* bmp = get_part(part_i);
return gfx::Size(bmp->w, bmp->h);
she::Surface* bmp = get_part(part_i);
ASSERT(bmp);
return gfx::Size(bmp->width(), bmp->height());
}
void SkinTheme::onRegenerate()
@ -489,12 +490,10 @@ void SkinTheme::onRegenerate()
delete m_cursors[c];
m_cursors[c] = NULL;
BITMAP* bmp = cropPartFromSheet(NULL, x, y, w, h);
she::Surface* surface =
she::Instance()->createSurfaceFromNativeHandle(reinterpret_cast<void*>(bmp));
she::Surface* slice = sliceSheet(NULL, gfx::Rect(x, y, w, h));
m_cursors[c] = new Cursor(surface, gfx::Point(focusx*jguiscale(),
focusy*jguiscale()));
m_cursors[c] = new Cursor(slice,
gfx::Point(focusx*jguiscale(), focusy*jguiscale()));
break;
}
@ -524,7 +523,8 @@ void SkinTheme::onRegenerate()
PRINTF("Loading tool icon '%s'...\n", tool_id);
// Crop the tool-icon from the sheet
m_toolicon[tool_id] = cropPartFromSheet(m_toolicon[tool_id], x, y, w, h);
m_toolicon[tool_id] = sliceSheet(
m_toolicon[tool_id], gfx::Rect(x, y, w, h));
xmlIcon = xmlIcon->NextSiblingElement();
}
@ -551,7 +551,8 @@ void SkinTheme::onRegenerate()
part = m_parts_by_id[part_id] = SkinPartPtr(new SkinPart);
if (w > 0 && h > 0) {
part->setBitmap(0, cropPartFromSheet(part->getBitmap(0), x, y, w, h));
part->setBitmap(0,
sliceSheet(part->getBitmap(0), gfx::Rect(x, y, w, h)));
}
else if (xmlPart->Attribute("w1")) { // 3x3-1 part (NW, N, NE, E, SE, S, SW, W)
int w1 = strtol(xmlPart->Attribute("w1"), NULL, 10);
@ -561,14 +562,14 @@ void SkinTheme::onRegenerate()
int h2 = strtol(xmlPart->Attribute("h2"), NULL, 10);
int h3 = strtol(xmlPart->Attribute("h3"), NULL, 10);
part->setBitmap(0, cropPartFromSheet(part->getBitmap(0), x, y, w1, h1)); // NW
part->setBitmap(1, cropPartFromSheet(part->getBitmap(1), x+w1, y, w2, h1)); // N
part->setBitmap(2, cropPartFromSheet(part->getBitmap(2), x+w1+w2, y, w3, h1)); // NE
part->setBitmap(3, cropPartFromSheet(part->getBitmap(3), x+w1+w2, y+h1, w3, h2)); // E
part->setBitmap(4, cropPartFromSheet(part->getBitmap(4), x+w1+w2, y+h1+h2, w3, h3)); // SE
part->setBitmap(5, cropPartFromSheet(part->getBitmap(5), x+w1, y+h1+h2, w2, h3)); // S
part->setBitmap(6, cropPartFromSheet(part->getBitmap(6), x, y+h1+h2, w1, h3)); // SW
part->setBitmap(7, cropPartFromSheet(part->getBitmap(7), x, y+h1, w1, h2)); // W
part->setBitmap(0, sliceSheet(part->getBitmap(0), gfx::Rect(x, y, w1, h1))); // NW
part->setBitmap(1, sliceSheet(part->getBitmap(1), gfx::Rect(x+w1, y, w2, h1))); // N
part->setBitmap(2, sliceSheet(part->getBitmap(2), gfx::Rect(x+w1+w2, y, w3, h1))); // NE
part->setBitmap(3, sliceSheet(part->getBitmap(3), gfx::Rect(x+w1+w2, y+h1, w3, h2))); // E
part->setBitmap(4, sliceSheet(part->getBitmap(4), gfx::Rect(x+w1+w2, y+h1+h2, w3, h3))); // SE
part->setBitmap(5, sliceSheet(part->getBitmap(5), gfx::Rect(x+w1, y+h1+h2, w2, h3))); // S
part->setBitmap(6, sliceSheet(part->getBitmap(6), gfx::Rect(x, y+h1+h2, w1, h3))); // SW
part->setBitmap(7, sliceSheet(part->getBitmap(7), gfx::Rect(x, y+h1, w1, h2))); // W
}
// Prepare the m_part vector (which is used for backward
@ -658,23 +659,27 @@ void SkinTheme::onRegenerate()
}
}
BITMAP* SkinTheme::cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h)
she::Surface* SkinTheme::sliceSheet(she::Surface* sur, const gfx::Rect& bounds)
{
int colordepth = 32;
if (bmp &&
(bmp->w != w ||
bmp->h != h ||
bitmap_color_depth(bmp) != colordepth)) {
destroy_bitmap(bmp);
bmp = NULL;
if (sur && (sur->width() != bounds.w ||
sur->height() != bounds.h)) {
sur->dispose();
sur = NULL;
}
if (!bmp)
bmp = create_bitmap_ex(colordepth, w, h);
if (!sur)
sur = she::instance()->createSurface(bounds.w, bounds.h);
blit(m_sheet_bmp, bmp, x, y, 0, 0, w, h);
return ji_apply_guiscale(bmp);
{
she::ScopedSurfaceLock src(m_sheet);
she::ScopedSurfaceLock dst(sur);
src->blitTo(dst, bounds.x, bounds.y, 0, 0, bounds.w, bounds.h);
}
sur->applyScale(jguiscale());
return sur;
}
Cursor* SkinTheme::getCursor(CursorType type)
@ -712,10 +717,11 @@ void SkinTheme::initWidget(Widget* widget)
break;
case kButtonWidget:
BORDER4(m_part[PART_BUTTON_NORMAL_W]->w,
m_part[PART_BUTTON_NORMAL_N]->h,
m_part[PART_BUTTON_NORMAL_E]->w,
m_part[PART_BUTTON_NORMAL_S]->h);
BORDER4(
m_part[PART_BUTTON_NORMAL_W]->width(),
m_part[PART_BUTTON_NORMAL_N]->height(),
m_part[PART_BUTTON_NORMAL_E]->width(),
m_part[PART_BUTTON_NORMAL_S]->height());
widget->child_spacing = 0;
break;
@ -732,10 +738,11 @@ void SkinTheme::initWidget(Widget* widget)
break;
case kEntryWidget:
BORDER4(m_part[PART_SUNKEN_NORMAL_W]->w,
m_part[PART_SUNKEN_NORMAL_N]->h,
m_part[PART_SUNKEN_NORMAL_E]->w,
m_part[PART_SUNKEN_NORMAL_S]->h);
BORDER4(
m_part[PART_SUNKEN_NORMAL_W]->width(),
m_part[PART_SUNKEN_NORMAL_N]->height(),
m_part[PART_SUNKEN_NORMAL_E]->width(),
m_part[PART_SUNKEN_NORMAL_S]->height());
break;
case kGridWidget:
@ -834,10 +841,11 @@ void SkinTheme::initWidget(Widget* widget)
break;
case kSliderWidget:
BORDER4(m_part[PART_SLIDER_EMPTY_W]->w-1*scale,
m_part[PART_SLIDER_EMPTY_N]->h,
m_part[PART_SLIDER_EMPTY_E]->w-1*scale,
m_part[PART_SLIDER_EMPTY_S]->h-1*scale);
BORDER4(
m_part[PART_SLIDER_EMPTY_W]->width()-1*scale,
m_part[PART_SLIDER_EMPTY_N]->height(),
m_part[PART_SLIDER_EMPTY_E]->width()-1*scale,
m_part[PART_SLIDER_EMPTY_S]->height()-1*scale);
widget->child_spacing = widget->getTextHeight();
widget->setAlign(JI_CENTER | JI_MIDDLE);
break;
@ -848,10 +856,11 @@ void SkinTheme::initWidget(Widget* widget)
break;
case kViewWidget:
BORDER4(m_part[PART_SUNKEN_NORMAL_W]->w-1*scale,
m_part[PART_SUNKEN_NORMAL_N]->h,
m_part[PART_SUNKEN_NORMAL_E]->w-1*scale,
m_part[PART_SUNKEN_NORMAL_S]->h-1*scale);
BORDER4(
m_part[PART_SUNKEN_NORMAL_W]->width()-1*scale,
m_part[PART_SUNKEN_NORMAL_N]->height(),
m_part[PART_SUNKEN_NORMAL_E]->width()-1*scale,
m_part[PART_SUNKEN_NORMAL_S]->height()-1*scale);
widget->child_spacing = 0;
widget->setBgColor(getColorById(kWindowFaceColorId));
break;
@ -904,8 +913,8 @@ void SkinTheme::setDecorativeWidgetBounds(Widget* widget)
Widget* window = widget->getParent();
gfx::Rect rect(0, 0, 0, 0);
rect.w = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->w;
rect.h = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->h;
rect.w = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->width();
rect.h = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->height();
rect.offset(window->getBounds().x2() - 3*jguiscale() - rect.w,
window->getBounds().y + 3*jguiscale());
@ -1158,7 +1167,7 @@ void SkinTheme::paintLabel(PaintEvent& ev)
rc.shrink(widget->getBorder());
widget->getTextIconInfo(NULL, &text);
g->drawString(widget->getText(), fg, bg, false, text.getOrigin());
g->drawUIString(widget->getText(), fg, bg, false, text.getOrigin());
}
void SkinTheme::paintLinkLabel(PaintEvent& ev)
@ -1264,12 +1273,14 @@ void SkinTheme::paintMenuItem(ui::PaintEvent& ev)
// Draw an indicator for selected items
if (widget->isSelected()) {
BITMAP* icon = m_part[widget->isEnabled() ? PART_CHECK_SELECTED:
PART_CHECK_DISABLED];
she::Surface* icon =
m_part[widget->isEnabled() ?
PART_CHECK_SELECTED:
PART_CHECK_DISABLED];
int x = bounds.x+4*scale-icon->w/2;
int y = bounds.y+bounds.h/2-icon->h/2;
g->drawAlphaBitmap(icon, x, y);
int x = bounds.x+4*scale-icon->width()/2;
int y = bounds.y+bounds.h/2-icon->height()/2;
g->drawRgbaSurface(icon, x, y);
}
// Text
@ -1406,7 +1417,6 @@ void SkinTheme::paintSlider(PaintEvent& ev)
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();
@ -1442,20 +1452,22 @@ void SkinTheme::paintSlider(PaintEvent& ev)
// Draw customized background
if (bgPainter) {
int nw = PART_MINI_SLIDER_EMPTY_NW;
BITMAP* thumb = widget->hasFocus() ? m_part[PART_MINI_SLIDER_THUMB_FOCUSED]:
m_part[PART_MINI_SLIDER_THUMB];
she::Surface* thumb =
widget->hasFocus() ? m_part[PART_MINI_SLIDER_THUMB_FOCUSED]:
m_part[PART_MINI_SLIDER_THUMB];
// Draw background
g->fillRect(BGCOLOR, rc);
// Draw thumb
g->drawAlphaBitmap(thumb, x-thumb->w/2, rc.y);
g->drawRgbaSurface(thumb, x-thumb->width()/2, rc.y);
// Draw borders
rc.shrink(Border(3 * jguiscale(),
thumb->h,
3 * jguiscale(),
1 * jguiscale()));
rc.shrink(Border(
3 * jguiscale(),
thumb->height(),
3 * jguiscale(),
1 * jguiscale()));
draw_bounds_nw(g, rc, nw, ui::ColorNone);
@ -1495,9 +1507,11 @@ void SkinTheme::paintSlider(PaintEvent& ev)
// Draw text
std::string old_text = widget->getText();
usprintf(buf, "%d", value);
widget->setTextQuiet(buf);
{
char buf[128];
sprintf(buf, "%d", value);
widget->setTextQuiet(buf);
}
{
IntersectClip clip(g, Rect(rc.x, rc.y, x-rc.x, rc.h));
@ -1742,10 +1756,10 @@ void SkinTheme::paintPopupWindow(PaintEvent& ev)
pos.shrink(window->getBorder());
g->drawString(window->getText(),
getColor(ThemeColor::Text),
window->getBgColor(), pos,
window->getAlign());
g->drawAlignedUIString(window->getText(),
getColor(ThemeColor::Text),
window->getBgColor(), pos,
window->getAlign());
}
void SkinTheme::paintWindowButton(ui::PaintEvent& ev)
@ -1762,7 +1776,7 @@ void SkinTheme::paintWindowButton(ui::PaintEvent& ev)
else
part = PART_WINDOW_CLOSE_BUTTON_NORMAL;
g->drawAlphaBitmap(m_part[part], rc.x, rc.y);
g->drawRgbaSurface(m_part[part], rc.x, rc.y);
}
void SkinTheme::paintTooltip(PaintEvent& ev)
@ -1792,36 +1806,41 @@ void SkinTheme::paintTooltip(PaintEvent& ev)
draw_bounds_template(g, rc, nw, n, ne, e, se, s, sw, w);
// Draw arrow in sides
BITMAP* arrow = NULL;
she::Surface* arrow = NULL;
switch (widget->getArrowAlign()) {
case JI_TOP:
arrow = m_part[PART_TOOLTIP_ARROW_N];
g->drawAlphaBitmap(arrow, rc.x+rc.w/2-arrow->w/2, rc.y);
g->drawRgbaSurface(arrow, rc.x+rc.w/2-arrow->width()/2, rc.y);
break;
case JI_BOTTOM:
arrow = m_part[PART_TOOLTIP_ARROW_S];
g->drawAlphaBitmap(arrow, rc.x+rc.w/2-arrow->w/2, rc.y+rc.h-arrow->h);
g->drawRgbaSurface(arrow,
rc.x+rc.w/2-arrow->width()/2,
rc.y+rc.h-arrow->height());
break;
case JI_LEFT:
arrow = m_part[PART_TOOLTIP_ARROW_W];
g->drawAlphaBitmap(arrow, rc.x, rc.y+rc.h/2-arrow->h/2);
g->drawRgbaSurface(arrow, rc.x, rc.y+rc.h/2-arrow->height()/2);
break;
case JI_RIGHT:
arrow = m_part[PART_TOOLTIP_ARROW_E];
g->drawAlphaBitmap(arrow, rc.x+rc.w-arrow->w, rc.y+rc.h/2-arrow->h/2);
g->drawRgbaSurface(arrow,
rc.x+rc.w-arrow->width(),
rc.y+rc.h/2-arrow->height()/2);
break;
}
// Fill background
g->fillRect(bg, Rect(rc).shrink(Border(m_part[w]->w,
m_part[n]->h,
m_part[e]->w,
m_part[s]->h)));
g->fillRect(bg, Rect(rc).shrink(
Border(
m_part[w]->width(),
m_part[n]->height(),
m_part[e]->width(),
m_part[s]->height())));
rc.shrink(widget->getBorder());
g->drawString(widget->getText(), fg, bg, rc, widget->getAlign());
g->drawAlignedUIString(widget->getText(), fg, bg, rc, widget->getAlign());
}
ui::Color SkinTheme::getWidgetBgColor(Widget* widget)
@ -1849,7 +1868,7 @@ void SkinTheme::drawTextString(Graphics* g, const char *t, ui::Color fg_color, u
if (!t)
t = widget->getText().c_str();
textrc.setSize(g->measureString(t));
textrc.setSize(g->measureUIString(t));
// Horizontally text alignment
@ -1893,17 +1912,17 @@ void SkinTheme::drawTextString(Graphics* g, const char *t, ui::Color fg_color, u
if (!widget->isEnabled()) {
// TODO avoid this
if (fill_bg) // Only to draw the background
g->drawString(t, ColorNone, bg_color, fill_bg, textrc.getOrigin());
g->drawUIString(t, ColorNone, bg_color, fill_bg, textrc.getOrigin());
// Draw white part
g->drawString(t, getColor(ThemeColor::Background), bg_color, fill_bg,
g->drawUIString(t, getColor(ThemeColor::Background), bg_color, fill_bg,
textrc.getOrigin() + Point(jguiscale(), jguiscale()));
if (fill_bg)
fill_bg = false;
}
g->drawString(t,
g->drawUIString(t,
(!widget->isEnabled() ?
getColor(ThemeColor::Disabled):
(ui::geta(fg_color) > 0 ? fg_color :
@ -1922,9 +1941,9 @@ void SkinTheme::drawEntryCaret(ui::Graphics* g, Entry* widget, int x, int y)
g->drawVLine(color, u, y-1, h+2);
}
BITMAP* SkinTheme::get_toolicon(const char* tool_id) const
she::Surface* SkinTheme::get_toolicon(const char* tool_id) const
{
std::map<std::string, BITMAP*>::const_iterator it = m_toolicon.find(tool_id);
std::map<std::string, she::Surface*>::const_iterator it = m_toolicon.find(tool_id);
if (it != m_toolicon.end())
return it->second;
else
@ -1935,85 +1954,85 @@ 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)
{
draw_bounds_template(g, rc,
m_part[nw],
m_part[n],
m_part[ne],
m_part[e],
m_part[se],
m_part[s],
m_part[sw],
m_part[w]);
m_part[nw],
m_part[n],
m_part[ne],
m_part[e],
m_part[se],
m_part[s],
m_part[sw],
m_part[w]);
}
void SkinTheme::draw_bounds_template(ui::Graphics* g, const gfx::Rect& rc, const SkinPartPtr& skinPart)
{
draw_bounds_template(g, rc,
skinPart->getBitmap(0),
skinPart->getBitmap(1),
skinPart->getBitmap(2),
skinPart->getBitmap(3),
skinPart->getBitmap(4),
skinPart->getBitmap(5),
skinPart->getBitmap(6),
skinPart->getBitmap(7));
skinPart->getBitmap(0),
skinPart->getBitmap(1),
skinPart->getBitmap(2),
skinPart->getBitmap(3),
skinPart->getBitmap(4),
skinPart->getBitmap(5),
skinPart->getBitmap(6),
skinPart->getBitmap(7));
}
void SkinTheme::draw_bounds_template(Graphics* g, const Rect& rc,
BITMAP* nw, BITMAP* n, BITMAP* ne,
BITMAP* e, BITMAP* se, BITMAP* s,
BITMAP* sw, BITMAP* w)
she::Surface* nw, she::Surface* n, she::Surface* ne,
she::Surface* e, she::Surface* se, she::Surface* s,
she::Surface* sw, she::Surface* w)
{
int x, y;
// Top
g->drawAlphaBitmap(nw, rc.x, rc.y);
g->drawRgbaSurface(nw, rc.x, rc.y);
{
IntersectClip clip(g, Rect(rc.x+nw->w, rc.y,
rc.w-nw->w-ne->w, rc.h));
IntersectClip clip(g, Rect(rc.x+nw->width(), rc.y,
rc.w-nw->width()-ne->width(), rc.h));
if (clip) {
for (x = rc.x+nw->w;
x < rc.x+rc.w-ne->w;
x += n->w) {
g->drawAlphaBitmap(n, x, rc.y);
for (x = rc.x+nw->width();
x < rc.x+rc.w-ne->width();
x += n->width()) {
g->drawRgbaSurface(n, x, rc.y);
}
}
}
g->drawAlphaBitmap(ne, rc.x+rc.w-ne->w, rc.y);
g->drawRgbaSurface(ne, rc.x+rc.w-ne->width(), rc.y);
// Bottom
g->drawAlphaBitmap(sw, rc.x, rc.y+rc.h-sw->h);
g->drawRgbaSurface(sw, rc.x, rc.y+rc.h-sw->height());
{
IntersectClip clip(g, Rect(rc.x+sw->w, rc.y,
rc.w-sw->w-se->w, rc.h));
IntersectClip clip(g, Rect(rc.x+sw->width(), rc.y,
rc.w-sw->width()-se->width(), rc.h));
if (clip) {
for (x = rc.x+sw->w;
x < rc.x+rc.w-se->w;
x += s->w) {
g->drawAlphaBitmap(s, x, rc.y+rc.h-s->h);
for (x = rc.x+sw->width();
x < rc.x+rc.w-se->width();
x += s->width()) {
g->drawRgbaSurface(s, x, rc.y+rc.h-s->height());
}
}
}
g->drawAlphaBitmap(se, rc.x+rc.w-se->w, rc.y+rc.h-se->h);
g->drawRgbaSurface(se, rc.x+rc.w-se->width(), rc.y+rc.h-se->height());
{
IntersectClip clip(g, Rect(rc.x, rc.y+nw->h,
rc.w, rc.h-nw->h-sw->h));
IntersectClip clip(g, Rect(rc.x, rc.y+nw->height(),
rc.w, rc.h-nw->height()-sw->height()));
if (clip) {
// Left
for (y = rc.y+nw->h;
y < rc.y+rc.h-sw->h;
y += w->h) {
g->drawAlphaBitmap(w, rc.x, y);
for (y = rc.y+nw->height();
y < rc.y+rc.h-sw->height();
y += w->height()) {
g->drawRgbaSurface(w, rc.x, y);
}
// Right
for (y = rc.y+ne->h;
y < rc.y+rc.h-se->h;
y += e->h) {
g->drawAlphaBitmap(e, rc.x+rc.w-e->w, y);
for (y = rc.y+ne->height();
y < rc.y+rc.h-se->height();
y += e->height()) {
g->drawRgbaSurface(e, rc.x+rc.w-e->width(), y);
}
}
}
@ -2030,7 +2049,6 @@ void SkinTheme::draw_bounds_array(ui::Graphics* g, const gfx::Rect& rc, int part
int sw = parts[6];
int w = parts[7];
set_alpha_blender();
draw_bounds_template(g, rc,
nw, n, ne, e,
se, s, sw, w);
@ -2044,10 +2062,12 @@ void SkinTheme::draw_bounds_nw(Graphics* g, const Rect& rc, int nw, ui::Color bg
// Center
if (!is_transparent(bg)) {
g->fillRect(bg, Rect(rc).shrink(Border(m_part[nw+7]->w,
m_part[nw+1]->h,
m_part[nw+3]->w,
m_part[nw+5]->h)));
g->fillRect(bg, Rect(rc).shrink(
Border(
m_part[nw+7]->width(),
m_part[nw+1]->height(),
m_part[nw+3]->width(),
m_part[nw+5]->height())));
}
}
@ -2059,10 +2079,10 @@ void SkinTheme::draw_bounds_nw(ui::Graphics* g, const gfx::Rect& rc, const SkinP
if (!is_transparent(bg)) {
gfx::Rect inside = rc;
inside.shrink(Border(
skinPart->getBitmap(7)->w,
skinPart->getBitmap(1)->h,
skinPart->getBitmap(3)->w,
skinPart->getBitmap(5)->h));
skinPart->getBitmap(7)->width(),
skinPart->getBitmap(1)->height(),
skinPart->getBitmap(3)->width(),
skinPart->getBitmap(5)->height()));
IntersectClip clip(g, inside);
if (clip)
@ -2092,16 +2112,16 @@ void SkinTheme::draw_part_as_hline(ui::Graphics* g, const gfx::Rect& rc, int par
int x;
for (x = rc.x;
x < rc.x2()-m_part[part]->w;
x += m_part[part]->w) {
g->drawAlphaBitmap(m_part[part], x, rc.y);
x < rc.x2()-m_part[part]->width();
x += m_part[part]->width()) {
g->drawRgbaSurface(m_part[part], x, rc.y);
}
if (x < rc.x2()) {
Rect rc2(x, rc.y, rc.w-(x-rc.x), m_part[part]->h);
Rect rc2(x, rc.y, rc.w-(x-rc.x), m_part[part]->height());
IntersectClip clip(g, rc2);
if (clip)
g->drawAlphaBitmap(m_part[part], x, rc.y);
g->drawRgbaSurface(m_part[part], x, rc.y);
}
}
@ -2110,16 +2130,16 @@ void SkinTheme::draw_part_as_vline(ui::Graphics* g, const gfx::Rect& rc, int par
int y;
for (y = rc.y;
y < rc.y2()-m_part[part]->h;
y += m_part[part]->h) {
g->drawAlphaBitmap(m_part[part], rc.x, y);
y < rc.y2()-m_part[part]->height();
y += m_part[part]->height()) {
g->drawRgbaSurface(m_part[part], rc.x, y);
}
if (y < rc.y2()) {
Rect rc2(rc.x, y, m_part[part]->w, rc.h-(y-rc.y));
Rect rc2(rc.x, y, m_part[part]->width(), rc.h-(y-rc.y));
IntersectClip clip(g, rc2);
if (clip)
g->drawAlphaBitmap(m_part[part], rc.x, y);
g->drawRgbaSurface(m_part[part], rc.x, y);
}
}
@ -2142,7 +2162,7 @@ void SkinTheme::paintProgressBar(ui::Graphics* g, const gfx::Rect& rc0, float pr
void SkinTheme::paintIcon(Widget* widget, Graphics* g, IButtonIcon* iconInterface, int x, int y)
{
BITMAP* icon_bmp = NULL;
she::Surface* icon_bmp = NULL;
// enabled
if (widget->isEnabled()) {
@ -2157,10 +2177,11 @@ void SkinTheme::paintIcon(Widget* widget, Graphics* g, IButtonIcon* iconInterfac
}
if (icon_bmp)
g->drawAlphaBitmap(icon_bmp, x, y);
g->drawRgbaSurface(icon_bmp, x, y);
}
FONT* SkinTheme::loadFont(const char* userFont, const std::string& path)
// static
she::Font* SkinTheme::loadFont(const char* userFont, const std::string& path)
{
ResourceFinder rf;
@ -2173,16 +2194,16 @@ FONT* SkinTheme::loadFont(const char* userFont, const std::string& path)
// Try to load the font
while (rf.next()) {
FONT* f = ji_font_load(rf.filename().c_str());
she::Font* f = she::load_bitmap_font(rf.filename().c_str(), jguiscale());
if (f) {
if (ji_font_is_scalable(f))
ji_font_set_size(f, 8*jguiscale());
if (f->isScalable())
f->setSize(8);
return f;
}
}
return font; // Use Allegro font by default
return she::instance()->defaultFont();
}
} // namespace skin

View File

@ -33,14 +33,16 @@
#include <map>
#include <string>
#include <allegro/color.h>
namespace ui {
class Entry;
class Graphics;
class IButtonIcon;
}
namespace she {
class Surface;
}
namespace app {
namespace skin {
@ -120,7 +122,7 @@ namespace app {
return m_colors[k];
}
FONT* getMiniFont() const { return m_minifont; }
she::Font* getMiniFont() const { return m_minifont; }
void reload_skin();
void reload_fonts();
@ -159,8 +161,8 @@ namespace app {
int get_button_selected_offset() const { return 0; } // TODO Configurable in xml
BITMAP* get_part(int part_i) const { return m_part[part_i]; }
BITMAP* get_toolicon(const char* tool_id) const;
she::Surface* get_part(int part_i) const { return m_part[part_i]; }
she::Surface* 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
@ -192,11 +194,11 @@ namespace app {
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);
void draw_bounds_template(ui::Graphics* g, const gfx::Rect& rc,
BITMAP* nw, BITMAP* n, BITMAP* ne,
BITMAP* e, BITMAP* se, BITMAP* s,
BITMAP* sw, BITMAP* w);
she::Surface* nw, she::Surface* n, she::Surface* ne,
she::Surface* e, she::Surface* se, she::Surface* s,
she::Surface* sw, she::Surface* w);
BITMAP* cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h);
she::Surface* sliceSheet(she::Surface* sur, const gfx::Rect& bounds);
ui::Color getWidgetBgColor(ui::Widget* widget);
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,
@ -205,18 +207,18 @@ namespace app {
void paintIcon(ui::Widget* widget, ui::Graphics* g, ui::IButtonIcon* iconInterface, int x, int y);
static FONT* loadFont(const char* userFont, const std::string& path);
static she::Font* loadFont(const char* userFont, const std::string& path);
std::string m_selected_skin;
BITMAP* m_sheet_bmp;
std::vector<BITMAP*> m_part;
she::Surface* m_sheet;
std::vector<she::Surface*> m_part;
std::map<std::string, SkinPartPtr> m_parts_by_id;
std::map<std::string, BITMAP*> m_toolicon;
std::map<std::string, she::Surface*> m_toolicon;
std::map<std::string, ui::Color> m_colors_by_id;
std::vector<ui::Cursor*> m_cursors;
std::vector<ui::Color> m_colors;
StyleSheet m_stylesheet;
FONT* m_minifont;
she::Font* m_minifont;
};
inline Style* get_style(const std::string& id) {

View File

@ -24,11 +24,10 @@
#include "app/ui/skin/skin_theme.h"
#include "css/sheet.h"
#include "she/surface.h"
#include "ui/graphics.h"
#include "ui/theme.h"
#include <allegro.h>
namespace app {
namespace skin {
@ -56,7 +55,7 @@ void BackgroundRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const cha
if (!ui::is_transparent(m_color))
g->fillRect(m_color, bounds);
g->drawAlphaBitmap(m_part->getBitmap(0), bounds.x, bounds.y);
g->drawRgbaSurface(m_part->getBitmap(0), bounds.x, bounds.y);
}
else if (m_part->size() == 8) {
theme->draw_bounds_nw(g, bounds, m_part, m_color);
@ -72,7 +71,7 @@ void TextRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* tex
SkinTheme* theme = static_cast<SkinTheme*>(ui::CurrentTheme::get());
if (text) {
g->drawString(text,
g->drawAlignedUIString(text,
(ui::is_transparent(m_color) ?
theme->getColor(ThemeColor::Text):
m_color),
@ -83,24 +82,24 @@ void TextRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* tex
void IconRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text)
{
BITMAP* bmp = m_part->getBitmap(0);
she::Surface* bmp = m_part->getBitmap(0);
int x, y;
if (m_align & JI_RIGHT)
x = bounds.x2() - bmp->w;
x = bounds.x2() - bmp->width();
else if (m_align & JI_CENTER)
x = bounds.x + bounds.w/2 - bmp->w/2;
x = bounds.x + bounds.w/2 - bmp->width()/2;
else
x = bounds.x;
if (m_align & JI_BOTTOM)
y = bounds.y2() - bmp->h;
y = bounds.y2() - bmp->height();
else if (m_align & JI_MIDDLE)
y = bounds.y + bounds.h/2 - bmp->h/2;
y = bounds.y + bounds.h/2 - bmp->height()/2;
else
y = bounds.y;
g->drawAlphaBitmap(bmp, x, y);
g->drawRgbaSurface(bmp, x, y);
}
Rules::Rules(const css::Query& query) :
@ -169,12 +168,12 @@ gfx::Size Rules::preferredSize(const char* text)
{
gfx::Size sz(0, 0);
if (m_icon) {
sz.w += m_icon->getPart()->getBitmap(0)->w;
sz.h = m_icon->getPart()->getBitmap(0)->h;
sz.w += m_icon->getPart()->getBitmap(0)->width();
sz.h = m_icon->getPart()->getBitmap(0)->height();
}
if (m_text && text) {
ui::ScreenGraphics g;
gfx::Size textSize = g.measureString(text);
gfx::Size textSize = g.measureUIString(text);
//if (sz.w > 0) sz.w += 2; // TODO text separation
sz.w += textSize.w;
sz.h = MAX(sz.h, textSize.h);

View File

@ -42,11 +42,12 @@
#include "raster/image.h"
#include "raster/layer.h"
#include "raster/sprite.h"
#include "she/font.h"
#include "she/surface.h"
#include "ui/ui.h"
#include "undo/undo_history.h"
#include <algorithm>
#include <allegro.h>
#include <cstdarg>
#include <cstdio>
#include <cstring>
@ -491,10 +492,10 @@ void StatusBar::onPaint(ui::PaintEvent& ev)
// Color
if (m_state == SHOW_COLOR) {
// Draw eyedropper icon
BITMAP* icon = theme->get_toolicon("eyedropper");
she::Surface* icon = theme->get_toolicon("eyedropper");
if (icon) {
g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2);
x += icon->w + 4*jguiscale();
g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2);
x += icon->width() + 4*jguiscale();
}
// Draw color
@ -507,33 +508,33 @@ void StatusBar::onPaint(ui::PaintEvent& ev)
std::string str = m_color.toHumanReadableString(app_get_current_pixel_format(),
app::Color::LongHumanReadableString);
if (m_alpha < 255) {
char buf[512];
usprintf(buf, ", Alpha %d", m_alpha);
char buf[256];
sprintf(buf, ", Alpha %d", m_alpha);
str += buf;
}
g->drawString(str, textColor, ColorNone, false,
gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2));
gfx::Point(x, rc.y + rc.h/2 - getFont()->height()/2));
x += ji_font_text_len(getFont(), str.c_str()) + 4*jguiscale();
x += getFont()->textLength(str.c_str()) + 4*jguiscale();
}
// Show tool
if (m_state == SHOW_TOOL) {
// Draw eyedropper icon
BITMAP* icon = theme->get_toolicon(m_tool->getId().c_str());
she::Surface* icon = theme->get_toolicon(m_tool->getId().c_str());
if (icon) {
g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2);
x += icon->w + 4*jguiscale();
g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2);
x += icon->width() + 4*jguiscale();
}
}
// Status bar text
if (getTextLength() > 0) {
g->drawString(getText(), textColor, ColorNone, false,
gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2));
gfx::Point(x, rc.y + rc.h/2 - getFont()->height()/2));
x += ji_font_text_len(getFont(), getText().c_str()) + 4*jguiscale();
x += getFont()->textLength(getText().c_str()) + 4*jguiscale();
}
// Draw progress bar

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
@ -22,17 +22,18 @@
//#define CLOSE_BUTTON_IN_EACH_TAB
#include <algorithm>
#include <allegro.h>
#include <cmath>
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/tabs.h"
#include "she/font.h"
#include "she/surface.h"
#include "ui/intern.h"
#include "ui/ui.h"
#include <algorithm>
#include <cmath>
#define ARROW_W (12*jguiscale())
#define ANI_ADDING_TAB_TICKS 5
@ -361,7 +362,7 @@ void Tabs::onPaint(PaintEvent& ev)
gfx::Rect rect = getClientBounds();
gfx::Rect box(rect.x-m_scrollX, rect.y,
2*jguiscale(),
m_list_of_tabs.empty() ? 0: theme->get_part(PART_TAB_FILLER)->h);
m_list_of_tabs.empty() ? 0: theme->get_part(PART_TAB_FILLER)->height());
g->fillRect(theme->getColorById(kWindowFaceColorId), g->getClipBounds());
@ -432,10 +433,10 @@ void Tabs::onResize(ResizeEvent& ev)
void Tabs::onPreferredSize(PreferredSizeEvent& ev)
{
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
gfx::Size reqsize(0, theme->get_part(PART_TAB_BOTTOM_NORMAL)->h);
gfx::Size reqsize(0, theme->get_part(PART_TAB_BOTTOM_NORMAL)->height());
if (!m_list_of_tabs.empty()) {
reqsize.h += theme->get_part(PART_TAB_FILLER)->h;
reqsize.h += theme->get_part(PART_TAB_FILLER)->height();
}
ev.setPreferredSize(reqsize);
@ -497,25 +498,28 @@ void Tabs::drawTab(Graphics* g, const gfx::Rect& box, Tab* tab, int y_delta, boo
face_color);
g->drawString(tab->text, text_color, face_color, false,
gfx::Point(box.x + 4*jguiscale(),
box.y + box.h/2 - text_height(this->getFont())/2+1 + y_delta));
gfx::Point(
box.x + 4*jguiscale(),
box.y + box.h/2 - getFont()->height()/2+1 + y_delta));
}
if (selected) {
theme->draw_bounds_nw(g, gfx::Rect(box.x, box.y2(), box.w, getBounds().y2()-box.y2()),
PART_TAB_BOTTOM_SELECTED_NW,
theme->getColor(ThemeColor::TabSelectedFace));
theme->draw_bounds_nw(g,
gfx::Rect(box.x, box.y2(), box.w, getBounds().y2()-box.y2()),
PART_TAB_BOTTOM_SELECTED_NW,
theme->getColor(ThemeColor::TabSelectedFace));
}
else {
theme->draw_part_as_hline(g, gfx::Rect(box.x, box.y2(), box.w, getBounds().y2()-box.y2()),
PART_TAB_BOTTOM_NORMAL);
theme->draw_part_as_hline(g,
gfx::Rect(box.x, box.y2(), box.w, getBounds().y2()-box.y2()),
PART_TAB_BOTTOM_NORMAL);
}
#ifdef CLOSE_BUTTON_IN_EACH_TAB
BITMAP* close_icon = theme->get_part(PART_WINDOW_CLOSE_BUTTON_NORMAL);
g->drawAlphaBitmap(close_icon,
box.x2() - 4*jguiscale() - close_icon->w,
box.y + box.h/2 - close_icon->h/2+1 * jguiscale());
she::Surface* close_icon = theme->get_part(PART_WINDOW_CLOSE_BUTTON_NORMAL);
g->drawRgbaSurface(close_icon,
box.x2() - 4*jguiscale() - close_icon->width(),
box.y + box.h/2 - close_icon->height()/2+1 * jguiscale());
#endif
}
@ -660,10 +664,10 @@ void Tabs::calcTabWidth(Tab* tab)
int border = 4*jguiscale();
#ifdef CLOSE_BUTTON_IN_EACH_TAB
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
int close_icon_w = theme->get_part(PART_WINDOW_CLOSE_BUTTON_NORMAL)->w;
tab->width = (border + text_length(getFont(), tab->text.c_str()) + border + close_icon_w + border);
int close_icon_w = theme->get_part(PART_WINDOW_CLOSE_BUTTON_NORMAL)->width();
tab->width = (border + getFont()->textLength(tab->text.c_str()) + border + close_icon_w + border);
#else
tab->width = (border + text_length(getFont(), tab->text.c_str()) + border);
tab->width = (border + getFont()->textLength(tab->text.c_str()) + border);
#endif
}

View File

@ -1146,10 +1146,9 @@ void Timeline::drawHeaderFrame(ui::Graphics* g, FrameNumber frame)
char buf[256];
std::sprintf(buf, "%d", (frame+1)%100); // Draw only the first two digits.
FONT* oldFont = g->getFont();
she::Font* oldFont = g->getFont();
g->setFont(((SkinTheme*)getTheme())->getMiniFont());
drawPart(g, bounds, buf, m_timelineBoxStyle,
is_active, is_hover, is_clicked);
drawPart(g, bounds, buf, m_timelineBoxStyle, is_active, is_hover, is_clicked);
g->setFont(oldFont);
}

View File

@ -39,9 +39,9 @@
#include "base/compiler_specific.h"
#include "base/signal.h"
#include "gfx/size.h"
#include "she/surface.h"
#include "ui/ui.h"
#include <allegro.h>
#include <string>
namespace app {
@ -78,9 +78,9 @@ private:
static Size getToolIconSize(Widget* widget)
{
SkinTheme* theme = static_cast<SkinTheme*>(widget->getTheme());
BITMAP* icon = theme->get_toolicon("configuration");
she::Surface* icon = theme->get_toolicon("configuration");
if (icon)
return Size(icon->w, icon->h);
return Size(icon->width(), icon->height());
else
return Size(16, 16) * jguiscale();
}
@ -349,11 +349,11 @@ void ToolBar::onPaint(ui::PaintEvent& ev)
theme->draw_bounds_nw(g, toolrc, nw, face);
// Draw the tool icon
BITMAP* icon = theme->get_toolicon(tool->getId().c_str());
she::Surface* icon = theme->get_toolicon(tool->getId().c_str());
if (icon) {
g->drawAlphaBitmap(icon,
toolrc.x+toolrc.w/2-icon->w/2,
toolrc.y+toolrc.h/2-icon->h/2);
g->drawRgbaSurface(icon,
toolrc.x+toolrc.w/2-icon->width()/2,
toolrc.y+toolrc.h/2-icon->height()/2);
}
}
@ -367,11 +367,11 @@ void ToolBar::onPaint(ui::PaintEvent& ev)
PART_TOOLBUTTON_LAST_NW,
isHot ? hotFace: normalFace);
BITMAP* icon = theme->get_toolicon("configuration");
she::Surface* icon = theme->get_toolicon("configuration");
if (icon) {
g->drawAlphaBitmap(icon,
toolrc.x+toolrc.w/2-icon->w/2,
toolrc.y+toolrc.h/2-icon->h/2);
g->drawRgbaSurface(icon,
toolrc.x+toolrc.w/2-icon->width()/2,
toolrc.y+toolrc.h/2-icon->height()/2);
}
// Draw button to show/hide mini editor
@ -387,9 +387,9 @@ void ToolBar::onPaint(ui::PaintEvent& ev)
icon = theme->get_toolicon("minieditor");
if (icon) {
g->drawAlphaBitmap(icon,
toolrc.x+toolrc.w/2-icon->w/2,
toolrc.y+toolrc.h/2-icon->h/2);
g->drawRgbaSurface(icon,
toolrc.x+toolrc.w/2-icon->width()/2,
toolrc.y+toolrc.h/2-icon->height()/2);
}
}
@ -759,11 +759,11 @@ void ToolBar::ToolStrip::onPaint(PaintEvent& ev)
theme->draw_bounds_nw(g, toolrc, nw, face);
// Draw the tool icon
BITMAP* icon = theme->get_toolicon(tool->getId().c_str());
she::Surface* icon = theme->get_toolicon(tool->getId().c_str());
if (icon) {
g->drawAlphaBitmap(icon,
toolrc.x+toolrc.w/2-icon->w/2,
toolrc.y+toolrc.h/2-icon->h/2);
g->drawRgbaSurface(icon,
toolrc.x+toolrc.w/2-icon->width()/2,
toolrc.y+toolrc.h/2-icon->height()/2);
}
}
}

View File

@ -20,9 +20,6 @@
#include "config.h"
#endif
#include <allegro.h>
#include <string.h>
#include "app/app.h"
#include "app/color.h"
#include "app/document_location.h"

View File

@ -87,7 +87,7 @@ int app_main(int argc, char* argv[])
try {
base::MemoryDump memoryDump;
she::ScopedHandle<she::System> system(she::CreateSystem());
she::ScopedHandle<she::System> system(she::create_system());
MemLeak memleak;
ui::GuiSystem guiSystem;
app::App app(argc, const_cast<const char**>(argv));

View File

@ -1,5 +1,6 @@
# SHE
# Copyright (C) 2012-2013 David Capello
# Copyright (C) 2012-2014 David Capello
add_library(she
she_alleg4.cpp)
alleg4/fontbmp.cpp
alleg4/she_alleg4.cpp)

View File

@ -0,0 +1,74 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef SHE_ALLEG4_FONT_H_INCLUDED
#define SHE_ALLEG4_FONT_H_INCLUDED
#pragma once
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include "base/compiler_specific.h"
#include "she/font.h"
namespace she {
class Alleg4Font : public Font {
public:
enum DestroyFlag {
None = 0,
DeleteThis = 1,
DestroyHandle = 2,
DeleteAndDestroy = DeleteThis | DestroyHandle,
};
Alleg4Font(FONT* font, DestroyFlag destroy)
: m_font(font)
, m_destroy(destroy) {
}
~Alleg4Font() {
if (m_destroy & DestroyHandle)
destroy_font(m_font);
}
virtual void dispose() OVERRIDE {
if (m_destroy & DeleteThis)
delete this;
}
virtual int height() const OVERRIDE {
return text_height(m_font);
}
virtual int charWidth(int chr) const OVERRIDE {
return m_font->vtable->char_length(m_font, chr);
}
virtual int textLength(const char* str) const OVERRIDE {
return text_length(m_font, str);
}
virtual bool isScalable() const {
return false;
}
virtual void setSize(int size) {
// Do nothing
}
virtual void* nativeHandle() OVERRIDE {
return reinterpret_cast<void*>(m_font);
}
private:
FONT* m_font;
DestroyFlag m_destroy;
};
} // namespace she
#endif

View File

@ -0,0 +1,128 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef SHE_ALLEG4_SURFACE_H_INCLUDED
#define SHE_ALLEG4_SURFACE_H_INCLUDED
#pragma once
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include "base/compiler_specific.h"
#include "she/locked_surface.h"
#include "she/surface.h"
namespace she {
class Alleg4Surface : public Surface
, public LockedSurface {
public:
enum DestroyFlag {
None = 0,
DeleteThis = 1,
DestroyHandle = 2,
DeleteAndDestroy = DeleteThis | DestroyHandle,
};
Alleg4Surface(BITMAP* bmp, DestroyFlag destroy)
: m_bmp(bmp)
, m_destroy(destroy) {
}
Alleg4Surface(int width, int height, DestroyFlag destroy)
: m_bmp(create_bitmap(width, height))
, m_destroy(destroy) {
}
Alleg4Surface(int width, int height, int bpp, DestroyFlag destroy)
: m_bmp(create_bitmap_ex(bpp, width, height))
, m_destroy(destroy) {
}
~Alleg4Surface() {
if (m_destroy & DestroyHandle)
destroy_bitmap(m_bmp);
}
// Surface implementation
void dispose() OVERRIDE {
if (m_destroy & DeleteThis)
delete this;
}
int width() const OVERRIDE {
return m_bmp->w;
}
int height() const OVERRIDE {
return m_bmp->h;
}
LockedSurface* lock() OVERRIDE {
acquire_bitmap(m_bmp);
return this;
}
void applyScale(int scale) OVERRIDE {
if (scale < 2)
return;
BITMAP* scaled =
create_bitmap_ex(bitmap_color_depth(m_bmp),
m_bmp->w*scale,
m_bmp->h*scale);
for (int y=0; y<scaled->h; ++y)
for (int x=0; x<scaled->w; ++x)
putpixel(scaled, x, y, getpixel(m_bmp, x/scale, y/scale));
if (m_destroy & DestroyHandle)
destroy_bitmap(m_bmp);
m_bmp = scaled;
m_destroy = DestroyHandle;
}
void* nativeHandle() OVERRIDE {
return reinterpret_cast<void*>(m_bmp);
}
// LockedSurface implementation
void unlock() OVERRIDE {
release_bitmap(m_bmp);
}
void clear() OVERRIDE {
clear_to_color(m_bmp, 0);
}
void blitTo(LockedSurface* dest, int srcx, int srcy, int dstx, int dsty, int width, int height) const OVERRIDE {
ASSERT(m_bmp);
ASSERT(dest);
ASSERT(static_cast<Alleg4Surface*>(dest)->m_bmp);
blit(m_bmp,
static_cast<Alleg4Surface*>(dest)->m_bmp,
srcx, srcy,
dstx, dsty,
width, height);
}
void drawRgbaSurface(const LockedSurface* src, int dstx, int dsty) OVERRIDE {
set_alpha_blender();
draw_trans_sprite(m_bmp, static_cast<const Alleg4Surface*>(src)->m_bmp, dstx, dsty);
}
private:
BITMAP* m_bmp;
DestroyFlag m_destroy;
};
} // namespace she
#endif

View File

@ -13,9 +13,17 @@
#include "config.h"
#endif
#include "she/alleg4/alleg4_font.h"
#include "she/alleg4/alleg4_surface.h"
#include "she/display.h"
#include "she/system.h"
#include <allegro.h>
#include <allegro/internal/aintern.h>
namespace {
/* state information for the bitmap font importer */
static BITMAP *import_bmp = NULL;
@ -170,9 +178,7 @@ static int bitmap_font_count(BITMAP* bmp)
return num;
}
namespace ui {
FONT* bitmapToFont(BITMAP* bmp)
FONT* bitmap_to_font(BITMAP* bmp)
{
FONT *f;
int begin = ' ';
@ -245,4 +251,32 @@ FONT* bitmapToFont(BITMAP* bmp)
return f;
}
} // namespace ui
}
namespace she {
Font* load_bitmap_font(const char* filename, int scale)
{
FONT* allegFont = NULL;
int old_color_conv = _color_conv;
set_color_conversion(COLORCONV_NONE);
PALETTE junk;
BITMAP* bmp = load_bitmap(filename, junk);
set_color_conversion(old_color_conv);
if (bmp) {
Alleg4Surface sur(bmp, Alleg4Surface::DestroyHandle);
if (scale > 1)
sur.applyScale(scale);
allegFont = bitmap_to_font(reinterpret_cast<BITMAP*>(sur.nativeHandle()));
}
if (allegFont)
return new Alleg4Font(allegFont, Alleg4Font::DeleteAndDestroy);
else
return NULL;
}
} // namespace she

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2012-2013 David Capello
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -15,6 +15,7 @@ namespace she {
class EventQueue;
class NonDisposableSurface;
class Surface;
class Font;
// A display or window to show graphics.
class Display {
@ -34,6 +35,7 @@ namespace she {
// The available surface size will be (Display::width() / scale,
// Display::height() / scale)
virtual void setScale(int scale) = 0;
virtual int scale() const = 0;
// Returns the main surface to draw into this display.
// You must not dispose this surface.

29
src/she/font.h Normal file
View File

@ -0,0 +1,29 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef SHE_FONT_H_INCLUDED
#define SHE_FONT_H_INCLUDED
#pragma once
namespace she {
class Font {
public:
virtual ~Font() { }
virtual void dispose() = 0;
virtual int height() const = 0;
virtual int charWidth(int chr) const = 0;
virtual int textLength(const char* chr) const = 0;
virtual bool isScalable() const = 0;
virtual void setSize(int size) = 0;
virtual void* nativeHandle() = 0;
};
Font* load_bitmap_font(const char* filename, int scale = 1);
} // namespace she
#endif

View File

@ -16,7 +16,7 @@ namespace she {
virtual void unlock() = 0;
virtual void clear() = 0;
virtual void blitTo(LockedSurface* dest, int srcx, int srcy, int dstx, int dsty, int width, int height) const = 0;
virtual void drawAlphaSurface(const LockedSurface* src, int dstx, int dsty) = 0;
virtual void drawRgbaSurface(const LockedSurface* src, int dstx, int dsty) = 0;
};
} // namespace she

View File

@ -19,6 +19,7 @@ namespace she {
virtual int width() const = 0;
virtual int height() const = 0;
virtual LockedSurface* lock() = 0;
virtual void applyScale(int scaleFactor) = 0;
virtual void* nativeHandle() = 0;
};

View File

@ -16,6 +16,7 @@ namespace she {
class Clipboard;
class Display;
class EventLoop;
class Font;
class Surface;
class DisplayCreationException : std::runtime_error {
@ -29,14 +30,18 @@ namespace she {
virtual ~System() { }
virtual void dispose() = 0;
virtual Capabilities capabilities() const = 0;
virtual Display* defaultDisplay() = 0;
virtual Font* defaultFont() = 0;
virtual Display* createDisplay(int width, int height, int scale) = 0;
virtual Surface* createSurface(int width, int height) = 0;
virtual Surface* createSurfaceFromNativeHandle(void* nativeHandle) = 0;
virtual Surface* createRgbaSurface(int width, int height) = 0;
virtual Surface* loadSurface(const char* filename) = 0;
virtual Surface* loadRgbaSurface(const char* filename) = 0;
virtual Clipboard* createClipboard() = 0;
};
System* CreateSystem();
System* Instance();
System* create_system();
System* instance();
} // namespace she

View File

@ -15,8 +15,6 @@ add_library(ui-lib
draw.cpp
entry.cpp
event.cpp
font.cpp
fontbmp.cpp
graphics.cpp
grid.cpp
image_view.cpp

View File

@ -14,28 +14,28 @@
#include <vector>
struct BITMAP;
namespace she {
class Surface;
}
namespace ui {
class Event;
class IButtonIcon
{
class IButtonIcon {
public:
virtual ~IButtonIcon() { }
virtual void destroy() = 0;
virtual int getWidth() = 0;
virtual int getHeight() = 0;
virtual BITMAP* getNormalIcon() = 0;
virtual BITMAP* getSelectedIcon() = 0;
virtual BITMAP* getDisabledIcon() = 0;
virtual she::Surface* getNormalIcon() = 0;
virtual she::Surface* getSelectedIcon() = 0;
virtual she::Surface* getDisabledIcon() = 0;
virtual int getIconAlign() = 0;
};
// Generic button
class ButtonBase : public Widget
{
class ButtonBase : public Widget {
public:
ButtonBase(const std::string& text,
WidgetType type,

View File

@ -7,8 +7,7 @@
#include "base/string.h"
#include <algorithm>
#include <allegro.h>
#include <winalleg.h>
#include <windows.h>
#pragma warning(disable:4996) // To void MSVC warning about std::copy() with unsafe arguments

View File

@ -10,10 +10,9 @@
#include "base/compiler_specific.h"
#include "gfx/size.h"
#include "she/font.h"
#include "ui/ui.h"
#include <allegro.h>
namespace ui {
using namespace gfx;
@ -365,7 +364,7 @@ void ComboBox::onPreferredSize(PreferredSizeEvent& ev)
for (it = m_items.begin(); it != end; ++it) {
int item_w =
2*jguiscale()+
text_length(getFont(), (*it)->getText().c_str())+
getFont()->textLength((*it)->getText().c_str())+
10*jguiscale();
reqSize.w = MAX(reqSize.w, item_w);

View File

@ -8,76 +8,19 @@
#include "config.h"
#endif
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include <vector>
#include "ui/draw.h"
#include "ui/font.h"
#include "ui/intern.h"
#include "ui/system.h"
#include "ui/widget.h"
/* TODO optional anti-aliased textout */
#define SETUP_ANTIALISING(f, bg, fill_bg) \
ji_font_set_aa_mode(f, fill_bg || \
bitmap_color_depth(ji_screen) == 8 ? to_system(bg): -1)
#include <allegro.h>
#include <vector>
namespace ui {
using namespace gfx;
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];
int hline_pos = -1;
int len = 0;
int in_pos = 0;
int out_pos = 0;
int c;
while (((c = ugetc(s+in_pos)) != 0) && (out_pos<(int)(sizeof(tmp)-ucwidth(0)))) {
if (c == '&') {
in_pos += uwidth(s+in_pos);
c = ugetc(s+in_pos);
if (c == '&') {
out_pos += usetc(tmp+out_pos, '&');
in_pos += uwidth(s+in_pos);
len++;
}
else
hline_pos = len;
}
else {
out_pos += usetc(tmp+out_pos, c);
in_pos += uwidth(s+in_pos);
len++;
}
}
usetc(tmp+out_pos, 0);
SETUP_ANTIALISING(font, bg_color, fill_bg);
textout_ex(bmp, font, tmp, x, y, to_system(fg_color), (fill_bg ? to_system(bg_color): -1));
if (hline_pos >= 0) {
c = ugetat(tmp, hline_pos);
usetat(tmp, hline_pos, 0);
hline_pos = text_length(font, tmp);
c = usetc(tmp, c);
usetc(tmp+c, 0);
c = text_length(font, tmp);
rectfill(bmp, x+hline_pos,
y+text_height(font),
x+hline_pos+c-1,
y+text_height(font)+underline_height-1, to_system(fg_color));
}
}
void _move_region(const Region& region, int dx, int dy)
{
size_t nrects = region.size();

View File

@ -13,14 +13,12 @@
#include "ui/base.h"
#include "ui/color.h"
struct FONT;
struct BITMAP;
// TODO all these functions are deprecated and must be replaced by Graphics methods.
namespace ui {
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

@ -11,8 +11,8 @@
#include "ui/entry.h"
#include "base/string.h"
#include "she/font.h"
#include "ui/clipboard.h"
#include "ui/font.h"
#include "ui/manager.h"
#include "ui/message.h"
#include "ui/preferred_size_event.h"
@ -20,12 +20,9 @@
#include "ui/theme.h"
#include "ui/widget.h"
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include <cstdarg>
#include <cstdio>
#define CHARACTER_LENGTH(f, c) ((f)->vtable->char_length((f), (c)))
#include <cctype>
namespace ui {
@ -120,7 +117,7 @@ void Entry::setCaretPos(int pos)
for (c=++m_scroll; ; c++) {
int ch = (c < textlen ? *(utf8_begin+c) : ' ');
x += CHARACTER_LENGTH(getFont(), ch);
x += getFont()->charWidth(ch);
if (x >= getBounds().x2()-this->border_width.r)
break;
@ -320,7 +317,7 @@ bool Entry::onProcessMessage(Message* msg)
for (c=m_scroll; utf8_begin != utf8_end; ++c) {
int ch = (c < textlen ? *(utf8_begin+c) : ' ');
x += CHARACTER_LENGTH(getFont(), ch);
x += getFont()->charWidth(ch);
if (x > getBounds().x2()-this->border_width.r) {
c--;
break;
@ -389,7 +386,7 @@ void Entry::onPreferredSize(PreferredSizeEvent& ev)
{
int w =
+ border_width.l
+ ji_font_char_len(getFont(), 'w') * MIN(m_maxsize, 6)
+ getFont()->charWidth('w') * MIN(m_maxsize, 6)
+ 2*jguiscale()
+ border_width.r;
@ -397,7 +394,7 @@ void Entry::onPreferredSize(PreferredSizeEvent& ev)
int h =
+ border_width.t
+ text_height(getFont())
+ getFont()->height()
+ border_width.b;
ev.setPreferredSize(w, h);
@ -441,7 +438,7 @@ int Entry::getCaretFromMouse(MouseMessage* mousemsg)
utf8_end);
for (c=m_scroll; utf8_it != utf8_end; ++c, ++utf8_it) {
w = CHARACTER_LENGTH(getFont(), *utf8_it);
w = getFont()->charWidth(*utf8_it);
if (x+w >= getBounds().x2()-this->border_width.r)
break;
if ((mx >= x) && (mx < x+w)) {
@ -641,7 +638,7 @@ void Entry::executeCmd(EntryCmd::Type cmd, int unicodeChar, bool shift_pressed)
}
#define IS_WORD_CHAR(ch) \
(!((!ch) || (uisspace(ch)) || \
(!((!ch) || (std::isspace(ch)) || \
((ch) == '/') || ((ch) == OTHER_PATH_SEPARATOR)))
void Entry::forwardWord()
@ -690,7 +687,7 @@ void Entry::backwardWord()
int Entry::getAvailableTextLength()
{
return getClientChildrenBounds().w / ji_font_char_len(getFont(), 'w');
return getClientChildrenBounds().w / getFont()->charWidth('w');
}
} // namespace ui

File diff suppressed because it is too large Load Diff

View File

@ -1,40 +0,0 @@
// Aseprite UI Library
// Copyright (C) 2001-2013 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef UI_FONT_H_INCLUDED
#define UI_FONT_H_INCLUDED
#pragma once
#include "ui/base.h"
struct FONT;
namespace ui {
FONT* ji_font_load(const char* filepathname);
FONT* ji_font_load_bmp(const char* filepathname);
FONT* ji_font_load_ttf(const char* filepathname);
int ji_font_get_size(FONT* f);
int ji_font_set_size(FONT* f, int height);
int ji_font_get_aa_mode(FONT* f);
int ji_font_set_aa_mode(FONT* f, int mode);
bool ji_font_is_fixed(FONT* f);
bool ji_font_is_scalable(FONT* f);
const int *ji_font_get_available_fixed_sizes(FONT* f, int* n);
int ji_font_get_char_extra_spacing(FONT* f);
void ji_font_set_char_extra_spacing(FONT* f, int spacing);
int ji_font_char_len(FONT* f, int chr);
int ji_font_text_len(FONT* f, const char* text);
} // namespace ui
#endif

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2001-2013 David Capello
// Copyright (C) 2001-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -10,11 +10,14 @@
#include "ui/graphics.h"
#include "base/string.h"
#include "gfx/point.h"
#include "gfx/rect.h"
#include "gfx/region.h"
#include "gfx/size.h"
#include "ui/draw.h"
#include "ui/font.h"
#include "she/font.h"
#include "she/surface.h"
#include "she/system.h"
#include "ui/theme.h"
#include <allegro.h>
@ -123,13 +126,16 @@ void Graphics::fillAreaBetweenRects(ui::Color color,
}
}
void Graphics::drawBitmap(BITMAP* sprite, int x, int y)
void Graphics::drawSurface(she::Surface* surface, int x, int y)
{
BITMAP* sprite = reinterpret_cast<BITMAP*>(surface->nativeHandle());
draw_sprite(m_bmp, sprite, m_dx+x, m_dy+y);
}
void Graphics::drawAlphaBitmap(BITMAP* sprite, int x, int y)
void Graphics::drawRgbaSurface(she::Surface* surface, int x, int y)
{
BITMAP* sprite = reinterpret_cast<BITMAP*>(surface->nativeHandle());
set_alpha_blender();
draw_trans_sprite(m_bmp, sprite, m_dx+x, m_dy+y);
}
@ -139,57 +145,121 @@ void Graphics::blit(BITMAP* src, int srcx, int srcy, int dstx, int dsty, int w,
::blit(src, m_bmp, srcx, srcy, m_dx+dstx, m_dy+dsty, w, h);
}
void Graphics::setFont(FONT* font)
void Graphics::setFont(she::Font* font)
{
m_currentFont = font;
m_font = font;
}
void Graphics::drawChar(int chr, Color fg, Color bg, int x, int y)
{
// 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);
FONT* font = reinterpret_cast<FONT*>(m_font->nativeHandle());
font->vtable->render_char(font, 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)
{
_draw_text(m_bmp, m_currentFont, str.c_str(), m_dx+pt.x, m_dy+pt.y,
fg, bg, fillbg, 1 * jguiscale());
FONT* font = reinterpret_cast<FONT*>(m_font->nativeHandle());
base::utf8_const_iterator it(str.begin()), end(str.end());
int length = 0;
int x = m_dx+pt.x;
int y = m_dy+pt.y;
int sysfg = to_system(fg);
int sysbg = (fillbg ? to_system(bg): -1);
while (it != end) {
font->vtable->render_char(font, *it, sysfg, sysbg, m_bmp, x, y);
x += m_font->charWidth(*it);
++it;
}
}
void Graphics::drawString(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align)
void Graphics::drawUIString(const std::string& str, Color fg, Color bg, bool fillbg, const gfx::Point& pt)
{
drawStringAlgorithm(str, fg, bg, rc, align, true);
FONT* font = reinterpret_cast<FONT*>(m_font->nativeHandle());
base::utf8_const_iterator it(str.begin()), end(str.end());
int length = 0;
int x = m_dx+pt.x;
int y = m_dy+pt.y;
int sysfg = to_system(fg);
int sysbg = (fillbg ? to_system(bg): -1);
int underscored_x;
int underscored_w = -1;
while (it != end) {
if (*it == '&') {
++it;
if (it != end && *it != '&') {
underscored_x = x;
underscored_w = m_font->charWidth(*it);
}
}
font->vtable->render_char(font, *it, sysfg, sysbg, m_bmp, x, y);
x += m_font->charWidth(*it);
++it;
}
if (underscored_w > 0) {
y += m_font->height();
rectfill(m_bmp, underscored_x, y,
underscored_x+underscored_w-1,
y+jguiscale()-1, sysfg);
}
}
void Graphics::drawAlignedUIString(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align)
{
doUIStringAlgorithm(str, fg, bg, rc, align, true);
}
gfx::Size Graphics::measureChar(int chr)
{
return gfx::Size(
getFont()->vtable->char_length(getFont(), chr),
text_height(getFont()));
m_font->charWidth(chr),
m_font->height());
}
gfx::Size Graphics::measureString(const std::string& str)
gfx::Size Graphics::measureUIString(const std::string& str)
{
return gfx::Size(
ji_font_text_len(getFont(), str.c_str()),
text_height(getFont()));
Graphics::measureUIStringLength(str, m_font),
m_font->height());
}
// static
int Graphics::measureUIStringLength(const std::string& str, she::Font* font)
{
base::utf8_const_iterator it(str.begin()), end(str.end());
int length = 0;
while (it != end) {
if (*it == '&')
++it;
length += font->charWidth(*it);
++it;
}
return length;
}
gfx::Size Graphics::fitString(const std::string& str, int maxWidth, int align)
{
return drawStringAlgorithm(str, ColorNone, ColorNone, gfx::Rect(0, 0, maxWidth, 0), align, false);
return doUIStringAlgorithm(str, ColorNone, ColorNone, gfx::Rect(0, 0, maxWidth, 0), align, false);
}
gfx::Size Graphics::drawStringAlgorithm(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align, bool draw)
gfx::Size Graphics::doUIStringAlgorithm(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align, bool draw)
{
FONT* font = reinterpret_cast<FONT*>(getFont()->nativeHandle());
gfx::Point pt(0, rc.y);
if ((align & (JI_MIDDLE | JI_BOTTOM)) != 0) {
gfx::Size preSize = drawStringAlgorithm(str, ColorNone, ColorNone, rc, 0, false);
gfx::Size preSize = doUIStringAlgorithm(str, ColorNone, ColorNone, rc, 0, false);
if (align & JI_MIDDLE)
pt.y = rc.y + rc.h/2 - preSize.h/2;
else if (align & JI_BOTTOM)
@ -217,7 +287,7 @@ gfx::Size Graphics::drawStringAlgorithm(const std::string& str, Color fg, Color
// If we have already a word to print (old_end != npos), and
// we are out of the available width (rc.w) using the new "end",
if ((old_end != std::string::npos) &&
(pt.x+measureString(str.substr(beg, end-beg)).w > rc.w)) {
(pt.x+measureUIString(str.substr(beg, end-beg)).w > rc.w)) {
// We go back to the "old_end" and paint from "beg" to "end"
end = old_end;
break;
@ -242,7 +312,7 @@ gfx::Size Graphics::drawStringAlgorithm(const std::string& str, Color fg, Color
// Get the entire line to be painted
line = str.substr(beg, end-beg);
gfx::Size lineSize = measureString(line);
gfx::Size lineSize = measureUIString(line);
calculatedSize.w = MAX(calculatedSize.w, lineSize.w);
// Render the text
@ -255,8 +325,7 @@ gfx::Size Graphics::drawStringAlgorithm(const std::string& str, Color fg, Color
else
xout = pt.x;
ji_font_set_aa_mode(m_currentFont, to_system(bg));
textout_ex(m_bmp, m_currentFont, line.c_str(), m_dx+xout, m_dy+pt.y, to_system(fg), to_system(bg));
textout_ex(m_bmp, font, line.c_str(), m_dx+xout, m_dy+pt.y, to_system(fg), to_system(bg));
if (!is_transparent(bg))
fillAreaBetweenRects(bg,
@ -284,7 +353,7 @@ gfx::Size Graphics::drawStringAlgorithm(const std::string& str, Color fg, Color
ScreenGraphics::ScreenGraphics()
: Graphics(screen, 0, 0)
{
setFont(font); // Allegro default font
setFont(CurrentTheme::get()->default_font);
}
ScreenGraphics::~ScreenGraphics()

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2001-2013 David Capello
// Copyright (C) 2001-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -18,17 +18,20 @@
#include <string>
struct BITMAP;
struct FONT;
namespace gfx {
class Region;
}
namespace she {
class Font;
class Surface;
}
namespace ui {
// Class to render a widget in the screen.
class Graphics
{
class Graphics {
public:
Graphics(BITMAP* bmp, int dx, int dy);
~Graphics();
@ -51,8 +54,8 @@ namespace ui {
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);
void drawSurface(she::Surface* surface, int x, int y);
void drawRgbaSurface(she::Surface* surface, int x, int y);
void blit(BITMAP* src, int srcx, int srcy, int dstx, int dsty, int w, int h);
@ -60,32 +63,31 @@ namespace ui {
// FONT & TEXT
// ======================================================================
void setFont(FONT* font);
FONT* getFont() {
return m_currentFont;
}
void setFont(she::Font* font);
she::Font* getFont() { return m_font; }
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);
void drawUIString(const std::string& str, Color fg, Color bg, bool fillbg, const gfx::Point& pt);
void drawAlignedUIString(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 measureUIString(const std::string& str);
static int measureUIStringLength(const std::string& str, she::Font* font);
gfx::Size fitString(const std::string& str, int maxWidth, int align);
private:
gfx::Size drawStringAlgorithm(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align, bool draw);
gfx::Size doUIStringAlgorithm(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align, bool draw);
BITMAP* m_bmp;
int m_dx;
int m_dy;
gfx::Rect m_clipBounds;
FONT* m_currentFont;
she::Font* m_font;
};
// Class to draw directly in the screen.
class ScreenGraphics : public Graphics
{
class ScreenGraphics : public Graphics {
public:
ScreenGraphics();
virtual ~ScreenGraphics();
@ -93,8 +95,7 @@ namespace ui {
// Class to temporary set the Graphics' clip region to a sub-rectangle
// (in the life-time of the IntersectClip instance).
class IntersectClip
{
class IntersectClip {
public:
IntersectClip(Graphics* g, const gfx::Rect& rc)
: m_graphics(g)

View File

@ -44,11 +44,12 @@ void removeWidget(Widget* widget)
widgets->erase(it);
}
void setFontOfAllWidgets(FONT* f)
void setFontOfAllWidgets(she::Font* font)
{
for (std::list<Widget*>::iterator it=widgets->begin(), end=widgets->end();
for (std::list<Widget*>::iterator
it=widgets->begin(), end=widgets->end();
it != end; ++it) {
(*it)->setFont(f);
(*it)->setFont(font);
}
}

View File

@ -11,8 +11,9 @@
#include "ui/base.h"
#include "ui/color.h"
struct FONT;
struct BITMAP;
namespace she {
class Font;
}
namespace ui {
@ -25,7 +26,7 @@ namespace ui {
void addWidget(Widget* widget);
void removeWidget(Widget* widget);
void setFontOfAllWidgets(FONT* f);
void setFontOfAllWidgets(she::Font* font);
void reinitThemeForAllWidgets();
// theme.cpp
@ -33,10 +34,6 @@ namespace ui {
void drawTextBox(Graphics* g, Widget* textbox,
int* w, int* h, ui::Color bg, ui::Color fg);
// fontbmp.c
struct FONT* bitmapToFont(BITMAP* bmp);
} // namespace ui
#endif

View File

@ -158,7 +158,7 @@ Manager::Manager()
m_defaultManager = this;
mouse_events_from_she =
((she::Instance()->capabilities() & she::kMouseEventsCapability)
((she::instance()->capabilities() & she::kMouseEventsCapability)
== she::kMouseEventsCapability);
}
}

View File

@ -8,7 +8,10 @@
#include "config.h"
#endif
#include "ui/menu.h"
#include "gfx/size.h"
#include "she/font.h"
#include "ui/intern.h"
#include "ui/ui.h"
@ -889,7 +892,7 @@ void MenuItem::onPreferredSize(PreferredSizeEvent& ev)
+ this->border_width.b;
if (m_accel && !m_accel->isEmpty()) {
size.w += ji_font_text_len(this->getFont(), m_accel->toString().c_str());
size.w += Graphics::measureUIStringLength(m_accel->toString().c_str(), getFont());
}
}

View File

@ -61,7 +61,7 @@ void Overlay::drawOverlay(she::LockedSurface* screen)
return;
she::ScopedSurfaceLock lockedSurface(m_surface);
screen->drawAlphaSurface(lockedSurface, m_pos.x, m_pos.y);
screen->drawRgbaSurface(lockedSurface, m_pos.x, m_pos.y);
}
void Overlay::moveOverlay(const gfx::Point& newPos)
@ -75,7 +75,7 @@ void Overlay::captureOverlappedArea(she::LockedSurface* screen)
return;
if (!m_overlap)
m_overlap = she::Instance()->createSurface(m_surface->width(), m_surface->height());
m_overlap = she::instance()->createSurface(m_surface->width(), m_surface->height());
she::ScopedSurfaceLock lock(m_overlap);
screen->blitTo(lock, m_pos.x, m_pos.y, 0, 0,

View File

@ -8,8 +8,6 @@
#include "config.h"
#endif
#include <allegro.h>
#include "gfx/size.h"
#include "ui/graphics.h"
#include "ui/intern.h"

View File

@ -8,11 +8,12 @@
#include "config.h"
#endif
#include "ui/font.h"
#include "ui/slider.h"
#include "she/font.h"
#include "ui/manager.h"
#include "ui/message.h"
#include "ui/preferred_size_event.h"
#include "ui/slider.h"
#include "ui/system.h"
#include "ui/theme.h"
#include "ui/widget.h"
@ -216,17 +217,15 @@ not_used:;
void Slider::onPreferredSize(PreferredSizeEvent& ev)
{
int w, h, min_w, max_w;
char buf[256];
std::sprintf(buf, "%d", m_min);
min_w = ji_font_text_len(this->getFont(), buf);
int min_w = getFont()->textLength(buf);
std::sprintf(buf, "%d", m_max);
max_w = ji_font_text_len(this->getFont(), buf);
int max_w = getFont()->textLength(buf);
w = MAX(min_w, max_w);
h = getTextHeight();
int w = MAX(min_w, max_w);
int h = getTextHeight();
w += this->border_width.l + this->border_width.r;
h += this->border_width.t + this->border_width.b;

View File

@ -130,13 +130,13 @@ int _ji_system_init()
void _ji_system_exit()
{
SetDisplay(NULL);
set_display(NULL);
update_mouse_overlay(NULL);
remove_int(clock_inc);
}
void SetDisplay(she::Display* display)
void set_display(she::Display* display)
{
CursorType cursor = jmouse_get_cursor();

View File

@ -34,7 +34,7 @@ namespace ui {
// so a flip to the real screen is needed.
extern bool dirty_display_flag;
void SetDisplay(she::Display* display);
void set_display(she::Display* display);
// Timer related

View File

@ -13,8 +13,9 @@
#include "gfx/point.h"
#include "gfx/size.h"
#include "she/font.h"
#include "she/system.h"
#include "ui/draw.h"
#include "ui/font.h"
#include "ui/intern.h"
#include "ui/manager.h"
#include "ui/system.h"
@ -29,15 +30,15 @@ static Theme* current_theme = NULL;
Theme::Theme()
{
this->name = "Theme";
this->default_font = font; // Default Allegro font
this->default_font = she::instance()->defaultFont();
this->scrollbar_size = 0;
this->guiscale = 1;
}
Theme::~Theme()
{
if (default_font && default_font != font)
destroy_font(default_font);
if (default_font)
default_font->dispose();
if (current_theme == this)
CurrentTheme::set(NULL);
@ -73,25 +74,6 @@ Theme* CurrentTheme::get()
return current_theme;
}
BITMAP* ji_apply_guiscale(BITMAP* original)
{
int scale = jguiscale();
if (scale > 1) {
BITMAP* scaled = create_bitmap_ex(bitmap_color_depth(original),
original->w*scale,
original->h*scale);
for (int y=0; y<scaled->h; ++y)
for (int x=0; x<scaled->w; ++x)
putpixel(scaled, x, y, getpixel(original, x/scale, y/scale));
destroy_bitmap(original);
return scaled;
}
else
return original;
}
void drawTextBox(Graphics* g, Widget* widget,
int* w, int* h, Color bg, Color fg)
{
@ -103,7 +85,7 @@ void drawTextBox(Graphics* g, Widget* widget,
gfx::Point scroll;
int viewport_w, viewport_h;
int textheight = widget->getTextHeight();
FONT *font = widget->getFont();
she::Font* font = widget->getFont();
char *beg_end, *old_end;
int width;
@ -181,7 +163,7 @@ void drawTextBox(Graphics* g, Widget* widget,
}
// To here we can print
if ((old_end) && (x+text_length(font, beg) > x1-scroll.x+width)) {
if ((old_end) && (x+font->textLength(beg) > x1-scroll.x+width)) {
if (end)
*end = chr;
@ -207,7 +189,7 @@ void drawTextBox(Graphics* g, Widget* widget,
}
}
len = text_length(font, beg);
len = font->textLength(beg);
// Render the text
if (g) {
@ -220,7 +202,7 @@ void drawTextBox(Graphics* g, Widget* widget,
else // Left align
xout = x;
g->drawString(beg, fg, bg, true, gfx::Point(xout, y));
g->drawUIString(beg, fg, bg, true, gfx::Point(xout, y));
g->fillAreaBetweenRects(bg,
gfx::Rect(x1, y, x2 - x1, textheight),
gfx::Rect(xout, y, len, textheight));

View File

@ -12,12 +12,15 @@
#include "ui/cursor_type.h"
struct BITMAP;
struct FONT;
namespace gfx {
class Region;
}
namespace she {
class Font;
}
namespace ui {
class Cursor;
@ -28,7 +31,7 @@ namespace ui {
{
public:
const char* name;
struct FONT* default_font;
she::Font* default_font;
int scrollbar_size;
int guiscale;
@ -78,8 +81,6 @@ namespace ui {
Theme* get();
}
BITMAP* ji_apply_guiscale(BITMAP* original);
// This value is a factor to multiply every screen size/coordinate.
// Every icon/graphics/font should be scaled to this factor.
inline int jguiscale()

View File

@ -8,9 +8,6 @@
#include "config.h"
#endif
#include <allegro.h>
#include <string>
#include "base/unique_ptr.h"
#include "gfx/size.h"
#include "ui/graphics.h"
@ -19,6 +16,8 @@
#include "ui/preferred_size_event.h"
#include "ui/ui.h"
#include <string>
static const int kTooltipDelayMsecs = 300;
namespace ui {

View File

@ -20,14 +20,10 @@ void _ji_widgets_exit();
int _ji_system_init();
void _ji_system_exit();
int _ji_font_init();
void _ji_font_exit();
GuiSystem::GuiSystem()
{
// initialize system
_ji_system_init();
_ji_font_init();
_ji_widgets_init();
}
@ -40,7 +36,6 @@ GuiSystem::~GuiSystem()
// shutdown system
_ji_widgets_exit();
_ji_font_exit();
_ji_system_exit();
}

View File

@ -23,7 +23,6 @@
#include "ui/draw.h"
#include "ui/entry.h"
#include "ui/event.h"
#include "ui/font.h"
#include "ui/graphics.h"
#include "ui/grid.h"
#include "ui/hit_test_event.h"

View File

@ -11,6 +11,7 @@
#endif
#include "base/memory.h"
#include "she/font.h"
#include "ui/intern.h"
#include "ui/ui.h"
@ -61,7 +62,7 @@ Widget::Widget(WidgetType type)
this->m_theme = CurrentTheme::get();
this->m_align = 0;
this->m_font = this->m_theme ? this->m_theme->default_font: NULL;
this->m_font = (this->m_theme ? this->m_theme->default_font: NULL);
this->m_bgColor = ui::ColorNone;
this->theme_data[0] = NULL;
@ -157,14 +158,14 @@ void Widget::setTextQuiet(const std::string& text)
flags |= JI_HASTEXT;
}
FONT *Widget::getFont() const
she::Font* Widget::getFont() const
{
return m_font;
}
void Widget::setFont(FONT* f)
void Widget::setFont(she::Font* font)
{
m_font = f;
m_font = font;
invalidate();
}
@ -735,16 +736,12 @@ void Widget::getDrawableRegion(gfx::Region& region, DrawableRegionFlags flags)
int Widget::getTextWidth() const
{
#if 1
return ji_font_text_len(getFont(), getText().c_str());
#else /* use cached text size */
return text_size_pix;
#endif
return Graphics::measureUIStringLength(getText().c_str(), getFont());
}
int Widget::getTextHeight() const
{
return text_height(getFont());
return getFont()->height();
}
void Widget::getTextIconInfo(

View File

@ -24,7 +24,9 @@
#define ASSERT_VALID_WIDGET(widget) ASSERT((widget) != NULL)
struct FONT;
namespace she {
class Font;
}
namespace ui {
@ -143,8 +145,8 @@ namespace ui {
// LOOK & FEEL
// ===============================================================
FONT* getFont() const;
void setFont(FONT* font);
she::Font* getFont() const;
void setFont(she::Font* font);
// Gets the background color of the widget.
ui::Color getBgColor() const {
@ -378,7 +380,7 @@ namespace ui {
Theme* m_theme; // Widget's theme
int m_align; // Widget alignment
std::string m_text; // Widget text
struct FONT *m_font; // Text font type
she::Font* m_font; // Text font type
ui::Color m_bgColor; // Background color
gfx::Rect m_bounds;
gfx::Region m_updateRegion; // Region to be redrawed.

View File

@ -10,8 +10,6 @@
#include "config.h"
#endif
#include <allegro.h>
#include "gfx/size.h"
#include "ui/graphics.h"
#include "ui/intern.h"