Seperate dependent package include files for different architectures. Speed up build.
[fltk_mvc_template.git] / _template / src / ViewFluid.cxx
1 // generated by Fast Light User Interface Designer (fluid) version 1.0304
2
3 #include "ViewFluid.h"
4 #include <FL/fl_draw.H>
5 #include <FL/Fl_Table_Row.H>
6 #include <string>
7 #include <vector>
8
9 void SimpleTable::draw_cell(TableContext context, int R, int C, int X, int Y, int W, int H) {
10   static char s[40];
11       switch ( context ) {
12         case CONTEXT_STARTPAGE:                   // before page is drawn..
13           fl_font(FL_HELVETICA, 16);              // set the font for our drawing operations
14           return; 
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);
18           return; 
19         case CONTEXT_ROW_HEADER:                  // Draw row headers
20           sprintf(s,"%02d:",R);                 // "001:", "002:", etc
21           DrawHeader(s,X,Y,W,H);
22           return; 
23         case CONTEXT_CELL:                        // Draw data in cells
24                 if((int)m_TableData.size()-1 < R)
25                         SetTableData("", 0, R);
26                 
27                 if((int)m_TableData.at(R).size()-1 < C)
28                         SetTableData("", C, 0);
29                                         
30           DrawData(m_TableData.at(R).at(C).c_str(),
31                    m_CellColors.at(R).at(C),X,Y,W,H);
32           return;
33         default:
34           return;
35    }
36 }
37
38 SimpleTable::SimpleTable(int x, int y, int w, int h, const char *l ) : Fl_Table_Row(x,y,w,h,l) {
39 }
40
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))
43   {
44       m_TableData.resize(y+1);
45       rows(y+1);
46   }
47   
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))
51       {
52           m_TableData.at(i).resize(x+1, "");   
53           cols(x+1);
54       }   
55   
56   m_TableData.at(y).at(x) = data;
57   SetCellColor(color,x,y);
58 }
59
60 void SimpleTable::SetCellColor(Fl_Color color, unsigned int x , unsigned int y ) {
61   if(m_CellColors.empty() || (m_CellColors.size() < y+1))
62   {
63       m_CellColors.resize(y+1);
64       rows(y+1);
65   }
66   
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))
70       {
71           m_CellColors.at(i).resize(x+1, FL_WHITE);   
72           cols(x+1);
73       }   
74   
75   m_CellColors.at(y).at(x) = color;
76 }
77
78 std::vector<std::vector<std::string>> SimpleTable::GetTableData() {
79   return m_TableData;
80 }
81
82 void SimpleTable::Resize(unsigned int x , unsigned int y ) {
83   m_TableData.resize(y+1);
84   m_CellColors.resize(y+1);
85   rows(y+1);
86   for (unsigned int i = 0; i < m_TableData.size(); ++i)
87   {
88       m_CellColors.at(i).resize(x+1, FL_WHITE);
89       m_TableData.at(i).resize(x+1, "");   
90   }       
91   cols(x+1);
92 }
93
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);
96         // Draw cell bg
97         fl_color(cell_color); fl_rectf(X,Y,W,H);
98         // Draw cell data
99         fl_color(FL_GRAY0); fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
100         // Draw box border
101         fl_color(color()); fl_rect(X,Y,W,H);
102   fl_pop_clip();
103 }
104
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());
108         fl_color(FL_BLACK);
109         fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
110   fl_pop_clip();
111 }
112
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);
131       tbl_example->end();
132     } // SimpleTable* tbl_example
133     win_exmpl->size_range(585, 555);
134     win_exmpl->end();
135   } // Fl_Double_Window* win_exmpl
136 }