Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GUI_WIDGETS_GRID_HPP_INCLUDED
00017 #define GUI_WIDGETS_GRID_HPP_INCLUDED
00018
00019 #include "gui/widgets/widget.hpp"
00020
00021 namespace gui2 {
00022
00023
00024
00025
00026
00027
00028
00029 class tgrid : public virtual twidget
00030 {
00031 friend class tdebug_layout_graph;
00032 friend struct tgrid_implementation;
00033
00034 public:
00035
00036 explicit tgrid(const unsigned rows = 0, const unsigned cols = 0);
00037
00038 virtual ~tgrid();
00039
00040
00041 static const unsigned VERTICAL_SHIFT = 0;
00042 static const unsigned VERTICAL_GROW_SEND_TO_CLIENT = 1 << VERTICAL_SHIFT;
00043 static const unsigned VERTICAL_ALIGN_TOP = 2 << VERTICAL_SHIFT;
00044 static const unsigned VERTICAL_ALIGN_CENTER = 3 << VERTICAL_SHIFT;
00045 static const unsigned VERTICAL_ALIGN_BOTTOM = 4 << VERTICAL_SHIFT;
00046 static const unsigned VERTICAL_MASK = 7 << VERTICAL_SHIFT;
00047
00048 static const unsigned HORIZONTAL_SHIFT = 3;
00049 static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT = 1 << HORIZONTAL_SHIFT;
00050 static const unsigned HORIZONTAL_ALIGN_LEFT = 2 << HORIZONTAL_SHIFT;
00051 static const unsigned HORIZONTAL_ALIGN_CENTER = 3 << HORIZONTAL_SHIFT;
00052 static const unsigned HORIZONTAL_ALIGN_RIGHT = 4 << HORIZONTAL_SHIFT;
00053 static const unsigned HORIZONTAL_MASK = 7 << HORIZONTAL_SHIFT;
00054
00055 static const unsigned BORDER_TOP = 1 << 6;
00056 static const unsigned BORDER_BOTTOM = 1 << 7;
00057 static const unsigned BORDER_LEFT = 1 << 8;
00058 static const unsigned BORDER_RIGHT = 1 << 9;
00059 static const unsigned BORDER_ALL =
00060 BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT;
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 unsigned add_row(const unsigned count = 1);
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 void set_row_grow_factor(const unsigned row, const unsigned factor)
00082 {
00083 assert(row < row_grow_factor_.size());
00084 row_grow_factor_[row] = factor;
00085 set_dirty();
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 void set_column_grow_factor(const unsigned column, const unsigned factor)
00097 {
00098 assert(column< col_grow_factor_.size());
00099 col_grow_factor_[column] = factor;
00100 set_dirty();
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 void set_child(twidget* widget, const unsigned row,
00121 const unsigned col, const unsigned flags, const unsigned border_size);
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 twidget* swap_child(
00139 const std::string& id, twidget* widget, const bool recurse,
00140 twidget* new_parent = NULL);
00141
00142
00143
00144
00145
00146
00147
00148 void remove_child(const unsigned row, const unsigned col);
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 void remove_child(const std::string& id, const bool find_all = false);
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 void set_active(const bool active);
00169
00170
00171
00172 const twidget* widget(const unsigned row, const unsigned col) const
00173 { return child(row, col).widget(); }
00174
00175
00176 twidget* widget(const unsigned row, const unsigned col)
00177 { return child(row, col).widget(); }
00178
00179
00180
00181
00182 void layout_init(const bool full_initialization);
00183
00184
00185
00186
00187
00188
00189
00190
00191 void reduce_width(const unsigned maximum_width);
00192
00193
00194 void request_reduce_width(const unsigned maximum_width);
00195
00196
00197 void demand_reduce_width(const unsigned maximum_width);
00198
00199
00200
00201
00202
00203
00204
00205
00206 void reduce_height(const unsigned maximum_height);
00207
00208
00209 void request_reduce_height(const unsigned maximum_height);
00210
00211
00212 void demand_reduce_height(const unsigned maximum_height);
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 tpoint recalculate_best_size();
00223
00224 private:
00225
00226
00227 tpoint calculate_best_size() const;
00228 public:
00229
00230
00231 bool can_wrap() const;
00232
00233 public:
00234
00235 void place(const tpoint& origin, const tpoint& size);
00236
00237
00238
00239
00240 void set_origin(const tpoint& origin);
00241
00242
00243 void set_visible_area(const SDL_Rect& area);
00244
00245
00246 void layout_children();
00247
00248
00249 void child_populate_dirty_list(twindow& caller,
00250 const std::vector<twidget*>& call_stack);
00251
00252
00253 twidget* find_at(const tpoint& coordinate, const bool must_be_active);
00254
00255
00256 const twidget* find_at(const tpoint& coordinate,
00257 const bool must_be_active) const;
00258
00259
00260 twidget* find(const std::string& id, const bool must_be_active);
00261
00262
00263 const twidget* find(const std::string& id,
00264 const bool must_be_active) const;
00265
00266
00267 bool has_widget(const twidget* widget) const;
00268
00269
00270 bool disable_click_dismiss() const;
00271
00272
00273 virtual iterator::twalker_* create_walker();
00274
00275
00276
00277 void set_rows(const unsigned rows);
00278 unsigned int get_rows() const { return rows_; }
00279
00280 void set_cols(const unsigned cols);
00281 unsigned int get_cols() const { return cols_; }
00282
00283
00284
00285
00286
00287
00288
00289 void set_rows_cols(const unsigned rows, const unsigned cols);
00290
00291 private:
00292
00293 class tchild
00294 {
00295 friend struct tgrid_implementation;
00296 public:
00297 tchild() :
00298 flags_(0),
00299 border_size_(0),
00300 widget_(NULL)
00301
00302
00303
00304 {}
00305
00306
00307 tpoint get_best_size() const;
00308
00309
00310
00311
00312
00313
00314
00315 void place(tpoint origin, tpoint size);
00316
00317
00318 void layout_init(const bool full_initialization);
00319
00320
00321 bool can_wrap() const
00322 { return widget_ ? widget_->can_wrap() : false; }
00323
00324
00325 const std::string& id() const;
00326
00327 unsigned get_flags() const { return flags_; }
00328 void set_flags(const unsigned flags) { flags_ = flags; }
00329
00330 unsigned get_border_size() const { return border_size_; }
00331 void set_border_size(const unsigned border_size)
00332 { border_size_ = border_size; }
00333
00334 const twidget* widget() const { return widget_; }
00335 twidget* widget() { return widget_; }
00336
00337 void set_widget(twidget* widget) { widget_ = widget; }
00338
00339 private:
00340
00341 unsigned flags_;
00342
00343
00344
00345
00346
00347 unsigned border_size_;
00348
00349
00350
00351
00352
00353
00354
00355 twidget* widget_;
00356
00357
00358 tpoint border_space() const;
00359
00360 };
00361
00362 public:
00363
00364 class iterator
00365 {
00366
00367 public:
00368
00369 iterator(std::vector<tchild>::iterator itor) :
00370 itor_(itor)
00371 {}
00372
00373 iterator operator++() { return iterator(++itor_); }
00374 iterator operator--() { return iterator(--itor_); }
00375 twidget* operator->() { return itor_->widget(); }
00376 twidget* operator*() { return itor_->widget(); }
00377
00378 bool operator==(const iterator& i) const
00379 { return i.itor_ == this->itor_; }
00380
00381 bool operator!=(const iterator& i) const
00382 { return i.itor_ != this->itor_; }
00383
00384 private:
00385 std::vector<tchild>::iterator itor_;
00386
00387 };
00388
00389 iterator begin() { return iterator(children_.begin()); }
00390 iterator end() { return iterator(children_.end()); }
00391
00392 private:
00393
00394 unsigned rows_;
00395
00396
00397 unsigned cols_;
00398
00399
00400
00401
00402 mutable std::vector<unsigned> row_height_;
00403
00404
00405 mutable std::vector<unsigned> col_width_;
00406
00407
00408 std::vector<unsigned> row_grow_factor_;
00409
00410
00411 std::vector<unsigned> col_grow_factor_;
00412
00413
00414
00415
00416
00417
00418
00419 std::vector<tchild> children_;
00420 const tchild& child(const unsigned row, const unsigned col) const
00421 { return children_[rows_ * col + row]; }
00422 tchild& child(const unsigned row, const unsigned col)
00423 { return children_[rows_ * col + row]; }
00424
00425
00426 void layout(const tpoint& origin);
00427
00428
00429 void impl_draw_children(surface& frame_buffer);
00430 void impl_draw_children(surface& frame_buffer, int x_offset, int y_offset);
00431
00432 };
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 void set_single_child(tgrid& grid, twidget* widget);
00444
00445 }
00446
00447 #endif
00448