mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-16 23:42:57 +00:00
New simplified color-bar (still WIP).
This commit is contained in:
parent
2e6ac640d6
commit
62d0c1db1d
@ -99,6 +99,16 @@
|
||||
<part id="tab_filler" x="0" y="112" w="2" h="12" />
|
||||
<part id="editor_normal" x="32" y="112" w1="3" w2="10" w3="3" h1="3" h2="10" h3="3" />
|
||||
<part id="editor_selected" x="48" y="112" w1="3" w2="10" w3="3" h1="3" h2="10" h3="3" />
|
||||
<part id="colorbar_0" x="0" y="192" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
<part id="colorbar_1" x="16" y="192" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
<part id="colorbar_2" x="0" y="208" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
<part id="colorbar_3" x="16" y="208" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
<part id="colorbar_border_0" x="32" y="192" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
<part id="colorbar_border_1" x="48" y="192" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
<part id="colorbar_border_2" x="32" y="208" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
<part id="colorbar_border_3" x="48" y="208" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
<part id="colorbar_border_fg" x="0" y="224" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
<part id="colorbar_border_bg" x="16" y="224" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
|
||||
</parts>
|
||||
|
||||
</skin>
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.9 KiB |
@ -27,6 +27,7 @@
|
||||
#include "jinete/jrect.h"
|
||||
|
||||
#include "Vaca/Rect.h"
|
||||
#include "Vaca/Point.h"
|
||||
|
||||
#include "console.h"
|
||||
#include "app.h"
|
||||
@ -35,11 +36,13 @@
|
||||
#include "modules/gfx.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/palettes.h"
|
||||
#include "modules/skinneable_theme.h"
|
||||
#include "raster/blend.h"
|
||||
#include "raster/image.h"
|
||||
#include "widgets/editor.h"
|
||||
|
||||
using Vaca::Rect;
|
||||
using Vaca::Point;
|
||||
|
||||
static BITMAP* gfx_bmps[GFX_BITMAP_COUNT];
|
||||
|
||||
@ -420,18 +423,15 @@ void draw_emptyset_symbol(const Rect& rc, int color)
|
||||
center.x+size/2, center.y-size/2, color);
|
||||
}
|
||||
|
||||
void draw_color(BITMAP* bmp, int x1, int y1, int x2, int y2,
|
||||
int imgtype, color_t color)
|
||||
void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, color_t color)
|
||||
{
|
||||
int type = color_type(color);
|
||||
int data;
|
||||
int w = x2 - x1 + 1;
|
||||
int h = y2 - y1 + 1;
|
||||
BITMAP* graph;
|
||||
|
||||
if (type == COLOR_TYPE_INDEX) {
|
||||
data = color_get_index(imgtype, color);
|
||||
rectfill(bmp, x1, y1, x2, y2,
|
||||
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1,
|
||||
/* get_color_for_allegro(bitmap_color_depth(bmp), color)); */
|
||||
palette_color[data]);
|
||||
return;
|
||||
@ -440,12 +440,12 @@ void draw_color(BITMAP* bmp, int x1, int y1, int x2, int y2,
|
||||
switch (imgtype) {
|
||||
|
||||
case IMAGE_INDEXED:
|
||||
rectfill(bmp, x1, y1, x2, y2,
|
||||
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1,
|
||||
palette_color[get_color_for_image(imgtype, color)]);
|
||||
break;
|
||||
|
||||
case IMAGE_RGB:
|
||||
graph = create_bitmap_ex(32, w, h);
|
||||
graph = create_bitmap_ex(32, rc.w, rc.h);
|
||||
if (!graph)
|
||||
return;
|
||||
|
||||
@ -454,31 +454,31 @@ void draw_color(BITMAP* bmp, int x1, int y1, int x2, int y2,
|
||||
color_t color2 = color_rgb(_rgba_getr(rgb_bitmap_color),
|
||||
_rgba_getg(rgb_bitmap_color),
|
||||
_rgba_getb(rgb_bitmap_color));
|
||||
rectfill(graph, 0, 0, w-1, h-1, get_color_for_allegro(32, color2));
|
||||
rectfill(graph, 0, 0, rc.w-1, rc.h-1, get_color_for_allegro(32, color2));
|
||||
}
|
||||
|
||||
{
|
||||
CurrentSpriteRgbMap rgbmap;
|
||||
blit(graph, bmp, 0, 0, x1, y1, w, h);
|
||||
blit(graph, bmp, 0, 0, rc.x, rc.y, rc.w, rc.h);
|
||||
}
|
||||
|
||||
destroy_bitmap(graph);
|
||||
break;
|
||||
|
||||
case IMAGE_GRAYSCALE:
|
||||
graph = create_bitmap_ex(32, w, h);
|
||||
graph = create_bitmap_ex(32, rc.w, rc.h);
|
||||
if (!graph)
|
||||
return;
|
||||
|
||||
{
|
||||
int gray_bitmap_color = get_color_for_image(imgtype, color);
|
||||
color_t color2 = color_gray(_graya_getv(gray_bitmap_color));
|
||||
rectfill(graph, 0, 0, w-1, h-1, get_color_for_allegro(32, color2));
|
||||
rectfill(graph, 0, 0, rc.w-1, rc.h-1, get_color_for_allegro(32, color2));
|
||||
}
|
||||
|
||||
{
|
||||
CurrentSpriteRgbMap rgbmap;
|
||||
blit(graph, bmp, 0, 0, x1, y1, w, h);
|
||||
blit(graph, bmp, 0, 0, rc.x, rc.y, rc.w, rc.h);
|
||||
}
|
||||
|
||||
destroy_bitmap(graph);
|
||||
@ -487,67 +487,72 @@ void draw_color(BITMAP* bmp, int x1, int y1, int x2, int y2,
|
||||
}
|
||||
|
||||
void draw_color_button(BITMAP* bmp,
|
||||
int x1, int y1, int x2, int y2,
|
||||
int b0, int b1, int b2, int b3,
|
||||
int imgtype, color_t color,
|
||||
bool hot, bool drag,
|
||||
int bg)
|
||||
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,
|
||||
int imgtype, color_t color, bool hot, bool drag)
|
||||
{
|
||||
SkinneableTheme* theme = (SkinneableTheme*)ji_get_theme();
|
||||
int fore = ji_color_foreground();
|
||||
int scale = jguiscale();
|
||||
|
||||
draw_color(bmp, x1, y1, x2, y2, imgtype, color);
|
||||
// Draw background (the color)
|
||||
draw_color(bmp,
|
||||
Rect(rc.x+1*jguiscale(),
|
||||
rc.y+1*jguiscale(),
|
||||
rc.w-((outer_e) ? 2*jguiscale(): 1*jguiscale()),
|
||||
rc.h-((outer_s) ? 2*jguiscale(): 1*jguiscale())), imgtype, color);
|
||||
|
||||
hline(bmp, x1, y1, x2, fore);
|
||||
if (b2 && b3)
|
||||
hline(bmp, x1, y2, x2, fore);
|
||||
vline(bmp, x1, y1, y2, fore);
|
||||
vline(bmp, x2, y1, y2, fore);
|
||||
|
||||
if (!hot) {
|
||||
int r = color_get_red(imgtype, color);
|
||||
int g = color_get_green(imgtype, color);
|
||||
int b = color_get_blue(imgtype, color);
|
||||
int c = makecol(MIN(255, r+64),
|
||||
MIN(255, g+64),
|
||||
MIN(255, b+64));
|
||||
rect(bmp, x1+1, y1+1, x2-1, y2-((b2 && b3)?1:0), c);
|
||||
}
|
||||
else {
|
||||
rect(bmp, x1+1, y1+1, x2-1, y2-((b2 && b3)?1:0), fore);
|
||||
bevel_box(bmp,
|
||||
x1+1, y1+1, x2-1, y2-((b2 && b3)?1:0),
|
||||
ji_color_facelight(), ji_color_faceshadow(), 1);
|
||||
// Draw opaque border
|
||||
{
|
||||
int parts[8] = {
|
||||
outer_nw ? PART_COLORBAR_0_NW: PART_COLORBAR_3_NW,
|
||||
outer_n ? PART_COLORBAR_0_N : PART_COLORBAR_2_N,
|
||||
outer_ne ? PART_COLORBAR_1_NE: (outer_e ? PART_COLORBAR_3_NE: PART_COLORBAR_2_NE),
|
||||
outer_e ? PART_COLORBAR_1_E : PART_COLORBAR_0_E,
|
||||
outer_se ? PART_COLORBAR_3_SE: (outer_s ? PART_COLORBAR_2_SE: (outer_e ? PART_COLORBAR_1_SE: PART_COLORBAR_0_SE)),
|
||||
outer_s ? PART_COLORBAR_2_S : PART_COLORBAR_0_S,
|
||||
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,
|
||||
};
|
||||
BITMAP* old_ji_screen = ji_screen; // TODO fix this ugly hack
|
||||
ji_screen = bmp;
|
||||
theme->draw_bounds0(rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, parts);
|
||||
ji_screen = old_ji_screen;
|
||||
}
|
||||
|
||||
if (b0) {
|
||||
hline(bmp, x1, y1, x1+1, bg);
|
||||
putpixel(bmp, x1, y1+1, bg);
|
||||
putpixel(bmp, x1+1, y1+1, fore);
|
||||
// Draw transparent border
|
||||
set_trans_blender(0, 0, 0, 128);
|
||||
{
|
||||
SkinneableTheme* theme = (SkinneableTheme*)ji_get_theme();
|
||||
int parts[8] = {
|
||||
outer_nw ? PART_COLORBAR_BORDER_0_NW: PART_COLORBAR_BORDER_3_NW,
|
||||
outer_n ? PART_COLORBAR_BORDER_0_N : PART_COLORBAR_BORDER_2_N,
|
||||
outer_ne ? PART_COLORBAR_BORDER_1_NE: (outer_e ? PART_COLORBAR_BORDER_3_NE: PART_COLORBAR_BORDER_2_NE),
|
||||
outer_e ? PART_COLORBAR_BORDER_1_E : PART_COLORBAR_BORDER_0_E,
|
||||
outer_se ? PART_COLORBAR_BORDER_3_SE: (outer_s ? PART_COLORBAR_BORDER_2_SE: (outer_e ? PART_COLORBAR_BORDER_1_SE: PART_COLORBAR_BORDER_0_SE)),
|
||||
outer_s ? PART_COLORBAR_BORDER_2_S : PART_COLORBAR_BORDER_0_S,
|
||||
outer_sw ? PART_COLORBAR_BORDER_2_SW: (outer_s ? PART_COLORBAR_BORDER_3_SW: PART_COLORBAR_BORDER_1_SW),
|
||||
outer_w ? PART_COLORBAR_BORDER_0_W : PART_COLORBAR_BORDER_1_W,
|
||||
};
|
||||
BITMAP* old_ji_screen = ji_screen; // TODO fix this ugly hack
|
||||
ji_screen = bmp;
|
||||
theme->draw_trans_bounds0(rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, parts);
|
||||
ji_screen = old_ji_screen;
|
||||
}
|
||||
set_trans_blender(0, 0, 0, 0);
|
||||
|
||||
if (b1) {
|
||||
hline(bmp, x2-1, y1, x2, bg);
|
||||
putpixel(bmp, x2, y1+1, bg);
|
||||
putpixel(bmp, x2-1, y1+1, fore);
|
||||
}
|
||||
|
||||
if (b2) {
|
||||
putpixel(bmp, x1, y2-1, bg);
|
||||
hline(bmp, x1, y2, x1+1, bg);
|
||||
putpixel(bmp, x1+1, y2-1, fore);
|
||||
}
|
||||
|
||||
if (b3) {
|
||||
putpixel(bmp, x2, y2-1, bg);
|
||||
hline(bmp, x2-1, y2, x2, bg);
|
||||
putpixel(bmp, x2-1, y2-1, fore);
|
||||
}
|
||||
|
||||
if (drag) {
|
||||
rect(bmp, x1+2, y1+2, x2-2, y2-2,
|
||||
blackandwhite_neg(color_get_red(imgtype, color),
|
||||
color_get_green(imgtype, color),
|
||||
color_get_blue(imgtype, color)));
|
||||
// Draw hot
|
||||
if (hot) {
|
||||
set_trans_blender(0, 0, 0, 128);
|
||||
BITMAP* old_ji_screen = ji_screen; // TODO fix this ugly hack
|
||||
ji_screen = bmp;
|
||||
theme->draw_trans_bounds(rc.x, rc.y,
|
||||
rc.x+rc.w-1,
|
||||
rc.y+rc.h-1 - (outer_s ? 1*scale: 0),
|
||||
PART_COLORBAR_BORDER_FG_NW);
|
||||
ji_screen = old_ji_screen;
|
||||
set_trans_blender(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,14 +115,13 @@ void rectdotted(BITMAP* bmp, int x1, int y1, int x2, int y2, int fg, int bg);
|
||||
void rectgrid(BITMAP* bmp, int x1, int y1, int x2, int y2, int w, int h);
|
||||
|
||||
void draw_emptyset_symbol(const Rect& rc, int color);
|
||||
void draw_color(BITMAP* bmp, int x1, int y1, int x2, int y2,
|
||||
int imgtype, color_t color);
|
||||
void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, color_t color);
|
||||
void draw_color_button(BITMAP* bmp,
|
||||
int x1, int y1, int x2, int y2,
|
||||
int b0, int b1, int b2, int b3,
|
||||
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,
|
||||
int imgtype, color_t color,
|
||||
bool hot, bool drag,
|
||||
int bg);
|
||||
bool hot, bool drag);
|
||||
void draw_progress_bar(BITMAP* bmp,
|
||||
int x1, int y1, int x2, int y2,
|
||||
float progress);
|
||||
|
@ -126,6 +126,16 @@ SkinneableTheme::SkinneableTheme()
|
||||
sheet_mapping["tab_filler"] = PART_TAB_FILLER;
|
||||
sheet_mapping["editor_normal"] = PART_EDITOR_NORMAL_NW;
|
||||
sheet_mapping["editor_selected"] = PART_EDITOR_SELECTED_NW;
|
||||
sheet_mapping["colorbar_0"] = PART_COLORBAR_0_NW;
|
||||
sheet_mapping["colorbar_1"] = PART_COLORBAR_1_NW;
|
||||
sheet_mapping["colorbar_2"] = PART_COLORBAR_2_NW;
|
||||
sheet_mapping["colorbar_3"] = PART_COLORBAR_3_NW;
|
||||
sheet_mapping["colorbar_border_0"] = PART_COLORBAR_BORDER_0_NW;
|
||||
sheet_mapping["colorbar_border_1"] = PART_COLORBAR_BORDER_1_NW;
|
||||
sheet_mapping["colorbar_border_2"] = PART_COLORBAR_BORDER_2_NW;
|
||||
sheet_mapping["colorbar_border_3"] = PART_COLORBAR_BORDER_3_NW;
|
||||
sheet_mapping["colorbar_border_fg"] = PART_COLORBAR_BORDER_FG_NW;
|
||||
sheet_mapping["colorbar_border_bg"] = PART_COLORBAR_BORDER_BG_NW;
|
||||
|
||||
// Load the skin sheet
|
||||
{
|
||||
@ -1473,71 +1483,100 @@ BITMAP* SkinneableTheme::get_toolicon(const char* tool_id) const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define draw_bounds_template(_nw, _n, _ne, _e, _se, _s, _sw, _w, draw_func) \
|
||||
{ \
|
||||
int x, y; \
|
||||
int cx1, cy1, cx2, cy2; \
|
||||
get_clip_rect(ji_screen, &cx1, &cy1, &cx2, &cy2); \
|
||||
\
|
||||
/* top */ \
|
||||
\
|
||||
draw_func(ji_screen, m_part[_nw], x1, y1); \
|
||||
\
|
||||
if (my_add_clip_rect(ji_screen, \
|
||||
x1+m_part[_nw]->w, y1, \
|
||||
x2-m_part[_ne]->w, y2)) { \
|
||||
for (x = x1+m_part[_nw]->w; \
|
||||
x <= x2-m_part[_ne]->w; \
|
||||
x += m_part[_n]->w) { \
|
||||
draw_func(ji_screen, m_part[_n], x, y1); \
|
||||
} \
|
||||
} \
|
||||
set_clip_rect(ji_screen, cx1, cy1, cx2, cy2); \
|
||||
\
|
||||
draw_func(ji_screen, m_part[_ne], x2-m_part[_ne]->w+1, y1); \
|
||||
\
|
||||
/* bottom */ \
|
||||
\
|
||||
draw_func(ji_screen, m_part[_sw], x1, y2-m_part[_sw]->h+1); \
|
||||
\
|
||||
if (my_add_clip_rect(ji_screen, \
|
||||
x1+m_part[_sw]->w, y1, \
|
||||
x2-m_part[_se]->w, y2)) { \
|
||||
for (x = x1+m_part[_sw]->w; \
|
||||
x <= x2-m_part[_se]->w; \
|
||||
x += m_part[_s]->w) { \
|
||||
draw_func(ji_screen, m_part[_s], x, y2-m_part[_s]->h+1); \
|
||||
} \
|
||||
} \
|
||||
set_clip_rect(ji_screen, cx1, cy1, cx2, cy2); \
|
||||
\
|
||||
draw_func(ji_screen, m_part[_se], x2-m_part[_se]->w+1, y2-m_part[_se]->h+1); \
|
||||
\
|
||||
if (my_add_clip_rect(ji_screen, \
|
||||
x1, y1+m_part[_nw]->h, \
|
||||
x2, y2-m_part[_sw]->h)) { \
|
||||
/* left */ \
|
||||
for (y = y1+m_part[_nw]->h; \
|
||||
y <= y2-m_part[_sw]->h; \
|
||||
y += m_part[_w]->h) { \
|
||||
draw_func(ji_screen, m_part[_w], x1, y); \
|
||||
} \
|
||||
\
|
||||
/* right */ \
|
||||
for (y = y1+m_part[_ne]->h; \
|
||||
y <= y2-m_part[_se]->h; \
|
||||
y += m_part[_e]->h) { \
|
||||
draw_func(ji_screen, m_part[_e], x2-m_part[_e]->w+1, y); \
|
||||
} \
|
||||
} \
|
||||
set_clip_rect(ji_screen, cx1, cy1, cx2, cy2); \
|
||||
}
|
||||
|
||||
void SkinneableTheme::draw_bounds0(int x1, int y1, int x2, int y2, int parts[8])
|
||||
{
|
||||
int nw = parts[0];
|
||||
int n = parts[1];
|
||||
int ne = parts[2];
|
||||
int e = parts[3];
|
||||
int se = parts[4];
|
||||
int s = parts[5];
|
||||
int sw = parts[6];
|
||||
int w = parts[7];
|
||||
|
||||
draw_bounds_template(nw, n, ne, e, se, s, sw, w, draw_sprite);
|
||||
}
|
||||
|
||||
void SkinneableTheme::draw_trans_bounds0(int x1, int y1, int x2, int y2, int parts[8])
|
||||
{
|
||||
int nw = parts[0];
|
||||
int n = parts[1];
|
||||
int ne = parts[2];
|
||||
int e = parts[3];
|
||||
int se = parts[4];
|
||||
int s = parts[5];
|
||||
int sw = parts[6];
|
||||
int w = parts[7];
|
||||
|
||||
draw_bounds_template(nw, n, ne, e, se, s, sw, w, draw_trans_sprite);
|
||||
}
|
||||
|
||||
void SkinneableTheme::draw_bounds(int x1, int y1, int x2, int y2, int nw, int bg)
|
||||
{
|
||||
int cx1, cy1, cx2, cy2;
|
||||
get_clip_rect(ji_screen, &cx1, &cy1, &cx2, &cy2);
|
||||
draw_bounds_template(nw+0, nw+1, nw+2, nw+3,
|
||||
nw+4, nw+5, nw+6, nw+7, draw_sprite);
|
||||
|
||||
int x, y;
|
||||
|
||||
// top
|
||||
|
||||
draw_sprite(ji_screen, m_part[nw], x1, y1);
|
||||
|
||||
if (my_add_clip_rect(ji_screen,
|
||||
x1+m_part[nw]->w, y1,
|
||||
x2-m_part[nw+2]->w, y2)) {
|
||||
for (x = x1+m_part[nw]->w;
|
||||
x < x2-m_part[nw+2]->w-m_part[nw+1]->w+1;
|
||||
x += m_part[nw+1]->w) {
|
||||
draw_sprite(ji_screen, m_part[nw+1], x, y1);
|
||||
}
|
||||
draw_sprite(ji_screen, m_part[nw+1], x2-m_part[nw+2]->w-m_part[nw+1]->w+1, y1);
|
||||
}
|
||||
set_clip_rect(ji_screen, cx1, cy1, cx2, cy2);
|
||||
|
||||
draw_sprite(ji_screen, m_part[nw+2], x2-m_part[nw+2]->w+1, y1);
|
||||
|
||||
// bottom
|
||||
|
||||
draw_sprite(ji_screen, m_part[nw+6], x1, y2-m_part[nw+6]->h+1);
|
||||
|
||||
if (my_add_clip_rect(ji_screen,
|
||||
x1+m_part[nw+6]->w, y1,
|
||||
x2-m_part[nw+4]->w, y2)) {
|
||||
for (x = x1+m_part[nw+6]->w;
|
||||
x < x2-m_part[nw+4]->w-m_part[nw+5]->w+1;
|
||||
x += m_part[nw+5]->w) {
|
||||
draw_sprite(ji_screen, m_part[nw+5], x, y2-m_part[nw+5]->h+1);
|
||||
}
|
||||
draw_sprite(ji_screen, m_part[nw+5], x2-m_part[nw+4]->w-m_part[nw+5]->w+1, y2-m_part[nw+5]->h+1);
|
||||
}
|
||||
set_clip_rect(ji_screen, cx1, cy1, cx2, cy2);
|
||||
|
||||
draw_sprite(ji_screen, m_part[nw+4], x2-m_part[nw+4]->w+1, y2-m_part[nw+4]->h+1);
|
||||
|
||||
if (my_add_clip_rect(ji_screen,
|
||||
x1, y1+m_part[nw]->h,
|
||||
x2, y2-m_part[nw+6]->h)) {
|
||||
// left
|
||||
for (y = y1+m_part[nw]->h;
|
||||
y < y2-m_part[nw+6]->h-m_part[nw+7]->h+1;
|
||||
y += m_part[nw+7]->h) {
|
||||
draw_sprite(ji_screen, m_part[nw+7], x1, y);
|
||||
}
|
||||
draw_sprite(ji_screen, m_part[nw+7], x1, y2-m_part[nw+6]->h-m_part[nw+7]->h+1);
|
||||
|
||||
// right
|
||||
for (y = y1+m_part[nw+2]->h;
|
||||
y < y2-m_part[nw+4]->h-m_part[nw+3]->h+1;
|
||||
y += m_part[nw+3]->h) {
|
||||
draw_sprite(ji_screen, m_part[nw+3], x2-m_part[nw+3]->w+1, y);
|
||||
}
|
||||
draw_sprite(ji_screen, m_part[nw+3], x2-m_part[nw+3]->w+1, y2-m_part[nw+4]->h-m_part[nw+3]->h+1);
|
||||
}
|
||||
set_clip_rect(ji_screen, cx1, cy1, cx2, cy2);
|
||||
|
||||
// background
|
||||
// Background
|
||||
if (bg >= 0) {
|
||||
x1 += m_part[nw+7]->w;
|
||||
y1 += m_part[nw+1]->h;
|
||||
@ -1548,6 +1587,12 @@ void SkinneableTheme::draw_bounds(int x1, int y1, int x2, int y2, int nw, int bg
|
||||
}
|
||||
}
|
||||
|
||||
void SkinneableTheme::draw_trans_bounds(int x1, int y1, int x2, int y2, int nw)
|
||||
{
|
||||
draw_bounds_template(nw+0, nw+1, nw+2, nw+3,
|
||||
nw+4, nw+5, nw+6, nw+7, draw_trans_sprite);
|
||||
}
|
||||
|
||||
void SkinneableTheme::draw_bounds2(int x1, int y1, int x2, int y2, int x_mid, int nw1, int nw2, int bg1, int bg2)
|
||||
{
|
||||
int cx1, cy1, cx2, cy2;
|
||||
|
@ -315,6 +315,96 @@ enum {
|
||||
PART_EDITOR_SELECTED_SW,
|
||||
PART_EDITOR_SELECTED_W,
|
||||
|
||||
PART_COLORBAR_0_NW,
|
||||
PART_COLORBAR_0_N,
|
||||
PART_COLORBAR_0_NE,
|
||||
PART_COLORBAR_0_E,
|
||||
PART_COLORBAR_0_SE,
|
||||
PART_COLORBAR_0_S,
|
||||
PART_COLORBAR_0_SW,
|
||||
PART_COLORBAR_0_W,
|
||||
|
||||
PART_COLORBAR_1_NW,
|
||||
PART_COLORBAR_1_N,
|
||||
PART_COLORBAR_1_NE,
|
||||
PART_COLORBAR_1_E,
|
||||
PART_COLORBAR_1_SE,
|
||||
PART_COLORBAR_1_S,
|
||||
PART_COLORBAR_1_SW,
|
||||
PART_COLORBAR_1_W,
|
||||
|
||||
PART_COLORBAR_2_NW,
|
||||
PART_COLORBAR_2_N,
|
||||
PART_COLORBAR_2_NE,
|
||||
PART_COLORBAR_2_E,
|
||||
PART_COLORBAR_2_SE,
|
||||
PART_COLORBAR_2_S,
|
||||
PART_COLORBAR_2_SW,
|
||||
PART_COLORBAR_2_W,
|
||||
|
||||
PART_COLORBAR_3_NW,
|
||||
PART_COLORBAR_3_N,
|
||||
PART_COLORBAR_3_NE,
|
||||
PART_COLORBAR_3_E,
|
||||
PART_COLORBAR_3_SE,
|
||||
PART_COLORBAR_3_S,
|
||||
PART_COLORBAR_3_SW,
|
||||
PART_COLORBAR_3_W,
|
||||
|
||||
PART_COLORBAR_BORDER_0_NW,
|
||||
PART_COLORBAR_BORDER_0_N,
|
||||
PART_COLORBAR_BORDER_0_NE,
|
||||
PART_COLORBAR_BORDER_0_E,
|
||||
PART_COLORBAR_BORDER_0_SE,
|
||||
PART_COLORBAR_BORDER_0_S,
|
||||
PART_COLORBAR_BORDER_0_SW,
|
||||
PART_COLORBAR_BORDER_0_W,
|
||||
|
||||
PART_COLORBAR_BORDER_1_NW,
|
||||
PART_COLORBAR_BORDER_1_N,
|
||||
PART_COLORBAR_BORDER_1_NE,
|
||||
PART_COLORBAR_BORDER_1_E,
|
||||
PART_COLORBAR_BORDER_1_SE,
|
||||
PART_COLORBAR_BORDER_1_S,
|
||||
PART_COLORBAR_BORDER_1_SW,
|
||||
PART_COLORBAR_BORDER_1_W,
|
||||
|
||||
PART_COLORBAR_BORDER_2_NW,
|
||||
PART_COLORBAR_BORDER_2_N,
|
||||
PART_COLORBAR_BORDER_2_NE,
|
||||
PART_COLORBAR_BORDER_2_E,
|
||||
PART_COLORBAR_BORDER_2_SE,
|
||||
PART_COLORBAR_BORDER_2_S,
|
||||
PART_COLORBAR_BORDER_2_SW,
|
||||
PART_COLORBAR_BORDER_2_W,
|
||||
|
||||
PART_COLORBAR_BORDER_3_NW,
|
||||
PART_COLORBAR_BORDER_3_N,
|
||||
PART_COLORBAR_BORDER_3_NE,
|
||||
PART_COLORBAR_BORDER_3_E,
|
||||
PART_COLORBAR_BORDER_3_SE,
|
||||
PART_COLORBAR_BORDER_3_S,
|
||||
PART_COLORBAR_BORDER_3_SW,
|
||||
PART_COLORBAR_BORDER_3_W,
|
||||
|
||||
PART_COLORBAR_BORDER_FG_NW,
|
||||
PART_COLORBAR_BORDER_FG_N,
|
||||
PART_COLORBAR_BORDER_FG_NE,
|
||||
PART_COLORBAR_BORDER_FG_E,
|
||||
PART_COLORBAR_BORDER_FG_SE,
|
||||
PART_COLORBAR_BORDER_FG_S,
|
||||
PART_COLORBAR_BORDER_FG_SW,
|
||||
PART_COLORBAR_BORDER_FG_W,
|
||||
|
||||
PART_COLORBAR_BORDER_BG_NW,
|
||||
PART_COLORBAR_BORDER_BG_N,
|
||||
PART_COLORBAR_BORDER_BG_NE,
|
||||
PART_COLORBAR_BORDER_BG_E,
|
||||
PART_COLORBAR_BORDER_BG_SE,
|
||||
PART_COLORBAR_BORDER_BG_S,
|
||||
PART_COLORBAR_BORDER_BG_SW,
|
||||
PART_COLORBAR_BORDER_BG_W,
|
||||
|
||||
PARTS
|
||||
};
|
||||
|
||||
@ -415,7 +505,10 @@ public:
|
||||
BITMAP* get_toolicon(const char* tool_id) const;
|
||||
|
||||
// helper functions to draw parts
|
||||
void draw_bounds0(int x1, int y1, int x2, int y2, int parts[8]);
|
||||
void draw_trans_bounds0(int x1, int y1, int x2, int y2, int parts[8]);
|
||||
void draw_bounds(int x1, int y1, int x2, int y2, int nw, int bg);
|
||||
void draw_trans_bounds(int x1, int y1, int x2, int y2, int nw);
|
||||
void draw_bounds2(int x1, int y1, int x2, int y2, int x_mid, int nw1, int nw2, int bg1, int bg2);
|
||||
void draw_hline(int x1, int y1, int x2, int y2, int part);
|
||||
|
||||
|
@ -18,11 +18,13 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <allegro.h>
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
#include "Vaca/Point.h"
|
||||
#include "Vaca/Rect.h"
|
||||
|
||||
#include "commands/commands.h"
|
||||
#include "app.h"
|
||||
@ -45,23 +47,29 @@
|
||||
#include "ui_context.h"
|
||||
#include "console.h"
|
||||
|
||||
using Vaca::Point;
|
||||
using Vaca::Rect;
|
||||
|
||||
#define COLORBAR_MAX_COLORS 256
|
||||
|
||||
#define FGBGSIZE (16*jguiscale())
|
||||
// Pixels
|
||||
#define FGBUTTON_SIZE (16*jguiscale())
|
||||
#define BGBUTTON_SIZE (18*jguiscale())
|
||||
|
||||
typedef enum {
|
||||
HOTCOLOR_NONE = -3,
|
||||
HOTCOLOR_FGCOLOR = -2,
|
||||
HOTCOLOR_BGCOLOR = -1,
|
||||
HOTCOLOR_GRADIENT = 0,
|
||||
} hotcolor_t;
|
||||
|
||||
class ColorBar : public Widget
|
||||
{
|
||||
Frame* m_tooltip_window;
|
||||
int m_ncolor;
|
||||
int m_refresh_timer_id;
|
||||
color_t m_color[COLORBAR_MAX_COLORS];
|
||||
size_t m_firstIndex;
|
||||
size_t m_columns;
|
||||
size_t m_colorsPerColum;
|
||||
int m_entrySize;
|
||||
color_t m_fgcolor;
|
||||
color_t m_bgcolor;
|
||||
hotcolor_t m_hot;
|
||||
@ -72,8 +80,7 @@ class ColorBar : public Widget
|
||||
|
||||
public:
|
||||
ColorBar(int align);
|
||||
|
||||
void setBarSize(int size);
|
||||
~ColorBar();
|
||||
|
||||
color_t getFgColor() const { return m_fgcolor; }
|
||||
color_t getBgColor() const { return m_bgcolor; }
|
||||
@ -87,11 +94,17 @@ protected:
|
||||
virtual bool msg_proc(JMessage msg);
|
||||
|
||||
private:
|
||||
int getEntriesCount() const { return m_columns*m_colorsPerColum; }
|
||||
color_t getEntryColor(size_t i) const { return color_index(i+m_firstIndex); }
|
||||
|
||||
color_t getHotColor(hotcolor_t hot);
|
||||
void setHotColor(hotcolor_t hot, color_t color);
|
||||
void openTooltip(int x1, int x2, int y1, int y2, color_t color, hotcolor_t hot);
|
||||
void closeTooltip();
|
||||
void getRange(int& beg, int& end);
|
||||
Rect getColumnBounds(size_t column) const;
|
||||
Rect getEntryBounds(size_t index) const;
|
||||
Rect getFgBounds() const;
|
||||
Rect getBgBounds() const;
|
||||
void updateStatusBar(color_t color, int msecs);
|
||||
|
||||
static bool tooltip_window_msg_proc(JWidget widget, JMessage msg);
|
||||
@ -112,7 +125,7 @@ Widget* colorbar_new(int align)
|
||||
|
||||
void colorbar_set_size(JWidget widget, int size)
|
||||
{
|
||||
((ColorBar*)widget)->setBarSize(size);
|
||||
// TODO remove this
|
||||
}
|
||||
|
||||
color_t colorbar_get_fg_color(JWidget widget)
|
||||
@ -152,10 +165,13 @@ ColorBar::ColorBar(int align)
|
||||
: Widget(colorbar_type())
|
||||
{
|
||||
m_tooltip_window = NULL;
|
||||
m_ncolor = 16;
|
||||
m_entrySize = 16;
|
||||
m_firstIndex = 0;
|
||||
m_columns = 2;
|
||||
m_colorsPerColum = 12;
|
||||
m_refresh_timer_id = jmanager_add_timer(this, 250);
|
||||
m_fgcolor = color_mask();
|
||||
m_bgcolor = color_mask();
|
||||
m_fgcolor = color_index(15);
|
||||
m_bgcolor = color_index(0);
|
||||
m_hot = HOTCOLOR_NONE;
|
||||
m_hot_editing = HOTCOLOR_NONE;
|
||||
m_hot_drag = HOTCOLOR_NONE;
|
||||
@ -168,12 +184,30 @@ ColorBar::ColorBar(int align)
|
||||
this->border_width.t = 2;
|
||||
this->border_width.r = 2;
|
||||
this->border_width.b = 2;
|
||||
|
||||
// Get selected colors
|
||||
m_fgcolor = get_config_color("ColorBar", "FG", m_fgcolor);
|
||||
m_bgcolor = get_config_color("ColorBar", "BG", m_bgcolor);
|
||||
|
||||
// Get color-bar configuration
|
||||
m_columns = get_config_int("ColorBar", "Columns", m_columns);
|
||||
m_columns = MID(1, m_columns, 4);
|
||||
|
||||
m_entrySize = get_config_int("ColorBar", "EntrySize", m_entrySize);
|
||||
m_entrySize = MID(12, m_entrySize, 256);
|
||||
}
|
||||
|
||||
void ColorBar::setBarSize(int size)
|
||||
ColorBar::~ColorBar()
|
||||
{
|
||||
m_ncolor = MID(1, size, COLORBAR_MAX_COLORS);
|
||||
dirty();
|
||||
jmanager_remove_timer(m_refresh_timer_id);
|
||||
|
||||
if (m_tooltip_window != NULL)
|
||||
jwidget_free(m_tooltip_window);
|
||||
|
||||
set_config_color("ColorBar", "FG", m_fgcolor);
|
||||
set_config_color("ColorBar", "BG", m_bgcolor);
|
||||
set_config_int("ColorBar", "Columns", m_columns);
|
||||
set_config_int("ColorBar", "EntrySize", m_entrySize);
|
||||
}
|
||||
|
||||
void ColorBar::setFgColor(color_t color)
|
||||
@ -194,48 +228,23 @@ void ColorBar::setBgColor(color_t color)
|
||||
|
||||
void ColorBar::setColor(int index, color_t color)
|
||||
{
|
||||
assert(index >= 0 && index < COLORBAR_MAX_COLORS);
|
||||
m_color[index] = color;
|
||||
dirty();
|
||||
// TODO remove me
|
||||
}
|
||||
|
||||
color_t ColorBar::getColorByPosition(int x, int y)
|
||||
{
|
||||
int x1, y1, x2, y2, v1, v2;
|
||||
int c, h, beg, end;
|
||||
|
||||
getRange(beg, end);
|
||||
|
||||
x1 = this->rc->x1;
|
||||
y1 = this->rc->y1;
|
||||
x2 = this->rc->x2-1;
|
||||
y2 = this->rc->y2-1;
|
||||
|
||||
++x1, ++y1, --x2, --y2;
|
||||
|
||||
h = (y2-y1+1-(4+FGBGSIZE*2+4));
|
||||
|
||||
for (c=beg; c<=end; c++) {
|
||||
v1 = y1 + h*(c-beg )/(end-beg+1);
|
||||
v2 = y1 + h*(c-beg+1)/(end-beg+1) - 1;
|
||||
|
||||
if ((y >= v1) && (y <= v2))
|
||||
return m_color[c];
|
||||
for (int i=0; i<getEntriesCount(); ++i) {
|
||||
if (getEntryBounds(i).contains(Point(x, y)))
|
||||
return getEntryColor(i);
|
||||
}
|
||||
|
||||
/* in foreground color */
|
||||
v1 = y2-4-FGBGSIZE*2;
|
||||
v2 = y2-4-FGBGSIZE;
|
||||
if ((y >= v1) && (y <= v2)) {
|
||||
// In foreground color
|
||||
if (getFgBounds().contains(Point(x, y)))
|
||||
return m_fgcolor;
|
||||
}
|
||||
|
||||
/* in background color */
|
||||
v1 = y2-4-FGBGSIZE+1;
|
||||
v2 = y2-4;
|
||||
if ((y >= v1) && (y <= v2)) {
|
||||
// In background color
|
||||
if (getBgBounds().contains(Point(x, y)))
|
||||
return m_bgcolor;
|
||||
}
|
||||
|
||||
return color_mask();
|
||||
}
|
||||
@ -244,127 +253,114 @@ bool ColorBar::msg_proc(JMessage msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case JM_OPEN: {
|
||||
int ncolor = get_config_int("ColorBar", "NColors", m_ncolor);
|
||||
char buf[256];
|
||||
int c, beg, end;
|
||||
|
||||
m_ncolor = MID(1, ncolor, COLORBAR_MAX_COLORS);
|
||||
|
||||
getRange(beg, end);
|
||||
|
||||
/* fill color-bar with saved colors in the configuration file */
|
||||
for (c=0; c<COLORBAR_MAX_COLORS; c++) {
|
||||
usprintf(buf, "Color%03d", c);
|
||||
m_color[c] = get_config_color("ColorBar",
|
||||
buf, color_index(c));
|
||||
}
|
||||
|
||||
/* get selected colors */
|
||||
m_fgcolor = get_config_color("ColorBar", "FG", color_rgb(0, 0, 0));
|
||||
m_bgcolor = get_config_color("ColorBar", "BG", color_rgb(255, 255, 255));
|
||||
break;
|
||||
}
|
||||
|
||||
case JM_DESTROY: {
|
||||
char buf[256];
|
||||
int c;
|
||||
|
||||
jmanager_remove_timer(m_refresh_timer_id);
|
||||
|
||||
if (m_tooltip_window != NULL)
|
||||
jwidget_free(m_tooltip_window);
|
||||
|
||||
set_config_int("ColorBar", "NColors", m_ncolor);
|
||||
set_config_color("ColorBar", "FG", m_fgcolor);
|
||||
set_config_color("ColorBar", "BG", m_bgcolor);
|
||||
|
||||
for (c=0; c<m_ncolor; c++) {
|
||||
usprintf(buf, "Color%03d", c);
|
||||
set_config_color("ColorBar", buf, m_color[c]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case JM_REQSIZE:
|
||||
msg->reqsize.w = msg->reqsize.h = 24 * jguiscale();
|
||||
if (get_config_bool("ColorBar", "CanGrow", false))
|
||||
msg->reqsize.w = 20*jguiscale() * m_columns;
|
||||
else
|
||||
msg->reqsize.w = 20*jguiscale() * MAX(1, m_columns);
|
||||
msg->reqsize.h = 20*jguiscale();
|
||||
return true;
|
||||
|
||||
case JM_DRAW: {
|
||||
// Update the number of colors per column
|
||||
{
|
||||
m_colorsPerColum = getColumnBounds(1).h / (m_entrySize*jguiscale());
|
||||
m_colorsPerColum = MAX(1, m_colorsPerColum);
|
||||
|
||||
if (m_colorsPerColum*m_columns > 256) {
|
||||
m_colorsPerColum = 256 / m_columns;
|
||||
if (m_colorsPerColum*m_columns > 256)
|
||||
m_colorsPerColum--;
|
||||
}
|
||||
|
||||
assert(m_colorsPerColum*m_columns <= 256);
|
||||
}
|
||||
|
||||
SkinneableTheme* theme = static_cast<SkinneableTheme*>(this->theme);
|
||||
BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect),
|
||||
jrect_h(&msg->draw.rect));
|
||||
int imgtype = app_get_current_image_type();
|
||||
int x1, y1, x2, y2, v1, v2;
|
||||
int c, h, beg, end;
|
||||
int bg = theme->get_panel_face_color();
|
||||
// int bg = theme->get_panel_face_color();
|
||||
int bg = theme->get_tab_selected_face_color();
|
||||
|
||||
getRange(beg, end);
|
||||
clear_to_color(doublebuffer, bg);
|
||||
|
||||
x1 = this->rc->x1 - msg->draw.rect.x1;
|
||||
y1 = this->rc->y1 - msg->draw.rect.y1;
|
||||
x2 = x1 + jrect_w(this->rc) - 1;
|
||||
y2 = y1 + jrect_h(this->rc) - 1;
|
||||
for (int i=0; i<getEntriesCount(); ++i) {
|
||||
Rect entryBounds = getEntryBounds(i);
|
||||
|
||||
rectfill(doublebuffer, x1, y1, x2, y2, bg);
|
||||
++x1, ++y1, --x2, --y2;
|
||||
// The button is not even visible
|
||||
if (!entryBounds.intersects(Rect(msg->draw.rect.x1,
|
||||
msg->draw.rect.y1,
|
||||
jrect_w(&msg->draw.rect),
|
||||
jrect_h(&msg->draw.rect))))
|
||||
continue;
|
||||
|
||||
h = (y2-y1+1-(4+FGBGSIZE*2+4));
|
||||
entryBounds.offset(-msg->draw.rect.x1,
|
||||
-msg->draw.rect.y1);
|
||||
|
||||
/* draw range */
|
||||
for (c=beg; c<=end; c++) {
|
||||
v1 = y1 + h*(c-beg )/(end-beg+1);
|
||||
v2 = y1 + h*(c-beg+1)/(end-beg+1) - 1;
|
||||
int col = (i / m_colorsPerColum);
|
||||
int row = (i % m_colorsPerColum);
|
||||
color_t color = color_index(m_firstIndex + i);
|
||||
|
||||
draw_color_button(doublebuffer, x1, v1, x2, v2,
|
||||
c == beg, c == beg,
|
||||
c == end, c == end, imgtype, m_color[c],
|
||||
(c == m_hot ||
|
||||
c == m_hot_editing),
|
||||
(m_hot_drag == c &&
|
||||
m_hot_drag != m_hot_drop),
|
||||
bg);
|
||||
draw_color_button(doublebuffer, entryBounds,
|
||||
row == 0 && col == 0, // nw
|
||||
row == 0, // n
|
||||
row == 0 && col == m_columns-1, // ne
|
||||
col == m_columns-1, // e
|
||||
row == m_colorsPerColum-1 && col == m_columns-1, // se
|
||||
row == m_colorsPerColum-1, // s
|
||||
row == m_colorsPerColum-1 && col == 0, // sw
|
||||
col == 0, // w
|
||||
imgtype,
|
||||
color,
|
||||
(i == m_hot ||
|
||||
i == m_hot_editing),
|
||||
(m_hot_drag == i &&
|
||||
m_hot_drag != m_hot_drop));
|
||||
|
||||
if (color_equals(m_fgcolor, m_color[c])) {
|
||||
int neg = blackandwhite_neg(color_get_red(imgtype, m_fgcolor),
|
||||
color_get_green(imgtype, m_fgcolor),
|
||||
color_get_blue(imgtype, m_fgcolor));
|
||||
|
||||
textout_ex(doublebuffer, this->getFont(), "FG",
|
||||
x1+4, v1+2, neg, -1);
|
||||
if (color_equals(m_bgcolor, color)) {
|
||||
BITMAP* old_ji_screen = ji_screen; // TODO fix this ugly hack
|
||||
ji_screen = doublebuffer;
|
||||
theme->draw_bounds(entryBounds.x, entryBounds.y,
|
||||
entryBounds.x+entryBounds.w-1,
|
||||
entryBounds.y+entryBounds.h-1 - (row == m_colorsPerColum-1 ? jguiscale(): 0),
|
||||
PART_COLORBAR_BORDER_BG_NW, -1);
|
||||
ji_screen = old_ji_screen;
|
||||
}
|
||||
|
||||
if (color_equals(m_bgcolor, m_color[c])) {
|
||||
int neg = blackandwhite_neg(color_get_red(imgtype, m_bgcolor),
|
||||
color_get_green(imgtype, m_bgcolor),
|
||||
color_get_blue(imgtype, m_bgcolor));
|
||||
|
||||
textout_ex(doublebuffer, this->getFont(), "BG",
|
||||
x2-3-text_length(this->getFont(), "BG"),
|
||||
v2-jwidget_get_text_height(this), neg, -1);
|
||||
if (color_equals(m_fgcolor, color)) {
|
||||
BITMAP* old_ji_screen = ji_screen; // TODO fix this ugly hack
|
||||
ji_screen = doublebuffer;
|
||||
theme->draw_bounds(entryBounds.x, entryBounds.y,
|
||||
entryBounds.x+entryBounds.w-1,
|
||||
entryBounds.y+entryBounds.h-1 - (row == m_colorsPerColum-1 ? jguiscale(): 0),
|
||||
PART_COLORBAR_BORDER_FG_NW, -1);
|
||||
ji_screen = old_ji_screen;
|
||||
}
|
||||
}
|
||||
|
||||
/* draw foreground color */
|
||||
v1 = y2-4-FGBGSIZE*2;
|
||||
v2 = y2-4-FGBGSIZE;
|
||||
draw_color_button(doublebuffer, x1, v1, x2, v2, 1, 1, 0, 0,
|
||||
// Draw foreground color
|
||||
Rect fgBounds = getFgBounds().offset(-msg->draw.rect.x1,
|
||||
-msg->draw.rect.y1);
|
||||
draw_color_button(doublebuffer, fgBounds,
|
||||
true, true, true, true,
|
||||
false, false, false, true,
|
||||
imgtype, m_fgcolor,
|
||||
(m_hot == HOTCOLOR_FGCOLOR ||
|
||||
m_hot_editing == HOTCOLOR_FGCOLOR),
|
||||
(m_hot_drag == HOTCOLOR_FGCOLOR &&
|
||||
m_hot_drag != m_hot_drop), bg);
|
||||
m_hot_drag != m_hot_drop));
|
||||
|
||||
/* draw background color */
|
||||
v1 = y2-4-FGBGSIZE+1;
|
||||
v2 = y2-4;
|
||||
draw_color_button(doublebuffer, x1, v1, x2, v2, 0, 0, 1, 1,
|
||||
// Draw background color
|
||||
Rect bgBounds = getBgBounds().offset(-msg->draw.rect.x1,
|
||||
-msg->draw.rect.y1);
|
||||
draw_color_button(doublebuffer, bgBounds,
|
||||
false, false, false, true,
|
||||
true, true, true, true,
|
||||
imgtype, m_bgcolor,
|
||||
(m_hot == HOTCOLOR_BGCOLOR ||
|
||||
m_hot_editing == HOTCOLOR_BGCOLOR),
|
||||
(m_hot_drag == HOTCOLOR_BGCOLOR &&
|
||||
m_hot_drag != m_hot_drop),
|
||||
bg);
|
||||
m_hot_drag != m_hot_drop));
|
||||
|
||||
blit(doublebuffer, ji_screen, 0, 0,
|
||||
msg->draw.rect.x1,
|
||||
@ -383,55 +379,37 @@ bool ColorBar::msg_proc(JMessage msg)
|
||||
|
||||
case JM_MOUSEENTER:
|
||||
case JM_MOTION: {
|
||||
int x1, y1, x2, y2, v1, v2;
|
||||
int c, h, beg, end;
|
||||
int old_hot = m_hot;
|
||||
int hot_v1 = 0;
|
||||
int hot_v2 = 0;
|
||||
|
||||
m_hot = HOTCOLOR_NONE;
|
||||
|
||||
getRange(beg, end);
|
||||
for (int i=0; i<getEntriesCount(); ++i) {
|
||||
Rect entryBounds = getEntryBounds(i);
|
||||
|
||||
x1 = this->rc->x1;
|
||||
y1 = this->rc->y1;
|
||||
x2 = this->rc->x2-1;
|
||||
y2 = this->rc->y2-1;
|
||||
|
||||
++x1, ++y1, --x2, --y2;
|
||||
|
||||
h = (y2-y1+1-(4+FGBGSIZE*2+4));
|
||||
|
||||
for (c=beg; c<=end; c++) {
|
||||
v1 = y1 + h*(c-beg )/(end-beg+1);
|
||||
v2 = y1 + h*(c-beg+1)/(end-beg+1) - 1;
|
||||
|
||||
if ((msg->mouse.y >= v1) && (msg->mouse.y <= v2)) {
|
||||
if (m_hot != c) {
|
||||
m_hot = static_cast<hotcolor_t>(c);
|
||||
hot_v1 = v1;
|
||||
hot_v2 = v2;
|
||||
if (entryBounds.contains(Point(msg->mouse.x, msg->mouse.y))) {
|
||||
if (m_hot != i) {
|
||||
m_hot = static_cast<hotcolor_t>(i);
|
||||
hot_v1 = entryBounds.y;
|
||||
hot_v2 = entryBounds.y+entryBounds.h-1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* in foreground color */
|
||||
v1 = y2-4-FGBGSIZE*2;
|
||||
v2 = y2-4-FGBGSIZE;
|
||||
if ((msg->mouse.y >= v1) && (msg->mouse.y <= v2)) {
|
||||
Rect fgBounds = getFgBounds();
|
||||
if (fgBounds.contains(Point(msg->mouse.x, msg->mouse.y))) {
|
||||
m_hot = HOTCOLOR_FGCOLOR;
|
||||
hot_v1 = v1;
|
||||
hot_v2 = v2;
|
||||
hot_v1 = fgBounds.y;
|
||||
hot_v2 = fgBounds.y+fgBounds.h-1;
|
||||
}
|
||||
|
||||
/* in background color */
|
||||
v1 = y2-4-FGBGSIZE+1;
|
||||
v2 = y2-4;
|
||||
if ((msg->mouse.y >= v1) && (msg->mouse.y <= v2)) {
|
||||
Rect bgBounds = getBgBounds();
|
||||
if (bgBounds.contains(Point(msg->mouse.x, msg->mouse.y))) {
|
||||
m_hot = HOTCOLOR_BGCOLOR;
|
||||
hot_v1 = v1;
|
||||
hot_v2 = v2;
|
||||
hot_v1 = bgBounds.y;
|
||||
hot_v2 = bgBounds.y+bgBounds.h-1;
|
||||
}
|
||||
|
||||
// Drop target
|
||||
@ -443,7 +421,7 @@ bool ColorBar::msg_proc(JMessage msg)
|
||||
dirty();
|
||||
|
||||
// Close the old tooltip window to edit the 'old_hot' color slot
|
||||
closeTooltip();
|
||||
//closeTooltip();
|
||||
|
||||
// Open the new hot-color to be edited
|
||||
if ((m_hot != HOTCOLOR_NONE) &&
|
||||
@ -452,9 +430,9 @@ bool ColorBar::msg_proc(JMessage msg)
|
||||
|
||||
updateStatusBar(color, 0);
|
||||
|
||||
// Open the tooltip window to edit the hot color
|
||||
openTooltip(this->rc->x1-1, this->rc->x2+1,
|
||||
hot_v1, hot_v2, color, m_hot);
|
||||
// // Open the tooltip window to edit the hot color
|
||||
// openTooltip(this->rc->x1-1, this->rc->x2+1,
|
||||
// hot_v1, hot_v2, color, m_hot);
|
||||
}
|
||||
}
|
||||
|
||||
@ -470,6 +448,64 @@ bool ColorBar::msg_proc(JMessage msg)
|
||||
}
|
||||
break;
|
||||
|
||||
case JM_WHEEL:
|
||||
{
|
||||
int delta = jmouse_z(1) - jmouse_z(0);
|
||||
|
||||
// Without Ctrl or Alt
|
||||
if (!(msg->any.shifts & (KB_ALT_FLAG |
|
||||
KB_CTRL_FLAG))) {
|
||||
if (msg->any.shifts & KB_SHIFT_FLAG)
|
||||
delta *= m_colorsPerColum/2;
|
||||
|
||||
if (((int)m_firstIndex)+delta < 0)
|
||||
m_firstIndex = 0;
|
||||
else if (m_firstIndex+delta > 256-getEntriesCount())
|
||||
m_firstIndex = 256-getEntriesCount();
|
||||
else
|
||||
m_firstIndex += delta;
|
||||
}
|
||||
|
||||
// With Ctrl only
|
||||
if ((msg->any.shifts & (KB_ALT_FLAG |
|
||||
KB_CTRL_FLAG |
|
||||
KB_SHIFT_FLAG)) == KB_CTRL_FLAG) {
|
||||
if (((int)m_entrySize)+delta < 12)
|
||||
m_entrySize = 12;
|
||||
else if (m_entrySize+delta > 256)
|
||||
m_entrySize = 256;
|
||||
else
|
||||
m_entrySize += delta;
|
||||
}
|
||||
|
||||
// With Alt only
|
||||
if ((msg->any.shifts & (KB_ALT_FLAG |
|
||||
KB_CTRL_FLAG |
|
||||
KB_SHIFT_FLAG)) == KB_ALT_FLAG) {
|
||||
int old_columns = m_columns;
|
||||
|
||||
if (((int)m_columns)+delta < 1)
|
||||
m_columns = 1;
|
||||
else if (m_columns+delta > 4)
|
||||
m_columns = 4;
|
||||
else
|
||||
m_columns += delta;
|
||||
|
||||
if (get_config_bool("ColorBar", "CanGrow", false) ||
|
||||
(old_columns == 1 || m_columns == 1)) {
|
||||
app_get_top_window()->remap_window();
|
||||
app_get_top_window()->dirty();
|
||||
}
|
||||
}
|
||||
|
||||
// Redraw the whole widget
|
||||
dirty();
|
||||
|
||||
// Update the status bar
|
||||
updateStatusBar(getColorByPosition(jmouse_x(0), jmouse_y(0)), 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case JM_BUTTONRELEASED:
|
||||
if (jwidget_has_capture(this)) {
|
||||
/* drag and drop a color */
|
||||
@ -505,7 +541,7 @@ bool ColorBar::msg_proc(JMessage msg)
|
||||
jmouse_set_cursor(JI_CURSOR_MOVE);
|
||||
return true;
|
||||
}
|
||||
else if (m_hot != HOTCOLOR_NONE) {
|
||||
else if (m_hot >= 0) {
|
||||
jmouse_set_cursor(JI_CURSOR_EYEDROPPER);
|
||||
return true;
|
||||
}
|
||||
@ -540,8 +576,8 @@ color_t ColorBar::getHotColor(hotcolor_t hot)
|
||||
case HOTCOLOR_FGCOLOR: return m_fgcolor;
|
||||
case HOTCOLOR_BGCOLOR: return m_bgcolor;
|
||||
default:
|
||||
assert(hot >= 0 && hot < m_ncolor);
|
||||
return m_color[hot];
|
||||
assert(hot >= 0 && hot < getEntriesCount());
|
||||
return getEntryColor(hot);
|
||||
}
|
||||
}
|
||||
|
||||
@ -558,7 +594,8 @@ void ColorBar::setHotColor(hotcolor_t hot, color_t color)
|
||||
m_bgcolor = color;
|
||||
break;
|
||||
default:
|
||||
assert(hot >= 0 && hot < m_ncolor);
|
||||
assert(hot >= 0 && hot < getEntriesCount());
|
||||
#if 0
|
||||
m_color[hot] = color;
|
||||
|
||||
if (hot == 0 || hot == m_ncolor-1) {
|
||||
@ -580,6 +617,7 @@ void ColorBar::setHotColor(hotcolor_t hot, color_t color)
|
||||
m_color[c] = color_rgb(r, g, b);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -727,6 +765,7 @@ bool ColorBar::tooltip_window_msg_proc(JWidget widget, JMessage msg)
|
||||
break;
|
||||
|
||||
case JM_SIGNAL:
|
||||
#if 0
|
||||
if (msg->signal.num == SIGNAL_COLORSELECTOR_COLOR_CHANGED) {
|
||||
ColorBar* colorbar = (ColorBar*)widget->user_data[0];
|
||||
color_t color = colorselector_get_color(widget);
|
||||
@ -786,6 +825,7 @@ bool ColorBar::tooltip_window_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
colorbar->dirty();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
}
|
||||
@ -793,10 +833,49 @@ bool ColorBar::tooltip_window_msg_proc(JWidget widget, JMessage msg)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ColorBar::getRange(int& beg, int& end)
|
||||
Rect ColorBar::getColumnBounds(size_t column) const
|
||||
{
|
||||
beg = 0;
|
||||
end = m_ncolor-1;
|
||||
Rect rc = getBounds().shrink(jguiscale());
|
||||
Rect fgRc = getFgBounds();
|
||||
|
||||
rc.w /= m_columns;
|
||||
rc.x += (rc.w * column);
|
||||
rc.h = (fgRc.y - rc.y);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Rect ColorBar::getEntryBounds(size_t index) const
|
||||
{
|
||||
size_t row = (index % m_colorsPerColum);
|
||||
size_t col = (index / m_colorsPerColum);
|
||||
Rect rc = getColumnBounds(col);
|
||||
|
||||
rc.h -= 2*jguiscale();
|
||||
|
||||
rc.y += row * rc.h / m_colorsPerColum;
|
||||
rc.h = ((row+1) * rc.h / m_colorsPerColum) - (row * rc.h / m_colorsPerColum);
|
||||
|
||||
if (row == m_colorsPerColum-1)
|
||||
rc.h += 2*jguiscale();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Rect ColorBar::getFgBounds() const
|
||||
{
|
||||
Rect rc = getBounds().shrink(jguiscale());
|
||||
|
||||
return Rect(rc.x, rc.y+rc.h-BGBUTTON_SIZE-FGBUTTON_SIZE,
|
||||
rc.w, FGBUTTON_SIZE);
|
||||
}
|
||||
|
||||
Rect ColorBar::getBgBounds() const
|
||||
{
|
||||
Rect rc = getBounds().shrink(jguiscale());
|
||||
|
||||
return Rect(rc.x, rc.y+rc.h-BGBUTTON_SIZE,
|
||||
rc.w, BGBUTTON_SIZE);
|
||||
}
|
||||
|
||||
void ColorBar::updateStatusBar(color_t color, int msecs)
|
||||
|
@ -223,15 +223,16 @@ static void colorbutton_draw(JWidget widget)
|
||||
|
||||
jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0);
|
||||
|
||||
jdraw_rectfill(widget->rc, ji_color_face());
|
||||
|
||||
draw_color_button
|
||||
(ji_screen,
|
||||
widget->rc->x1, widget->rc->y1,
|
||||
widget->rc->x2-1, widget->rc->y2-1,
|
||||
1, 1, 1, 1,
|
||||
widget->getBounds(),
|
||||
true, true, true, true,
|
||||
true, true, true, true,
|
||||
colorbutton->imgtype,
|
||||
colorbutton->color,
|
||||
jwidget_has_mouse(widget),
|
||||
false, ji_color_face());
|
||||
jwidget_has_mouse(widget), false);
|
||||
|
||||
/* draw text */
|
||||
color_to_formalstring(colorbutton->imgtype,
|
||||
|
@ -130,7 +130,7 @@ static bool colorviewer_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
/* draw color background */
|
||||
jrect_shrink(rect, 1);
|
||||
draw_color(ji_screen, rect->x1, rect->y1, rect->x2-1, rect->y2-1,
|
||||
draw_color(ji_screen, Rect(rect->x1, rect->y1, jrect_w(rect->x2), jrect_h(rect->y2)),
|
||||
colorviewer->imgtype,
|
||||
colorviewer->color);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user