r199: This commit was manufactured by cvs2svn to create tag 'hv_1_1_9'.
[cinelerra_cv/ct.git] / hvirtual / guicast / bctitle.C
blob6e0711c0cba2871ef8b364097a6fe566c157cf35
1 #include "bctitle.h"
2 #include <string.h>
3 #include <unistd.h>
5 BC_Title::BC_Title(int x, 
6                 int y, 
7                 char *text, 
8                 int font, 
9                 int color, 
10                 int centered,
11                 int fixed_w)
12  : BC_SubWindow(x, y, -1, -1, -1)
14         this->font = font;
15         this->color = color;
16         this->centered = centered;
17         this->fixed_w = fixed_w;
18         strcpy(this->text, text);
21 BC_Title::~BC_Title()
26 int BC_Title::initialize()
28         if(w <= 0 || h <= 0)
29                 get_size(w, h);
31         if(centered) x -= w / 2;
33         BC_SubWindow::initialize();
34         draw();
35         return 0;
38 int BC_Title::set_color(int color)
40         this->color = color;
41         draw();
42         return 0;
45 int BC_Title::resize(int w, int h)
47         resize_window(w, h);
48         draw();
49         return 0;
52 int BC_Title::reposition(int x, int y)
54         reposition_window(x, y, w, h);
55         draw();
56         return 0;
60 int BC_Title::update(char *text)
62         int new_w, new_h;
64         strcpy(this->text, text);
65         get_size(new_w, new_h);
66         if(new_w > w || new_h > h)
67         {
68                 resize_window(new_w, new_h);
69         }
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;
150         return 0;