r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / bctitle.C
blob7c1ebde66b87ccd95d988932d74d12405d564548
1 #include "bctitle.h"
2 #include <string.h>
4 BC_Title::BC_Title(int x, 
5                 int y, 
6                 char *text, 
7                 int font, 
8                 int color, 
9                 int centered,
10                 int fixed_w)
11  : BC_SubWindow(x, y, -1, -1, -1)
13         this->font = font;
14         this->color = color;
15         this->centered = centered;
16         this->fixed_w = fixed_w;
17         strcpy(this->text, text);
20 BC_Title::~BC_Title()
25 int BC_Title::initialize()
27         if(w <= 0 || h <= 0)
28                 get_size(w, h);
30         if(centered) x -= w / 2;
32         BC_SubWindow::initialize();
33         draw();
34         return 0;
37 int BC_Title::set_color(int color)
39         this->color = color;
40         draw();
41         return 0;
44 int BC_Title::resize(int w, int h)
46         resize_window(w, h);
47         draw();
48         return 0;
51 int BC_Title::reposition(int x, int y)
53         reposition_window(x, y, w, h);
54         draw();
55         return 0;
59 int BC_Title::update(char *text)
61         int new_w, new_h;
63         strcpy(this->text, text);
64         get_size(new_w, new_h);
65         if(new_w > w || new_h > h)
66         {
67                 resize_window(new_w, new_h);
68         }
70         draw();
71         return 0;
74 int BC_Title::draw()
76         int i, j, x, y;
78 // Fix background for block fonts.
79 // This should eventually be included in a BC_WindowBase::is_blocked_font()
81         if(font == MEDIUM_7SEGMENT)
82         {
83                 BC_WindowBase::set_color(BLACK);
84                 draw_box(0, 0, w, h);
85         }
86         else
87                 draw_top_background(parent_window, 0, 0, w, h);
89         set_font(font);
90         BC_WindowBase::set_color(color);
91         for(i = 0, j = 0, x = 0, y = get_text_ascent(font); 
92                 i <= strlen(text); 
93                 i++)
94         {
95                 if(text[i] == '\n' || text[i] == 0)
96                 {
97                         if(centered)
98                         {
99                                 draw_center_text(get_w() / 2, 
100                                         y,
101                                         &text[j],
102                                         i - j);
103                                 j = i + 1;
104                         }
105                         else
106                         {
107                                 draw_text(x, 
108                                         y,
109                                         &text[j],
110                                         i - j);
111                                 j = i + 1;
112                         }
113                         y += get_text_height(font);
114                 }
115         }
116         set_font(MEDIUMFONT);    // reset
117         flash();
118         flush();
119         return 0;
122 int BC_Title::get_size(int &w, int &h)
124         int i, j, x, y, line_w = 0;
125         w = 0;
126         h = 0;
128         for(i = 0, j = 0; i <= strlen(text); i++)
129         {
130                 line_w = 0;
131                 if(text[i] == '\n')
132                 {
133                         h++;
134                         line_w = get_text_width(font, &text[j], i - j);
135                         j = i + 1;
136                 }
137                 else
138                 if(text[i] == 0)
139                 {
140                         h++;
141                         line_w = get_text_width(font, &text[j]);
142                 }
143                 if(line_w > w) w = line_w;
144         }
146         h *= get_text_height(font);
147         w += 5;
148         if(fixed_w > 0) w = fixed_w;
149 //printf("BC_Title::get_size %d\n", w);
150         return 0;