r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / guicast / bcwidgetgrid.C
blobd8fa4a5b22478aba17e7213a0c59121154d4f511
1 #include "clip.h"
2 #include "bctitle.h"
3 #include "bcpot.h"
4 #include "bcslider.h"
5 #include "bcwidgetgrid.h"
8 BC_WidgetGrid::BC_WidgetGrid(int x1, int y1, int x2, int y2,int cgs,int rgs){
9         x_l = x1;  // x position
10         y_t = y1;  // y position
11         x_r = x2;  // right margin (used only in get_w_wm)
12         y_b = y2;  // left margin (used only in get_w_wm)
13         rowgaps = rgs; 
14         colgaps = cgs;
16         for (int r = 0; r < BC_WG_Rows; r++)
17           minh[r] = 0;
19         for (int c = 0; c < BC_WG_Cols; c++) 
20           minw[c] = 0;
22         for (int r = 0; r < BC_WG_Rows; r++)
23                 for (int c = 0; c < BC_WG_Cols; c++) {
24                         widget_types[r][c] = BC_WT_NONE;
25                         widget_valign[r][c] = VALIGN_CENTER;
26                         widget_halign[r][c] = HALIGN_LEFT;
27                         widget_colspan[r][c] = 1;
28                         widget_rowspan[r][c] = 1;
29                 }
32 BC_RelocatableWidget * BC_WidgetGrid::add(BC_RelocatableWidget *h, int row, int column) {
33         widget_types[row][column] = BC_WT_RelocatableWidget;
34         widget_widgs[row][column] = h;
35         return(h);
40 void BC_WidgetGrid::calculate_maxs(){
41         int r,c;
42         for (r = 0; r < BC_WG_Rows; r++) {
43                 maxh[r] = minh[r];
44                 for (c = 0; c < BC_WG_Cols; c++) {
45                         if ((widget_rowspan[r][c] == 1) && (getw_h(r,c) > maxh[r]))
46                                 maxh[r] = getw_h(r,c);
47                 }
48         }
50         for (c = 0; c < BC_WG_Cols; c++) {
51                 maxw[c] = minw[c];
52                 for (r = 0; r < BC_WG_Rows; r++) {
53                         if ((widget_colspan[r][c] == 1) && (getw_w(r,c) > maxw[c]))
54                                 maxw[c] = getw_w(r,c);
55                 }
56         }
58         // Fix up for row & colspans:
59         for (c = 0; c < BC_WG_Cols; c++) {
60                 for (r = 0; r < BC_WG_Rows; r++) {
61                         int c_cs = MIN(BC_WG_Cols - c + 1, widget_colspan[r][c]);
62                         int c_rs = MIN(BC_WG_Rows - c + 1, widget_rowspan[r][c]);
64                         if ((widget_colspan[r][c] > 1)) {
65                                 int csw = 0;
66                                 int c2;
67                                 for (c2 = c; c2 < c + c_cs; c2++) {
68                                         csw += maxw[c2];
69                                 }
70                                 if (csw < getw_w(r,c)) {
71                                         for (c2 = c; c2 < c + c_cs; c2++) {
72                                                 maxw[c2] += (csw - getw_w(r,c))/c_cs;
73                                         }
74                                 }
75                         }
77                         if ((widget_rowspan[r][c] > 1)) {
78                                 int csh = 0;
79                                 int r2;
80                                 for (r2 = c; r2 < r + c_rs; r2++) {
81                                         csh += maxh[r2];
82                                 }
83                                 if (csh < getw_h(r,c)) {
84                                         for (r2 = c; r2 < r + c_rs; r2++) {
85                                                 maxh[r2] += (csh - getw_h(r,c))/c_rs;
86                                         }
87                                 }
88                         }
89                 }
90         }
93 void BC_WidgetGrid::clear_widget(int row, int column){
94         widget_types[row][column] = BC_WT_NONE;
97 int BC_WidgetGrid::get_h(){
98         calculate_maxs();
99         int y = 0;
100         for (int i = 0; i < BC_WG_Rows; i++)
101                 if (maxh[i] > 0)
102                         y += maxh[i] + rowgaps;
103         return (y);
106 int BC_WidgetGrid::get_h_wm(){
107         return (y_t + get_h() + y_b);
110 int BC_WidgetGrid::get_w(){
111         calculate_maxs();
112         int x = 0;
113         for (int i = 0; i < BC_WG_Cols; i++)
114                 if (maxw[i] > 0)
115                         x += maxw[i] + colgaps;
116         return (x);
119 int BC_WidgetGrid::get_w_wm(){
120         return (x_l + get_w() + x_r);
123 int BC_WidgetGrid::getw_h(int row, int column) {
124         switch (widget_types[row][column]) {
125         case BC_WT_NONE:
126                 return(0);
127         case BC_WT_RelocatableWidget: 
128                 return(widget_widgs[row][column]->get_h());
129         }
132 int BC_WidgetGrid::getw_w(int row, int column) {
133         switch (widget_types[row][column]) {
134         case BC_WT_NONE:
135                 return(0);
136         case BC_WT_RelocatableWidget: 
137                 return(widget_widgs[row][column]->get_w());
138         }
141 int BC_WidgetGrid::guess_x(int colno){
142         calculate_maxs();
143         int x = x_l;
144         for (int i = 0; i < colno; i++)
145                 x += maxw[i] + colgaps;
146         return (x);
149 int BC_WidgetGrid::guess_y(int colno){
150         calculate_maxs();
151         int y = y_t;
152         for (int i = 0; i < colno; i++)
153                 y += maxh[i] + rowgaps;
154         return (y);
157 void BC_WidgetGrid::move_widgets(){
158         calculate_maxs();
159         int r,c,x,y;
160         int xn,yn;
161         y = y_t;
162         for (r = 0; r < BC_WG_Rows; r++) {
163                 x = x_l;
164                 for (c = 0; c < BC_WG_Cols; c++) {
165                         switch (widget_valign[r][c]){
166                         case VALIGN_TOP:
167                                 yn = y;
168                                 break;
169                         case VALIGN_CENTER:
170                                 yn = y + (maxh[r] - getw_h(r,c))/2;
171                                 break;
172                         case VALIGN_BOTTOM:
173                                 yn = y + (maxh[r] - getw_h(r,c));
174                                 break;
175                         }
176                                 
177                         switch (widget_halign[r][c]){
178                         case HALIGN_LEFT:
179                                 xn = x;
180                                 break;
181                         case HALIGN_CENTER:
182                                 xn = x + (maxw[c] - getw_w(r,c))/2;
183                                 break;
184                         case HALIGN_RIGHT:
185                                 xn = x + (maxw[c] - getw_w(r,c));
186                                 break;
187                         }
188                         setw_position(r,c,xn,yn); // + (maxh[r] - getw_h(r,c))/2);
189                         x += colgaps + maxw[c];
190                 }
191                 y += rowgaps + maxh[r];
192         }
195 void BC_WidgetGrid::print(){
196         printf("\nWidget Grid: Widths: x_l=%d y_t=%d x_r=%d y_b=%d\n",x_l,y_t,x_r,y_b);
197         calculate_maxs();
198         for (int r = 0; r < BC_WG_Rows; r++) {
199                 for (int c = 0; c < BC_WG_Cols; c++) {
200                         printf("%d,%d\t",getw_w(r,c),getw_h(r,c));
201                 }
202                 printf("MAX: %d\n",maxh[r]);
203         }
204         printf("---------------------------------------------\n");
205         for (int c = 0; c < BC_WG_Cols; c++) 
206                 printf("%d\t",maxw[c]);
207         printf("\n\n");
211 int BC_WidgetGrid::reposition_widget(int x, int y, int w1, int h){
212         x_l = x;
213         y_t = y;
214         move_widgets();
215         return(0);
218 void BC_WidgetGrid::set_align(int r,int c,int va, int ha){
219         widget_valign[r][c] = va;
220         widget_halign[r][c] = ha;
223 void BC_WidgetGrid::set_crspan(int r,int c,int cs, int rs){
224         widget_colspan[r][c] = cs;
225         widget_rowspan[r][c] = rs;
228 void BC_WidgetGrid::set_minw(int c,int w){
229         minw[c] = w;
232 void BC_WidgetGrid::set_minh(int c,int h){
233         minh[c] = h;
236 void BC_WidgetGrid::setw_position(int row,int column,int x, int y) {
237         switch (widget_types[row][column]) {
238         case BC_WT_NONE:
239                 break;
240         case BC_WT_RelocatableWidget: 
241                 widget_widgs[row][column]->reposition_widget(x,y);
242                 break;
243         }
247 BC_WidgetGridList::BC_WidgetGridList()
248  : ArrayList<BC_WidgetGrid*>()
252 BC_WidgetGridList::~BC_WidgetGridList()