1 // generated by Fast Light User Interface Designer (fluid) version 1.0304
4 #include <FL/fl_draw.H>
5 #include <FL/Fl_Table_Row.H>
9 void SimpleTable::draw_cell(TableContext context, int R, int C, int X, int Y, int W, int H) {
12 case CONTEXT_STARTPAGE: // before page is drawn..
13 fl_font(FL_HELVETICA, 16); // set the font for our drawing operations
15 case CONTEXT_COL_HEADER: // Draw column headers
16 sprintf(s,"%c",'A'+C); // "A", "B", "C", etc.
17 DrawHeader(s,X,Y,W,H);
19 case CONTEXT_ROW_HEADER: // Draw row headers
20 sprintf(s,"%02d:",R); // "001:", "002:", etc
21 DrawHeader(s,X,Y,W,H);
23 case CONTEXT_CELL: // Draw data in cells
24 if((int)m_TableData.size()-1 < R)
25 SetTableData("", 0, R);
27 if((int)m_TableData.at(R).size()-1 < C)
28 SetTableData("", C, 0);
30 DrawData(m_TableData.at(R).at(C).c_str(),
31 m_CellColors.at(R).at(C),X,Y,W,H);
38 SimpleTable::SimpleTable(int x, int y, int w, int h, const char *l ) : Fl_Table_Row(x,y,w,h,l) {
41 void SimpleTable::SetTableData(std::string data, unsigned int x , unsigned int y , Fl_Color color ) {
42 if(m_TableData.empty() || (m_TableData.size() < y+1))
44 m_TableData.resize(y+1);
48 for (unsigned int i = 0; i < m_TableData.size(); ++i)
49 if(m_TableData.at(i).empty() ||
50 (m_TableData.at(i).size() < x+1))
52 m_TableData.at(i).resize(x+1, "");
56 m_TableData.at(y).at(x) = data;
57 SetCellColor(color,x,y);
60 void SimpleTable::SetCellColor(Fl_Color color, unsigned int x , unsigned int y ) {
61 if(m_CellColors.empty() || (m_CellColors.size() < y+1))
63 m_CellColors.resize(y+1);
67 for (unsigned int i = 0; i < m_CellColors.size(); ++i)
68 if(m_CellColors.at(i).empty() ||
69 (m_CellColors.at(i).size() < x+1))
71 m_CellColors.at(i).resize(x+1, FL_WHITE);
75 m_CellColors.at(y).at(x) = color;
78 std::vector<std::vector<std::string>> SimpleTable::GetTableData() {
82 void SimpleTable::Resize(unsigned int x , unsigned int y ) {
83 m_TableData.resize(y+1);
84 m_CellColors.resize(y+1);
86 for (unsigned int i = 0; i < m_TableData.size(); ++i)
88 m_CellColors.at(i).resize(x+1, FL_WHITE);
89 m_TableData.at(i).resize(x+1, "");
94 void SimpleTable::DrawData(const char *s, Fl_Color cell_color, int X, int Y, int W, int H) {
95 fl_push_clip(X,Y,W,H);
97 fl_color(cell_color); fl_rectf(X,Y,W,H);
99 fl_color(FL_GRAY0); fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
101 fl_color(color()); fl_rect(X,Y,W,H);
105 void SimpleTable::DrawHeader(const char *s, int X, int Y, int W, int H) {
106 fl_push_clip(X,Y,W,H);
107 fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, row_header_color());
109 fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
113 ViewFluid::ViewFluid() {
114 { win_exmpl = new Fl_Double_Window(500, 300, "Example");
115 win_exmpl->box(FL_GTK_DOWN_BOX);
116 win_exmpl->user_data((void*)(this));
117 win_exmpl->hotspot(win_exmpl);
118 { btn_exception = new Fl_Button(20, 120, 135, 45, "Throw Exception");
119 } // Fl_Button* btn_exception
120 { tbl_example = new SimpleTable(170, 0, 330, 300);
121 tbl_example->tooltip("Simple Table Implementation Example");
122 tbl_example->box(FL_THIN_DOWN_FRAME);
123 tbl_example->color(FL_BACKGROUND_COLOR);
124 tbl_example->selection_color(FL_BACKGROUND_COLOR);
125 tbl_example->labeltype(FL_NORMAL_LABEL);
126 tbl_example->labelfont(0);
127 tbl_example->labelsize(14);
128 tbl_example->labelcolor(FL_FOREGROUND_COLOR);
129 tbl_example->align(Fl_Align(FL_ALIGN_TOP));
130 tbl_example->when(FL_WHEN_RELEASE);
132 } // SimpleTable* tbl_example
133 win_exmpl->size_range(585, 555);
135 } // Fl_Double_Window* win_exmpl