mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-02 11:59:58 +00:00
Draw alpha slider in ColorSliders correctly
This commit is contained in:
parent
1576e42ff2
commit
629c359627
@ -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; x<rc.w; ++x) {
|
||||
const int a = (255 * x / xmax);
|
||||
const doc::color_t c1 = doc::rgba_blender_normal(gridColor1, c, a);
|
||||
const doc::color_t c2 = doc::rgba_blender_normal(gridColor2, c, a);
|
||||
const int mid = rc.h/2;
|
||||
const int odd = (x / rc.h) & 1;
|
||||
g->drawVLine(
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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; x<rc.w; ++x) {
|
||||
const int a = (255 * x / xmax);
|
||||
|
||||
// TODO These values are hard-coded in rectgrid() (modules/gfx.cpp) too, use pref.xml values
|
||||
const doc::color_t c1 = doc::rgba_blender_normal(gfx::rgba(128, 128, 128), c, a);
|
||||
const doc::color_t c2 = doc::rgba_blender_normal(gfx::rgba(192, 192, 192), c, a);
|
||||
const int mid = rc.h/2;
|
||||
const int odd = (x / rc.h) & 1;
|
||||
g->drawVLine(
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user