merged bitmap buttons

This commit is contained in:
Scott Moynes 2002-09-14 03:44:44 +00:00
parent 499b1620c1
commit c2d992a35c
6 changed files with 301 additions and 75 deletions

View file

@ -621,6 +621,23 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
} }
if (dooppsel && item->isSelected()) { if (dooppsel && item->isSelected()) {
if ( style->tick_image.mask != None) {
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(),
oppsel_x, item_y + menu.item_h/2 - style->tick_image.h/2);
XSetClipMask(blackbox->getXDisplay(), pen.gc(),
style->tick_image.mask);
cout << oppsel_x << ' ' << sel_x << endl;
XFillRectangle(blackbox->getXDisplay(), menu.frame, pen.gc(),
oppsel_x, item_y + menu.item_h/2 - style->tick_image.h/2,
style->tick_image.w,
style->tick_image.h);
XSetClipMask(blackbox->getXDisplay(), pen.gc(), None);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(),
0, 0);
} else {
XPoint pts[6]; XPoint pts[6];
pts[0].x = oppsel_x + 0; pts[0].x = oppsel_x + 0;
@ -645,6 +662,7 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
XFillPolygon(display, menu.frame, pen.gc(), pts, 6, Nonconvex, XFillPolygon(display, menu.frame, pen.gc(), pts, 6, Nonconvex,
CoordModePrevious); CoordModePrevious);
} }
}
if (dotext && text) { if (dotext && text) {
style->f_font->drawString(menu.frame, text_x, text_y, style->f_font->drawString(menu.frame, text_x, text_y,
@ -655,6 +673,22 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
} }
if (dosel && item->submenu()) { if (dosel && item->submenu()) {
if ( style->bullet_image.mask != None) {
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(),
sel_x, item_y + menu.item_h/2 - style->bullet_image.h/2);
XSetClipMask(blackbox->getXDisplay(), pen.gc(),
style->bullet_image.mask);
XFillRectangle(blackbox->getXDisplay(), menu.frame, pen.gc(),
sel_x, item_y + menu.item_h/2 - style->bullet_image.h/2,
sel_x + style->bullet_image.w,
item_y + menu.item_h/2 + style->bullet_image.h/2);
XSetClipMask(blackbox->getXDisplay(), pen.gc(), None);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(),
0, 0);
} else {
const int bullet_size = 3; const int bullet_size = 3;
switch (screen->getMenuStyle()->bullet) { switch (screen->getMenuStyle()->bullet) {
@ -703,6 +737,7 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
break; break;
} }
} }
}
} }

View file

