Exemplo n.º 1
0
AG_Label *
AG_StatusbarAddLabel(AG_Statusbar *sbar, const char *fmt, ...)
{
	AG_Label *lab;
	va_list ap;

	AG_ObjectLock(sbar);
#ifdef AG_DEBUG
	if (sbar->nlabels+1 >= AG_STATUSBAR_MAX_LABELS)
		AG_FatalError("AG_StatusbarAddLabel: Too many labels");
#endif
	sbar->labels[sbar->nlabels] = Malloc(sizeof(AG_Label));
	lab = sbar->labels[sbar->nlabels];

	AG_ObjectInit(lab, &agLabelClass);
	lab->type = AG_LABEL_STATIC;
	va_start(ap, fmt);
	Vasprintf(&lab->text, fmt, ap);
	va_end(ap);
	AG_ExpandHoriz(lab);

	AG_ObjectAttach(&sbar->box, lab);
	lab = sbar->labels[sbar->nlabels++];
	AG_ObjectUnlock(sbar);
	AG_Redraw(sbar);
	return (lab);
}
Exemplo n.º 2
0
ffmpegPlayer *
ffmpegPlayerNew(void *parent, int w, int h, int flags, SDL_Surface *screen)
{
	ffmpegPlayer *me;

	assert(screen != NULL);

	/* Create a new instance of the class */
	me = malloc(sizeof(ffmpegPlayer));
	AG_ObjectInit(me, &ffmpegPlayerClass);

	/* Save the user-requested geometry */
	me->w = w;
	me->h = h;
	me->flags = flags;
	me->screen = screen;

	if (flags & AG_FFMPEGPLAYER_HFILL)
		AGWIDGET(me)->flags |= AG_WIDGET_HFILL;
	if (flags & AG_FFMPEGPLAYER_VFILL)
		AGWIDGET(me)->flags |= AG_WIDGET_VFILL;

	/* Attach the object to the parent (no-op if parent is NULL) */
	AG_ObjectAttach(parent, me);

	return me;
}
Exemplo n.º 3
0
AG_Titlebar *
AG_TitlebarNew(void *parent, Uint flags)
{
	AG_Titlebar *tbar;

	tbar = Malloc(sizeof(AG_Titlebar));
	AG_ObjectInit(tbar, &agTitlebarClass);
	tbar->flags |= flags;
	
	AG_ObjectAttach(parent, tbar);

	/*
	 * Manually update the window/driver pointers since AG_TitlebarNew()
	 * is called from the Window attach routine.
	 */
	AG_ObjectLock(tbar);
	tbar->win = (AG_Window *)parent;
	WIDGET(tbar)->window = tbar->win;
	WIDGET(tbar)->drv = WIDGET(parent)->drv;
	WIDGET(tbar)->drvOps = AGDRIVER_CLASS(WIDGET(tbar)->drv);
	AG_ObjectUnlock(tbar);
	
	if ((flags & AG_TITLEBAR_NO_MAXIMIZE) == 0)
		CreateMaximizeButton(tbar);
	if ((flags & AG_TITLEBAR_NO_MINIMIZE) == 0)
		CreateMinimizeButton(tbar);
	if ((flags & AG_TITLEBAR_NO_CLOSE) == 0)
		CreateCloseButton(tbar);

	return (tbar);
}
Exemplo n.º 4
0
static void
Init(void *obj)
{
    AG_FileSelector *fs = obj;

    fs->flags = 0;
    fs->panel = NULL;
    fs->wSaved = 0;
    fs->hSaved = 0;
    fs->inTxt[0] = '\0';

    /* XXX TODO: Check for UTF-8 support in filesystem. */
    fs->tbox = AG_TextboxNewS(fs, AG_TEXTBOX_COMBO|AG_TEXTBOX_EXCL, NULL);
    AG_TextboxBindUTF8(fs->tbox, fs->inTxt, sizeof(fs->inTxt));

    fs->button = AG_ButtonNewS(fs, AG_BUTTON_STICKY, _("Browse..."));
    AG_ButtonSetPadding(fs->button, 1,1,1,1);
    AG_WidgetSetFocusable(fs->button, 0);

    fs->filedlg = Malloc(sizeof(AG_FileDlg));
    AG_ObjectInit(fs->filedlg, &agFileDlgClass);
    AG_Expand(fs->filedlg);

    AG_SetEvent(fs->button, "button-pushed", Expand, "%p", fs);
    AG_SetEvent(fs->filedlg, "file-chosen", FileChosen, "%p", fs);
    AG_SetEvent(fs->tbox, "textbox-return", Return, "%p", fs);
}
Exemplo n.º 5
0
Arquivo: textbox.c Projeto: adsr/agar
AG_Textbox *
AG_TextboxNewS(void *parent, Uint flags, const char *label)
{
	AG_Textbox *tb;

	tb = Malloc(sizeof(AG_Textbox));
	AG_ObjectInit(tb, &agTextboxClass);

	if (flags & AG_TEXTBOX_HFILL)
		AG_ExpandHoriz(tb);
	if (flags & AG_TEXTBOX_VFILL)
		AG_ExpandVert(tb);
	if (flags & AG_TEXTBOX_READONLY) {
		AG_WidgetDisable(tb);
		AG_WidgetDisable(tb->ed);
	}
	if (flags & AG_TEXTBOX_PASSWORD)
		tb->ed->flags |= AG_EDITABLE_PASSWORD;
	if (flags & AG_TEXTBOX_ABANDON_FOCUS)
		tb->ed->flags |= AG_EDITABLE_ABANDON_FOCUS;
	if (flags & AG_TEXTBOX_INT_ONLY)
		tb->ed->flags |= AG_EDITABLE_INT_ONLY;
	if (flags & AG_TEXTBOX_FLT_ONLY)
		tb->ed->flags |= AG_EDITABLE_FLT_ONLY;
	if (flags & AG_TEXTBOX_CATCH_TAB) {
		WIDGET(tb)->flags |= AG_WIDGET_CATCH_TAB;
		WIDGET(tb->ed)->flags |= AG_WIDGET_CATCH_TAB;
	}
	if (flags & AG_TEXTBOX_NOEMACS)
		tb->ed->flags |= AG_EDITABLE_NOEMACS;
	if (flags & AG_TEXTBOX_NOWORDSEEK)
		tb->ed->flags |= AG_EDITABLE_NOWORDSEEK;
	if (flags & AG_TEXTBOX_NOLATIN1)
		tb->ed->flags |= AG_EDITABLE_NOLATIN1;
	
	if (flags & AG_TEXTBOX_MULTILINE) {
		tb->ed->flags |= AG_EDITABLE_MULTILINE;

		tb->vBar = AG_ScrollbarNew(tb, AG_SCROLLBAR_VERT,
		    AG_SCROLLBAR_AUTOHIDE);
		AG_BindInt(tb->vBar, "value", &tb->ed->y);
		AG_BindInt(tb->vBar, "max", &tb->ed->yMax);
		AG_BindInt(tb->vBar, "visible", &tb->ed->yVis);
		AG_SetEvent(tb->vBar, "scrollbar-drag-begin", BeginScrollbarDrag, "%p", tb);
		AG_SetEvent(tb->vBar, "scrollbar-drag-end", EndScrollbarDrag, "%p", tb);
	}
	
	AG_TextboxSetStatic(tb, (flags & AG_TEXTBOX_STATIC));
	AG_TextboxSetWordWrap(tb, (flags & AG_TEXTBOX_WORDWRAP));

	tb->flags |= flags;
	if (label != NULL) {
		tb->lbl = AG_LabelNewS(tb, 0, label);
		AG_LabelSetPadding(tb->lbl, -1, 10, -1, -1);
	}
	AG_ObjectAttach(parent, tb);
	return (tb);
}
Exemplo n.º 6
0
Arquivo: animal.c Projeto: adsr/agar
/*
 * Constructor function. This is optional and only a convenience for
 * developers who want to use our "Animal" API directly.
 */
