From 629c3596276827be83e65449c01f0603f7e91c57 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 30 May 2017 13:52:53 -0300 Subject: [PATCH] Draw alpha slider in ColorSliders correctly --- src/app/modules/gfx.cpp | 44 +++++++++++++++++++++++++++++++---- src/app/modules/gfx.h | 6 ++++- src/app/ui/color_selector.cpp | 31 ++++-------------------- src/app/ui/color_sliders.cpp | 8 ++++++- 4 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/app/modules/gfx.cpp b/src/app/modules/gfx.cpp index 976a88b91..34beb14d8 100644 --- a/src/app/modules/gfx.cpp +++ b/src/app/modules/gfx.cpp @@ -21,16 +21,25 @@ #include "app/modules/palettes.h" #include "app/ui/editor/editor.h" #include "app/ui/skin/skin_theme.h" -#include "gfx/point.h" -#include "gfx/rect.h" +#include "doc/blend_funcs.h" #include "doc/image.h" #include "doc/palette.h" +#include "gfx/point.h" +#include "gfx/rect.h" namespace app { using namespace app::skin; using namespace gfx; +namespace { + +// TODO hard-coded values, use pref.xml values +gfx::Color gridColor1 = gfx::rgba(128, 128, 128); +gfx::Color gridColor2 = gfx::rgba(192, 192, 192); + +} // anonymous namespace + static void rectgrid(ui::Graphics* g, const gfx::Rect& rc, const gfx::Size& tile) { if (tile.w < 1 || tile.h < 1) @@ -38,9 +47,8 @@ static void rectgrid(ui::Graphics* g, const gfx::Rect& rc, const gfx::Size& tile int x, y, u, v; - // TODO these values are hard-coded in ColorSelector::onPaintAlphaBar() too, use pref.xml values - gfx::Color c1 = gfx::rgba(128, 128, 128); - gfx::Color c2 = gfx::rgba(192, 192, 192); + const gfx::Color c1 = gridColor1; + const gfx::Color c2 = gridColor2; u = 0; v = 0; @@ -147,4 +155,30 @@ void draw_color_button(ui::Graphics* g, } } +void draw_alpha_slider(ui::Graphics* g, + const gfx::Rect& rc, + const app::Color& color) +{ + const int xmax = MAX(1, rc.w-1); + const doc::color_t c = + (color.getType() != app::Color::MaskType ? + doc::rgba(color.getRed(), + color.getGreen(), + color.getBlue(), 255): 0); + + for (int x=0; xdrawVLine( + app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c2: c1)), + rc.x+x, rc.y, mid); + g->drawVLine( + app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c1: c2)), + rc.x+x, rc.y+mid, rc.h-mid); + } +} + } // namespace app diff --git a/src/app/modules/gfx.h b/src/app/modules/gfx.h index 7a9de202c..4efe54a7d 100644 --- a/src/app/modules/gfx.h +++ b/src/app/modules/gfx.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -30,6 +30,10 @@ namespace app { const bool hot, const bool drag); + void draw_alpha_slider(ui::Graphics* g, + const gfx::Rect& rc, + const app::Color& color); + } // namespace app #endif diff --git a/src/app/ui/color_selector.cpp b/src/app/ui/color_selector.cpp index 9307a4137..bb584b61a 100644 --- a/src/app/ui/color_selector.cpp +++ b/src/app/ui/color_selector.cpp @@ -11,10 +11,10 @@ #include "app/ui/color_selector.h" #include "app/color_utils.h" +#include "app/modules/gfx.h" #include "app/ui/skin/skin_theme.h" #include "app/ui/status_bar.h" #include "base/scoped_value.h" -#include "doc/blend_funcs.h" #include "she/surface.h" #include "ui/manager.h" #include "ui/message.h" @@ -202,32 +202,11 @@ void ColorSelector::onPaint(ui::PaintEvent& ev) void ColorSelector::onPaintAlphaBar(ui::Graphics* g, const gfx::Rect& rc) { - const int xmax = MAX(1, rc.w-1); + draw_alpha_slider(g, rc, m_color); + const int alpha = m_color.getAlpha(); - const doc::color_t c = - (m_color.getType() != app::Color::MaskType ? - doc::rgba(m_color.getRed(), - m_color.getGreen(), - m_color.getBlue(), 255): 0); - - for (int x=0; xdrawVLine( - app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c2: c1)), - rc.x+x, rc.y, mid); - g->drawVLine( - app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c1: c2)), - rc.x+x, rc.y+mid, rc.h-mid); - } - - gfx::Point pos(rc.x + int(rc.w * alpha / 255), - rc.y + rc.h/2); + const gfx::Point pos(rc.x + int(rc.w * alpha / 255), + rc.y + rc.h/2); paintColorIndicator(g, pos, false); } diff --git a/src/app/ui/color_sliders.cpp b/src/app/ui/color_sliders.cpp index 5ff76ba15..e874d0679 100644 --- a/src/app/ui/color_sliders.cpp +++ b/src/app/ui/color_sliders.cpp @@ -9,6 +9,7 @@ #endif #include "app/color_utils.h" +#include "app/modules/gfx.h" #include "app/ui/color_sliders.h" #include "app/ui/skin/skin_slider_property.h" #include "app/ui/skin/skin_theme.h" @@ -48,6 +49,12 @@ namespace { } void paint(Slider* slider, Graphics* g, const gfx::Rect& rc) { + // Special alpha bar (with two vertical lines) + if (m_channel == ColorSliders::Alpha) { + draw_alpha_slider(g, rc, m_color); + return; + } + gfx::Color color = gfx::ColorNone; int w = MAX(rc.w-1, 1); @@ -102,7 +109,6 @@ namespace { break; case ColorSliders::Gray: - case ColorSliders::Alpha: color = color_utils::color_for_ui( app::Color::fromGray(255 * x / w)); break;