4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcresources.h"
29 BC_Title::BC_Title(int x,
36 : BC_SubWindow(x, y, -1, -1, -1)
40 this->color = get_resources()->default_text_color;
43 this->centered = centered;
44 this->fixed_w = fixed_w;
45 strcpy(this->text, text);
53 int BC_Title::initialize()
56 get_size(this, font, text, fixed_w, w, h);
58 if(centered) x -= w / 2;
60 BC_SubWindow::initialize();
66 int BC_Title::set_color(int color)
73 int BC_Title::resize(int w, int h)
80 int BC_Title::reposition(int x, int y)
82 reposition_window(x, y, w, h);
88 int BC_Title::update(const char *text, int flush)
92 strcpy(this->text, text);
93 get_size(this, font, text, fixed_w, new_w, new_h);
94 if(new_w > w || new_h > h)
96 resize_window(new_w, new_h);
102 void BC_Title::update(float value)
104 char string[BCTEXTLEN];
105 sprintf(string, "%.04f", value);
109 char* BC_Title::get_text()
114 int BC_Title::draw(int flush)
116 // Fix background for block fonts.
117 // This should eventually be included in a BC_WindowBase::is_blocked_font()
119 if(font == MEDIUM_7SEGMENT)
121 //leave it up to the theme to decide if we need a background or not.
122 if (top_level->get_resources()->draw_clock_background) {
123 BC_WindowBase::set_color(get_bg_color());
124 draw_box(0, 0, w, h);
128 draw_top_background(parent_window, 0, 0, w, h);
131 BC_WindowBase::set_color(color);
132 return draw(flush, 0, 0);
135 int BC_Title::draw(int flush, int x, int y)
137 y += get_text_ascent(font);
138 int len = strlen(text);
139 for( int i=0,j=0; i<=len; ++i ) {
140 if( text[i] && text[i] != '\n' ) continue;
142 draw_center_text(get_w()/2, y, &text[j], i - j);
144 draw_text(x, y, &text[j], i - j);
146 y += get_text_height(font);
148 set_font(MEDIUMFONT); // reset
153 int BC_Title::calculate_w(BC_WindowBase *gui, const char *text, int font)
156 get_size(gui, font, text, 0, temp_w, temp_h);
160 int BC_Title::calculate_h(BC_WindowBase *gui, const char *text, int font)
163 get_size(gui, font, text, 0, temp_w, temp_h);
169 void BC_Title::get_size(BC_WindowBase *gui, int font, const char *text, int fixed_w, int &w, int &h)
176 int text_len = strlen(text);
177 for(i = 0; i <= text_len; i++)
183 line_w = gui->get_text_width(font, &text[j], i - j);
190 line_w = gui->get_text_width(font, &text[j]);
192 if(line_w > w) w = line_w;
195 h *= gui->get_text_height(font);
197 if(fixed_w > 0) w = fixed_w;
201 BC_TitleBar::BC_TitleBar(int x, int y, int w, int offset, int margin,
202 const char *text, int font, int color, VFrame *data)
203 : BC_Title(x, y, text, font, color, 0, w)
205 this->offset = offset;
206 this->margin = margin;
211 BC_TitleBar::~BC_TitleBar()
216 void BC_TitleBar::set_image(VFrame *data)
219 image = new BC_Pixmap(get_parent_window(), data, PIXMAP_ALPHA);
222 int BC_TitleBar::initialize()
227 set_image(get_resources()->bar_data);
228 BC_Title::initialize();
233 int BC_TitleBar::draw(int flush)
235 int w = get_w(), h = get_h(), h2 = h/2;
236 draw_top_background(get_parent_window(), 0, 0,w, h);
237 draw_3segmenth(0,h2, offset, 0, offset, image);
238 int tx = offset + margin, tw, th;
240 BC_WindowBase::set_color(color);
241 BC_Title::draw(flush, tx, 0);
242 get_size(get_parent_window(), font, text, 0, tw, th);
244 draw_3segmenth(tx,h2, w-tx, tx,w-tx, image);