Added alpha support for skin sheet.

This commit is contained in:
David Capello 2010-04-23 21:56:59 -03:00
parent 0feed51cde
commit 917127ce37
6 changed files with 77 additions and 105 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -103,12 +103,9 @@
<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" />
<part id="colorbar_border_hotfg" x="32" y="224" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
</parts>
</skin>

View File

@ -513,38 +513,15 @@ void draw_color_button(BITMAP* bmp,
ji_screen = old_ji_screen;
}
// 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);
// 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);
PART_COLORBAR_BORDER_HOTFG_NW);
ji_screen = old_ji_screen;
set_trans_blender(0, 0, 0, 0);
}
}

View File

@ -126,12 +126,9 @@ SkinneableTheme::SkinneableTheme()
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;
sheet_mapping["colorbar_border_hotfg"] = PART_COLORBAR_BORDER_HOTFG_NW;
reload_skin();
}
@ -234,7 +231,7 @@ void SkinneableTheme::regen()
cursors_info[c].focusx = focusx;
cursors_info[c].focusy = focusy;
m_cursors[c] = cropPartFromSheet(m_cursors[c], x, y, w, h);
m_cursors[c] = cropPartFromSheet(m_cursors[c], x, y, w, h, true);
break;
}
@ -314,24 +311,31 @@ void SkinneableTheme::regen()
dirs_free(dirs);
}
BITMAP* SkinneableTheme::cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h)
BITMAP* SkinneableTheme::cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h, bool cursor)
{
int colordepth = (cursor ? bitmap_color_depth(screen): 32);
if (bmp &&
(bmp->w != w ||
bmp->h != h ||
bitmap_color_depth(bmp) != bitmap_color_depth(screen))) {
bitmap_color_depth(bmp) != colordepth)) {
destroy_bitmap(bmp);
bmp = NULL;
}
if (!bmp)
bmp = create_bitmap(w, h);
bmp = create_bitmap_ex(colordepth, w, h);
if (cursor) {
clear_to_color(bmp, bitmap_mask_color(bmp));
set_alpha_blender();
draw_trans_sprite(bmp, m_sheet_bmp, -x, -y);
set_trans_blender(0, 0, 0, 0);
}
else {
blit(m_sheet_bmp, bmp, x, y, 0, 0, w, h);
}
return ji_apply_guiscale(bmp);
}
@ -717,7 +721,8 @@ void SkinneableTheme::draw_check(JWidget widget, JRect clip)
draw_textstring(NULL, -1, bg, false, widget, &text, 0);
/* icon */
draw_sprite(ji_screen,
set_alpha_blender();
draw_trans_sprite(ji_screen,
jwidget_is_selected(widget) ? m_part[PART_CHECK_SELECTED]:
m_part[PART_CHECK_NORMAL],
icon.x1, icon.y1);
@ -915,7 +920,8 @@ void SkinneableTheme::draw_menuitem(JWidget widget, JRect clip)
int x = widget->rc->x1+4-icon->w/2;
int y = (widget->rc->y1+widget->rc->y2)/2-icon->h/2;
draw_sprite(ji_screen, icon, x, y);
set_alpha_blender();
draw_trans_sprite(ji_screen, icon, x, y);
}
/* text */
@ -1007,7 +1013,8 @@ void SkinneableTheme::draw_radio(JWidget widget, JRect clip)
draw_textstring(NULL, -1, bg, false, widget, &text, 0);
/* icon */
draw_sprite(ji_screen,
set_alpha_blender();
draw_trans_sprite(ji_screen,
jwidget_is_selected(widget) ? m_part[PART_RADIO_SELECTED]:
m_part[PART_RADIO_NORMAL],
icon.x1, icon.y1);
@ -1266,7 +1273,8 @@ void SkinneableTheme::draw_combobox_button(JWidget widget, JRect clip)
get_button_selected_offset(),
get_button_selected_offset());
draw_sprite(ji_screen, icon_bmp, icon.x1, icon.y1);
set_alpha_blender();
draw_trans_sprite(ji_screen, icon_bmp, icon.x1, icon.y1);
}
void SkinneableTheme::draw_textbox(JWidget widget, JRect clip)
@ -1398,7 +1406,8 @@ void SkinneableTheme::draw_frame_button(JWidget widget, JRect clip)
else
part = PART_WINDOW_CLOSE_BUTTON_NORMAL;
draw_sprite(ji_screen, m_part[part], widget->rc->x1, widget->rc->y1);
set_alpha_blender();
draw_trans_sprite(ji_screen, m_part[part], widget->rc->x1, widget->rc->y1);
}
int SkinneableTheme::get_bg_color(JWidget widget)
@ -1568,7 +1577,8 @@ void SkinneableTheme::draw_bounds0(int x1, int y1, int x2, int y2, int parts[8])
int sw = parts[6];
int w = parts[7];
draw_bounds_template(nw, n, ne, e, se, s, sw, w, draw_sprite);
set_alpha_blender();
draw_bounds_template(nw, n, ne, e, se, s, sw, w, draw_trans_sprite);
}
void SkinneableTheme::draw_trans_bounds0(int x1, int y1, int x2, int y2, int parts[8])
@ -1587,10 +1597,11 @@ void SkinneableTheme::draw_trans_bounds0(int x1, int y1, int x2, int y2, int par
void SkinneableTheme::draw_bounds(int x1, int y1, int x2, int y2, int nw, int bg)
{
set_alpha_blender();
draw_bounds_template(nw+0, nw+1, nw+2, nw+3,
nw+4, nw+5, nw+6, nw+7, draw_sprite);
nw+4, nw+5, nw+6, nw+7, draw_trans_sprite);
// Background
// Center
if (bg >= 0) {
x1 += m_part[nw+7]->w;
y1 += m_part[nw+1]->h;
@ -1627,14 +1638,23 @@ void SkinneableTheme::draw_hline(int x1, int y1, int x2, int y2, int part)
{
int x;
set_alpha_blender();
for (x = x1;
x <= x2-m_part[part]->w;
x += m_part[part]->w) {
draw_sprite(ji_screen, m_part[part], x, y1);
draw_trans_sprite(ji_screen, m_part[part], x, y1);
}
if (x <= x2)
blit(m_part[part], ji_screen, 0, 0, x, y1, x2-x+1, m_part[part]->h);
if (x <= x2) {
int cx1, cy1, cx2, cy2;
get_clip_rect(ji_screen, &cx1, &cy1, &cx2, &cy2);
if (my_add_clip_rect(ji_screen, x, y1, x2, y1+m_part[part]->h-1))
draw_trans_sprite(ji_screen, m_part[part], x, y1);
set_clip_rect(ji_screen, cx1, cy1, cx2, cy2);
}
}
void SkinneableTheme::draw_bevel_box(int x1, int y1, int x2, int y2, int c1, int c2, int *bevel)

View File

@ -354,42 +354,6 @@ enum {
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,
@ -408,6 +372,15 @@ enum {
PART_COLORBAR_BORDER_BG_SW,
PART_COLORBAR_BORDER_BG_W,
PART_COLORBAR_BORDER_HOTFG_NW,
PART_COLORBAR_BORDER_HOTFG_N,
PART_COLORBAR_BORDER_HOTFG_NE,
PART_COLORBAR_BORDER_HOTFG_E,
PART_COLORBAR_BORDER_HOTFG_SE,
PART_COLORBAR_BORDER_HOTFG_S,
PART_COLORBAR_BORDER_HOTFG_SW,
PART_COLORBAR_BORDER_HOTFG_W,
PARTS
};
@ -527,7 +500,7 @@ public:
private:
BITMAP* cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h);
BITMAP* cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h, bool cursor = false);
int get_bg_color(JWidget widget);
void draw_textstring(const char *t, int fg_color, int bg_color,
bool fill_bg, JWidget widget, const JRect rect,

View File

@ -217,11 +217,13 @@ bool ToolBar::msg_proc(JMessage msg)
// Draw the tool icon
BITMAP* icon = theme->get_toolicon(tool->getId().c_str());
if (icon)
draw_sprite(doublebuffer, icon,
if (icon) {
set_alpha_blender();
draw_trans_sprite(doublebuffer, icon,
toolrc.x+toolrc.w/2-icon->w/2,
toolrc.y+toolrc.h/2-icon->h/2);
}
}
toolrc = getToolGroupBounds(-1);
toolrc.offset(-msg->draw.rect.x1, -msg->draw.rect.y1);
@ -234,7 +236,8 @@ bool ToolBar::msg_proc(JMessage msg)
// Draw the tool icon
BITMAP* icon = theme->get_toolicon("configuration");
if (icon) {
draw_sprite(doublebuffer, icon,
set_alpha_blender();
draw_trans_sprite(doublebuffer, icon,
toolrc.x+toolrc.w/2-icon->w/2,
toolrc.y+toolrc.h/2-icon->h/2);
}
@ -573,12 +576,14 @@ bool ToolStrip::msg_proc(JMessage msg)
// Draw the tool icon
BITMAP* icon = theme->get_toolicon(tool->getId().c_str());
if (icon)
draw_sprite(doublebuffer, icon,
if (icon) {
set_alpha_blender();
draw_trans_sprite(doublebuffer, icon,
toolrc.x+toolrc.w/2-icon->w/2,
toolrc.y+toolrc.h/2-icon->h/2);
}
}
}
ji_screen = old_ji_screen;