On 07/11/12 02:03, Julien Nadeau wrote:
> 
> Hi Josh,
> 
> Admittedly this isn't obvious from the documentation, but windows
> should be destroyed this way:
> 
>       AG_ObjectDetach(win);
> 
> Detached windows are automatically freed by the event loop, so calls
> such as AG_ObjectDestroy() or free() must not be used. To pass a
> pointer to the window to your event handler routine:
> 
>       AG_ButtonNewFn(win, 0,
>           "Button Function", Button_Function, "%p", win);
> 
>       static void
>       Button_Function(AG_Event *event)
>       {
>               AG_Window *win = AG_PTR(1);
>       
>               AG_ObjectDetach(win);
>        }
> 
> On Wed, Nov 07, 2012 at 01:30:46AM +0000, Josh Branning wrote:
>> Hello all, I've got agar working on Debian now, I had to do ldconfig
>> after installing.
>>
>> I now attempting to close a window, using a function that is triggered
>> from a button, but I am running into difficulties. If anyone knows what
>> I need to replace /* Close "win" */ with in order to close the window
>> named "win", I'd be a very happy person! :)
>>
>> #include <string.h>
>>
>> static void
>> Button_Function(AG_Event *event)
>> {
>>
>>      /* Do something then ... */
>>      
>>      /* Close "win" */
>> }
>>
>> static void
>> Button(AG_Event *event)
>> {
>>      AG_Window *winParent = AG_PTR(1);
>>      AG_Window *win;
>>
>>      /* Create our window. */
>>      if ((win = AG_WindowNew(0)) == NULL) {
>>              return;
>>      }
>>      AG_WindowSetCaption(win, "This is the window I would like to close from
>> Button_Function");
>>
>>      AG_ButtonNewFn(win, 0,
>>          "Button Function", Button_Function, "%p", 0);
>>
>>      AG_WindowSetGeometryAligned(win, AG_WINDOW_ML, 320, 240);
>>      AG_WindowAttach(winParent, win);
>>      AG_WindowShow(win);
>> }
>>
>> int
>> main(int argc, char *argv[])
>> {
>>
>>      if (AG_InitCore(NULL, 0) == -1 ||
>>          AG_InitGraphics(0) == -1)
>>              return (1);
>>
>>      AG_Window *mainWin;
>>
>>      /* Create our window. */
>>      if ((mainWin = AG_WindowNew(0)) == NULL) {
>>              return -1;
>>      }
>>      AG_WindowSetCaption(mainWin, "Test");
>>
>>      /* Create a polled table. */
>>      AG_ButtonNewFn(mainWin, 0,
>>          "Button", Button, NULL, 0);
>>
>>      /* Display and resize our window. */
>>      AG_WindowSetGeometryAligned(mainWin, AG_WINDOW_ML, 640, 480);
>>      AG_WindowShow(mainWin);
>>
>>      AG_EventLoop();
>>      return (0);
>> }
>>
>> _______________________________________________
>> Agar mailing list
>> [email protected]
>> http://libagar.org/lists.html

Thanks for this, works great,

Josh.

_______________________________________________
Agar mailing list
[email protected]
http://libagar.org/lists.html

Reply via email to