/* ParaGUI - crossplatform widgetset TUTORIAL 3 - callback functions Copyright (C) 2000 Alexander Pipelka 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 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Alexander Pipelka pipelka@teleweb.at Last Update: $Author: pipelka $ Update Date: $Date: 2001/01/31 17:23:17 $ Source File: $Source: /usr/local/CVSROOT/linux/paragui/doc/html/tut3_cpp-example.html,v $ CVS/RCS Revision: $Revision: 1.10 $ Status: $State: Exp $ */ #include "sdlapplication.h" #include "sdlbutton.h" // to process events we can use callback functions // callbacks are defined the following: // bool funcname (int id, SDLWidget* widget, unsigned long data, void *clientdata) // for your convenience there is a macro that makes your live easier: // PARAGUI_CALLBACK(funcname) PARAGUI_CALLBACK(exit_handler) { // we can pass in some pointer to any userdata // (in this case we get a pointer to the application object) SDLApplication* app = (SDLApplication*) clientdata; // exit the application eventloop app->Quit(); // return true to signal that we have processed this message return true; } // your main func int main(int argc, char* argv[]) { // every ParaGUI application need an application-object SDLApplication app; // every application needs a theme (the look & feel of the widgets) app.LoadTheme("default"); // we must initialize the screen where we want to draw on // 640 - screen width // 480 - screen height // 16 - bitdepth (hicolor) // SDL_SWSURFACE - SDL option to generate surface in system memory app.InitScreen(640, 480, 16, SDL_SWSURFACE); // ok - now we have a nice 640x480x16 window on the screen :) // after that we can create some widgets SDL_Rect rect; rect.x = 260; rect.y = 100; rect.w = 120; rect.h = 50; SDLButton myButton( NULL, // an optional parent widget for our button - NULL for no parent 1, // the widget id (used to identify events) rect, // the screen position where the button should appear "Hello World!" // some textlabel for the button ); // this defines our callback handler for the message MSG_BUTTONCLICK, // we pass a pointer to the app object as userdata myButton.SetEventCallback(MSG_BUTTONCLICK, exit_handler, &app); // now we have to make the button visible myButton.Show(); // Every ParaGUI application is event driven, so we need a loop where // we process all events (like mouse handling, keystrokes,...) // usually this is done with SDLApplication::Run() app.Run(); // this function will only exit when the application was closed return 0; }