From f44b282b001d2479586215cdc722ce426ca1782a Mon Sep 17 00:00:00 2001 From: fluxgen Date: Thu, 21 Mar 2002 10:54:29 +0000 Subject: added FbTk font to MenuStyle --- src/Basemenu.cc | 88 +++++++++++++++++++++++++++------------------------------ src/Theme.cc | 77 +++++++++++++++++++++++++------------------------- src/Theme.hh | 13 ++++----- 3 files changed, 85 insertions(+), 93 deletions(-) diff --git a/src/Basemenu.cc b/src/Basemenu.cc index 559bb97..f78b47e 100644 --- a/src/Basemenu.cc +++ b/src/Basemenu.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Basemenu.cc,v 1.13 2002/03/20 14:10:03 fluxgen Exp $ +// $Id: Basemenu.cc,v 1.14 2002/03/21 10:54:29 fluxgen Exp $ // stupid macros needed to access some functions in version 2 of the GNU C // library @@ -49,7 +49,10 @@ # include #endif // STDC_HEADERS +#ifdef DEBUG #include +using namespace std; +#endif //DEBUG static Basemenu *shown = (Basemenu *) 0; @@ -93,12 +96,12 @@ Basemenu::Basemenu(BScreen *scrn) { if (i18n->multibyte()) { menu.width = menu.title_h = menu.item_w = menu.frame_h = - screen->getMenuStyle()->titlefont.set_extents->max_ink_extent.height + + screen->getMenuStyle()->titlefont->getFontSetExtents()->max_ink_extent.height + (menu.bevel_w * 2); } else { menu.width = menu.title_h = menu.item_w = menu.frame_h = - screen->getMenuStyle()->titlefont.fontstruct->ascent + - screen->getMenuStyle()->titlefont.fontstruct->descent + + screen->getMenuStyle()->titlefont->getFontStruct()->ascent + + screen->getMenuStyle()->titlefont->getFontStruct()->descent + (menu.bevel_w * 2); } menu.label = 0; @@ -108,11 +111,11 @@ Basemenu::Basemenu(BScreen *scrn) { menu.minsub = 0; if (i18n->multibyte()) { - menu.item_h = screen->getMenuStyle()->framefont.set_extents->max_ink_extent.height + + menu.item_h = screen->getMenuStyle()->framefont->getFontSetExtents()->max_ink_extent.height + (menu.bevel_w); } else { - menu.item_h = screen->getMenuStyle()->framefont.fontstruct->ascent + - screen->getMenuStyle()->framefont.fontstruct->descent + + menu.item_h = screen->getMenuStyle()->framefont->getFontStruct()->ascent + + screen->getMenuStyle()->framefont->getFontStruct()->descent + (menu.bevel_w); } menu.height = menu.title_h + screen->getBorderWidth() + menu.frame_h; @@ -277,37 +280,33 @@ void Basemenu::update(void) { I18n *i18n = I18n::instance(); if (i18n->multibyte()) { - menu.item_h = screen->getMenuStyle()->framefont.set_extents->max_ink_extent.height + + menu.item_h = screen->getMenuStyle()->framefont->getFontSetExtents()->max_ink_extent.height + menu.bevel_w; - menu.title_h = screen->getMenuStyle()->titlefont.set_extents->max_ink_extent.height + + menu.title_h = screen->getMenuStyle()->titlefont->getFontSetExtents()->max_ink_extent.height + (menu.bevel_w * 2); } else { - menu.item_h = screen->getMenuStyle()->framefont.fontstruct->ascent + - screen->getMenuStyle()->framefont.fontstruct->descent + + menu.item_h = screen->getMenuStyle()->framefont->getFontStruct()->ascent + + screen->getMenuStyle()->framefont->getFontStruct()->descent + menu.bevel_w; - menu.title_h = screen->getMenuStyle()->titlefont.fontstruct->ascent + - screen->getMenuStyle()->titlefont.fontstruct->descent + + menu.title_h = screen->getMenuStyle()->titlefont->getFontStruct()->ascent + + screen->getMenuStyle()->titlefont->getFontStruct()->descent + (menu.bevel_w * 2); } if (title_vis) { const char *s = (menu.label) ? menu.label : - i18n->getMessage( -#ifdef NLS - BasemenuSet, BasemenuBlackboxMenu, -#else // !NLS - 0, 0, -#endif // NLS - "fluxbox Menu"); + i18n->getMessage( + BasemenuSet, BasemenuBlackboxMenu, + "fluxbox Menu"); int l = strlen(s); if (i18n->multibyte()) { XRectangle ink, logical; - XmbTextExtents(screen->getMenuStyle()->titlefont.set, s, l, &ink, &logical); + XmbTextExtents(screen->getMenuStyle()->titlefont->getFontSet(), s, l, &ink, &logical); menu.item_w = logical.width; } else - menu.item_w = XTextWidth(screen->getMenuStyle()->titlefont.fontstruct, s, l); + menu.item_w = XTextWidth(screen->getMenuStyle()->titlefont->getFontStruct(), s, l); menu.item_w += (menu.bevel_w * 2); } else @@ -324,10 +323,10 @@ void Basemenu::update(void) { if (i18n->multibyte()) { XRectangle ink, logical; - XmbTextExtents(screen->getMenuStyle()->framefont.set, s, l, &ink, &logical); + XmbTextExtents(screen->getMenuStyle()->framefont->getFontSet(), s, l, &ink, &logical); ii = logical.width; } else - ii = XTextWidth(screen->getMenuStyle()->framefont.fontstruct, s, l); + ii = XTextWidth(screen->getMenuStyle()->framefont->getFontStruct(), s, l); ii += (menu.bevel_w * 2) + (menu.item_h * 2); @@ -509,16 +508,12 @@ void Basemenu::redrawTitle(void) { int dx = menu.bevel_w, len = strlen(text); unsigned int l; - if (i18n->multibyte()) { - XRectangle ink, logical; - XmbTextExtents(screen->getMenuStyle()->titlefont.set, text, len, &ink, &logical); - l = logical.width; - } else - l = XTextWidth(screen->getMenuStyle()->titlefont.fontstruct, text, len); + l = screen->getMenuStyle()->titlefont->getTextWidth(text, len); - l += (menu.bevel_w * 2); + l += (menu.bevel_w * 2); - switch (screen->getMenuStyle()->titlefont.justify) { + //titlefont.justify + switch (screen->getMenuStyle()->titlefont_justify) { case DrawUtil::Font::RIGHT: dx += menu.width - l; break; @@ -531,13 +526,13 @@ void Basemenu::redrawTitle(void) { } if (i18n->multibyte()) - XmbDrawString(display, menu.title, screen->getMenuStyle()->titlefont.set, + XmbDrawString(display, menu.title, screen->getMenuStyle()->titlefont->getFontSet(), screen->getMenuStyle()->t_text_gc, dx, menu.bevel_w - - screen->getMenuStyle()->titlefont.set_extents->max_ink_extent.y, + screen->getMenuStyle()->titlefont->getFontSetExtents()->max_ink_extent.y, text, len); else XDrawString(display, menu.title, screen->getMenuStyle()->t_text_gc, dx, - screen->getMenuStyle()->titlefont.fontstruct->ascent + menu.bevel_w, + screen->getMenuStyle()->titlefont->getFontStruct()->ascent + menu.bevel_w, text, len); } @@ -681,20 +676,19 @@ void Basemenu::drawItem(unsigned int index, bool highlight, bool clear, I18n *i18n = I18n::instance(); if (text) { - if (i18n->multibyte()) { - XRectangle ink, logical; - XmbTextExtents(screen->getMenuStyle()->framefont.set, text, len, &ink, &logical); - text_w = logical.width; + text_w = screen->getMenuStyle()->framefont->getTextWidth(text, len); + + if (screen->getMenuStyle()->framefont->multibyte()) { text_y = item_y + (menu.bevel_w / 2) - - screen->getMenuStyle()->framefont.set_extents->max_ink_extent.y; + screen->getMenuStyle()->framefont->getFontSetExtents()->max_ink_extent.y; } else { - text_w = XTextWidth(screen->getMenuStyle()->framefont.fontstruct, text, len); - text_y = item_y + - screen->getMenuStyle()->framefont.fontstruct->ascent + + text_y = item_y + + screen->getMenuStyle()->framefont->getFontStruct()->ascent + (menu.bevel_w / 2); } - - switch(screen->getMenuStyle()->framefont.justify) { + + // framfont.justify + switch(screen->getMenuStyle()->framefont_justify) { case DrawUtil::Font::LEFT: text_x = item_x + menu.bevel_w + menu.item_h + 1; break; @@ -706,7 +700,7 @@ void Basemenu::drawItem(unsigned int index, bool highlight, bool clear, text_x = item_x + ((menu.item_w + 1 - text_w) / 2); break; } - + text_h = menu.item_h - menu.bevel_w; } @@ -781,7 +775,7 @@ void Basemenu::drawItem(unsigned int index, bool highlight, bool clear, if (dotext && text) { if (i18n->multibyte()) { - XmbDrawString(display, menu.frame, screen->getMenuStyle()->framefont.set, + XmbDrawString(display, menu.frame, screen->getMenuStyle()->framefont->getFontSet(), tgc, text_x, text_y, text, len); } else XDrawString(display, menu.frame, tgc, text_x, text_y, text, len); diff --git a/src/Theme.cc b/src/Theme.cc index 9045b67..d712f86 100644 --- a/src/Theme.cc +++ b/src/Theme.cc @@ -41,7 +41,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Theme.cc,v 1.17 2002/01/27 13:16:07 fluxgen Exp $ +// $Id: Theme.cc,v 1.18 2002/03/21 10:54:29 fluxgen Exp $ #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -77,12 +77,15 @@ m_colormap(colormap), m_screennum(screennum), m_rootcommand(rootcommand==0 ? "" : rootcommand) //we dont want to send 0-pointer to std::string { + #ifdef DEBUG + cerr<<__FILE__<<"("<<__LINE__<<"): Creating."<fid; + if (m_menustyle.titlefont->getFontStruct()) + gcv.font = m_menustyle.titlefont->getFontStruct()->fid; m_menustyle.t_text_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv); gcv.foreground = m_menustyle.f_text.getPixel(); - if (m_menustyle.framefont.fontstruct) - gcv.font = m_menustyle.framefont.fontstruct->fid; + if (m_menustyle.framefont->getFontStruct()) + gcv.font = m_menustyle.framefont->getFontStruct()->fid; m_menustyle.f_text_gc = XCreateGC(m_display, rootwindow, @@ -210,17 +213,10 @@ Theme::~Theme() { // should only be called from ~Theme //-------------------- void Theme::freeMenuStyle() { - if (m_menustyle.titlefont.set) - XFreeFontSet(m_display, m_menustyle.titlefont.set); - - if (m_menustyle.titlefont.fontstruct) - XFreeFont(m_display, m_menustyle.titlefont.fontstruct); - - if (m_menustyle.framefont.set) - XFreeFontSet(m_display, m_menustyle.framefont.set); - - if (m_menustyle.framefont.fontstruct) - XFreeFont(m_display, m_menustyle.framefont.fontstruct); + delete m_menustyle.framefont; + m_menustyle.framefont = 0; + delete m_menustyle.titlefont; + m_menustyle.titlefont = 0; XFreeGC(m_display, m_menustyle.t_text_gc); XFreeGC(m_display, m_menustyle.f_text_gc); @@ -304,7 +300,9 @@ void Theme::load(const char *filename){ } void Theme::loadMenuStyle() { - + if (m_menustyle.titlefont==0) + m_menustyle.titlefont = new FbTk::Font(m_display); + readDatabaseTexture("menu.title", "Menu.Title", &m_menustyle.title, WhitePixel(m_display, m_screennum)); @@ -334,27 +332,27 @@ void Theme::loadMenuStyle() { "Menu.Title.Justify", &value_type, &value)) { if (strstr(value.addr, "right") || strstr(value.addr, "Right")) - m_menustyle.titlefont.justify = DrawUtil::Font::RIGHT; + m_menustyle.titlefont_justify = DrawUtil::Font::RIGHT; else if (strstr(value.addr, "center") || strstr(value.addr, "Center")) - m_menustyle.titlefont.justify = DrawUtil::Font::CENTER; + m_menustyle.titlefont_justify = DrawUtil::Font::CENTER; else - m_menustyle.titlefont.justify = DrawUtil::Font::LEFT; - + m_menustyle.titlefont_justify = DrawUtil::Font::LEFT; + } else - m_menustyle.titlefont.justify = DrawUtil::Font::LEFT; + m_menustyle.titlefont_justify = DrawUtil::Font::LEFT; if (XrmGetResource(m_database, "menu.frame.justify", "Menu.Frame.Justify", &value_type, &value)) { if (strstr(value.addr, "right") || strstr(value.addr, "Right")) - m_menustyle.framefont.justify = DrawUtil::Font::RIGHT; + m_menustyle.framefont_justify = DrawUtil::Font::RIGHT; else if (strstr(value.addr, "center") || strstr(value.addr, "Center")) - m_menustyle.framefont.justify = DrawUtil::Font::CENTER; + m_menustyle.framefont_justify = DrawUtil::Font::CENTER; else - m_menustyle.framefont.justify = DrawUtil::Font::LEFT; + m_menustyle.framefont_justify = DrawUtil::Font::LEFT; } else - m_menustyle.framefont.justify = DrawUtil::Font::LEFT; + m_menustyle.framefont_justify = DrawUtil::Font::LEFT; if (XrmGetResource(m_database, "menu.bullet", "Menu.Bullet", &value_type, &value)) { @@ -383,19 +381,22 @@ void Theme::loadMenuStyle() { m_menustyle.bullet_pos = Basemenu::LEFT; //---------- font - + m_menustyle.framefont->loadFromDatabase(m_database, "menu.frame.font", "Menu.Frame.Font"); + m_menustyle.titlefont->loadFromDatabase(m_database, "menu.Title.font", "Menu.Title.Font"); + /* if (I18n::instance()->multibyte()) { readDatabaseFontSet("menu.title.font", "Menu.Title.Font", &m_menustyle.titlefont.set); readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font", &m_menustyle.framefont.set); - + m_menustyle.titlefont.set_extents = XExtentsOfFontSet(m_menustyle.titlefont.set); m_menustyle.framefont.set_extents = XExtentsOfFontSet(m_menustyle.framefont.set); - + + } else { readDatabaseFont("menu.title.font", "Menu.Title.Font", @@ -403,7 +404,7 @@ void Theme::loadMenuStyle() { readDatabaseFont("menu.frame.font", "Menu.Frame.Font", &m_menustyle.framefont.fontstruct); - } + }*/ } @@ -1001,14 +1002,14 @@ void Theme::reconfigure() { GCForeground, &gcv); gcv.foreground = m_menustyle.t_text.getPixel(); - if (m_menustyle.titlefont.fontstruct) - gcv.font = m_menustyle.titlefont.fontstruct->fid; + if (m_menustyle.titlefont->getFontStruct()) + gcv.font = m_menustyle.titlefont->getFontStruct()->fid; XChangeGC(m_display, m_menustyle.t_text_gc, gc_value_mask, &gcv); gcv.foreground = m_menustyle.f_text.getPixel(); - if (m_menustyle.framefont.fontstruct) - gcv.font = m_menustyle.framefont.fontstruct->fid; + if (m_menustyle.framefont->getFontStruct()) + gcv.font = m_menustyle.framefont->getFontStruct()->fid; XChangeGC(m_display, m_menustyle.f_text_gc, gc_value_mask, &gcv); diff --git a/src/Theme.hh b/src/Theme.hh index 5cafbf6..7e2e6f0 100644 --- a/src/Theme.hh +++ b/src/Theme.hh @@ -42,19 +42,14 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Theme.hh,v 1.6 2002/02/17 18:49:50 fluxgen Exp $ +// $Id: Theme.hh,v 1.7 2002/03/21 10:54:29 fluxgen Exp $ #ifndef THEME_HH #define THEME_HH - -#ifndef _IMAGE_HH_ #include "Image.hh" -#endif //!_IMAGE_HH_ - -#ifndef _DRAWUTIL_HH_ #include "DrawUtil.hh" -#endif //!_MISC_HH_ +#include "Font.hh" #include #include @@ -74,7 +69,9 @@ public: BColor t_text, f_text, h_text, d_text; BTexture title, frame, hilite; GC t_text_gc, f_text_gc, h_text_gc, d_text_gc, hilite_gc; - DrawUtil::Font titlefont, framefont; + FbTk::Font *titlefont, *framefont; + DrawUtil::Font::FontJustify framefont_justify; + DrawUtil::Font::FontJustify titlefont_justify; int bullet, bullet_pos; } MenuStyle; -- cgit v0.11.2