fltk summer course - part iii - third impact

Post on 10-May-2015

342 Views

Category:

Education

7 Downloads

Preview:

Click to see full reader

DESCRIPTION

FLTK (pronounced "fulltick") is a cross-platform C++ GUI toolkit for UNIX®/Linux® (X11), Microsoft® Windows®, and MacOS® X. FLTK provides modern GUI functionality without the bloat and supports 3D graphics via OpenGL® and its built-in GLUT emulation. FLTK is designed to be small and modular enough to be statically linked, but works fine as a shared library. FLTK also includes an excellent UI builder called FLUID that can be used to create applications in minutes. FLTK is provided under the terms of the GNU Library Public License, Version 2 with exceptions that allow for static linking. More informations in http://www.fltk.org.

TRANSCRIPT

1 de 15INTRODUÇÃO AO FAST LIGHT TOOLKIT - FLTK

The Fast Light ToolKit

Curso de Verão – Instituto de Computação & CA ComputaçãoMichel Alves dos Santos - UFALBolsista do Centro de Pesquisa em Matemática Computacional

3º Impacto

2 de 15

Componentes oferecidos pelo FLUID

[Paleta de componentes da ferramenta FLUID]

FLUID E SUA PALETA DE COMPONENTES

• Componentes de codificação: Code, Class, …• “Containers” : Group, Window, Pack, Tile, Tabs, …• “Buttons”: Button, Return_Button, Light_Button, …• “Valuators” : Slider, Adjuster, Spinner, Dial, …• “Text” : Input, Output, Text_Editor, …• “Menus” : Menu_Bar, MenuButton, Choice, …• “Browsers” : Browser, Check_Browser, …

3 de 15

Mas antes ...

MAS ANTES VAMOS CODIFICAR UM POUCO MANUALMENTE

4 de 15

Codificação do exemplo “Alô, Mundo !”#include <FL/Fl.H>#include <FL/Fl_Box.H>#include <FL/Fl_Window.H>int main(int argc, char* argv[]){ Fl_Window *window = new Fl_Window(300,180); Fl_Box *box = new Fl_Box(20,40,260,100,“Alô, Mundo!"); box->box(FL_UP_BOX); box->labelsize(36); box->labelfont(FL_BOLD+FL_ITALIC); box->labeltype(FL_SHADOW_LABEL); window->end(); window->show(argc, argv); return Fl::run();}

O CLÁSSICO EXEMPLO HELLO WORLD !

5 de 15

Uso de Callbacks - Exemplo

COMO RESPONDER A EVENTOS DENTRO DO FLTK – USO DE CALLBACKS - EXEMPLO

#include <cstdlib>#include <FL/Fl.H>#include <FL/Fl_ask.H>#include <FL/Fl_Window.H>void MyCallback(Fl_Widget* mywidget, void* userdata){ fl_message(“Saindo …"); exit(0);} int main(int argc, char* argv[]){ Fl_Window *window = new Fl_Window(300,180); window->callback(MyCallback,0); window->show(argc, argv); return Fl::run();}

6 de 15

Mudando o Scheme

COMO MUDAR O ESQUEMA DAS APLICAÇÕES EM FLTK

Implemente uma classe que herde de Fl_Window e possua a seguinte aparência :

A janela deve possuir um grupo [Fl_Group] e 3 botões do tipo Fl_Button [com os rótulos visualizados acima].

#include <FL/Fl.H>#include <FL/Fl_Group.H>#include <FL/Fl_Button.H>#include <FL/Fl_Window.H>

[Cabeçalhos necessários]

7 de 15