@ -339,6 +339,31 @@ BScreen::~BScreen(void) {
if (resource.tstyle.font) if (resource.tstyle.font)
delete resource.tstyle.font; delete resource.tstyle.font;
if (resource.wstyle.close_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.wstyle.close_button.mask);
if (resource.wstyle.max_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.wstyle.max_button.mask);
if (resource.wstyle.icon_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.wstyle.icon_button.mask);
if (resource.wstyle.stick_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.wstyle.stick_button.mask);
if (resource.tstyle.left_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.tstyle.left_button.mask);
if (resource.tstyle.right_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.tstyle.right_button.mask);
if (resource.mstyle.bullet_image.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.mstyle.bullet_image.mask);
if (resource.mstyle.tick_image.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.mstyle.tick_image.mask);
resource.wstyle.max_button.mask = resource.wstyle.close_button.mask =
resource.wstyle.icon_button.mask =
resource.wstyle.stick_button.mask = None;
resource.tstyle.left_button.mask = resource.tstyle.right_button.mask = None;
resource.mstyle.bullet_image.mask = resource.mstyle.tick_image.mask = None;
XFreeGC(blackbox->getXDisplay(), opGC); XFreeGC(blackbox->getXDisplay(), opGC);
} }
@ -1037,6 +1062,28 @@ void BScreen::LoadStyle(void) {
resource.wstyle.b_pressed = resource.wstyle.b_pressed =
readDatabaseTexture("window.button.pressed", "black", style); readDatabaseTexture("window.button.pressed", "black", style);
if (resource.wstyle.close_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.wstyle.close_button.mask);
if (resource.wstyle.max_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.wstyle.max_button.mask);
if (resource.wstyle.icon_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.wstyle.icon_button.mask);
if (resource.wstyle.stick_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.wstyle.stick_button.mask);
resource.wstyle.close_button.mask = resource.wstyle.max_button.mask =
resource.wstyle.icon_button.mask =
resource.wstyle.icon_button.mask = None;
readDatabaseMask("window.button.close_mask", resource.wstyle.close_button,
style);
readDatabaseMask("window.button.max_mask", resource.wstyle.max_button,
style);
readDatabaseMask("window.button.icon_mask", resource.wstyle.icon_button,
style);
readDatabaseMask("window.button.stick_mask", resource.wstyle.stick_button,
style);
// we create the window.frame texture by hand because it exists only to // we create the window.frame texture by hand because it exists only to
// make the code cleaner and is not actually used for display // make the code cleaner and is not actually used for display
BColor color = readDatabaseColor("window.frame.focusColor", "white", style); BColor color = readDatabaseColor("window.frame.focusColor", "white", style);
@ -1076,7 +1123,12 @@ void BScreen::LoadStyle(void) {
if (resource.wstyle.h_unfocus.texture() == BTexture::Parent_Relative) if (resource.wstyle.h_unfocus.texture() == BTexture::Parent_Relative)
resource.wstyle.h_unfocus = resource.wstyle.f_unfocus; resource.wstyle.h_unfocus = resource.wstyle.f_unfocus;
// load toolbar config // load toolbar config
if (resource.tstyle.left_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.tstyle.left_button.mask);
if (resource.tstyle.right_button.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.tstyle.right_button.mask);
resource.tstyle.toolbar = resource.tstyle.toolbar =
readDatabaseTexture("toolbar", "black", style); readDatabaseTexture("toolbar", "black", style);
resource.tstyle.label = resource.tstyle.label =
@ -1097,6 +1149,10 @@ void BScreen::LoadStyle(void) {
readDatabaseColor("toolbar.clock.textColor", "white", style); readDatabaseColor("toolbar.clock.textColor", "white", style);
resource.tstyle.b_pic = resource.tstyle.b_pic =
readDatabaseColor("toolbar.button.picColor", "black", style); readDatabaseColor("toolbar.button.picColor", "black", style);
readDatabaseMask("toolbar.button.left_mask", resource.tstyle.left_button,
style);
readDatabaseMask("toolbar.button.right_mask", resource.tstyle.right_button,
style);
resource.tstyle.justify = LeftJustify; resource.tstyle.justify = LeftJustify;
if (style.getValue("toolbar.justify", s)) { if (style.getValue("toolbar.justify", s)) {
@ -1115,6 +1171,11 @@ void BScreen::LoadStyle(void) {
} }
// load menu config // load menu config
if (resource.mstyle.bullet_image.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.mstyle.bullet_image.mask);
if (resource.mstyle.tick_image.mask != None)
XFreePixmap(blackbox->getXDisplay(), resource.mstyle.tick_image.mask);
resource.mstyle.title = resource.mstyle.title =
readDatabaseTexture("menu.title", "white", style); readDatabaseTexture("menu.title", "white", style);
resource.mstyle.frame = resource.mstyle.frame =
@ -1129,6 +1190,8 @@ void BScreen::LoadStyle(void) {
readDatabaseColor("menu.frame.disableColor", "black", style); readDatabaseColor("menu.frame.disableColor", "black", style);
resource.mstyle.h_text = resource.mstyle.h_text =
readDatabaseColor("menu.hilite.textColor", "black", style); readDatabaseColor("menu.hilite.textColor", "black", style);
readDatabaseMask("menu.bullet.mask", resource.mstyle.bullet_image, style);
readDatabaseMask("menu.selected.mask", resource.mstyle.tick_image, style);
resource.mstyle.t_justify = LeftJustify; resource.mstyle.t_justify = LeftJustify;
if (style.getValue("menu.title.justify", s)) { if (style.getValue("menu.title.justify", s)) {
@ -2566,6 +2629,32 @@ void BScreen::toggleFocusModel(FocusModel model) {
std::mem_fun(&BlackboxWindow::grabButtons)); std::mem_fun(&BlackboxWindow::grabButtons));
} }
void BScreen::readDatabaseMask(const string &rname, PixmapMask &pixmapMask,
const Configuration &style) {
string s;
int hx, hy; //ignored
int ret = BitmapOpenFailed; //default to failure.
if (style.getValue(rname, s))
{
if (s[0] != '/' && s[0] != '~')
{
std::string xbmFile = std::string("~/.openbox/buttons/") + s;
ret = XReadBitmapFile(blackbox->getXDisplay(), getRootWindow(),
expandTilde(xbmFile).c_str(), &pixmapMask.w,
&pixmapMask.h, &pixmapMask.mask, &hx, &hy);
} else
ret = XReadBitmapFile(blackbox->getXDisplay(), getRootWindow(),
expandTilde(s).c_str(), &pixmapMask.w,
&pixmapMask.h, &pixmapMask.mask, &hx, &hy);
if (ret == BitmapSuccess)
return;
}
pixmapMask.mask = None;
pixmapMask.w = pixmapMask.h = 0;
}
BTexture BScreen::readDatabaseTexture(const string &rname, BTexture BScreen::readDatabaseTexture(const string &rname,
const string &default_color, const string &default_color,

View file

@ -61,12 +61,19 @@ struct Strut;
enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify }; enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify };
struct PixmapMask {
Pixmap mask;
unsigned int w, h;
};
struct WindowStyle { struct WindowStyle {
BColor l_text_focus, l_text_unfocus, b_pic_focus, BColor l_text_focus, l_text_unfocus, b_pic_focus,
b_pic_unfocus; b_pic_unfocus;
BTexture f_focus, f_unfocus, t_focus, t_unfocus, l_focus, l_unfocus, BTexture f_focus, f_unfocus, t_focus, t_unfocus, l_focus, l_unfocus,
h_focus, h_unfocus, b_focus, b_unfocus, b_pressed, g_focus, g_unfocus; h_focus, h_unfocus, b_focus, b_unfocus, b_pressed, g_focus, g_unfocus;
PixmapMask close_button, max_button, icon_button, stick_button;
BFont *font; BFont *font;
TextJustify justify; TextJustify justify;
@ -79,6 +86,8 @@ struct ToolbarStyle {
BColor l_text, w_text, c_text, b_pic; BColor l_text, w_text, c_text, b_pic;
BTexture toolbar, label, window, button, pressed, clock; BTexture toolbar, label, window, button, pressed, clock;
PixmapMask left_button, right_button; //these should probably be the same
BFont *font; BFont *font;
TextJustify justify; TextJustify justify;
@ -91,6 +100,8 @@ struct MenuStyle {
BColor t_text, f_text, h_text, d_text; BColor t_text, f_text, h_text, d_text;
BTexture title, frame, hilite; BTexture title, frame, hilite;
PixmapMask bullet_image, tick_image;
BFont *t_font, *f_font; BFont *t_font, *f_font;
TextJustify t_justify, f_justify; TextJustify t_justify, f_justify;
@ -180,6 +191,9 @@ private:
bool parseMenuFile(FILE *file, Rootmenu *menu); bool parseMenuFile(FILE *file, Rootmenu *menu);
void readDatabaseMask(const string &rname,
PixmapMask &pixmapMask,
const Configuration &style);
BTexture readDatabaseTexture(const std::string &rname, BTexture readDatabaseTexture(const std::string &rname,
const std::string &default_color, const std::string &default_color,
const Configuration &style); const Configuration &style);

View file

@ -623,28 +623,67 @@ void Toolbar::redrawWorkspaceLabel(bool redraw) {
void Toolbar::drawArrow(Drawable surface, bool left) const { void Toolbar::drawArrow(Drawable surface, bool left) const {
ToolbarStyle *style = screen->getToolbarStyle();
BPen pen(style->b_pic);
int hh = frame.button_w / 2, hw = frame.button_w / 2; int hh = frame.button_w / 2, hw = frame.button_w / 2;
XPoint pts[3]; XPoint pts[3];
const int bullet_size = 3; const int bullet_size = 3;
if (left) { if (left) {
if (style->left_button.mask == None) {
pts[0].x = hw - bullet_size; pts[0].x = hw - bullet_size;
pts[0].y = hh; pts[0].y = hh;
pts[1].x = 2 * bullet_size; pts[1].x = 2 * bullet_size;
pts[1].y = bullet_size; pts[1].y = bullet_size;
pts[2].x = 0; pts[2].x = 0;
pts[2].y = -(2 * bullet_size); pts[2].y = -(2 * bullet_size);
XFillPolygon(display, surface, pen.gc(), pts, 3, Convex,
CoordModePrevious);
} else { } else {
XSetClipMask(blackbox->getXDisplay(), pen.gc(), style->left_button.mask);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(),
(frame.button_w - style->left_button.w)/2,
(frame.button_w - style->left_button.h)/2);
XFillRectangle(blackbox->getXDisplay(), surface, pen.gc(),
(frame.button_w - style->left_button.w)/2,
(frame.button_w - style->left_button.h)/2,
(frame.button_w + style->left_button.w)/2,
(frame.button_w + style->left_button.h)/2);
XSetClipMask(blackbox->getXDisplay(), pen.gc(), None);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(), 0, 0);
}
} else {
if (style->right_button.mask == None) {
pts[0].x = hw - bullet_size; pts[0].x = hw - bullet_size;
pts[0].y = hh - bullet_size; pts[0].y = hh - bullet_size;
pts[1].x = (2 * bullet_size); pts[1].x = (2 * bullet_size);
pts[1].y = bullet_size; pts[1].y = bullet_size;
pts[2].x = -(2 * bullet_size); pts[2].x = -(2 * bullet_size);
pts[2].y = bullet_size; pts[2].y = bullet_size;
} XFillPolygon(display, surface, pen.gc(), pts, 3, Convex,
CoordModePrevious);
} else {
XSetClipMask(blackbox->getXDisplay(), pen.gc(),
style->right_button.mask);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(),
(frame.button_w - style->right_button.w)/2,
(frame.button_w - style->right_button.h)/2);
BPen pen(screen->getToolbarStyle()->b_pic); XFillRectangle(blackbox->getXDisplay(), surface, pen.gc(),
XFillPolygon(display, surface, pen.gc(), pts, 3, Convex, CoordModePrevious); (frame.button_w - style->right_button.w)/2,
(frame.button_w - style->right_button.h)/2,
(frame.button_w + style->right_button.w)/2,
(frame.button_w + style->right_button.h)/2);
XSetClipMask(blackbox->getXDisplay(), pen.gc(), None);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(), 0, 0);
}
}
} }

View file

@ -2614,12 +2614,29 @@ void BlackboxWindow::redrawIconifyButton(bool pressed) const {
XSetWindowBackground(blackbox->getXDisplay(), XSetWindowBackground(blackbox->getXDisplay(),
frame.iconify_button, frame.pbutton_pixel); frame.iconify_button, frame.pbutton_pixel);
} }
XClearWindow(blackbox->getXDisplay(), frame.iconify_button);
XClearWindow(blackbox->getXDisplay(), frame.iconify_button);
BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus : BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus :
screen->getWindowStyle()->b_pic_unfocus); screen->getWindowStyle()->b_pic_unfocus);
PixmapMask pm = screen->getWindowStyle()->icon_button;
if (screen->getWindowStyle()->icon_button.mask != None) {
XSetClipMask(blackbox->getXDisplay(), pen.gc(), pm.mask);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(),
(frame.button_w - pm.w)/2, (frame.button_w - pm.h)/2);
XFillRectangle(blackbox->getXDisplay(), frame.iconify_button, pen.gc(),
(frame.button_w - pm.w)/2, (frame.button_w - pm.h)/2,
(frame.button_w + pm.w)/2, (frame.button_w + pm.h)/2);
XSetClipMask(blackbox->getXDisplay(), pen.gc(), None);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(), 0, 0);
} else {
XDrawRectangle(blackbox->getXDisplay(), frame.iconify_button, pen.gc(), XDrawRectangle(blackbox->getXDisplay(), frame.iconify_button, pen.gc(),
2, (frame.button_w - 5), (frame.button_w - 5), 2); 2, (frame.button_w - 5), (frame.button_w - 5), 2);
}
} }
@ -2652,10 +2669,26 @@ void BlackboxWindow::redrawMaximizeButton(bool pressed) const {
BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus : BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus :
screen->getWindowStyle()->b_pic_unfocus); screen->getWindowStyle()->b_pic_unfocus);
PixmapMask pm = screen->getWindowStyle()->max_button;
if (pm.mask != None) {
XSetClipMask(blackbox->getXDisplay(), pen.gc(), pm.mask);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(),
(frame.button_w - pm.w)/2, (frame.button_w - pm.h)/2);
XFillRectangle(blackbox->getXDisplay(), frame.maximize_button, pen.gc(),
(frame.button_w - pm.w)/2, (frame.button_w - pm.h)/2,
(frame.button_w + pm.w)/2, (frame.button_w + pm.h)/2);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(), 0, 0 );
XSetClipMask( blackbox->getXDisplay(), pen.gc(), None );
} else {
XDrawRectangle(blackbox->getXDisplay(), frame.maximize_button, pen.gc(), XDrawRectangle(blackbox->getXDisplay(), frame.maximize_button, pen.gc(),
2, 2, (frame.button_w - 5), (frame.button_w - 5)); 2, 2, (frame.button_w - 5), (frame.button_w - 5));
XDrawLine(blackbox->getXDisplay(), frame.maximize_button, pen.gc(), XDrawLine(blackbox->getXDisplay(), frame.maximize_button, pen.gc(),
2, 3, (frame.button_w - 3), 3); 2, 3, (frame.button_w - 3), 3);
}
} }
@ -2663,8 +2696,8 @@ void BlackboxWindow::redrawCloseButton(bool pressed) const {
if (! pressed) { if (! pressed) {
if (flags.focused) { if (flags.focused) {
if (frame.fbutton) if (frame.fbutton)
XSetWindowBackgroundPixmap(blackbox->getXDisplay(), frame.close_button, XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
frame.fbutton); frame.close_button, frame.fbutton);
else else
XSetWindowBackground(blackbox->getXDisplay(), frame.close_button, XSetWindowBackground(blackbox->getXDisplay(), frame.close_button,
frame.fbutton_pixel); frame.fbutton_pixel);
@ -2725,8 +2758,24 @@ void BlackboxWindow::redrawStickyButton(bool pressed) const {
BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus : BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus :
screen->getWindowStyle()->b_pic_unfocus); screen->getWindowStyle()->b_pic_unfocus);
PixmapMask pm = screen->getWindowStyle()->stick_button;
if (pm.mask != None) {
XSetClipMask(blackbox->getXDisplay(), pen.gc(), pm.mask);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(),
(frame.button_w - pm.w)/2, (frame.button_w - pm.h)/2);
XFillRectangle(blackbox->getXDisplay(), frame.stick_button, pen.gc(),
(frame.button_w - pm.w)/2, (frame.button_w - pm.h)/2,
(frame.button_w + pm.w)/2, (frame.button_w + pm.h)/2);
XSetClipOrigin(blackbox->getXDisplay(), pen.gc(), 0, 0 );
XSetClipMask( blackbox->getXDisplay(), pen.gc(), None );
} else {
XFillRectangle(blackbox->getXDisplay(), frame.stick_button, pen.gc(), XFillRectangle(blackbox->getXDisplay(), frame.stick_button, pen.gc(),
frame.button_w/2 - 1, frame.button_w/2 -1, 2, 2 ); frame.button_w/2 - 1, frame.button_w/2 -1, 2, 2 );
}
} }
void BlackboxWindow::mapRequestEvent(const XMapRequestEvent *re) { void BlackboxWindow::mapRequestEvent(const XMapRequestEvent *re) {