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)
find_package(FLTK REQUIRED)
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()
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>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#pragma comment(lib, "fltk.lib")
#pragma comment(lib, "wsock32.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(linker, "/NODEFAULTLIB:LIBCMTD.lib")
#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){
Fl_Button* but = (Fl_Button*)wid;
if(but->label()=="&Good job"){
but->label("&Click me");
} else
but->label("&Good job");
but->redraw();
}
switch (e)
{
case FL_MOVE:
x = Fl::event_x();
y = Fl::event_y();
std::cout<<"Postion X:"<< x <<" Postion Y:"<< y <<std::endl;
return 1;
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) {
Fl_Window win(300,200,"Testing");
int i = 7;
win.begin();
Fl_Button but(20,150,70,30,"&Click me");
win.end();
but.callback(button_cb);
win.show();
return Fl::run();
}
int x, y, button;
My_Window* window = new My_Window(window_size, window_size, "example");
Fl_Box* box = new Fl_Box(10,10,380,380);
window->begin();
Fl_PNG_Image* background = new Fl_PNG_Image("../image/background.png");
std::cout<<background->Fl_Image::fail()<<std::endl;
box->image(background);
box->redraw();
window->end();
window->show(argc,argv);
return Fl::run();
} // main