class WindowChangeSchema : public Fl_Window{ public: WindowChangeSchema(const char *L = 0); WindowChangeSchema(int W, int H, const char *L = 0); Fl_Group *grpGrupo; Fl_Button *btnSchemaNativo; Fl_Button *btnSchemaPlastic; Fl_Button *btnSchemaGtk;private: /*Método que auxilia no desenho da janela*/ void _WindowChangeSchema(); /*Métodos para callback*/ void cb_btnSchemaNativo_i(Fl_Button*, void*); static void cb_btnSchemaNativo(Fl_Button*, void*); void cb_btnSchemaPlastic_i(Fl_Button*, void*); static void cb_btnSchemaPlastic(Fl_Button*, void*); void cb_btnSchemaGtk_i(Fl_Button*, void*); static void cb_btnSchemaGtk(Fl_Button*, void*); };

CÓDIGO DA CLASSE WINDOWCHANGESCHEMA

8 de 15CÓDIGO DO MÉTODO QUE DESENHA A INTERFACE

void WindowChangeSchema::_WindowChangeSchema(){ grpGrupo = new Fl_Group(25, 15, 300, 50, “GRUPO"); grpGrupo->box(FL_ENGRAVED_FRAME); grpGrupo->labelsize(20); grpGrupo->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE); grpGrupo->end(); btnSchemaNativo = new Fl_Button(25, 83, 80, 50, “&Nativo"); btnSchemaNativo->callback((Fl_Callback*)cb_btnSchemaNativo, (void*)(this)); btnSchemaPlastic = new Fl_Button(135, 83, 80, 50, “&Plastic"); btnSchemaPlastic->callback((Fl_Callback*)cb_btnSchemaPlastic, (void*)(this)); btnSchemaGtk = new Fl_Button(245, 83, 80, 50, “&GTK+"); btnSchemaGtk->callback((Fl_Callback*)cb_btnSchemaGtk, (void*)(this)); end();}

Construindo a interface manualmente

9 de 15

Construtores da classe

CONSTRUTORES DA CLASSE

WindowChangeSchema::WindowChangeSchema(const char *L):Fl_Window(0, 0, 350, 150, L){ clear_flag(16); _WindowChangeSchema();}WindowChangeSchema::WindowChangeSchema(int W, int H, const char *L):Fl_Window(0, 0, W, H, L){ clear_flag(16); _WindowChangeSchema();}

10 de 15

void WindowChangeSchema::cb_btnSchemaNativo_i(Fl_Button* o, void*){ Fl::scheme("none");}void WindowChangeSchema::cb_btnSchemaPlastic_i(Fl_Button* o, void*){ Fl::scheme("plastic");}void WindowChangeSchema::cb_btnSchemaGtk_i(Fl_Button* o, void*){ Fl::scheme("gtk+");}

Callbacks internos

CALLBACKS INTERNOS A CLASSE

11 de 15

Callbacks “estáticos”

CALLBACKS “ESTÁTICOS” – MANIPULADOS DIRETAMENTE NOS EVENTOS

void WindowChangeSchema::cb_btnSchemaNativo(Fl_Button* o, void* v) { ((WindowChangeSchema*)(v))->cb_btnSchemaNativo_i(o,v);}void WindowChangeSchema::cb_btnSchemaPlastic(Fl_Button* o, void* v) { ((WindowChangeSchema*)(v))->cb_btnSchemaPlastic_i(o,v);}void WindowChangeSchema::cb_btnSchemaGtk(Fl_Button* o, void* v){ ((WindowChangeSchema*)(v))->cb_btnSchemaGtk_i(o,v);}

12 de 15

int main(int argc, char** argv){ WindowChangeSchema win("Muda Schema !!!"); win.show(argc,argv); return Fl::run();}

Função Principal

FUNÇÃO PRINCIPAL DO PROGRAMA

[Os três schemes suportados pelo pacote FLTK – None (Nativo), Plastic e GTK+]

13 de 15DÚVIDAS ?

Dúvidas ?

14 de 15PENSAMENTO DO DIA !

Provérbio japonês

“É um grande erro não fazer nada, quando se pode fazer pouco...”

15 de 15FIM !!!

top related