<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Fltk :: CS3 course</title><link>https://robark.gitlab.io/fltk/index.html</link><description>Chapter FLTK Fast Light Toolkit C++</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 17 May 2023 16:04:30 -0700</lastBuildDate><atom:link href="https://robark.gitlab.io/fltk/index.xml" rel="self" type="application/rss+xml"/><item><title>Intro</title><link>https://robark.gitlab.io/fltk/intro/index.html</link><pubDate>Wed, 17 May 2023 15:42:51 -0700</pubDate><guid>https://robark.gitlab.io/fltk/intro/index.html</guid><description>Introduction On the stack or the heap
#include &lt;FL/Fl_Window.H&gt; #include &lt;FL/Fl_Button.H&gt; #include &lt;FL/Fl_PNG_Image.H&gt; // fltk-config --use-images --compile #include &lt;FL/Fl.H&gt; using namespace std; /* int main(){ Fl_Window win(300,300); win.begin(); Fl_Button but(20,20,70,40); win.end(); Fl_PNG_Image pic("flag.png"); but.image(pic.copy(40,40)); win.show(); Fl::run(); } */ int main(){ Fl_Window* win = new Fl_Window(300,300); win-&gt;begin(); Fl_Button* but = new Fl_Button(20,20,70,40); win-&gt;end(); Fl_PNG_Image* pic = new Fl_PNG_Image("flag.png"); but-&gt;image(pic-&gt;copy(40,40)); win-&gt;show(); Fl::run(); } Simple callback</description></item><item><title>Oop</title><link>https://robark.gitlab.io/fltk/oop/index.html</link><pubDate>Wed, 17 May 2023 16:04:30 -0700</pubDate><guid>https://robark.gitlab.io/fltk/oop/index.html</guid><description>Object Oriented FLTK Programming #include &lt;FL/Fl_Window.H&gt; #include &lt;FL/Fl_Button.H&gt; #include &lt;FL/Fl_Input.H&gt; #include &lt;FL/Fl.H&gt; #include &lt;stdio.h&gt; //for spintf using namespace std; class Grid : public Fl_Window{ public: Grid(int x, int y, int w, int h, const char* l); //vars optional Fl_Button* buts[4][4]; //array instead of vector Fl_Input* inp; private: static void but_cb(Fl_Widget* o, void* v); void but_cbi(Fl_Button* wid); }; Grid::Grid(int x, int y, int w, int h,const char* l=0):Fl_Window(x,y,w,h,l){ //call base class ctor begin(); for (int r=0; r&lt;4; r++) { for (int c=0; c&lt;4; c++) { buts[r][c]=new Fl_Button(c*40, r*40, 40, 40); buts[r][c]-&gt;callback(but_cb, this); //notice we send the "this" pointer as user_data arg (this = instance of Grid class) } } inp=new Fl_Input(0,160,100,40); end(); resizable(this); show(); } void Grid::but_cb(Fl_Widget* o, void* v){ //static functions don't have "this" pointer. But we sent it through with v Grid* win = (Grid*)v; Fl_Button* b = (Fl_Button*)o; win-&gt;but_cbi(b); } void Grid::but_cbi(Fl_Button* wid){ //now "this" pointer exists implicitly as the function belongs to every instance of the class //so we can access every widget in the instance of the class like python //find index char s[64]; for (int r=0; r&lt;4; r++) for (int c=0; c&lt;4; c++) { if (buts[r][c] == wid) { sprintf(s, "%d", r*4+c); wid-&gt;copy_label(s); //must use copy_label as char s does not exist after foo strcat(s, inp-&gt;value()); inp-&gt;value(s); } } wid-&gt;color(FL_RED); } int main(){ Grid g(50,50,200,200); Fl::run(); } A better way. Create an Fl_Button subclass that also has integer data.</description></item></channel></rss>