// generated by Fast Light User Interface Designer (fluid) version 1.0304
#include "ViewFluid.h"
+#include <FL/fl_draw.H>
+#include <FL/Fl_Table_Row.H>
+#include <string>
+#include <vector>
+
+void SimpleTable::draw_cell(TableContext context, int R, int C, int X, int Y, int W, int H) {
+ static char s[40];
+ switch ( context ) {
+ case CONTEXT_STARTPAGE: // before page is drawn..
+ fl_font(FL_HELVETICA, 16); // set the font for our drawing operations
+ return;
+ case CONTEXT_COL_HEADER: // Draw column headers
+ sprintf(s,"%c",'A'+C); // "A", "B", "C", etc.
+ DrawHeader(s,X,Y,W,H);
+ return;
+ case CONTEXT_ROW_HEADER: // Draw row headers
+ sprintf(s,"%02d:",R); // "001:", "002:", etc
+ DrawHeader(s,X,Y,W,H);
+ return;
+ case CONTEXT_CELL: // Draw data in cells
+ if((int)m_TableData.size()-1 < R)
+ SetTableData("", 0, R);
+
+ if((int)m_TableData.at(R).size()-1 < C)
+ SetTableData("", C, 0);
+
+ DrawData(m_TableData.at(R).at(C).c_str(),
+ m_CellColors.at(R).at(C),X,Y,W,H);
+ return;
+ default:
+ return;
+ }
+}
+
+SimpleTable::SimpleTable(int x, int y, int w, int h, const char *l ) : Fl_Table_Row(x,y,w,h,l) {
+}
+
+void SimpleTable::SetTableData(std::string data, unsigned int x , unsigned int y , Fl_Color color ) {
+ if(m_TableData.empty() || (m_TableData.size() < y+1))
+ {
+ m_TableData.resize(y+1);
+ rows(y+1);
+ }
+
+ for (unsigned int i = 0; i < m_TableData.size(); ++i)
+ if(m_TableData.at(i).empty() ||
+ (m_TableData.at(i).size() < x+1))
+ {
+ m_TableData.at(i).resize(x+1, "");
+ cols(x+1);
+ }
+
+ m_TableData.at(y).at(x) = data;
+ SetCellColor(color,x,y);
+}
+
+void SimpleTable::SetCellColor(Fl_Color color, unsigned int x , unsigned int y ) {
+ if(m_CellColors.empty() || (m_CellColors.size() < y+1))
+ {
+ m_CellColors.resize(y+1);
+ rows(y+1);
+ }
+
+ for (unsigned int i = 0; i < m_CellColors.size(); ++i)
+ if(m_CellColors.at(i).empty() ||
+ (m_CellColors.at(i).size() < x+1))
+ {
+ m_CellColors.at(i).resize(x+1, FL_WHITE);
+ cols(x+1);
+ }
+
+ m_CellColors.at(y).at(x) = color;
+}
+
+std::vector<std::vector<std::string>> SimpleTable::GetTableData() {
+ return m_TableData;
+}
+
+void SimpleTable::Resize(unsigned int x , unsigned int y ) {
+ m_TableData.resize(y+1);
+ m_CellColors.resize(y+1);
+ rows(y+1);
+ for (unsigned int i = 0; i < m_TableData.size(); ++i)
+ {
+ m_CellColors.at(i).resize(x+1, FL_WHITE);
+ m_TableData.at(i).resize(x+1, "");
+ }
+ cols(x+1);
+}
+
+void SimpleTable::DrawData(const char *s, Fl_Color cell_color, int X, int Y, int W, int H) {
+ fl_push_clip(X,Y,W,H);
+ // Draw cell bg
+ fl_color(cell_color); fl_rectf(X,Y,W,H);
+ // Draw cell data
+ fl_color(FL_GRAY0); fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
+ // Draw box border
+ fl_color(color()); fl_rect(X,Y,W,H);
+ fl_pop_clip();
+}
+
+void SimpleTable::DrawHeader(const char *s, int X, int Y, int W, int H) {
+ fl_push_clip(X,Y,W,H);
+ fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, row_header_color());
+ fl_color(FL_BLACK);
+ fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
+ fl_pop_clip();
+}
ViewFluid::ViewFluid() {
- { win_exmpl = new Fl_Double_Window(340, 150, "Example");
+ { win_exmpl = new Fl_Double_Window(500, 300, "Example");
win_exmpl->box(FL_GTK_DOWN_BOX);
win_exmpl->user_data((void*)(this));
win_exmpl->hotspot(win_exmpl);
- { btn_exception = new Fl_Button(100, 45, 135, 45, "Throw Exception");
+ { btn_exception = new Fl_Button(20, 120, 135, 45, "Throw Exception");
} // Fl_Button* btn_exception
+ { tbl_example = new SimpleTable(170, 0, 330, 300);
+ tbl_example->tooltip("Simple Table Implementation Example");
+ tbl_example->box(FL_THIN_DOWN_FRAME);
+ tbl_example->color(FL_BACKGROUND_COLOR);
+ tbl_example->selection_color(FL_BACKGROUND_COLOR);
+ tbl_example->labeltype(FL_NORMAL_LABEL);
+ tbl_example->labelfont(0);
+ tbl_example->labelsize(14);
+ tbl_example->labelcolor(FL_FOREGROUND_COLOR);
+ tbl_example->align(Fl_Align(FL_ALIGN_TOP));
+ tbl_example->when(FL_WHEN_RELEASE);
+ tbl_example->end();
+ } // SimpleTable* tbl_example
win_exmpl->size_range(585, 555);
win_exmpl->end();
- win_exmpl->resizable(win_exmpl);
} // Fl_Double_Window* win_exmpl
}