1 #include "bcresources.h"
3 #include "bcresources.h"
7 BC_Title::BC_Title(int x,
14 : BC_SubWindow(x, y, -1, -1, -1)
18 this->color = get_resources()->default_text_color;
21 this->centered = centered;
22 this->fixed_w = fixed_w;
23 strcpy(this->text, text);
31 int BC_Title::initialize()
34 get_size(this, font, text, fixed_w, w, h);
36 if(centered) x -= w / 2;
38 BC_SubWindow::initialize();
43 int BC_Title::set_color(int color)
50 int BC_Title::resize(int w, int h)
57 int BC_Title::reposition(int x, int y)
59 reposition_window(x, y, w, h);
65 int BC_Title::update(char *text)
69 strcpy(this->text, text);
70 get_size(this, font, text, fixed_w, new_w, new_h);
71 if(new_w > w || new_h > h)
73 resize_window(new_w, new_h);
79 void BC_Title::update(float value)
81 char string[BCTEXTLEN];
82 sprintf(string, "%.04f", value);
86 char* BC_Title::get_text()
95 // Fix background for block fonts.
96 // This should eventually be included in a BC_WindowBase::is_blocked_font()
98 if(font == MEDIUM_7SEGMENT)
100 //leave it up to the theme to decide if we need a background or not.
101 if (top_level->get_resources()->draw_clock_background)
103 BC_WindowBase::set_color(BLACK);
104 draw_box(0, 0, w, h);
108 draw_top_background(parent_window, 0, 0, w, h);
111 BC_WindowBase::set_color(color);
112 for(i = 0, j = 0, x = 0, y = get_text_ascent(font);
116 if(text[i] == '\n' || text[i] == 0)
120 draw_center_text(get_w() / 2,
134 y += get_text_height(font);
137 set_font(MEDIUMFONT); // reset
143 int BC_Title::calculate_w(BC_WindowBase *gui, char *text, int font)
146 get_size(gui, font, text, 0, temp_w, temp_h);
150 int BC_Title::calculate_h(BC_WindowBase *gui, char *text, int font)
153 get_size(gui, font, text, 0, temp_w, temp_h);
159 void BC_Title::get_size(BC_WindowBase *gui, int font, char *text, int fixed_w, int &w, int &h)
161 int i, j, x, y, line_w = 0;
165 for(i = 0, j = 0; i <= strlen(text); i++)
171 line_w = gui->get_text_width(font, &text[j], i - j);
178 line_w = gui->get_text_width(font, &text[j]);
180 if(line_w > w) w = line_w;
183 h *= gui->get_text_height(font);
185 if(fixed_w > 0) w = fixed_w;
190 // c-file-style: "linux"