From wabsie at gmail.com Sun Mar 15 16:56:51 2009 From: wabsie at gmail.com (Mark Ruvald Pedersen) Date: Sun, 15 Mar 2009 20:56:51 +0000 (UTC) Subject: [Agar] =?utf-8?q?trying_to_wrap_Agar_GUI_elements_in_C++_class_?= =?utf-8?q?=28failing_with=09callbacks=29?= References: Message-ID: Ocamler writes: > Hi,I'm trying to use Agar from C++, and am having trouble getting event callbacks, like those initiated by AG_Button click events, to call a class method properly.? Try this: #include #include #include #include class cppgui { private: AG_Window *win_; int foo; // Callbacks must be global (and thus static)!!! static void ButtonCallback(AG_Event *event) { cppgui *This = (cppgui*)AG_PTR(1); // Let the static metod have acces to the calling object instance printf("You clicked the button! And foo is %i\n", This->foo); } public: cppgui() { this->foo = 1234; // something... win_ = AG_WindowNew(0); AG_ButtonNewFn(win_, 0, "Click me", ButtonCallback, "%p", this); AG_WindowShow(win_); } ~cppgui() { AG_Destroy(); } void run() { AG_EventLoop(); } }; void die(const char *format, ...) { va_list arg; va_start(arg, format); vfprintf(stderr, format, arg); va_end(arg); exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { if (AG_InitCore("test", 0) == -1) die("%s\n", AG_GetError()); if (AG_InitVideo(200, 200, 32, 0) == -1) die("%s\n", AG_GetError()); cppgui test; test.run(); return 0; } Let me know if you found some other way. - Eisbaw From rmorales2005 at gmail.com Mon Mar 16 17:49:26 2009 From: rmorales2005 at gmail.com (Robert J. Morales) Date: Mon, 16 Mar 2009 16:49:26 -0500 Subject: [Agar] AG_Console not auto-scrolling properly Message-ID: As demonstrated in the test program below, AG_Console will not properly "auto-scroll" as is documented. Another demonstrated bug is that the scrollbar's "box" will draw itself outside of the actual scrollbar. ----------------------------------------------------------------------- #include #include static AG_Timeout timeout; static AG_Console* cons; static Uint32 cons_timer(void *obj, Uint32 ival, void *arg) { static unsigned long int counter; AG_ConsoleMsg(cons, "%lu", ++counter); return ival; } int main(int argc, char** argv) { AG_Window* wnd; if (AG_InitCore("agar-test", 0) == -1) return -1; if (AG_InitVideo(320, 240, 32, AG_VIDEO_BGPOPUPMENU|AG_VIDEO_HWSURFACE) == -1) return -1; wnd = AG_WindowNew(AG_WINDOW_NOBUTTONS|AG_WINDOW_NORESIZE); AG_WindowSetCaption(wnd, "%s", "Console Test"); cons = AG_ConsoleNew(wnd, AG_CONSOLE_EXPAND); AG_SetTimeout(&timeout, cons_timer, NULL, 0); AG_AddTimeout(wnd, &timeout, 500); AG_WindowSetGeometryAlignedPct(wnd, AG_WINDOW_MC, 75, 75); AG_WindowShow(wnd); AG_EventLoop(); return 0; } From rmorales2005 at gmail.com Mon Mar 16 19:54:35 2009 From: rmorales2005 at gmail.com (Robert J. Morales) Date: Mon, 16 Mar 2009 18:54:35 -0500 Subject: [Agar] Auto-scrolling fixed (was Re: AG_Console not auto-scrolling properly) In-Reply-To: References: Message-ID: Robert J. Morales wrote: > As demonstrated in the test program below, AG_Console will not properly "auto-scroll" as is documented. > > Another demonstrated bug is that the scrollbar's "box" will draw itself outside of the actual scrollbar. Ok, I managed to fix the auto-scrolling behavior by making a very simple change to AG_ConsoleAppendLine(). The bug with the scrollbar remains, however. ---------------------------------------------------------------------- AG_ConsoleLine * AG_ConsoleAppendLine(AG_Console *cons, const char *s) { AG_ConsoleLine *ln; int max_lines; AG_ObjectLock(cons); cons->lines = Realloc(cons->lines, (cons->nLines+1) * sizeof(AG_ConsoleLine)); ln = &cons->lines[cons->nLines++]; if (s != NULL) { ln->text = Strdup(s); ln->len = strlen(s); } else { ln->text = NULL; ln->len = 0; } ln->cons = cons; ln->selected = 0; ln->p = NULL; ln->font = NULL; ln->surface = -1; ln->cBg = AG_MapRGBA(agVideoFmt, 0,0,0,0); ln->cFg = AG_MapRGB(agVideoFmt, 250,250,230); max_lines = (cons->r.h / agTextFontHeight) - 1; if (cons->nLines > max_lines) cons->rOffs = cons->nLines - max_lines; AG_ObjectUnlock(cons); return (ln); } From jrenggli at gmail.com Tue Mar 17 05:26:08 2009 From: jrenggli at gmail.com (Julien Renggli) Date: Tue, 17 Mar 2009 09:26:08 +0000 Subject: [Agar] libglade-like manager Message-ID: Hello, I'm new to Agar but I really like what I'm seeing. It looks like it's working well, easy to use, and the concepts sound very good. Well done guys ! And now for a round of questions I couldn't find answers on the website: I have searched for a libglade-like manager that would basically read an (xml?) file and take care of widgets' allocation/deallocation, and other painful-to-maintain stuff. I couldn't find any (did I miss the obvious?). Is that something existing? Being prepared? I tried writing something myself, but progress is slow (the step back from C++ to C is not so easy...) and it's more guesswork than anything else (can provide it if there is interest). But at least I'm learning the library that way :) On the same line, is there an Agar editor (again, similar to Glade)? That would be useful for UI desing, no need to restart an app everytime a widget is moved 3px to the left. And what about the C++ wrapper? Is it already there, or can we expect it sometime soon (weeks, months, years?). Thanks, Julien