//---------------------------- // version 3.0 using LaserBoy //---------------------------- #include #include #include #include #include #include #include // Use this header for PNG images #include // Use this header for BMP images #include // Use this header for JPEG images #include "LaserBoy_bmp.hpp" using namespace std; //############################################################################ class LB_Window : public Fl_Window { public: LB_Window(int w, int h, const char* title) : Fl_Window (w, h, title), key (' '), new_key (false) {} //------------------------------------------------------------------------ int handle(int event) override { if(event == FL_KEYDOWN) { int e_key = Fl::event_key(); if(is_special(e_key)) { key = e_key; new_key = true; return 1; } if(Fl::event_length()) { key = composed_ascii(e_key, Fl::event_state() & FL_SHIFT); new_key = true; return 1; } } // end if(event == FL_KEYDOWN) return Fl_Window::handle(event); } //------------------------------------------------------------------------ int composed_ascii(int _key, bool shifted) { if(shifted) { if(_key >= 'a' && _key <= 'z') return toupper((char)_key); switch(_key) { case '1': return '!'; case '2': return '@'; case '3': return '#'; case '4': return '$'; case '5': return '%'; case '6': return '^'; case '7': return '&'; case '8': return '*'; case '9': return '('; case '0': return ')'; case '`': return '~'; case '-': return '_'; case '=': return '+'; case '[': return '{'; case ']': return '}'; case '\\': return '|'; case ';': return ':'; case '"': return '"'; case ',': return '<'; case '.': return '>'; case '/': return '?'; } } return _key; } //------------------------------------------------------------------------ bool is_special(int _key) { if( _key == FL_Left || _key == FL_Up || _key == FL_Right || _key == FL_Down || _key == FL_BackSpace || _key == FL_Tab || _key == FL_Enter || _key == FL_Escape || _key == FL_F || _key == FL_Delete || ( _key > FL_F && _key < FL_F + 13 ) ) return true; return false; } //------------------------------------------------------------------------ int key; bool new_key; }; //############################################################################ int main(int argc, char** argv) { struct LaserBoy_bmp bmp_file = {0}; struct LaserBoy_bmp bmp_display = {0}; if(bmp_from_file(&bmp_file, "test.bmp")) { bmp_init(&bmp_display, bmp_file.xres, bmp_file.yres, 24); for(int y = 0; y < bmp_file.yres; y++) for(int x = 0; x < bmp_file.xres; x++) bmp_display.put_pixel(&bmp_display, x, bmp_file.yres - y, bmp_display.make_rgb(bmp_file.r_from_rgb(bmp_file.get_pixel_rgb(&bmp_file, x, y)), bmp_file.g_from_rgb(bmp_file.get_pixel_rgb(&bmp_file, x, y)), bmp_file.b_from_rgb(bmp_file.get_pixel_rgb(&bmp_file, x, y)) ) ); // Create the custom window LB_Window *window = new LB_Window(bmp_display.xres, bmp_display.yres, "FLTK Window with Bitmap"); Fl_Box *box = new Fl_Box(0, 0, bmp_display.xres, bmp_display.yres); Fl_RGB_Image *screen = new Fl_RGB_Image(bmp_display.image, bmp_display.xres, bmp_display.yres, 3); box->image(screen); window->end(); window->show(argc, argv); while(window->key != 'x') { while(!window->new_key) Fl::wait(); window->new_key = false; switch(window->key) { case FL_Enter: std::cout << "ENTER" << std::endl; break; case FL_Left: std::cout << "LEFT_ARROW" << std::endl; break; case FL_Up: std::cout << "UP_ARROW" << std::endl; break; case FL_Right: std::cout << "RIGHT_ARROW" << std::endl; break; case FL_Down: std::cout << "DOWN_ARROW" << std::endl; break; case FL_F + 1: case FL_F + 2: case FL_F + 3: case FL_F + 4: case FL_F + 5: case FL_F + 6: case FL_F + 7: case FL_F + 8: case FL_F + 9: case FL_F + 10: case FL_F + 11: case FL_F + 12: std::cout << "F" << window->key - FL_F << std::endl; break; default: std::cout << (char) window->key << " : " << window->key << std::endl; break; } } } return 0; } //############################################################################ ////////////////////////////////////////////////////////////////////////////// //############################################################################ /* FL_BackSpace FL_Tab FL_Enter FL_Pause FL_Scroll_Lock FL_Escape FL_Home FL_Left FL_Up FL_Right FL_Down FL_Page_Up FL_Page_Down FL_End FL_Print FL_Insert FL_Menu FL_Num_Lock FL_KP - One of the keypad numbers; use FL_KP + n for number n. FL_KP_Enter - The enter key on the keypad. FL_F - One of the function keys; use FL_F + n for function key n. FL_Shift_L FL_Shift_R FL_Control_L FL_Control_R FL_Caps_Lock FL_Meta_L FL_Meta_R FL_Alt_L FL_Alt_R FL_Delete # arguments to main -bg2 color -bg color -di[splay] host:n.n -dn[d] -fg color -g[eometry] WxH+X+Y -i[conic] -k[bd] -na[me] classname -nod[nd] -nok[bd] -not[ooltips] -s[cheme] scheme -ti[tle] windowtitle -to[oltips] # macOS time g++ -std=c++17 \ fltk_LB_bmp_test.cpp \ LaserBoy_bmp.cpp \ LaserBoy_font.cpp \ -o fltk_LB_bmp_macOS \ -lfltk \ -lfltk_images \ -lfltk_png \ -lfltk_jpeg \ -lfltk_z \ -L/usr/local/lib \ -ljpeg \ -lz \ -lpng \ -framework Cocoa \ -framework CoreGraphics \ -framework CoreFoundation \ -framework ApplicationServices # msys2 time g++ \ fltk_LB_bmp_test.cpp \ LaserBoy_bmp.cpp \ LaserBoy_font.cpp \ -o fltk_LB_bmp.exe \ -std=c++17 \ -O3 \ -Wall \ -Wextra \ -I/path/to/fltk/include \ -L/path/to/fltk/lib \ -lfltk \ -lfltk_images \ -lpthread # Linux time g++ \ -std=c++17 \ fltk_LB_bmp_test.cpp \ LaserBoy_bmp.cpp \ LaserBoy_font.cpp \ -o fltk_LB_bmp \ -lfltk \ -lfltk_images \ -ljpeg \ -lz # piDAC time g++ \ -std=c++17 \ fltk_LB_bmp_test.cpp \ LaserBoy_bmp.cpp \ LaserBoy_font.cpp \ -o fltk_LB_bmp_pi \ -lfltk \ -lfltk_images \ -ljpeg \ -lz \ -lX11 \ -lXcursor \ -lXfixes \ -lXrender \ -lXinerama */