Animal *
AnimalNew(void *parent)
{
	Animal *animal;

	animal = AG_Malloc(sizeof(Animal));
	AG_ObjectInit(animal, &AnimalClass);	/* Will invoke Init() */
	AG_ObjectAttach(parent, animal);
	return (animal);
}
Exemplo n.º 7
0
/* Create a new database-bound object. */
AG_DbObject *
AG_DbObjectNew(void)
{
	AG_DbObject *dbo;

	if ((dbo = TryMalloc(sizeof(AG_DbObject))) == NULL) {
		return (NULL);
	}
	AG_ObjectInit(dbo, &agDbObjectClass);
	return (dbo);
}
Exemplo n.º 8
0
AG_Statusbar *
AG_StatusbarNew(void *parent, Uint flags)
{
	AG_Statusbar *sbar;

	sbar = Malloc(sizeof(AG_Statusbar));
	AG_ObjectInit(sbar, &agStatusbarClass);
	sbar->flags |= flags;
	if (flags & AG_STATUSBAR_HFILL) { AG_ExpandHoriz(sbar); }
	if (flags & AG_STATUSBAR_VFILL) { AG_ExpandVert(sbar); }
	AG_ObjectAttach(parent, sbar);
	return (sbar);
}
Exemplo n.º 9
0
/*
 * This is a generic constructor function. It is completely optional, but
 * customary of FooNew() functions to allocate, initialize and attach an
 * instance of the class.
 */
