mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Move kPaintMessage code to onPaint() event for some widgets
The affected widgets are: ColorBar::ScrollableView, ColorButton, and StatusBar. * Added Graphics::drawLine() * Moved rectgrid and draw_color to modules/gfx.cpp
This commit is contained in:
parent
66f357098c
commit
f8e8657093
@ -165,34 +165,33 @@ void dotted_mode(int offset)
|
||||
drawing_mode(DRAW_MODE_COPY_PATTERN, pattern, 0, 0);
|
||||
}
|
||||
|
||||
void rectgrid(BITMAP* bmp, int x1, int y1, int x2, int y2, int w, int h)
|
||||
static void rectgrid(ui::Graphics* g, const gfx::Rect& rc, const gfx::Size& tile)
|
||||
{
|
||||
if (w < 1 || h < 1)
|
||||
if (tile.w < 1 || tile.h < 1)
|
||||
return;
|
||||
|
||||
int x, y, u, v, c1, c2;
|
||||
|
||||
c1 = makecol_depth(bitmap_color_depth(bmp), 128, 128, 128);
|
||||
c2 = makecol_depth(bitmap_color_depth(bmp), 192, 192, 192);
|
||||
int x, y, u, v;
|
||||
ui::Color c1 = ui::rgba(128, 128, 128);
|
||||
ui::Color c2 = ui::rgba(192, 192, 192);
|
||||
|
||||
u = 0;
|
||||
v = 0;
|
||||
for (y=y1; y<=y2-h; y+=h) {
|
||||
for (x=x1; x<=x2-w; x+=w)
|
||||
rectfill(bmp, x, y, x+w-1, y+h-1, ((u++)&1)? c1: c2);
|
||||
for (y=rc.y; y<rc.y2()-tile.h; y+=tile.h) {
|
||||
for (x=rc.x; x<rc.x2()-tile.w; x+=tile.w)
|
||||
g->fillRect(((u++)&1)? c1: c2, gfx::Rect(x, y, tile.w, tile.h));
|
||||
|
||||
if (x <= x2)
|
||||
rectfill(bmp, x, y, x2, y+h-1, ((u++)&1)? c1: c2);
|
||||
if (x < rc.x2())
|
||||
g->fillRect(((u++)&1)? c1: c2, gfx::Rect(x, y, rc.x2()-x, tile.h));
|
||||
|
||||
u = (++v);
|
||||
}
|
||||
|
||||
if (y <= y2) {
|
||||
for (x=x1; x<=x2-w; x+=w)
|
||||
rectfill(bmp, x, y, x+w-1, y2, ((u++)&1)? c1: c2);
|
||||
if (y < rc.y2()) {
|
||||
for (x=rc.x; x<rc.x2()-tile.w; x+=tile.w)
|
||||
g->fillRect(((u++)&1)? c1: c2, gfx::Rect(x, y, tile.w, rc.y2()-y));
|
||||
|
||||
if (x <= x2)
|
||||
rectfill(bmp, x, y, x2, y2, ((u++)&1)? c1: c2);
|
||||
if (x < rc.x2())
|
||||
g->fillRect(((u++)&1)? c1: c2, gfx::Rect(x, y, rc.x2()-x, rc.y2()-y));
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,28 +207,29 @@ void draw_emptyset_symbol(BITMAP* bmp, const Rect& rc, ui::Color color)
|
||||
center.x+size/2, center.y-size/2, ui::to_system(color));
|
||||
}
|
||||
|
||||
void draw_color(BITMAP* bmp, const Rect& rc, PixelFormat pixelFormat, const app::Color& color)
|
||||
static void draw_color(ui::Graphics* g, const Rect& rc, PixelFormat pixelFormat, const app::Color& color)
|
||||
{
|
||||
if (rc.w <= 0 || rc.h <= 0)
|
||||
if (rc.w < 1 || rc.h < 1)
|
||||
return;
|
||||
|
||||
app::Color::Type type = color.getType();
|
||||
BITMAP* graph;
|
||||
|
||||
if (type == app::Color::MaskType) {
|
||||
rectgrid(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, rc.w/4, rc.h/2);
|
||||
rectgrid(g, rc, gfx::Size(rc.w/4, rc.h/2));
|
||||
return;
|
||||
}
|
||||
else if (type == app::Color::IndexType) {
|
||||
int index = color.getIndex();
|
||||
|
||||
if (index >= 0 && index < get_current_palette()->size()) {
|
||||
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1,
|
||||
color_utils::color_for_allegro(color, bitmap_color_depth(bmp)));
|
||||
g->fillRect(color_utils::color_for_ui(color), rc);
|
||||
}
|
||||
else {
|
||||
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, makecol(0, 0, 0));
|
||||
line(bmp, rc.x+rc.w-2, rc.y+1, rc.x+1, rc.y+rc.h-2, makecol(255, 255, 255));
|
||||
g->fillRect(ui::rgba(0, 0, 0), rc);
|
||||
g->drawLine(ui::rgba(255, 255, 255),
|
||||
gfx::Point(rc.x+rc.w-2, rc.y+1),
|
||||
gfx::Point(rc.x+1, rc.y+rc.h-2));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -237,9 +237,11 @@ void draw_color(BITMAP* bmp, const Rect& rc, PixelFormat pixelFormat, const app:
|
||||
switch (pixelFormat) {
|
||||
|
||||
case IMAGE_INDEXED:
|
||||
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1,
|
||||
color_utils::color_for_allegro(app::Color::fromIndex(color_utils::color_for_image(color, pixelFormat)),
|
||||
bitmap_color_depth(bmp)));
|
||||
g->fillRect(
|
||||
color_utils::color_for_ui(
|
||||
app::Color::fromIndex(
|
||||
color_utils::color_for_image(color, pixelFormat))),
|
||||
rc);
|
||||
break;
|
||||
|
||||
case IMAGE_RGB:
|
||||
@ -248,7 +250,7 @@ void draw_color(BITMAP* bmp, const Rect& rc, PixelFormat pixelFormat, const app:
|
||||
return;
|
||||
|
||||
{
|
||||
int rgb_bitmap_color = color_utils::color_for_image(color, pixelFormat);
|
||||
raster::color_t rgb_bitmap_color = color_utils::color_for_image(color, pixelFormat);
|
||||
app::Color color2 = app::Color::fromRgb(rgba_getr(rgb_bitmap_color),
|
||||
rgba_getg(rgb_bitmap_color),
|
||||
rgba_getb(rgb_bitmap_color));
|
||||
@ -256,7 +258,7 @@ void draw_color(BITMAP* bmp, const Rect& rc, PixelFormat pixelFormat, const app:
|
||||
color_utils::color_for_allegro(color2, 32));
|
||||
}
|
||||
|
||||
blit(graph, bmp, 0, 0, rc.x, rc.y, rc.w, rc.h);
|
||||
g->blit(graph, 0, 0, rc.x, rc.y, rc.w, rc.h);
|
||||
|
||||
destroy_bitmap(graph);
|
||||
break;
|
||||
@ -273,14 +275,14 @@ void draw_color(BITMAP* bmp, const Rect& rc, PixelFormat pixelFormat, const app:
|
||||
color_utils::color_for_allegro(color2, 32));
|
||||
}
|
||||
|
||||
blit(graph, bmp, 0, 0, rc.x, rc.y, rc.w, rc.h);
|
||||
g->blit(graph, 0, 0, rc.x, rc.y, rc.w, rc.h);
|
||||
|
||||
destroy_bitmap(graph);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_color_button(BITMAP* bmp,
|
||||
void draw_color_button(ui::Graphics* g,
|
||||
const Rect& rc,
|
||||
bool outer_nw, bool outer_n, bool outer_ne, bool outer_e,
|
||||
bool outer_se, bool outer_s, bool outer_sw, bool outer_w,
|
||||
@ -290,11 +292,11 @@ void draw_color_button(BITMAP* bmp,
|
||||
int scale = ui::jguiscale();
|
||||
|
||||
// Draw background (the color)
|
||||
draw_color(bmp,
|
||||
Rect(rc.x+1*scale,
|
||||
rc.y+1*scale,
|
||||
rc.w-((outer_e) ? 2*scale: 1*scale),
|
||||
rc.h-((outer_s) ? 2*scale: 1*scale)), pixelFormat, color);
|
||||
draw_color(g,
|
||||
Rect(rc.x+1*scale,
|
||||
rc.y+1*scale,
|
||||
rc.w-((outer_e) ? 2*scale: 1*scale),
|
||||
rc.h-((outer_s) ? 2*scale: 1*scale)), pixelFormat, color);
|
||||
|
||||
// Draw opaque border
|
||||
{
|
||||
@ -308,16 +310,14 @@ void draw_color_button(BITMAP* bmp,
|
||||
outer_sw ? PART_COLORBAR_2_SW: (outer_s ? PART_COLORBAR_3_SW: PART_COLORBAR_1_SW),
|
||||
outer_w ? PART_COLORBAR_0_W : PART_COLORBAR_1_W,
|
||||
};
|
||||
theme->draw_bounds_array(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, parts);
|
||||
theme->draw_bounds_array(g, rc, parts);
|
||||
}
|
||||
|
||||
// Draw hot
|
||||
if (hot) {
|
||||
theme->draw_bounds_nw(bmp,
|
||||
rc.x, rc.y,
|
||||
rc.x+rc.w-1,
|
||||
rc.y+rc.h-1 - (outer_s ? 1*scale: 0),
|
||||
PART_COLORBAR_BORDER_HOTFG_NW);
|
||||
theme->draw_bounds_nw(g,
|
||||
gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - (outer_s ? 1*scale: 0)),
|
||||
PART_COLORBAR_BORDER_HOTFG_NW);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "gfx/rect.h"
|
||||
#include "ui/base.h"
|
||||
#include "ui/color.h"
|
||||
#include "ui/graphics.h"
|
||||
|
||||
struct FONT;
|
||||
struct BITMAP;
|
||||
@ -32,11 +33,8 @@ namespace app {
|
||||
|
||||
void dotted_mode(int offset);
|
||||
|
||||
void rectgrid(BITMAP* bmp, int x1, int y1, int x2, int y2, int w, int h);
|
||||
|
||||
void draw_emptyset_symbol(BITMAP* bmp, const gfx::Rect& rc, ui::Color color);
|
||||
void draw_color(BITMAP* bmp, const gfx::Rect& rc, PixelFormat pixelFormat, const app::Color& color);
|
||||
void draw_color_button(BITMAP* bmp,
|
||||
void draw_color_button(ui::Graphics* g,
|
||||
const gfx::Rect& rc,
|
||||
bool outer_nw, bool outer_n, bool outer_ne, bool outer_e,
|
||||
bool outer_se, bool outer_s, bool outer_sw, bool outer_w,
|
||||
|
@ -24,17 +24,18 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "app/color.h"
|
||||
#include "app/ui/color_bar.h"
|
||||
#include "app/ui/status_bar.h"
|
||||
#include "base/bind.h"
|
||||
#include "app/commands/commands.h"
|
||||
#include "app/commands/params.h"
|
||||
#include "app/ini_file.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "raster/image.h"
|
||||
#include "app/ui/color_bar.h"
|
||||
#include "app/ui/skin/skin_theme.h"
|
||||
#include "ui/message.h"
|
||||
#include "app/ui/status_bar.h"
|
||||
#include "app/ui_context.h"
|
||||
#include "base/bind.h"
|
||||
#include "raster/image.h"
|
||||
#include "ui/graphics.h"
|
||||
#include "ui/paint_event.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
@ -55,23 +56,15 @@ ColorBar::ScrollableView::ScrollableView()
|
||||
jwidget_set_border(this, l, t, r, b);
|
||||
}
|
||||
|
||||
bool ColorBar::ScrollableView::onProcessMessage(Message* msg)
|
||||
void ColorBar::ScrollableView::onPaint(ui::PaintEvent& ev)
|
||||
{
|
||||
switch (msg->type()) {
|
||||
|
||||
case kPaintMessage:
|
||||
{
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
||||
theme->draw_bounds_nw(ji_screen,
|
||||
getBounds(),
|
||||
hasFocus() ? PART_EDITOR_SELECTED_NW:
|
||||
PART_EDITOR_NORMAL_NW,
|
||||
ColorNone);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
return View::onProcessMessage(msg);
|
||||
ui::Graphics* g = ev.getGraphics();
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
||||
theme->draw_bounds_nw(g,
|
||||
getClientBounds(),
|
||||
hasFocus() ? PART_EDITOR_SELECTED_NW:
|
||||
PART_EDITOR_NORMAL_NW,
|
||||
ColorNone);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -71,7 +71,7 @@ namespace app {
|
||||
public:
|
||||
ScrollableView();
|
||||
protected:
|
||||
bool onProcessMessage(ui::Message* msg) OVERRIDE;
|
||||
void onPaint(ui::PaintEvent& ev) OVERRIDE;
|
||||
};
|
||||
|
||||
ui::CheckBox m_paletteButton;
|
||||
|
@ -173,15 +173,19 @@ void ColorButton::onPreferredSize(PreferredSizeEvent& ev)
|
||||
box.h + border_width.t + border_width.b);
|
||||
}
|
||||
|
||||
void ColorButton::onPaint(PaintEvent& ev) // TODO use "ev.getGraphics()"
|
||||
void ColorButton::onPaint(PaintEvent& ev)
|
||||
{
|
||||
gfx::Rect box, text, icon;
|
||||
jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0);
|
||||
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))
|
||||
bg = static_cast<SkinTheme*>(getTheme())->getColor(ThemeColor::Face);
|
||||
jdraw_rectfill(getBounds(), bg);
|
||||
bg = theme->getColor(ThemeColor::Face);
|
||||
g->fillRect(bg, rc);
|
||||
|
||||
app::Color color;
|
||||
|
||||
@ -195,28 +199,26 @@ void ColorButton::onPaint(PaintEvent& ev) // TODO use "ev.getGraphics()"
|
||||
else
|
||||
color = m_color;
|
||||
|
||||
draw_color_button
|
||||
(ji_screen,
|
||||
this->getBounds(),
|
||||
true, true, true, true,
|
||||
true, true, true, true,
|
||||
m_pixelFormat,
|
||||
color,
|
||||
this->hasMouseOver(), false);
|
||||
draw_color_button(g, rc,
|
||||
true, true, true, true,
|
||||
true, true, true, true,
|
||||
m_pixelFormat,
|
||||
color,
|
||||
hasMouseOver(), false);
|
||||
|
||||
// Draw text
|
||||
std::string str = m_color.toHumanReadableString(m_pixelFormat,
|
||||
app::Color::ShortHumanReadableString);
|
||||
app::Color::ShortHumanReadableString);
|
||||
|
||||
setTextQuiet(str.c_str());
|
||||
jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0);
|
||||
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()));
|
||||
|
||||
jdraw_text(ji_screen, getFont(), getText().c_str(), text.x, text.y,
|
||||
textcolor, ColorNone, false, jguiscale());
|
||||
g->drawString(getText(), textcolor, ColorNone, false,
|
||||
text.getOrigin() - getBounds().getOrigin());
|
||||
}
|
||||
|
||||
void ColorButton::onClick(Event& ev)
|
||||
|
@ -2196,7 +2196,7 @@ void SkinTheme::draw_bounds_template(Graphics* g, const Rect& rc,
|
||||
}
|
||||
}
|
||||
|
||||
void SkinTheme::draw_bounds_array(BITMAP* bmp, int x1, int y1, int x2, int y2, int parts[8])
|
||||
void SkinTheme::draw_bounds_array(ui::Graphics* g, const gfx::Rect& rc, int parts[8])
|
||||
{
|
||||
int nw = parts[0];
|
||||
int n = parts[1];
|
||||
@ -2208,9 +2208,9 @@ void SkinTheme::draw_bounds_array(BITMAP* bmp, int x1, int y1, int x2, int y2, i
|
||||
int w = parts[7];
|
||||
|
||||
set_alpha_blender();
|
||||
draw_bounds_template(bmp, x1, y1, x2, y2,
|
||||
nw, n, ne, e,
|
||||
se, s, sw, w);
|
||||
draw_bounds_template(g, rc,
|
||||
nw, n, ne, e,
|
||||
se, s, sw, w);
|
||||
}
|
||||
|
||||
void SkinTheme::draw_bounds_nw(BITMAP* bmp, int x1, int y1, int x2, int y2, int nw, ui::Color bg)
|
||||
@ -2377,6 +2377,23 @@ void SkinTheme::drawProgressBar(BITMAP* bmp, int x1, int y1, int x2, int y2, flo
|
||||
ui::to_system(getColor(ThemeColor::Background)));
|
||||
}
|
||||
|
||||
void SkinTheme::paintProgressBar(ui::Graphics* g, const gfx::Rect& rc0, float progress)
|
||||
{
|
||||
g->drawRect(getColor(ThemeColor::Text), rc0);
|
||||
|
||||
gfx::Rect rc = rc0;
|
||||
rc.shrink(1);
|
||||
|
||||
int u = (int)((float)rc.w*progress);
|
||||
u = MID(0, u, rc.w);
|
||||
|
||||
if (u > 0)
|
||||
g->fillRect(getColor(ThemeColor::Selected), gfx::Rect(rc.x, rc.y, u, rc.h));
|
||||
|
||||
if (1+u < rc.w)
|
||||
g->fillRect(getColor(ThemeColor::Background), gfx::Rect(rc.x+u, rc.y, rc.w-u, rc.h));
|
||||
}
|
||||
|
||||
void SkinTheme::paintIcon(Widget* widget, Graphics* g, IButtonIcon* iconInterface, int x, int y)
|
||||
{
|
||||
BITMAP* icon_bmp = NULL;
|
||||
|
@ -165,7 +165,7 @@ namespace app {
|
||||
gfx::Size get_part_size(int part_i) const;
|
||||
|
||||
// helper functions to draw bounds/hlines with sheet parts
|
||||
void draw_bounds_array(BITMAP* bmp, int x1, int y1, int x2, int y2, int parts[8]);
|
||||
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);
|
||||
@ -181,6 +181,7 @@ namespace app {
|
||||
}
|
||||
|
||||
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) {
|
||||
return m_stylesheet.getStyle(id);
|
||||
|
@ -152,6 +152,8 @@ StatusBar::StatusBar()
|
||||
{
|
||||
m_instance = this;
|
||||
|
||||
setDoubleBuffered(true);
|
||||
|
||||
#define BUTTON_NEW(name, text, action) \
|
||||
{ \
|
||||
(name) = new Button(text); \
|
||||
@ -174,7 +176,7 @@ StatusBar::StatusBar()
|
||||
|
||||
// The extra pixel in left and right borders are necessary so
|
||||
// m_commandsBox and m_movePixelsBox do not overlap the upper-left
|
||||
// and upper-right pixels drawn in kPaintMessage message (see putpixels)
|
||||
// and upper-right pixels drawn in onPaint() event (see putpixels)
|
||||
jwidget_set_border(this, 1*jguiscale(), 0, 1*jguiscale(), 0);
|
||||
|
||||
// Construct the commands box
|
||||
@ -427,111 +429,6 @@ bool StatusBar::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type()) {
|
||||
|
||||
case kPaintMessage: {
|
||||
gfx::Rect clip = static_cast<PaintMessage*>(msg)->rect();
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
|
||||
ui::Color text_color = theme->getColor(ThemeColor::Text);
|
||||
ui::Color face_color = theme->getColor(ThemeColor::Face);
|
||||
Rect rc = getBounds();
|
||||
BITMAP* doublebuffer = create_bitmap(clip.w, clip.h);
|
||||
rc.offset(-clip.x, -clip.y);
|
||||
|
||||
clear_to_color(doublebuffer, to_system(face_color));
|
||||
|
||||
rc.shrink(Border(2*jguiscale(), 1*jguiscale(),
|
||||
2*jguiscale(), 2*jguiscale()));
|
||||
|
||||
int x = rc.x + 4*jguiscale();
|
||||
|
||||
// Color
|
||||
if (m_state == SHOW_COLOR) {
|
||||
// Draw eyedropper icon
|
||||
BITMAP* icon = theme->get_toolicon("eyedropper");
|
||||
if (icon) {
|
||||
set_alpha_blender();
|
||||
draw_trans_sprite(doublebuffer, icon,
|
||||
x, rc.y + rc.h/2 - icon->h/2);
|
||||
|
||||
x += icon->w + 4*jguiscale();
|
||||
}
|
||||
|
||||
// Draw color
|
||||
draw_color_button(doublebuffer, Rect(x, rc.y, 32*jguiscale(), rc.h),
|
||||
true, true, true, true,
|
||||
true, true, true, true,
|
||||
app_get_current_pixel_format(), m_color,
|
||||
false, false);
|
||||
|
||||
x += (32+4)*jguiscale();
|
||||
|
||||
// Draw color description
|
||||
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);
|
||||
str += buf;
|
||||
}
|
||||
|
||||
textout_ex(doublebuffer, this->getFont(), str.c_str(),
|
||||
x, rc.y + rc.h/2 - text_height(this->getFont())/2,
|
||||
to_system(text_color), -1);
|
||||
|
||||
x += ji_font_text_len(this->getFont(), 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());
|
||||
if (icon) {
|
||||
set_alpha_blender();
|
||||
draw_trans_sprite(doublebuffer, icon, x, rc.y + rc.h/2 - icon->h/2);
|
||||
x += icon->w + 4*jguiscale();
|
||||
}
|
||||
}
|
||||
|
||||
// Status bar text
|
||||
if (getTextSize() > 0) {
|
||||
textout_ex(doublebuffer, getFont(), getText().c_str(),
|
||||
x,
|
||||
rc.y + rc.h/2 - text_height(getFont())/2,
|
||||
to_system(text_color), -1);
|
||||
|
||||
x += ji_font_text_len(getFont(), getText().c_str()) + 4*jguiscale();
|
||||
}
|
||||
|
||||
// Draw progress bar
|
||||
if (!m_progress.empty()) {
|
||||
int width = 64;
|
||||
int y1, y2;
|
||||
int x = rc.x2() - (width+4);
|
||||
|
||||
y1 = rc.y;
|
||||
y2 = rc.y2()-1;
|
||||
|
||||
for (ProgressList::iterator it = m_progress.begin(); it != m_progress.end(); ++it) {
|
||||
Progress* progress = *it;
|
||||
|
||||
theme->drawProgressBar(doublebuffer,
|
||||
x, y1, x+width-1, y2,
|
||||
progress->getPos());
|
||||
|
||||
x -= width+4;
|
||||
}
|
||||
}
|
||||
|
||||
updateSubwidgetsVisibility();
|
||||
|
||||
blit(doublebuffer, ji_screen, 0, 0,
|
||||
clip.x,
|
||||
clip.y,
|
||||
doublebuffer->w,
|
||||
doublebuffer->h);
|
||||
destroy_bitmap(doublebuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
case kMouseEnterMessage: {
|
||||
updateSubwidgetsVisibility();
|
||||
|
||||
@ -580,6 +477,90 @@ void StatusBar::onPreferredSize(PreferredSizeEvent& ev)
|
||||
ev.setPreferredSize(Size(s, s));
|
||||
}
|
||||
|
||||
void StatusBar::onPaint(ui::PaintEvent& ev)
|
||||
{
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
|
||||
ui::Color text_color = theme->getColor(ThemeColor::Text);
|
||||
ui::Color face_color = theme->getColor(ThemeColor::Face);
|
||||
Rect rc = getClientBounds();
|
||||
Graphics* g = ev.getGraphics();
|
||||
|
||||
g->fillRect(face_color, rc);
|
||||
|
||||
rc.shrink(Border(2, 1, 2, 2)*jguiscale());
|
||||
|
||||
int x = rc.x + 4*jguiscale();
|
||||
|
||||
// Color
|
||||
if (m_state == SHOW_COLOR) {
|
||||
// Draw eyedropper icon
|
||||
BITMAP* icon = theme->get_toolicon("eyedropper");
|
||||
if (icon) {
|
||||
g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2);
|
||||
x += icon->w + 4*jguiscale();
|
||||
}
|
||||
|
||||
// Draw color
|
||||
draw_color_button(g, gfx::Rect(x, rc.y, 32*jguiscale(), rc.h),
|
||||
true, true, true, true,
|
||||
true, true, true, true,
|
||||
app_get_current_pixel_format(), m_color,
|
||||
false, false);
|
||||
|
||||
x += (32+4)*jguiscale();
|
||||
|
||||
// Draw color description
|
||||
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);
|
||||
str += buf;
|
||||
}
|
||||
|
||||
g->drawString(str, text_color, ColorNone, false,
|
||||
gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2));
|
||||
|
||||
x += ji_font_text_len(getFont(), 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());
|
||||
if (icon) {
|
||||
g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2);
|
||||
x += icon->w + 4*jguiscale();
|
||||
}
|
||||
}
|
||||
|
||||
// Status bar text
|
||||
if (getTextSize() > 0) {
|
||||
g->drawString(getText(), text_color, ColorNone, false,
|
||||
gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2));
|
||||
|
||||
x += ji_font_text_len(getFont(), getText().c_str()) + 4*jguiscale();
|
||||
}
|
||||
|
||||
// Draw progress bar
|
||||
if (!m_progress.empty()) {
|
||||
int width = 64;
|
||||
int x = rc.x2() - (width+4);
|
||||
|
||||
for (ProgressList::iterator it = m_progress.begin(); it != m_progress.end(); ++it) {
|
||||
Progress* progress = *it;
|
||||
|
||||
theme->paintProgressBar(g,
|
||||
gfx::Rect(x, rc.y, width, rc.h),
|
||||
progress->getPos());
|
||||
|
||||
x -= width+4;
|
||||
}
|
||||
}
|
||||
|
||||
updateSubwidgetsVisibility();
|
||||
}
|
||||
|
||||
bool StatusBar::CustomizedTipWindow::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type()) {
|
||||
|
@ -86,6 +86,7 @@ namespace app {
|
||||
bool onProcessMessage(ui::Message* msg) OVERRIDE;
|
||||
void onResize(ui::ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(ui::PreferredSizeEvent& ev) OVERRIDE;
|
||||
void onPaint(ui::PaintEvent& ev) OVERRIDE;
|
||||
|
||||
private:
|
||||
void onCurrentToolChange();
|
||||
|
@ -77,6 +77,15 @@ void Graphics::drawVLine(ui::Color color, int x, int y, int h)
|
||||
m_dy+y+h-1, to_system(color));
|
||||
}
|
||||
|
||||
void Graphics::drawLine(ui::Color color, const gfx::Point& a, const gfx::Point& b)
|
||||
{
|
||||
line(m_bmp,
|
||||
m_dx+a.x,
|
||||
m_dy+a.y,
|
||||
m_dx+b.x,
|
||||
m_dy+b.y, to_system(color));
|
||||
}
|
||||
|
||||
void Graphics::drawRect(ui::Color color, const gfx::Rect& rc)
|
||||
{
|
||||
rect(m_bmp,
|
||||
|
@ -32,6 +32,7 @@ namespace ui {
|
||||
|
||||
void drawHLine(ui::Color color, int x, int y, int w);
|
||||
void drawVLine(ui::Color color, int x, int y, int h);
|
||||
void drawLine(ui::Color color, const gfx::Point& a, const gfx::Point& b);
|
||||
|
||||
void drawRect(ui::Color color, const gfx::Rect& rc);
|
||||
void fillRect(ui::Color color, const gfx::Rect& rc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user