Added examples directory
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7628 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
cc7b798179
commit
384929e7d2
19
examples/Makefile
Normal file
19
examples/Makefile
Normal file
@ -0,0 +1,19 @@
|
||||
include ../makeinclude
|
||||
|
||||
ALL = tabs-simple$(EXEEXT) \
|
||||
tree-simple$(EXEEXT)
|
||||
|
||||
# default target -- build everything
|
||||
default: $(ALL)
|
||||
|
||||
tabs-simple$(EXEEXT): tabs-simple.cxx
|
||||
fltk-config --compile tabs-simple.cxx
|
||||
|
||||
tree-simple$(EXEEXT): tree-simple.cxx
|
||||
fltk-config --compile tree-simple.cxx
|
||||
|
||||
# clean everything
|
||||
clean:
|
||||
$(RM) $(ALL)
|
||||
$(RM) *.o
|
||||
$(RM) core
|
113
examples/README.examples
Normal file
113
examples/README.examples
Normal file
@ -0,0 +1,113 @@
|
||||
FLTK EXAMPLE PROGRAMS
|
||||
---------------------
|
||||
|
||||
This directory contains example FLTK programs that demonstrate
|
||||
recommended programming practices and techniques for FLTK application
|
||||
programmers. The "*-simple.cxx" files are a good starting point for
|
||||
those new to FLTK.
|
||||
|
||||
The programs in this directory are NOT built automatically
|
||||
when you build FLTK; you have to manually build them.
|
||||
|
||||
The goals of these example programs:
|
||||
|
||||
o Show good programming style for app programmers to emulate
|
||||
|
||||
o Show simple examples of how to use widgets to new users of FLTK.
|
||||
|
||||
o Show intermediate or advanced examples that show particular
|
||||
techniques often misused or hard to document
|
||||
|
||||
o Demonstrate code that are FAQs on the newsgroup forum.
|
||||
(such as how to use threads, callbacks, etc)
|
||||
|
||||
o Example code should be short, but not at the expense of clarity.
|
||||
|
||||
o Where possible, examples should emphasize FLTK's simplicity.
|
||||
|
||||
|
||||
NEW SUBMISSIONS: RECOMMENDED PRACTICES
|
||||
|
||||
These programs must follow FLTK coding style as defined in the FLTK
|
||||
"CMP" (Configuration Management Plan/Coding Standards).
|
||||
|
||||
Example code should demonstrate recommended techniques the FLTK
|
||||
developers think application programmers should use in their own
|
||||
applications.
|
||||
|
||||
The best examples are those that are as short and clear as possible;
|
||||
terse, but not at the expense of clarity.
|
||||
|
||||
To avoid cluttering up the top level directory with ancillary files
|
||||
(such as image files or icons), examples that depend on more than
|
||||
just a .cxx/.h file pair should have their own subdirectory.
|
||||
|
||||
Data files common to several examples should be located in the
|
||||
examples/data directory.
|
||||
|
||||
Ancillary data files should be as small as possible, to keep the
|
||||
distribution tar files small. Avoid high resolution images or
|
||||
uncompressed images when possible.
|
||||
|
||||
Examples that need very large data sets should not be part of the
|
||||
FLTK distribution; they can be provided as separate packages
|
||||
(eg. as articles or external links).
|
||||
|
||||
Some widgets have multiple common uses that are best demonstrated
|
||||
separately. For instance, the table widget can be used as a
|
||||
custom data table, or as a spreadsheet, or as a widget container.
|
||||
So separate examples for each would be e.g. "table-custom-data.cxx",
|
||||
"table-spreadsheet.cxx", "table-widget-container.cxx", etc.
|
||||
|
||||
Example programs should contain comments that help understand the
|
||||
concepts shown, but not so verbose as to dwarf the code or make
|
||||
the code hard to read. Within code, it's best to use single line
|
||||
comments to emphasize code that might be unclear. Let the code
|
||||
speak as much as possible.
|
||||
|
||||
Examples programs may be referred to from the documentation
|
||||
as good examples on how to do particular programming techniques.
|
||||
|
||||
|
||||
NAMING CONVENTIONS
|
||||
|
||||
Example programs that demonstrate a particular widget should start
|
||||
with that widget's name in lowercase, eg. "table.cxx" for Fl_Table.
|
||||
|
||||
Demonstrations of a particular technique should start with
|
||||
"howto-xxx.cxx" to avoid naming conflicts with future widgets
|
||||
of the same name.
|
||||
|
||||
xxx-simple.cxx -- Simplest possible example of widget xxx
|
||||
eg. table-simple.cxx
|
||||
|
||||
xxx-<technique>.cxx -- A particular "technique" using widget xxx
|
||||
eg. "table-spreadsheet.cxx"
|
||||
|
||||
howto-<technique>.cxx -- Demonstrate a particular technique, eg. "howto-threading.cxx"
|
||||
|
||||
Some example programs may depend on multiple files. To avoid
|
||||
cluttering up the top level examples directory, such examples will
|
||||
have their own subdirectory with the files they depend on localized
|
||||
to that directory.
|
||||
|
||||
Example programs should be as small as possible, to keep the
|
||||
distribution tar files small.
|
||||
|
||||
Very large examples, or examples that depend on large data sets
|
||||
should be submitted as separate articles on the FLTK site, or as
|
||||
external links on the FLTK site's 'links' page.
|
||||
|
||||
|
||||
HISTORY
|
||||
|
||||
Previous to FLTK 1.3.0, the fltk/test directory served the dual
|
||||
purpose of containing test suites as well as example code.
|
||||
|
||||
But the fltk/test programs started becoming necessarily complex,
|
||||
testing for obscure problems, and not necessarily good demos for
|
||||
applications programmers.
|
||||
|
||||
The fltk/examples directory was created in FLTK 1.3.0 to separate
|
||||
'good programming examples' from the test suite code.
|
||||
|
87
examples/tabs-simple.cxx
Normal file
87
examples/tabs-simple.cxx
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// Simple Fl_Tabs widget example.
|
||||
// Originally from erco's cheat sheet 06/05/2010, permission by author.
|
||||
//
|
||||
// Copyright 1998-2010 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems on the following page:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/Fl_Window.H>
|
||||
#include <FL/Fl_Tabs.H>
|
||||
#include <FL/Fl_Group.H>
|
||||
#include <FL/Fl_Button.H>
|
||||
//
|
||||
// Simple tabs example
|
||||
// _____ _____
|
||||
// __/ Aaa \/ Bbb \______________________
|
||||
// | _______ |
|
||||
// | |_______| |
|
||||
// | _______ |
|
||||
// | |_______| |
|
||||
// | _______ |
|
||||
// | |_______| |
|
||||
// |______________________________________|
|
||||
//
|
||||
int main(int argc, char *argv[]) {
|
||||
Fl::scheme("gtk+");
|
||||
Fl_Window *win = new Fl_Window(500,200,"Tabs Example");
|
||||
{
|
||||
// Create the tab widget
|
||||
Fl_Tabs *tabs = new Fl_Tabs(10,10,500-20,200-20);
|
||||
{
|
||||
// ADD THE "Aaa" TAB
|
||||
// We do this by adding a child group to the tab widget.
|
||||
// The child group's label defined the label of the tab.
|
||||
//
|
||||
Fl_Group *aaa = new Fl_Group(10,35,500-20,200-45,"Aaa");
|
||||
{
|
||||
// Put some different buttons into the group, which will be shown
|
||||
// when the tab is selected.
|
||||
Fl_Button *b1 = new Fl_Button(50, 60,90,25,"Button A1"); b1->color(88+1);
|
||||
Fl_Button *b2 = new Fl_Button(50, 90,90,25,"Button A2"); b2->color(88+2);
|
||||
Fl_Button *b3 = new Fl_Button(50,120,90,25,"Button A3"); b3->color(88+3);
|
||||
}
|
||||
aaa->end();
|
||||
|
||||
// ADD THE "Bbb" TAB
|
||||
// Same details as above.
|
||||
//
|
||||
Fl_Group *bbb = new Fl_Group(10,35,500-10,200-35,"Bbb");
|
||||
{
|
||||
// Put some different buttons into the group, which will be shown
|
||||
// when the tab is selected.
|
||||
Fl_Button *b1 = new Fl_Button( 50,60,90,25,"Button B1"); b1->color(88+1);
|
||||
Fl_Button *b2 = new Fl_Button(150,60,90,25,"Button B2"); b2->color(88+3);
|
||||
Fl_Button *b3 = new Fl_Button(250,60,90,25,"Button B3"); b3->color(88+5);
|
||||
Fl_Button *b4 = new Fl_Button( 50,90,90,25,"Button B4"); b4->color(88+2);
|
||||
Fl_Button *b5 = new Fl_Button(150,90,90,25,"Button B5"); b5->color(88+4);
|
||||
Fl_Button *b6 = new Fl_Button(250,90,90,25,"Button B6"); b6->color(88+6);
|
||||
}
|
||||
bbb->end();
|
||||
}
|
||||
tabs->end();
|
||||
}
|
||||
win->end();
|
||||
win->show(argc, argv);
|
||||
return(Fl::run());
|
||||
}
|
71
examples/tree-simple.cxx
Normal file
71
examples/tree-simple.cxx
Normal file
@ -0,0 +1,71 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// Simple Fl_Tree widget example. - erco 06/05/2010
|
||||
//
|
||||
// Copyright 1998-2010 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems on the following page:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/Fl_Double_Window.H>
|
||||
#include <FL/Fl_Tree.H>
|
||||
|
||||
// Tree's callback
|
||||
// Invoked whenever someone clicks an item.
|
||||
//
|
||||
void TreeCallback(Fl_Widget *w, void *data) {
|
||||
Fl_Tree *tree = (Fl_Tree*)w;
|
||||
Fl_Tree_Item *item = (Fl_Tree_Item*)tree->item_clicked();
|
||||
fprintf(stderr, "TreeCallback: item clicked='%s'\n", (item)?item->label():"???");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Fl::scheme("gtk+");
|
||||
Fl_Double_Window *win = new Fl_Double_Window(250, 400, "Simple Tree");
|
||||
win->begin();
|
||||
{
|
||||
// Create the tree
|
||||
Fl_Tree *tree = new Fl_Tree(10, 10, win->w()-20, win->h()-20);
|
||||
tree->showroot(0); // don't show root of tree
|
||||
tree->callback(TreeCallback); // setup a callback for the tree
|
||||
|
||||
// Add some items
|
||||
tree->add("Flintstones/Fred");
|
||||
tree->add("Flintstones/Wilma");
|
||||
tree->add("Flintstones/Pebbles");
|
||||
tree->add("Simpsons/Homer");
|
||||
tree->add("Simpsons/Marge");
|
||||
tree->add("Simpsons/Bart");
|
||||
tree->add("Simpsons/Lisa");
|
||||
|
||||
// Start with one of the items closed
|
||||
tree->close("Simpsons");
|
||||
}
|
||||
win->end();
|
||||
win->resizable(win);
|
||||
win->show(argc, argv);
|
||||
return(Fl::run());
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
85
examples/wizard-simple.cxx
Normal file
85
examples/wizard-simple.cxx
Normal file
@ -0,0 +1,85 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// Simple Fl_Wizard widget example.
|
||||
// Originally from erco's cheat sheet 06/05/2010, permission by author.
|
||||
//
|
||||
// Copyright 1998-2010 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Library General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems on the following page:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
#include <stdlib.h>
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/Fl_Window.H>
|
||||
#include <FL/Fl_Group.H>
|
||||
#include <FL/Fl_Wizard.H>
|
||||
#include <FL/Fl_Button.H>
|
||||
#include <FL/Fl_Multiline_Output.H>
|
||||
//
|
||||
// Simple 'wizard' using fltk's new Fl_Wizard widget
|
||||
//
|
||||
Fl_Window *G_win = 0;
|
||||
Fl_Wizard *G_wiz = 0;
|
||||
|
||||
void back_cb(Fl_Widget*,void*) { G_wiz->prev(); }
|
||||
void next_cb(Fl_Widget*,void*) { G_wiz->next(); }
|
||||
void done_cb(Fl_Widget*,void*) { exit(0); }
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
G_win = new Fl_Window(400,300,"Example Wizard");
|
||||
G_wiz = new Fl_Wizard(0,0,400,300);
|
||||
|
||||
// Wizard: page 1
|
||||
{
|
||||
Fl_Group *g = new Fl_Group(0,0,400,300);
|
||||
Fl_Button *next = new Fl_Button(290,265,100,25,"Next"); next->callback(next_cb);
|
||||
Fl_Multiline_Output *out = new Fl_Multiline_Output(10,30,400-20,300-80,"Welcome");
|
||||
out->labelsize(20);
|
||||
out->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
|
||||
out->value("This is First page");
|
||||
g->end();
|
||||
}
|
||||
// Wizard: page 2
|
||||
{
|
||||
Fl_Group *g = new Fl_Group(0,0,400,300);
|
||||
Fl_Button *next = new Fl_Button(290,265,100,25,"Next"); next->callback(next_cb);
|
||||
Fl_Button *back = new Fl_Button(180,265,100,25,"Back"); back->callback(back_cb);
|
||||
Fl_Multiline_Output *out = new Fl_Multiline_Output(10,30,400-20,300-80,"Terms And Conditions");
|
||||
out->labelsize(20);
|
||||
out->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
|
||||
out->value("This is the Second page");
|
||||
g->end();
|
||||
}
|
||||
// Wizard: page 3
|
||||
{
|
||||
Fl_Group *g = new Fl_Group(0,0,400,300);
|
||||
Fl_Button *done = new Fl_Button(290,265,100,25,"Finish"); done->callback(done_cb);
|
||||
Fl_Button *back = new Fl_Button(180,265,100,25,"Back"); back->callback(back_cb);
|
||||
Fl_Multiline_Output *out = new Fl_Multiline_Output(10,30,400-20,300-80,"Finish");
|
||||
out->labelsize(20);
|
||||
out->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
|
||||
out->value("This is the Last page");
|
||||
g->end();
|
||||
}
|
||||
G_wiz->end();
|
||||
G_win->end();
|
||||
G_win->show(argc, argv);
|
||||
return Fl::run();
|
||||
}
|
Loading…
Reference in New Issue
Block a user