formaText *
formaTextNew(void *parent)
{
	formaText *my;

	/* Create a new instance of the formaText class */
	my = (formaText*)malloc(sizeof(formaText));
	AG_ObjectInit(my, &formaTextClass);

	/* Attach the object to the parent (no-op if parent is NULL) */
	AG_ObjectAttach(parent, my);

	return (my);
}
Exemplo n.º 10
0
AG_FontSelector *
AG_FontSelectorNew(void *parent, Uint flags)
{
	AG_FontSelector *fs;

	fs = Malloc(sizeof(AG_FontSelector));
	AG_ObjectInit(fs, &agFontSelectorClass);
	fs->flags |= flags;
	if (flags & AG_FONTSELECTOR_HFILL) { AG_ExpandHoriz(fs); }
	if (flags & AG_FONTSELECTOR_VFILL) { AG_ExpandVert(fs); }
	
	AG_ObjectAttach(parent, fs);
	return (fs);
}
Exemplo n.º 11
0
AG_HSVPal *
AG_HSVPalNew(void *parent, Uint flags)
{
	AG_HSVPal *pal;

	pal = Malloc(sizeof(AG_HSVPal));
	AG_ObjectInit(pal, &agHSVPalClass);
	pal->flags |= flags;

	if (flags & AG_HSVPAL_HFILL) { AG_ExpandHoriz(pal); }
	if (flags & AG_HSVPAL_VFILL) { AG_ExpandVert(pal); }

	AG_ObjectAttach(parent, pal);
	return (pal);
}
Exemplo n.º 12
0
AG_GLView *
AG_GLViewNew(void *parent, Uint flags)
{
	AG_GLView *glv;

	glv = Malloc(sizeof(AG_GLView));
	AG_ObjectInit(glv, &agGLViewClass);
	glv->flags |= flags;

	if (flags & AG_GLVIEW_HFILL) { AG_ExpandHoriz(glv); }
	if (flags & AG_GLVIEW_VFILL) { AG_ExpandVert(glv); }

	AG_ObjectAttach(parent, glv);
	return (glv);
}
Exemplo n.º 13
0
Arquivo: mpane.c Projeto: adsr/agar
AG_MPane *
AG_MPaneNew(void *parent, enum ag_mpane_layout layout, Uint flags)
{
	AG_MPane *mp;

	mp = Malloc(sizeof(AG_MPane));
	AG_ObjectInit(mp, &agMPaneClass);
	mp->flags |= flags;
	
	if (flags & AG_MPANE_HFILL) { AG_ExpandHoriz(mp); }
	if (flags & AG_MPANE_VFILL) { AG_ExpandVert(mp); }

	AG_MPaneSetLayout(mp, layout);
	AG_ObjectAttach(parent, mp);
	return (mp);
}
Exemplo n.º 14
0
AG_Slider *
AG_SliderNew(void *parent, enum ag_slider_type type, Uint flags)
{
	AG_Slider *sl;

	sl = Malloc(sizeof(AG_Slider));
	AG_ObjectInit(sl, &agSliderClass);
	sl->type = type;
	sl->flags |= flags;

	if (flags & AG_SLIDER_HFILL) { AG_ExpandHoriz(sl); }
	if (flags & AG_SLIDER_VFILL) { AG_ExpandVert(sl); }

	AG_ObjectAttach(parent, sl);
	return (sl);
}
Exemplo n.º 15
0
AG_Box *
AG_BoxNew(void *parent, enum ag_box_type type, Uint flags)
{
	AG_Box *box;

	box = Malloc(sizeof(AG_Box));
	AG_ObjectInit(box, &agBoxClass);

	box->type = type;
	box->flags |= flags;

	if (flags & AG_BOX_HFILL) { AG_ExpandHoriz(box); }
	if (flags & AG_BOX_VFILL) { AG_ExpandVert(box); }

	AG_ObjectAttach(parent, box);
	return (box);
}
Exemplo n.º 16
0
int
AG_ConfigInit(AG_Config *cfg, Uint flags)
{
	char path[AG_PATHNAME_MAX], *s;
	AG_User *sysUser;

	AG_ObjectInit(cfg, &agConfigClass);
	AG_ObjectSetName(cfg, "config");
	OBJECT(cfg)->save_pfx = NULL;

	AG_SetInt(cfg, "initial-run", 1);
	AG_SetInt(cfg, "no-confirm-quit", 0);

	if (agProgName != NULL &&
	    (sysUser = AG_GetRealUser()) != NULL) {
		AG_SetString(cfg, "home", sysUser->home);
		AG_SetString(cfg, "tmp-path", sysUser->tmp);

		Strlcpy(path, sysUser->home, sizeof(path));
		Strlcat(path, AG_PATHSEP, sizeof(path));
		Strlcat(path, ".", sizeof(path));
		Strlcat(path, agProgName, sizeof(path));
		AG_SetString(cfg, "save-path", path);

		if (strcmp(DATADIR, "NONE") != 0) {
			AG_PrtString(cfg, "load-path", "%s%s%s",
			    path, AG_PATHSEPMULTI, DATADIR);
		} else {
			AG_SetString(cfg, "load-path", path);
		}
		AG_UserFree(sysUser);
	} else {
		AG_SetString(cfg, "home", "");
		s = (strcmp(DATADIR,"NONE") != 0) ? DATADIR : ".";
		AG_SetString(cfg, "load-path", s);
		AG_SetString(cfg, "save-path", s);
		AG_SetString(cfg, "tmp-path", "tmp");
	}

	if ((flags & AG_CREATE_DATADIR) &&
	    AG_CreateDataDir() == -1) {
		return (-1);
	}
	return (0);
}
Exemplo n.º 17
0
AG_Separator *
AG_SpacerNew(void *parent, enum ag_separator_type type)
{
    AG_Separator *sep;

    sep = Malloc(sizeof(AG_Separator));
    AG_ObjectInit(sep, &agSeparatorClass);
    sep->type = type;
    sep->visible = 0;

    if (type == AG_SEPARATOR_HORIZ) {
        AG_ExpandHoriz(sep);
    } else {
        AG_ExpandVert(sep);
    }
    AG_ObjectAttach(parent, sep);
    return (sep);
}
Exemplo n.º 18
0
Arquivo: ucombo.c Projeto: adsr/agar
AG_UCombo *
AG_UComboNew(void *parent, Uint flags)
{
	AG_UCombo *com;

	com = Malloc(sizeof(AG_UCombo));
	AG_ObjectInit(com, &agUComboClass);
	com->flags |= flags;

	if (flags & AG_UCOMBO_HFILL) { AG_ExpandHoriz(com); }
	if (flags & AG_UCOMBO_VFILL) { AG_ExpandVert(com); }

	if (flags & AG_UCOMBO_SCROLLTOSEL)
		com->list->flags |= AG_TLIST_SCROLLTOSEL;

	AG_ObjectAttach(parent, com);
	return (com);
}
Exemplo n.º 19
0
AG_Button *
AG_ButtonNewS(void *parent, Uint flags, const char *label)
{
	AG_Button *bu;
	
	bu = Malloc(sizeof(AG_Button));
	AG_ObjectInit(bu, &agButtonClass);

	if (label != NULL) {
		bu->lbl = AG_LabelNewS(bu, 0, label);
		AG_LabelJustify(bu->lbl, bu->justify);
		AG_LabelValign(bu->lbl, bu->valign);
	}
	bu->flags |= flags;

	if (flags & AG_BUTTON_HFILL) { AG_ExpandHoriz(bu); }
	if (flags & AG_BUTTON_VFILL) { AG_ExpandVert(bu); }

	AG_ObjectAttach(parent, bu);
	return (bu);
}
Exemplo n.º 20
0
Arquivo: ucombo.c Projeto: adsr/agar
static void
Init(void *obj)
{
	AG_UCombo *com = obj;

	WIDGET(com)->flags |= AG_WIDGET_UNFOCUSED_BUTTONUP|
	                      AG_WIDGET_TABLE_EMBEDDABLE;

	com->flags = 0;
	com->panel = NULL;
	com->wSaved = 0;
	com->hSaved = 0;
	com->wPreList = -1;
	com->hPreList = -1;

	com->button = AG_ButtonNewS(com, AG_BUTTON_STICKY, _("..."));
	AG_ButtonSetPadding(com->button, 0,0,0,0);
	AG_LabelSetPadding(com->button->lbl, 0,0,0,0);
	AG_WidgetSetFocusable(com->button, 0);
	
	com->list = Malloc(sizeof(AG_Tlist));
	AG_ObjectInit(com->list, &agTlistClass);
	AG_Expand(com->list);
	AG_WidgetForwardFocus(com, com->button);
	
	AG_SetEvent(com, "detached", OnDetach, NULL);
	AG_SetEvent(com->button, "button-pushed", Expand, "%p", com);
	AG_SetEvent(com->list, "tlist-changed", SelectedItem, "%p", com);

#ifdef AG_DEBUG
	AG_BindUint(com, "flags", &com->flags);
	AG_BindPointer(com, "list", (void *)&com->list);
	AG_BindPointer(com, "panel", (void *)&com->panel);
	AG_BindInt(com, "wSaved", &com->wSaved);
	AG_BindInt(com, "hSaved", &com->hSaved);
	AG_BindInt(com, "wPreList", &com->wPreList);
	AG_BindInt(com, "hPreList", &com->hPreList);
#endif
}
Exemplo n.º 21
0
AG_FileSelector *
AG_FileSelectorNew(void *parent, Uint flags, const char *label)
{
    AG_FileSelector *fs;

    fs = Malloc(sizeof(AG_FileSelector));
    AG_ObjectInit(fs, &agFileSelectorClass);
    fs->flags |= flags;

    if (label != NULL) {
        AG_TextboxSetLabelS(fs->tbox, label);
    }
    if (flags & AG_FILE_SELECTOR_HFILL) {
        AG_ExpandHoriz(fs);
    }
    if (flags & AG_FILE_SELECTOR_VFILL) {
        AG_ExpandVert(fs);
    }

    AG_ObjectAttach(parent, fs);
    return (fs);
}
Exemplo n.º 22
0
Arquivo: combo.c Projeto: adsr/agar
AG_Combo *
AG_ComboNewS(void *parent, Uint flags, const char *label)
{
	AG_Combo *com;

	com = Malloc(sizeof(AG_Combo));
	AG_ObjectInit(com, &agComboClass);
	com->flags |= flags;

	if (label != NULL) {
		AG_TextboxSetLabelS(com->tbox, label);
	}
	if (flags & AG_COMBO_ANY_TEXT) { AG_WidgetDisable(com->tbox); }
	if (flags & AG_COMBO_TREE) { com->list->flags |= AG_TLIST_TREE; }
	if (flags & AG_COMBO_POLL) { com->list->flags |= AG_TLIST_POLL; }
	if (flags & AG_COMBO_SCROLLTOSEL) {
		com->list->flags |= AG_TLIST_SCROLLTOSEL;
	}
	if (flags & AG_COMBO_HFILL) { AG_ExpandHoriz(com); }
	if (flags & AG_COMBO_VFILL) { AG_ExpandVert(com); }
	
	AG_ObjectAttach(parent, com);
	return (com);
}
Exemplo n.º 23
0
Arquivo: db.c Projeto: varialus/agar
/* Create a new database handle for the given database backend. */
AG_Db *
AG_DbNew(const char *backend)
{
	AG_Db *db;
	AG_DbClass *dbc = NULL;

#ifdef HAVE_DB4
	/* XXX */
	if (strcmp(backend, "hash")) {
		dbc = &agDbHashClass;
	} else if (strcmp(backend, "btree")) {
		dbc = &agDbBtreeClass;
	}
#endif
	if (dbc == NULL) {
		AG_SetError("No such database backend: %s", backend);
		return (NULL);
	}
	if ((db = TryMalloc(sizeof(AG_Db))) == NULL) {
		return (NULL);
	}
	AG_ObjectInit(db, dbc);
	return (db);
}