1.remake the mouse input and the keyboard input

2.add a bild(image/background.png) and display this bild as background
This commit is contained in:
chenhuan 2019-10-26 16:39:25 +02:00
parent 71344ec3fd
commit 76cc27841e
3 changed files with 49 additions and 23 deletions

View File

@ -29,7 +29,8 @@ target_link_libraries(GUI ${LIB_PATH}/lib/liblibrary.a)
set(FLTK_SKIP_FLUID true) set(FLTK_SKIP_FLUID true)
find_package(FLTK REQUIRED) find_package(FLTK REQUIRED)
include_directories(${FLTK_INCLUDE_DIR}) include_directories(${FLTK_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${FLTK_BASE_LIBRARY} ${FLTK_PLATFORM_DEPENDENT_LIBS}) target_link_libraries(${PROJECT_NAME} ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES} ${OPENGL_LIBRARIES})
enable_testing() enable_testing()
find_package(Catch2 REQUIRED) find_package(Catch2 REQUIRED)

BIN
image/background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -1,28 +1,53 @@
#include <FL/Fl.H> #pragma comment(lib, "fltk.lib")
#include <FL/Fl_Window.H> #pragma comment(lib, "wsock32.lib")
#include <FL/Fl_Button.H> #pragma comment(lib, "comctl32.lib")
#pragma comment(linker, "/NODEFAULTLIB:LIBCMTD.lib")
#include <iostream> #include <iostream>
#include <Fl/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_PNG_Image.H>
using namespace std; #define window_size 400
/*****************************************************************************/
/* This class provides a view to copy the offscreen surface to */
class My_Window : public Fl_Window{
int x,y,button;
int handle(int e)
{
void button_cb(Fl_Widget* wid){ switch (e)
Fl_Button* but = (Fl_Button*)wid; {
case FL_MOVE:
if(but->label()=="&Good job"){ x = Fl::event_x();
but->label("&Click me"); y = Fl::event_y();
} else std::cout<<"Postion X:"<< x <<" Postion Y:"<< y <<std::endl;
but->label("&Good job"); return 1;
but->redraw(); case FL_KEYBOARD:
} button = Fl::event_button();
std::cout<<"Keyboard:"<< button <<std::endl;
return 1;
}
}
public:
My_Window(int x, int y, const char *l ) : Fl_Window(x,y,l){};
};
int main(int argc, char **argv) { int main(int argc, char **argv) {
Fl_Window win(300,200,"Testing");
int i = 7; int x, y, button;
win.begin(); My_Window* window = new My_Window(window_size, window_size, "example");
Fl_Button but(20,150,70,30,"&Click me"); Fl_Box* box = new Fl_Box(10,10,380,380);
win.end();
but.callback(button_cb); window->begin();
win.show(); Fl_PNG_Image* background = new Fl_PNG_Image("../image/background.png");
return Fl::run(); std::cout<<background->Fl_Image::fail()<<std::endl;
} box->image(background);
box->redraw();
window->end();
window->show(argc,argv);
return Fl::run();
} // main