static void Expand(AG_Event *event) { AG_UCombo *com = AG_PTR(1); AG_Driver *drv = WIDGET(com)->drv; int expand = AG_INT(2); AG_SizeReq rList; int x, y, w, h; Uint wView, hView; AG_ObjectLock(com); if (expand) { com->panel = AG_WindowNew(AG_WINDOW_POPUP|AG_WINDOW_MODAL| AG_WINDOW_NOTITLE); AG_ObjectSetName(com->panel, "_UComboPopup"); AG_WindowSetPadding(com->panel, 0,0,0,0); AG_ObjectAttach(com->panel, com->list); if (WIDGET(com)->window != NULL) AG_WindowAttach(WIDGET(com)->window, com->panel); if (com->wSaved > 0) { w = com->wSaved; h = com->hSaved; } else { if (com->wPreList != -1 && com->hPreList != -1) { AG_TlistSizeHintPixels(com->list, com->wPreList, com->hPreList); } AG_WidgetSizeReq(com->list, &rList); w = rList.w + com->panel->wBorderSide*2; h = rList.h + com->panel->wBorderBot; } x = WIDGET(com)->rView.x2 - w; y = WIDGET(com)->rView.y1; AG_GetDisplaySize(WIDGET(com)->drv, &wView, &hView); if (x+w > wView) { w = wView - x; } if (y+h > hView) { h = hView - y; } if (AGDRIVER_CLASS(drv)->wm == AG_WM_MULTIPLE && WIDGET(com)->window != NULL) { x += WIDGET(WIDGET(com)->window)->x; y += WIDGET(WIDGET(com)->window)->y; } if (x < 0) { x = 0; } if (y < 0) { y = 0; } if (w < 4 || h < 4) { Collapse(com); return; } AG_SetEvent(com->panel, "window-modal-close", ModalClose, "%p", com); AG_WindowSetGeometry(com->panel, x,y, w,h); AG_WindowShow(com->panel); } else { Collapse(com); } AG_ObjectUnlock(com); }
static void StartBrowser(AG_Event *event) { MyTestInstance *ti = AG_PTR(1); AG_Window *winParent = AG_PTR(2), *win; if ((win = DEV_Browser(&ti->vfsRoot)) != NULL) AG_WindowAttach(winParent, win); }
static void SelectFontDlg(AG_Event *event) { VG_Text *vt = AG_PTR(1); VG_View *vv = AG_PTR(2); AG_Window *win, *winParent; AG_FontSelector *fs; AG_Box *hBox; win = AG_WindowNew(0); AG_WindowSetCaptionS(win, _("Font selection")); fs = AG_FontSelectorNew(win, AG_FONTSELECTOR_EXPAND); hBox = AG_BoxNewHoriz(win, AG_BOX_HFILL|AG_BOX_HOMOGENOUS); AG_ButtonNewFn(hBox, 0, _("OK"), SelectFont, "%p,%p,%p", vt, win, fs); AG_ButtonNewFn(hBox, 0, _("Close"), AG_WindowCloseGenEv, "%p", win); AG_WindowShow(win); if ((winParent = AG_ParentWindow(vv)) != NULL) AG_WindowAttach(winParent, win); }
static void CreateTestWindow(AG_Event *event) { MyTestInstance *ti = AG_PTR(1); AG_Window *winParent = AG_PTR(2); AG_Window *win; if ((win = AG_WindowNew(ti->testFlags)) == NULL) { TestMsg(ti, "AG_WindowNew() failed: %s", AG_GetError()); return; } AG_WindowSetCaption(win, "Test window"); AG_LabelNewS(win, 0, "This is a test window"); AG_LabelNew(win, 0, "Flags = 0x%x", ti->testFlags); AG_ButtonNewFn(win, AG_BUTTON_HFILL, "Close this window", AGWINDETACH(win)); AG_WindowAttach(winParent, win); if (ti->makeTransient) AG_WindowMakeTransient(winParent, win); if (ti->makePinned) AG_WindowPin(winParent, win); AG_WindowShow(win); }
static void EditNumValues(AG_Event *event) { AG_HSVPal *pal = AG_PTR(1); AG_Window *pwin; AG_Window *win; AG_Numerical *num; AG_Variable *b1, *b2; float v; if ((pwin = AG_ParentWindow(pal)) == NULL) return; if ((win = AG_WindowNewNamed(AG_WINDOW_NOMAXIMIZE, "hsvpal-%p-numedit", pal)) == NULL) { return; } AG_WindowSetCaption(win, _("Color values")); AG_WindowSetPosition(win, AG_WINDOW_LOWER_LEFT, 0); AG_WindowSetCloseAction(win, AG_WINDOW_DETACH); { AG_Variable *bAlpha; void *pAlpha; num = AG_NumericalNew(win, 0, NULL, _("Hue: ")); AG_NumericalSizeHint(num, "000"); AG_WidgetCopyBinding(num, "value", pal, "hue"); AG_NumericalSetRange(num, 0.0, 359.0); AG_NumericalSetIncrement(num, 1); AG_NumericalSetPrecision(num, "f", 0); num = AG_NumericalNew(win, 0, NULL, _("Saturation: ")); AG_NumericalSizeHint(num, "00.00"); AG_WidgetCopyBinding(num, "value", pal, "saturation"); AG_NumericalSetRange(num, 0.0, 1.0); AG_NumericalSetIncrement(num, 0.01); AG_NumericalSetPrecision(num, "f", 2); num = AG_NumericalNew(win, 0, NULL, _("Value: ")); AG_NumericalSizeHint(num, "00.00"); AG_WidgetCopyBinding(num, "value", pal, "value"); AG_NumericalSetRange(num, 0.0, 1.0); AG_NumericalSetIncrement(num, 0.01); AG_NumericalSetPrecision(num, "f", 2); num = AG_NumericalNew(win, 0, NULL, _("Alpha: ")); AG_NumericalSizeHint(num, "0.000"); AG_WidgetCopyBinding(num, "value", pal, "alpha"); bAlpha = AG_GetVariable(pal, "alpha", &pAlpha); switch (AG_VARIABLE_TYPE(bAlpha)) { case AG_VARIABLE_FLOAT: case AG_VARIABLE_DOUBLE: AG_NumericalSetRange(num, 0.0, 1.0); AG_NumericalSetIncrement(num, 0.005); AG_NumericalSetPrecision(num, "f", 3); break; case AG_VARIABLE_INT: case AG_VARIABLE_UINT: case AG_VARIABLE_UINT8: AG_NumericalSetRange(num, 0.0, 255.0); AG_NumericalSetIncrement(num, 1.0); AG_NumericalSetPrecision(num, "f", 0); break; default: break; } AG_UnlockVariable(bAlpha); } AG_WindowAttach(pwin, win); AG_WindowShow(win); }
static void TestDesktopAlign(AG_Event *event) { AG_Window *winParent = AG_PTR(1); AG_Window *win; int i; for (i = 0; i < 2; i++) { if ((win = AG_WindowNew(0))) { AG_WindowSetCaption(win, "Auto%d", i); AG_LabelNew(win, 0, "Autopositioned #%d", i); AG_LabelNewS(win, 0, "(AG_WINDOW_ALIGNMENT_NONE)"); AG_WindowAttach(winParent, win); AG_WindowMakeTransient(winParent, win); AG_WindowShow(win); } if ((win = AG_WindowNew(0))) { AG_WindowSetCaption(win, "TL%d", i); AG_LabelNew(win, 0, "Top Left #%d", i); AG_LabelNewS(win, 0, "(AG_WINDOW_TL)"); AG_WindowSetPosition(win, AG_WINDOW_TL, 1); AG_WindowAttach(winParent, win); AG_WindowMakeTransient(winParent, win); AG_WindowShow(win); } if ((win = AG_WindowNew(0))) { AG_WindowSetCaption(win, "TC%d", i); AG_LabelNew(win, 0, "Top Center #%d", i); AG_LabelNewS(win, 0, "(AG_WINDOW_TC)"); AG_WindowSetPosition(win, AG_WINDOW_TC, 1); AG_WindowAttach(winParent, win); AG_WindowMakeTransient(winParent, win); AG_WindowShow(win); } if ((win = AG_WindowNew(0))) { AG_WindowSetCaption(win, "TR%d", i); AG_LabelNew(win, 0, "Top Right #%d", i); AG_LabelNewS(win, 0, "(AG_WINDOW_TR)"); AG_WindowSetPosition(win, AG_WINDOW_TR, 1); AG_WindowAttach(winParent, win); AG_WindowMakeTransient(winParent, win); AG_WindowShow(win); } if ((win = AG_WindowNew(0))) { AG_WindowSetCaption(win, "MC%d", i); AG_LabelNew(win, 0, "Center #%d", i); AG_LabelNewS(win, 0, "(AG_WINDOW_MC)"); AG_WindowSetPosition(win, AG_WINDOW_MC, 1); AG_WindowAttach(winParent, win); AG_WindowMakeTransient(winParent, win); AG_WindowShow(win); } if ((win = AG_WindowNew(0))) { AG_WindowSetCaption(win, "BL%d", i); AG_LabelNew(win, 0, "Bottom Left #%d", i); AG_LabelNewS(win, 0, "(AG_WINDOW_BL)"); AG_WindowSetPosition(win, AG_WINDOW_BL, 1); AG_WindowAttach(winParent, win); AG_WindowMakeTransient(winParent, win); AG_WindowShow(win); } if ((win = AG_WindowNew(0))) { AG_WindowSetCaption(win, "BR%d", i); AG_LabelNew(win, 0, "Bottom Right #%d", i); AG_LabelNewS(win, 0, "(AG_WINDOW_BR)"); AG_WindowSetPosition(win, AG_WINDOW_BR, 1); AG_WindowAttach(winParent, win); AG_WindowMakeTransient(winParent, win); AG_WindowShow(win); } if ((win = AG_WindowNew(0))) { AG_WindowSetCaption(win, "BC%d", i); AG_LabelNew(win, 0, "Bottom Center #%d", i); AG_LabelNewS(win, 0, "(AG_WINDOW_BC)"); AG_WindowSetPosition(win, AG_WINDOW_BC, 1); AG_WindowAttach(winParent, win); AG_WindowMakeTransient(winParent, win); AG_WindowShow(win); } } AG_LabelNewS(winParent, 0, "OK"); }
/* Callback routine for AG_FileDlg. */ static int LoadImage(AG_Event *event) { /* AG_FileDlg *fd = AG_SELF(); */ AG_Window *winParent = AG_PTR(1); char *file = AG_STRING(2); AG_FileType *ft = AG_PTR(3); AG_Surface *s; AG_Window *win; AG_Scrollview *sv; Uint8 *pSrc; Uint i; if (strcmp(ft->exts[0], "*.bmp") == 0) { s = AG_SurfaceFromBMP(file); } else if (strcmp(ft->exts[0], "*.jpg") == 0) { s = AG_SurfaceFromJPEG(file); } else if (strcmp(ft->exts[0], "*.png") == 0) { s = AG_SurfaceFromPNG(file); } else { AG_SetError("Unrecognized format: %s", ft->exts[0]); return (-1); } if (s == NULL) return (-1); if ((win = AG_WindowNew(0)) == NULL) { AG_SurfaceFree(s); return (-1); } AG_WindowSetCaption(win, "Image <%s>", AG_ShortFilename(file)); /* We use AG_FileOptionFoo() to retrieve per-type options. */ if (AG_FileOptionBool(ft,"invert")) { pSrc = (Uint8 *)s->pixels; for (i = 0; i < s->w*s->h; i++) { Uint8 r, g, b; AG_GetPixelRGB(AG_GET_PIXEL(s,pSrc), s->format, &r,&g,&b); r = 255 - r; g = 255 - g; b = 255 - b; AG_PUT_PIXEL(s, pSrc, AG_MapPixelRGB(s->format, r,g,b)); pSrc += s->format->BytesPerPixel; } } /* * Place an AG_Pixmap(3) widget inside of an AG_Scrollview(3) so * the user can pan the view. */ sv = AG_ScrollviewNew(win, AG_SCROLLVIEW_BY_MOUSE|AG_SCROLLVIEW_EXPAND); AG_PixmapFromSurfaceScaled(sv, 0, s, s->w, s->h); AG_SurfaceFree(s); AG_WindowSetGeometry(win, -1, -1, 320, 240); AG_WindowAttach(winParent, win); AG_WindowShow(win); return (0); }