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"
24 #include "bcresources.h"
28 BC_Title::BC_Title(int x,
35 : BC_SubWindow(x, y, -1, -1, -1)
39 this->color = get_resources()->default_text_color;
42 this->centered = centered;
43 this->fixed_w = fixed_w;
44 strcpy(this->text, text);
52 int BC_Title::initialize()
55 get_size(this, font, text, fixed_w, w, h);
57 if(centered) x -= w / 2;
59 BC_SubWindow::initialize();
65 int BC_Title::set_color(int color)
72 int BC_Title::resize(int w, int h)
79 int BC_Title::reposition(int x, int y)
81 reposition_window(x, y, w, h);
87 int BC_Title::update(const char *text, int flush)
91 strcpy(this->text, text);
92 get_size(this, font, text, fixed_w, new_w, new_h);
93 if(new_w > w || new_h > h)
95 resize_window(new_w, new_h);
101 void BC_Title::update(float value)
103 char string[BCTEXTLEN];
104 sprintf(string, "%.04f", value);
108 char* BC_Title::get_text()
113 int BC_Title::draw(int flush)
117 // Fix background for block fonts.
118 // This should eventually be included in a BC_WindowBase::is_blocked_font()
120 if(font == MEDIUM_7SEGMENT)
122 //leave it up to the theme to decide if we need a background or not.
123 if (top_level->get_resources()->draw_clock_background) {
124 BC_WindowBase::set_color(get_bg_color());
125 draw_box(0, 0, w, h);
129 draw_top_background(parent_window, 0, 0, w, h);
132 BC_WindowBase::set_color(color);
133 int text_len = strlen(text);
134 j = 0; x = 0; y = get_text_ascent(font);
135 for(i = 0; i <= text_len; i++)
137 if(text[i] == '\n' || text[i] == 0)
141 draw_center_text(get_w() / 2,
155 y += get_text_height(font);
158 set_font(MEDIUMFONT); // reset
163 int BC_Title::calculate_w(BC_WindowBase *gui, const char *text, int font)
166 get_size(gui, font, text, 0, temp_w, temp_h);
170 int BC_Title::calculate_h(BC_WindowBase *gui, const char *text, int font)
173 get_size(gui, font, text, 0, temp_w, temp_h);
179 void BC_Title::get_size(BC_WindowBase *gui, int font, const char *text, int fixed_w, int &w, int &h)
186 int text_len = strlen(text);
187 for(i = 0; i <= text_len; i++)
193 line_w = gui->get_text_width(font, &text[j], i - j);
200 line_w = gui->get_text_width(font, &text[j]);
202 if(line_w > w) w = line_w;
205 h *= gui->get_text_height(font);
207 if(fixed_w > 0) w = fixed_w;