[fltk.commit] [Library] r9839 - branches/branch-1.3/examples
Author: greg.ercolano Date: 2013-03-19 03:34:03 -0700 (Tue, 19 Mar 2013) New Revision: 9839 Log: Small fixes to keyboard navigation and 'current cell' coloring. Modified: branches/branch-1.3/examples/table-spreadsheet.cxx Modified: branches/branch-1.3/examples/table-spreadsheet.cxx === --- branches/branch-1.3/examples/table-spreadsheet.cxx 2013-03-18 20:00:04 UTC (rev 9838) +++ branches/branch-1.3/examples/table-spreadsheet.cxx 2013-03-19 10:34:03 UTC (rev 9839) @@ -52,10 +52,14 @@ input-callback(input_cb, (void*)this); input-when(FL_WHEN_ENTER_KEY_ALWAYS); // callback triggered when user hits Enter input-maximum_size(5); +input-color(FL_YELLOW); for (int c = 0; c MAX_COLS; c++) for (int r = 0; r MAX_ROWS; r++) values[r][c] = c + (r*MAX_COLS);// initialize cells end(); +row_edit = col_edit = 0; +select_row = current_row = 0; +select_col = current_col = 0; } ~Spreadsheet() { } @@ -156,7 +160,7 @@ } // Background if ( C cols()-1 R rows()-1 ) { - fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, FL_WHITE); + fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, (R==row_edit C==col_edit) ? FL_YELLOW : FL_WHITE); } else { fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, 0xbbddbb00); // money green } @@ -205,7 +209,11 @@ return; case FL_KEYBOARD: // key press in table? - if ( Fl::event_key() == FL_Escape ) exit(0); // ESC closes app + switch (Fl::event_key()) { + case FL_Escape: exit(0);// ESC closes app + case FL_Shift_L: return;// ignore shift + case FL_Shift_R: return; + } if (C == cols()-1 || R == rows()-1) return; // no editing of totals column done_editing(); // finish any previous editing start_editing(R,C); // start new edit @@ -229,6 +237,7 @@ } int main() { + Fl::option(Fl::OPTION_ARROW_FOCUS, 1); // we want arrow keys to navigate table's widgets Fl_Double_Window *win = new Fl_Double_Window(862, 322, Fl_Table Spreadsheet); Spreadsheet *table = new Spreadsheet(10, 10, win-w()-20, win-h()-20); // Table rows ___ fltk-commit mailing list fltk-commit@easysw.com http://lists.easysw.com/mailman/listinfo/fltk-commit
[fltk.commit] [Library] r9840 - branches/branch-1.3/examples
Author: greg.ercolano Date: 2013-03-19 14:02:12 -0700 (Tue, 19 Mar 2013) New Revision: 9840 Log: o Simplified example to take advantage of Fl_Table's existing features. o Replaced hard coded row/col counts. o Enabled arrow keyboard navigation (setting Fl::OPTION_ARROW_FOCUS) o Fixed small bug in handle() that was calling Fl_Table::handle() instead of Fl_Table_Row::handle() that was preventing Fl_Table_Row's row selection from working.. Modified: branches/branch-1.3/examples/table-with-keynav.cxx Modified: branches/branch-1.3/examples/table-with-keynav.cxx === --- branches/branch-1.3/examples/table-with-keynav.cxx 2013-03-19 10:34:03 UTC (rev 9839) +++ branches/branch-1.3/examples/table-with-keynav.cxx 2013-03-19 21:02:12 UTC (rev 9840) @@ -40,24 +40,11 @@ Fl_Output*G_sum = 0; // displays sum of user's selection class MyTable : public Fl_Table_Row { -int row_beg, col_beg, row_end, col_end;// kb nav + mouse selection protected: -// See if row R and column C is inside selection area -int IsSelected(int R, int C) { - if ( G_rowselect-value() == 0 ) - return( (R = row_beg R = col_end -C = col_beg C = row_end) ? 1 : 0); - else - return( (R = row_beg R = col_end) ? 1 : 0); -} // Handle drawing all cells in table void draw_cell(TableContext context, int R=0,int C=0, int X=0,int Y=0,int W=0,int H=0) { static char s[30]; switch ( context ) { - case CONTEXT_STARTPAGE: - // Whenever we redraw the table, update row/col selection vals first - get_selection(row_beg, col_beg, col_end, row_end); - break; case CONTEXT_COL_HEADER: case CONTEXT_ROW_HEADER: fl_font(FL_HELVETICA | FL_BOLD, 14); @@ -74,8 +61,8 @@ return; case CONTEXT_CELL: { // Keyboard nav and mouse selection highlighting - int is_select = IsSelected(R,C); - fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, is_select ? FL_YELLOW : FL_WHITE); + int selected = G_rowselect-value() ? row_selected(R) : is_selected(R,C); + fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, selected ? FL_YELLOW : FL_WHITE); // Draw text for the cell fl_push_clip(X+3, Y+3, W-6, H-6); { @@ -112,9 +99,9 @@ // Update the displayed sum value int GetSelectionSum() { int sum = -1; -for ( int R=0; R11; R++ ) { - for ( int C=0; C11; C++ ) { - if ( IsSelected(R,C) ) { +for ( int R=0; Rrows(); R++ ) { + for ( int C=0; Ccols(); C++ ) { + if ( G_rowselect-value() ? row_selected(R) : is_selected(R,C) ) { if ( sum == -1 ) sum = 0; sum += R*C; } @@ -133,10 +120,7 @@ } // Keyboard and mouse events int handle(int e) { -// See if selection changed -static int lastselect = 0; - int thisselect = row_beg + (row_end*11) + (col_beg*11*2) + (col_end*11*3); -int ret = Fl_Table::handle(e); +int ret = Fl_Table_Row::handle(e); if ( e == FL_KEYBOARD Fl::event_key() == FL_Escape ) exit(0); switch (e) { case FL_PUSH: @@ -144,11 +128,8 @@ case FL_KEYUP: case FL_KEYDOWN: case FL_DRAG: { - if ( lastselect != thisselect ) { // Selection changed? - UpdateSum();// update the sum - redraw(); // XXX: needed for row selection to redraw properly - lastselect = thisselect; - } + UpdateSum(); + redraw(); ret = 1; break; } @@ -167,11 +148,12 @@ G_table-UpdateSum(); } int main() { +Fl::option(Fl::OPTION_ARROW_FOCUS, 0); // disable arrow focus nav (we want arrows to control cells) Fl_Double_Window win(862, 312, table-with-keynav); win.begin(); // Create table G_table = new MyTable(10, 30, win.w()-20, win.h()-70, Times Table); - G_table-tooltip(Use mouse or arrow keys to make selections.\n + G_table-tooltip(Use mouse or Shift + Arrow Keys to make selections.\n Sum of selected values is shown.); // Row select toggle button G_rowselect = new Fl_Toggle_Button(140,10,12,12,Row selection); @@ -186,6 +168,7 @@ G_sum = new Fl_Output(140,G_table-y()+G_table-h()+10,160,25,Selection Sum:); G_sum-value((nothing selected)); G_sum-color(48); + G_sum-tooltip(This field shows the sum of the selected cells in the table); win.end(); win.resizable(G_table); win.show();
Re: [fltk.general] Smooth blinking
You have to realize a blinking message, or an object which periodically swaps two images : think of an alarm icon. The alarm is sounding, and the icon keeps alternating red/yellow horn images until the user pushes the ack button. Use a timer to blink... but things are not always smooth blinking. Not a big problem, anyway... just would like to know if there is a clever way to assure a smooth blinking (usually we are speaking of small objects). Not really sure this is what was being asked, but here's a simple demo of blinking widgets. Maybe this is what was wanted? -- // // Flashing Boxes // #include FL/Fl.H #include FL/Fl_Double_Window.H #include FL/Fl_Button.H #include FL/Fl_Box.H static Fl_Double_Window *main_win = 0; static Fl_Button *quit_bt = 0; static Fl_Box *box1 = 0; static Fl_Box *box2 = 0; static void cb_quit(Fl_Widget *, void *) { main_win-hide(); } // cb_quit void update_box1(void *) { static int state = 0; if(state) { state = 0; box1-color(FL_GREEN); } else { state = -1; box1-color(FL_RED); } Fl::repeat_timeout(0.7, update_box1); box1-redraw(); } // update_box1 void update_box2(void *) { static int state = 0; static int step = 1; const int thd = 15; state += step; if(state = thd) { step = -1; } else if (state = 0) { step = 1; } float alpha = (float)state / (float)thd; Fl_Color col = fl_color_average(FL_RED, FL_BACKGROUND_COLOR, alpha); box2-color(col); Fl::repeat_timeout(0.05, update_box2); box2-redraw(); } // update_box2 int main(int argc, char ** argv) { main_win = new Fl_Double_Window(370, 230, Flashing Widgets); main_win-begin(); box1 = new Fl_Box(10, 10, 60, 30, ALERT!); box1-box(FL_FLAT_BOX); box1-color(FL_GREEN); box2 = new Fl_Box(80, 10, 60, 30, ALERT!); box2-box(FL_FLAT_BOX); box2-color(FL_BACKGROUND_COLOR); quit_bt = new Fl_Button(300, 190, 60, 30, Quit); quit_bt-box(FL_THIN_UP_BOX); quit_bt-callback(cb_quit); main_win-end(); main_win-show(argc,argv); Fl::add_timeout(0.3, update_box1); Fl::add_timeout(0.05, update_box2); return Fl::run(); } // main // end of file // Selex ES Ltd Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL A company registered in England Wales. Company no. 02426132 This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person. ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
[fltk.general] R: Re: Smooth blinking
Hi Greg and Ian, Use a timer to blink... but things are not always smooth blinking. Not a big problem, anyway... just would like to know if there is a clever way to assure a smooth blinking (usually we are speaking of small objects). Not really sure this is what was being asked, but here's a simple demo of blinking widgets. Maybe this is what was wanted? Yes. The problem was that, under particular conditions (many redraw of images), my blinking could become irregular, as timers, if I understand well, are all at the same priority level. The technique you and Greg told me is clear ; will clean up something in my (growing!) app and try to avoid unnecessary redraws. Again, thank you a lot for your precious help. Best regards, Lucio ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk