Created
May 15, 2018 22:20
-
-
Save Cvetomird91/3a4e7e2d18beb2426376deb60b4acd9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
#include <cstdlib> | |
#include <FL/Fl.H> | |
#include <FL/fl_draw.H> | |
#include <FL/Fl_Window.H> | |
#include <FL/Fl_Box.H> | |
#include <FL/Fl_Native_File_Chooser.h> | |
#include <FL/Fl_Output.H> | |
#include <FL/Fl_Menu_Bar.H> | |
#include <FL/Fl_Value_Slider.H> | |
#include <FL/Fl_Button.H> | |
#include <FL/Fl_Text_Display.H> | |
#include <Fl/fl_ask.h> | |
#include <Fl/fl_file_chooser.h> | |
//this example isn't mine. It is taken from the following PDF: | |
//https://courses.cs.washington.edu/courses/cse557/00wi/projects/tutorial.pdf | |
Fl_Window *window; | |
Fl_Window *dlg; | |
Fl_Menu_Bar *menubar; | |
Fl_Slider *slider; | |
Fl_Button *button; | |
void cb_file_select(Fl_Widget *o, void*v) { | |
char msg[256]; | |
char *newfile = fl_file_chooser("Choose a file", "*.cpp", NULL); | |
if (newfile != NULL) { | |
sprintf(msg, "YOu choose %s", newfile); | |
fl_message(msg); | |
} | |
} | |
void cb_open_dialog(Fl_Widget *o, void *v) { | |
dlg->show(); | |
} | |
void cb_pass(Fl_Widget *o, void *v) { | |
fl_message((char*)v); | |
} | |
void cb_quit(Fl_Widget *o, void *v) { | |
dlg->hide(); | |
window->hide(); | |
} | |
void cb_about() { | |
fl_message("This is about."); | |
} | |
void cb_slides(Fl_Widget *o, void *v) { | |
window->resize(window->x(), window->y(), | |
10*(int)(((Fl_Slider*)o)->value()), window->h()); | |
menubar->resize(0, 0, 10*(int)(((Fl_Slider *)o)->value()), 25); | |
} | |
void cb_reset(Fl_Widget* o, void *v) { | |
slider->value(20); | |
cb_slides(slider, (void*)20); | |
} | |
char fltk[] = "fltk"; char opengl[] = "opengl"; | |
Fl_Menu_Item menuitems[] = { | |
{"&File", 0, 0, 0, FL_SUBMENU}, | |
{"File_&Selector...", FL_ALT + 's', (Fl_Callback*)cb_file_select}, | |
{"Open_&Dialog", FL_ALT +'d' , (Fl_Callback*)cb_open_dialog, 0, FL_MENU_DIVIDER}, | |
{"&Fltk", FL_ALT + 'f', (Fl_Callback*)cb_pass, (void*)fltk}, | |
{"&OpenGl", FL_ALT + 'o', (Fl_Callback*)cb_pass, (void*)opengl, FL_MENU_DIVIDER}, | |
{"&Quit", FL_ALT + 'q' , (Fl_Callback*)cb_quit}, | |
{0}, | |
{"&Help", 0, 0, 0, FL_SUBMENU}, | |
{"&About", FL_ALT + 'a', (Fl_Callback*)cb_about}, | |
{0}, | |
{0} | |
}; | |
int main (int argc, char ** argv) | |
{ | |
window = new Fl_Window(300, 300, 200, 200, "Foo"); | |
menubar = new Fl_Menu_Bar(0, 0, 200, 25); | |
menubar->menu(menuitems); | |
window->callback(cb_quit); | |
window->when(FL_HIDE); | |
window->end(); | |
dlg = new Fl_Window(300, 530, 200, 70, "dialog"); | |
slider = new Fl_Value_Slider(0, 10, 150, 20, "Slider"); | |
slider->type(FL_HOR_NICE_SLIDER); | |
slider->labelfont(FL_COURIER); | |
slider->labelsize(12); | |
slider->minimum(1); | |
slider->maximum(40); | |
slider->step(1); | |
slider->value(20); | |
slider->align(FL_ALIGN_RIGHT); | |
slider->callback(cb_slides); | |
Fl_Button *button = new Fl_Button(60, 40, 80, 20, "Reset"); | |
button->callback(cb_reset); | |
dlg->end(); | |
window->show(argc, argv); | |
return(Fl::run()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment