Eric Dunstan | 24 Jun 11:52
Picon

A Simple Agar Application with a text area

Here is my simple AGAR application that compiles and runs with Agar 1.3.3 with
no problem. This is implemented in C only. It is called main.c

I used this code to compile agains Agar compiled from source via SVN
repositories revision 8209, the latest, and it fails, but the error messages
point to the AGAR code itself.

#pragma comment(lib,"PthreadVC2.lib")

#include <agar/core.h>
#include <agar/gui.h> 

#include <string.h> 

static void
DisableInput(AG_Event *event) 
{
	AG_Textbox *textbox = AG_PTR(1); 
	int flag = AG_INT(2);

	if (flag) {
		AG_WidgetDisable(textbox);
	} else {
		AG_WidgetEnable(textbox);
	}
}

int
main(int argc, char *argv[])
{
	AG_Window *win; 
	AG_Textbox *textbox;
	char *someText;
	size_t size, bufSize;
	char *emerald;
	AG_Label *lab1, *lab2;

	if (AG_InitCore("hello", 0) == -1 ||
	    AG_InitVideo(640, 480, 32, AG_VIDEO_RESIZABLE) == -1)
		return (1);

	AG_BindGlobalKey(SDLK_ESCAPE, KMOD_NONE, AG_Quit);
	AG_BindGlobalKey(SDLK_F8, KMOD_NONE, AG_ViewCapture);

	win = AG_WindowNew(0);
	AG_WindowSetCaption(win, "Zillionare");

	emerald = "The woods are lovely, dark, and green. Or so I have seen...";
	size = strlen(emerald);
	bufSize = size+(1024 * 5);
	someText = AG_Malloc(bufSize); 
	strcpy(someText, emerald);
	someText[size] = '\0';
	
	lab1 = AG_LabelNew(win, 0, "Hello World, from Label 1");
	lab2 = AG_LabelNew(win, 0, "Hello Again, from Label 2");
	
	textbox = AG_TextboxNew(win,
	    AG_TEXTBOX_NO_HFILL|
		//AG_TEXTBOX_HFILL|
		//AG_TEXTBOX_VFILL|
		//AG_TEXTBOX_WORDWRAP|   
		AG_TEXTBOX_MULTILINE|   
		AG_TEXTBOX_EXPAND|
		AG_TEXTBOX_CATCH_TAB,
	    NULL); 
	AG_TextboxSizeHintPixels(textbox, 250, 100);
	/*
	 * Bind the buffer's contents to the Textbox. The size argument to
	 * AG_TextboxBindUTF8() must include space for the terminating NUL.
	 */

	AG_TextboxBindUTF8(textbox, someText, bufSize);
	AG_TextboxSetCursorPos(textbox, 0); 
	//AG_EditableSetWordWrap(textbox->ed, 1);

	AG_CheckboxNewFn(win, 0, "Disable input",
	    DisableInput, "%p", textbox);
	AG_SeparatorNewHoriz(win);
	AG_LabelNewPolled(win, AG_LABEL_HFILL,
		"Rows: %d", &textbox->ed->xMax);
	AG_LabelNewPolled(win, AG_LABEL_HFILL,
	    "Lines: %d", &textbox->ed->yMax);
	AG_LabelNewPolled(win, AG_LABEL_HFILL,
	    "Cursor position: %d", &textbox->ed->pos);

	AG_WindowSetGeometryAligned(win, AG_WINDOW_MC, 540, 380);

	AG_WindowShow(win);
	//AG_WindowUpdate(win);

	AG_EventLoop();
	AG_Destroy();
	return (0);
}

Gmane