4
I Use This!
Activity Not Available

News

Analyzed 3 months ago. based on code collected 4 months ago.
Posted over 10 years ago by Agar-SVN
Author: vedge Date: 2015-01-14 02:12:45 -0500 (Wed, 14 Jan 2015) New Revision: 9726 Modified: trunk/gui/scrollbar.c Log: don't move the scrollbar unless max > visible Modified: trunk/gui/scrollbar.c ... [More] =================================================================== --- trunk/gui/scrollbar.c2015-01-14 04:47:14 UTC (rev 9725) +++ trunk/gui/scrollbar.c2015-01-14 07:12:45 UTC (rev 9726) < at >< at > -169,15 +169,18 < at >< at > TYPE max = *(TYPE *)pMax;\ TYPE vis = *(TYPE *)pVis;\ int extentPx;\ -GET_EXTENT_PX(TYPE);\ -if (x <= 0) {\ -*(TYPE *)pVal = min;\ -} else if (x >= (int)extentPx) {\ -*(TYPE *)pVal = MAX(min, (max - vis));\ -} else {\ -*(TYPE *)pVal = min + x*(max-vis-min)/extentPx;\ -if (*(TYPE *)pVal < min) { *(TYPE *)pVal = min;}\ -if (*(TYPE *)pVal > max) { *(TYPE *)pVal = max;}\ +\ +if (*(TYPE *)pMax > *(TYPE *)pVis) {\ +GET_EXTENT_PX(TYPE);\ +if (x <= 0) {\ +*(TYPE *)pVal = min;\ +} else if (x >= (int)extentPx) {\ +*(TYPE *)pVal = MAX(min, (max - vis));\ +} else {\ +*(TYPE *)pVal = min + x*(max-vis-min)/extentPx;\ +if (*(TYPE *)pVal < min) { *(TYPE *)pVal = min;} \ +if (*(TYPE *)pVal > max) { *(TYPE *)pVal = max;} \ +}\ }\ } static __inline__ void < at >< at > -225,21 +228,25 < at >< at > */ #undef INCREMENT #define INCREMENT(TYPE){\ -if ((*(TYPE *)pVal + *(TYPE *)pInc) >\ - (*(TYPE *)pMax - (*(TYPE *)pVis))) {\ -*(TYPE *)pVal = (*(TYPE *)pMax) - (*(TYPE *)pVis);\ -rv = 1;\ -} else { \ -*(TYPE *)pVal += *(TYPE *)pInc;\ +if (*(TYPE *)pMax > *(TYPE *)pVis) {\ +if ((*(TYPE *)pVal + *(TYPE *)pInc) >\ + (*(TYPE *)pMax - (*(TYPE *)pVis))) {\ +*(TYPE *)pVal = (*(TYPE *)pMax) - (*(TYPE *)pVis); \ +rv = 1;\ +} else { \ +*(TYPE *)pVal += *(TYPE *)pInc;\ +}\ }\ } #undef DECREMENT #define DECREMENT(TYPE) {\ -if (*(TYPE *)pVal < *(TYPE *)pMin + *(TYPE *)pInc) {\ -*(TYPE *)pVal = *(TYPE *)pMin;\ -rv = 1;\ -} else { \ -*(TYPE *)pVal -= *(TYPE *)pInc;\ +if (*(TYPE *)pMax > *(TYPE *)pVis) {\ +if (*(TYPE *)pVal < *(TYPE *)pMin + *(TYPE *)pInc) {\ +*(TYPE *)pVal = *(TYPE *)pMin;\ +rv = 1;\ +} else { \ +*(TYPE *)pVal -= *(TYPE *)pInc;\ +}\ }\ } static int [Less]
Posted over 10 years ago by Agar-SVN
Author: vedge Date: 2014-11-04 03:15:57 -0500 (Tue, 04 Nov 2014) New Revision: 9720 Modified: trunk/core/AG_Variable.3 Log: specify behavior of AG_SetString() and AG_SetStringNODUP() where the variable exists as a reference to a fixed-size buffer ... [More] Modified: trunk/core/AG_Variable.3 =================================================================== --- trunk/core/AG_Variable.32014-11-04 08:15:09 UTC (rev 9719) +++ trunk/core/AG_Variable.32014-11-04 08:15:57 UTC (rev 9720) < at >< at > -596,9 +596,6 < at >< at > .Ft "void" .Fn AG_InitStringNODUP "AG_Variable *var" "const char *s" .Pp -.Ft "void" -.Fn AG_InitStringFixed "AG_Variable *var" "char *s" "size_t len" -.Pp .Ft "AG_Variable *" .Fn AG_SetString "AG_Object *obj" "const char *name" "const char *s" .Pp < at >< at > -609,9 +606,6 < at >< at > .Fn AG_PrtString "AG_Object *obj" "const char *name" "const char *fmt" "...." .Pp .Ft "AG_Variable *" -.Fn AG_SetStringFixed "AG_Object *obj" "const char *name" "char *s" "size_t len" -.Pp -.Ft "AG_Variable *" .Fn AG_BindString "AG_Object *obj" "const char *name" "char *s" "size_t len" .Pp .Ft "AG_Variable *" < at >< at > -675,39 +669,35 < at >< at > variant sets the .Fa s pointer without copying the string. +.Pp The -.Fn AG_InitStringFixed -variant initializes a string variable to use a fixed-size buffer -.Fa s , -of size -.Fa len . -.Pp .Fn AG_SetString -sets the named string variable to the given string -.Fa s . -The argument may be set to NULL (in which case further +function creates or modifies a string variable. +The +.Fa s +argument is a C string which will be duplicated or copied. +If the variable exists as a reference to a fixed-size buffer (i.e., +it has been created by +.Fn AG_BindString ) , +then the contents of +.Fa s +are copied to the buffer. +If the buffer has insufficient space, the string is truncated. +The +.Fa s +argument may be set to NULL (in which case further .Fn AG_GetString calls will return NULL). .Pp The .Fn AG_SetStringNODUP -variant is not free-threaded, it uses the -.Fa s -pointer directly without copying the string, assuming the pointer will -remain valid for as long as the variable exists. +variant accepts a pointer to a dynamically-allocated string buffer. +This buffer will be freed automatically when the parent object is destroyed. .Pp The .Fn AG_PrtString variant sets a string variable from a format string argument. .Pp -The -.Fn AG_SetStringFixed -function creates or modifies a string variable, tied to a fixed-size -string buffer -.Fa s , -of size -.Fa len . -.Pp .Fn AG_BindString creates or modifies a variable referencing a fixed-size string buffer .Fa s , [Less]
Posted over 10 years ago by Agar-SVN
Author: vedge Date: 2014-11-04 03:15:09 -0500 (Tue, 04 Nov 2014) New Revision: 9719 Modified: trunk/core/object.c trunk/core/variable.c trunk/core/variable.h trunk/tests/configsettings.c Log: - specify the behavior of AG_SetString() and ... [More] AG_SetStringNODUP() where the given variable exists as a fixed-size buffer reference. - Variable types should be portably encoded as Sint32. - remove redundant init in FetchVariable(). - with strings, consistently refer to V->data.s and not V->data.p. - remove AG_SetStringFixed() and AG_InitStringFixed() -- AG_BindString() should be used instead. Modified: trunk/core/object.c =================================================================== --- trunk/core/object.c2014-09-08 02:56:57 UTC (rev 9718) trunk/core/object.c2014-11-04 08:15:09 UTC (rev 9719) < at >< at > -1140,13 1140,16 < at >< at > count = AG_ReadUint32(ds); for (i = 0; i < count; i ) { char key[64]; -Uint32 code; Sint32 code; if (AG_CopyString(key, ds, sizeof(key)) >= sizeof(key)) { AG_SetError("Variable name too long: %s", key); goto fail; } -code = AG_ReadUint32(ds); code = AG_ReadSint32(ds); #if 0 Verbose("%s: %s (code %d)\n", ob->name, key, (int)code); #endif for (j = 0; j < AG_VARIABLE_TYPE_LAST; j ) { if (agVariableTypes[j].code == code) break; < at >< at > -1173,7 1176,9 < at >< at > #ifdef AG_HAVE_LONG_DOUBLE case AG_VARIABLE_LONG_DOUBLE: AG_SetLongDouble(ob, key, AG_ReadLongDouble(ds)); break; #endif -case AG_VARIABLE_STRING: AG_SetStringNODUP(ob, key, AG_ReadString(ds)); break; case AG_VARIABLE_STRING: AG_SetStringNODUP(ob, key, AG_ReadString(ds)); break; default: AG_SetError("Attempt to load variable of type %s", agVariableTypes[j].name); < at >< at > -1187,7 1192,7 < at >< at > return (-1); } -/* Save Object variables. */ /* Save persistent object variables. */ void AG_ObjectSaveVariables(void *pObj, AG_DataSource *ds) { < at >< at > -1206,22 1211,21 < at >< at > void *p; if (Vt->code == -1) { -fprintf(stderr, "skipping %s (non-persistent)\n", - V->name); -continue;/* Nonpersistent */ Verbose("Save: skipping %s (non-persistent)\n", V->name); continue; } AG_LockVariable(V); if (V->fn.fnVoid != NULL && AG_EvalVariable(ob, V) == -1) { -Debug(ob, "Failed to eval %s (%s); excluding from archive", - V->name, AG_GetError()); Verbose("Save: eval %s failed (%s); ignoring", V->name, AG_GetError()); AG_UnlockVariable(V); continue; } AG_WriteString(ds, (char *)V->name); -AG_WriteUint32(ds, Vt->code); AG_WriteSint32(ds, Vt->code); p = (agVariableTypes[V->type].indirLvl > 0) ? V->data.p : &V->data; < at >< at > -1258,8 1262,8 < at >< at > * Load an Agar object (or a virtual filesystem of Agar objects) from an * archive file. * - * Only the generic Object information is read, datasets are skipped and - * dependencies are left unresolved. * Only the generic part is read, datasets are skipped and dependencies * are left unresolved. */ int AG_ObjectLoadGenericFromFile(void *p, const char *pPath) < at >< at > -1351,7 1355,9 < at >< at > } goto fail; } -chld = Malloc(cl->size); if ((chld = TryMalloc(cl->size)) == NULL) { goto fail; } AG_ObjectInit(chld, cl); AG_ObjectSetNameS(chld, cname); AG_ObjectAttach(ob, chld); < at >< at > -1521,7 1527,7 < at >< at > AG_WriteUint32(ds, 0);/* Data offs */ AG_WriteUint32(ds, (Uint32)(ob->flags & AG_OBJECT_SAVED_FLAGS)); -/* Dependency and property tables */ /* Interobject dependency table */ countOffs = AG_Tell(ds); AG_WriteUint32(ds, 0); for (dep = TAILQ_FIRST(&ob->deps), count = 0; < at >< at > -1537,6 1543,8 < at >< at > count ; } AG_WriteUint32At(ds, count, countOffs); /* Persistent object variables */ AG_ObjectSaveVariables(ob, ds); /* Table of child objects */ Modified: trunk/core/variable.c =================================================================== --- trunk/core/variable.c2014-09-08 02:56:57 UTC (rev 9718) trunk/core/variable.c2014-11-04 08:15:09 UTC (rev 9719) < at >< at > -82,11 82,8 < at >< at > }; /* - * Fetch a variable for modification, or create a new variable if none - * was found. - * - * The Object must be locked. If a variable of same name but different - * type exists, it is replaced. * Allocate a new variable of the specified type, or return a pointer to * an existing variable. The Object must be locked. */ static __inline__ AG_Variable * FetchVariable(void *pObj, const char *name, enum ag_variable_type type) < at >< at > -98,14 95,12 < at >< at > if (strcmp(V->name, name) == 0) break; } -if (V != NULL) { -AG_FreeVariable(V); -} else { if (V == NULL) { V = Malloc(sizeof(AG_Variable)); AG_InitVariable(V, type); Strlcpy(V->name, name, sizeof(V->name)); TAILQ_INSERT_TAIL(&obj->vars, V, vars); } -AG_InitVariable(V, type); return (V); } < at >< at > -283,7 278,7 < at >< at > break; case AG_VARIABLE_P_STRING: case AG_VARIABLE_P_CONST_STRING: -Strlcpy(s, (char *)V->data.p, len); Strlcpy(s, V->data.s, len); break; case AG_VARIABLE_POINTER: case AG_VARIABLE_CONST_POINTER: < at >< at > -1251,8 1246,9 < at >< at > } /* - * Set a string value. As a special case, if there is an existing reference - * to a string buffer, the string is copied onto that existing buffer. * Set the value of a string variable. If the variable exists as a reference * to a fixed-size buffer, the string is copied to the buffer. Otherwise, the * string is duplicated. */ AG_Variable * AG_SetString(void *pObj, const char *name, const char *s) < at >< at > -1276,12 1272,15 < at >< at > } else { switch (V->type) { case AG_VARIABLE_STRING: -if (V->info.size == 0) { Free(V->data.s); } if (V->data.s != NULL && V->info.size == 0) { free(V->data.s); } V->data.s = Strdup(s); V->info.size = 0; break; case AG_VARIABLE_P_STRING: AG_LockVariable(V); -Strlcpy(*(char **)V->data.p, s, V->info.size); Strlcpy(V->data.s, s, V->info.size); AG_UnlockVariable(V); break; default: < at >< at > -1311,6 1310,13 < at >< at > V->data.s = v; V->info.size = 0; } /* * Variant of AG_SetString() where the string argument is taken to be * a dynamically-allocated string buffer which does not need to be * duplicated. The provided buffer will be freed automatically with * the parent object. */ AG_Variable * AG_SetStringNODUP(void *obj, const char *name, char *s) { < at >< at > -1318,30 1324,30 < at >< at > AG_ObjectLock(obj); V = FetchVariable(obj, name, AG_VARIABLE_STRING); -V->info.size = 0;/* Allocated */ -V->data.s = s; switch (V->type) { case AG_VARIABLE_STRING: if (V->data.s != NULL && V->info.size == 0) { free(V->data.s); } V->data.s = s; V->info.size = 0; break; case AG_VARIABLE_P_STRING: AG_LockVariable(V); Strlcpy(V->data.s, s, V->info.size); AG_UnlockVariable(V); break; default: AG_FreeVariable(V); AG_InitVariable(V, AG_VARIABLE_STRING); V->data.s = s; V->info.size = 0;/* Allocated */ break; } AG_ObjectUnlock(obj); return (V); } -AG_Variable * -AG_SetStringFixed(void *obj, const char *name, char *buf, size_t bufSize) -{ -AG_Variable *V; -AG_ObjectLock(obj); -V = FetchVariable(obj, name, AG_VARIABLE_STRING); -V->data.s = buf; -V->info.size = bufSize; -AG_ObjectUnlock(obj); -return (V); -} -void -AG_InitStringFixed(AG_Variable *V, char *v, size_t bufSize) -{ -AG_InitVariable(V, AG_VARIABLE_STRING); -V->data.s = v; -V->info.size = bufSize; -} AG_Variable * AG_PrtString(void *obj, const char *name, const char *fmt, ...) { < at >< at > -1381,7 1387,7 < at >< at > AG_ObjectLock(obj); V = FetchVariable(obj, name, AG_VARIABLE_P_STRING); V->mutex = mutex; -V->data.p = v; V->data.s = v; V->info.size = size; AG_PostEvent(NULL, obj, "bound", "%p", V); AG_ObjectUnlock(obj); Modified: trunk/core/variable.h =================================================================== --- trunk/core/variable.h2014-09-08 02:56:57 UTC (rev 9718) trunk/core/variable.h2014-11-04 08:15:09 UTC (rev 9719) < at >< at > -53,7 53,7 < at >< at > int indirLvl;/* Indirection level */ const char *name;/* Name string */ enum ag_variable_type typeTgt;/* Pointer target type (or AG_VARIABLE_NULL) */ -int code;/* Numerical code (-1 = non persistent) */ Sint32 code;/* Numerical code (-1 = non persistent) */ size_t size;/* Size in bytes (or 0) */ } AG_VariableTypeInfo; < at >< at > -275,12 275,8 < at >< at > char *AG_GetStringP(void *, const char *); AG_Variable *AG_SetString(void *, const char *, const char *); AG_Variable *AG_SetStringNODUP(void *, const char *, char *); -AG_Variable *AG_SetStringFixed(void *, const char *, char *, size_t) - BOUNDED_ATTRIBUTE(__string__, 3, 4); void AG_InitString(AG_Variable *, const char *); void AG_InitStringNODUP(AG_Variable *, char *); -void AG_InitStringFixed(AG_Variable *, char *, size_t) - BOUNDED_ATTRIBUTE(__string__, 2, 3); AG_Variable *AG_PrtString(void *, const char *, const char *, ...); AG_Variable *AG_BindString(void *, const char *, char *, size_t); AG_Variable *AG_BindStringFn(void *, const char *, AG_StringFn, const char *, ...); Modified: trunk/tests/configsettings.c =================================================================== --- trunk/tests/configsettings.c2014-09-08 02:56:57 UTC (rev 9718) trunk/tests/configsettings.c2014-11-04 08:15:09 UTC (rev 9719) < at >< at > -57,13 57,17 < at >< at > AG_TestInstance *ti = obj; AG_Box *box; AG_Textbox *tb; AG_Label *lbl; someString[0] = '\0'; AG_GetString(agConfig, "load-path", path, sizeof(path)); -AG_LabelNew(win, 0, "load-path: %s", path); lbl = AG_LabelNew(win, 0, "load-path: %s", path); AG_SetStyle(lbl, "font-size", "80%"); AG_GetString(agConfig, "save-path", path, sizeof(path)); -AG_LabelNew(win, 0, "save-path: %s", path); lbl = AG_LabelNew(win, 0, "save-path: %s", path); AG_SetStyle(lbl, "font-size", "80%"); /* Tie some globals to the config settings */ AG_BindInt(agConfig, "some-int", &someInt); [Less]
Posted almost 11 years ago by Agar-SVN
Author: vedge Date: 2014-09-07 22:56:57 -0400 (Sun, 07 Sep 2014) New Revision: 9718 Modified: trunk/gui/label.c Log: mark as %[W]-emeddable Modified: trunk/gui/label.c =================================================================== --- ... [More] trunk/gui/label.c2014-08-05 11:50:48 UTC (rev 9717) trunk/gui/label.c2014-09-08 02:56:57 UTC (rev 9718) < at >< at > -278,7 278,7 < at >< at > { AG_Label *lbl = obj; -WIDGET(lbl)->flags |= AG_WIDGET_USE_TEXT; WIDGET(lbl)->flags |= AG_WIDGET_USE_TEXT|AG_WIDGET_TABLE_EMBEDDABLE; lbl->type = AG_LABEL_STATIC; lbl->flags = 0; [Less]
Posted almost 11 years ago by Ritvik_Sharma-DYMqY+WieiM&lt; at &gt;public.gmane.org
Dell - Internal Use - Confidential Hi All, I am using the SDL driver in AGAR for rendering. The SDL mouse cursor is flickering and on going through the documentation of SDL I found that It is a persistent problem. * So I decided to disable ... [More] the default cursor (SDL_ShowCursor(SDL_DISABLE); ) * Load a bmp image of cursor and blit it at the current mouse position on the SDL screen. * To update the mouse cursor I fill the SDL screen with some color (SDL_FillRect(screen, NULL, 0x000000);) This approach seems to work fine in SDL, but when I draw a AGAR window and then use the SDL screen to blit my mouse cursor on, the AGAR window disappears after the screen is updated on calling SDL_FillRect(screen, NULL, 0x000000) If I don't clear the SDL screen then the AGAR window is displayed but it leaves a trail of the cursor (bmp) which is expected. Could someone please help me with this? Also is there a way to create the custom mouse cursor the same way I have done in SDL? How do I update the window I have attached the c file along with the mail as well. Thanks, Ritvik #include <agar/core.h> #include <agar/gui.h> #include <SDL/SDL_video.h> #include <SDL/SDL.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/ioctl.h> #include <limits.h> #include <unistd.h> #include <assert.h> #include <string.h> #include <stdbool.h> #include <stdlib.h> #define WIDTH 1024 #define HEIGHT 768 #define BPP 4 #define DEPTH 32 int pressedKey = 0;/* Last pressed key */ int xClick = 0, yClick = 0;/* Last clicked x,y */ int curFPS = 0;/* Measured frame rate */ const int nominalFPS = 1000/30;/* Nominal frame rate */ SDL_Surface * screen; SDL_Surface * mouse; AG_Window *win; AG_Button *btn; AG_Surface *agbmp; AG_Surface *s; bool running = true; void draw(SDL_Surface * from, SDL_Surface * dest, int x, int y) { SDL_Rect rect; rect.x = x; rect.y = y; if(from == NULL || dest == NULL) { return; } SDL_BlitSurface(from, NULL, dest, &rect); } void clearToColor(SDL_Surface * target, Uint32 color){ if (target == NULL) return; SDL_FillRect (target, NULL, color); } void drawTransparant(SDL_Surface * from, SDL_Surface * dest, int x, int y) { Uint32 colorkey = SDL_MapRGB(from->format, 0, 0, 255); SDL_SetColorKey(from, SDL_SRCCOLORKEY, colorkey); draw(from, dest, x, y); SDL_SetColorKey(from, 0, 0); } SDL_Surface *loadSurface(char * file) { SDL_Surface * temp = NULL; SDL_Surface * result = NULL; if((temp = SDL_LoadBMP(file)) == NULL) { printf("Failed to load file"); return NULL; } result = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); return result; } int init() { if (AG_InitCore("agar-sdl-demo", 0) == -1) { printf("AG_InitCore: %s\n", AG_GetError()); return 1; } if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ){ Print(L"Could not init subsystem"); return 1; } if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_SWSURFACE))) { printf(L"Could not set video mode\n"); SDL_Quit(); return 1; } if (AG_InitVideoSDL(screen, 0) == -1) { printf("%s\n", AG_GetError()); AG_Destroy(); return 1; } //Load the cursor imaege if ((mouse = loadSurface("ms_normal.bmp")) == NULL) { return 1; } AG_BindGlobalKey(AG_KEY_ESCAPE, AG_KEYMOD_ANY, AG_QuitGUI); AG_BindGlobalKey(AG_KEY_F8, AG_KEYMOD_ANY, AG_ViewCapture); win = AG_WindowNew(0); AG_WindowSetPosition(win, AG_WINDOW_TR, 1); AG_WindowSetCaption(win, "Agar Pane demo"); SDL_ShowCursor(SDL_DISABLE); AG_WindowSetGeometry(win,-1,-1,1024,768); AG_WindowShow(win); return 0; } //Render the mouse cursor on the screen.(This function is called from MyEventLoop whenever a mouse motion event is triggered.) void render(int mouseX, int mouseY) { clearToColor(screen,SDL_MapRGB(screen->format, 255, 0, 0)); drawTransparant(mouse, screen, mouseX, mouseY); // flip screen at the end SDL_Flip(screen); if ((agbmp = AG_SurfaceFromSDL(screen)) != NULL) { AG_PixmapFromSurface(win, 0, agbmp); } else { AG_LabelNewS(win, 0, AG_GetError()); } } static void MyEventLoop(void) { AG_Driver *drv; //AG_Window *win; Uint32 t1, t2; AG_DriverEvent dev; t1 = AG_GetTicks(); for (;;) { t2 = AG_GetTicks(); if (t2-t1 >= nominalFPS) { /* * Case 1: Update the video display. */ AG_LockVFS(&agDrivers); /* Render the Agar windows */ if (agDriverSw) { /* * We are using a single-window driver * (e.g., sdlfb). If one of the windows is * marked dirty, all windows must be redrawn. */ AG_FOREACH_WINDOW(win, agDriverSw) { if (win->dirty) break; } if (win != NULL) { AG_BeginRendering(agDriverSw); AG_FOREACH_WINDOW(win, agDriverSw) { if (!win->visible) { continue; } AG_ObjectLock(win); AG_WindowDraw(win); AG_ObjectUnlock(win); } AG_EndRendering(agDriverSw); } } else { /* * We are using a multiple-window driver * (e.g., glx). Windows marked dirty are * redrawn. */ AGOBJECT_FOREACH_CHILD(drv, &agDrivers, ag_driver) { if (!AGDRIVER_MULTIPLE(drv)) { continue; } win = AGDRIVER_MW(drv)->win; if (!win->visible || !win->dirty) { continue; } AG_BeginRendering(drv); AG_ObjectLock(win); AG_WindowDraw(win); AG_ObjectUnlock(win); AG_EndRendering(drv); } } AG_UnlockVFS(&agDrivers); t1 = AG_GetTicks(); curFPS = nominalFPS - (t1-t2); if (curFPS < 1) { curFPS = 1; } } else if (AG_PendingEvents(NULL) > 0) { /* * Case 2: There are events waiting to be processed. */ do { /* Retrieve the next queued event. */ if (AG_GetNextEvent(NULL, &dev) == 1) { switch (dev.type) { case AG_DRIVER_MOUSE_BUTTON_DOWN: xClick = dev.data.button.x; yClick = dev.data.button.y; printf("Click at %d,%d!\n", dev.data.button.x, dev.data.button.y); break; case AG_DRIVER_MOUSE_MOTION: //render the cursor image at the current mouse coordinates. render(dev.data.motion.x,dev.data.motion.y); break; case AG_DRIVER_KEY_DOWN: pressedKey = (int)dev.data.key.ks; printf("Key down: %d (0x%x)\n", (int)dev.data.key.ks, (Uint)dev.data.key.ucs); break; default: break; } /* Forward the event to Agar. */ if (AG_ProcessEvent(NULL, &dev) == -1) return; } } while (AG_PendingEvents(NULL) > 0); } else if (AG_TIMEOUTS_QUEUED()) { /* * Case 3: There are AG_Timeout(3) callbacks to run. */ AG_ProcessTimeouts(t2); } else { /* * Case 4: Nothing to do, idle. */ AG_Delay(1); } } } int main (int argc, char **argv) { if (init() != 0) { return -1; } MyEventLoop(); AG_Destroy(); return 0; } _______________________________________________ Agar mailing list Agar-FPEHb7Xf0XWpxCrVjSmSkw< at >public.gmane.org http://libagar.org/lists.html [Less]
Posted almost 11 years ago by Agar-SVN
Author: vedge Date: 2014-08-05 07:50:48 -0400 (Tue, 05 Aug 2014) New Revision: 9717 Added: trunk/tests/fontselector.c Modified: trunk/tests/Makefile trunk/tests/agartest.c Log: test for AG_FontSelector Modified: trunk/tests/Makefile ... [More] =================================================================== --- trunk/tests/Makefile2014-08-05 11:50:37 UTC (rev 9716) trunk/tests/Makefile2014-08-05 11:50:48 UTC (rev 9717) < at >< at > -35,6 35,7 < at >< at > customwidget_mywidget.c \ fixedres.c \ focusing.c \ fontselector.c \ fspaths.c \ glview.c \ imageloading.c \ Modified: trunk/tests/agartest.c =================================================================== --- trunk/tests/agartest.c2014-08-05 11:50:37 UTC (rev 9716) trunk/tests/agartest.c2014-08-05 11:50:48 UTC (rev 9717) < at >< at > -18,6 18,7 < at >< at > extern const AG_TestCase customWidgetTest; extern const AG_TestCase fixedResTest; extern const AG_TestCase focusingTest; extern const AG_TestCase fontSelectorTest; extern const AG_TestCase fsPathsTest; extern const AG_TestCase glviewTest; extern const AG_TestCase imageLoadingTest; < at >< at > -56,6 57,7 < at >< at > &customWidgetTest, &fixedResTest, &focusingTest, &fontSelectorTest, &fsPathsTest, #ifdef HAVE_OPENGL &glviewTest, Added: trunk/tests/fontselector.c =================================================================== --- trunk/tests/fontselector.c (rev 0) trunk/tests/fontselector.c2014-08-05 11:50:48 UTC (rev 9717) < at >< at > -0,0 1,49 < at >< at > /*Public domain*/ #include "agartest.h" static void SelectedFont(AG_Event *event) { AG_Window *win = AG_PTR(1); AG_SetString(agConfig, "font.face", AGOBJECT(agDefaultFont)->name); AG_SetInt(agConfig, "font.size", agDefaultFont->spec.size); AG_SetUint(agConfig, "font.flags", agDefaultFont->flags); if (AG_ConfigSave() == 0) { AG_TextTmsg(AG_MSG_INFO, 1000, "Default font has changed. Restart agartest to apply."); } else { AG_TextMsgFromError(); } } static int TestGUI(void *obj, AG_Window *win) { AG_FontSelector *fs; AG_Box *hBox; fs = AG_FontSelectorNew(win, AG_FONTSELECTOR_EXPAND); AG_BindPointer(fs, "font", (void *)&agDefaultFont); hBox = AG_BoxNewHoriz(win, AG_BOX_HFILL|AG_BOX_HOMOGENOUS); { AG_ButtonNewFn(hBox, 0, _("OK"), SelectedFont, "%p", win); AG_ButtonNewFn(hBox, 0, _("Cancel"), AG_WindowCloseGenEv, "%p", win); } return (0); } const AG_TestCase fontSelectorTest = { "fontSelector", N_("Test the AG_FontSelector(3) widget"), "1.5.0", 0, sizeof(AG_TestInstance), NULL,/* init */ NULL,/* destroy */ NULL,/* test */ TestGUI, NULL/* bench */ }; [Less]
Posted almost 11 years ago by Agar-SVN
Author: vedge Date: 2014-08-05 07:50:37 -0400 (Tue, 05 Aug 2014) New Revision: 9716 Modified: trunk/tests/charsets.c Log: make test more useful Modified: trunk/tests/charsets.c ... [More] =================================================================== --- trunk/tests/charsets.c2014-08-05 11:48:45 UTC (rev 9715) +++ trunk/tests/charsets.c2014-08-05 11:50:37 UTC (rev 9716) < at >< at > -22,31 +22,47 < at >< at > /* Bind to a C string in US-ASCII */ AG_Strlcpy(myASCII, "ASCII!", sizeof(myASCII)); -tb = AG_TextboxNew(win, AG_TEXTBOX_HFILL|AG_TEXTBOX_EXCL, "ASCII Buffer: "); +tb = AG_TextboxNew(win, AG_TEXTBOX_HFILL|AG_TEXTBOX_EXCL, + "ASCII Buffer: \n(%lu bytes)", sizeof(myASCII)); AG_TextboxBindASCII(tb, myASCII, sizeof(myASCII)); - +AG_TextboxSizeHintLines(tb, 2); + /* Bind to a C string in UTF-8 */ AG_Strlcpy(myUTF, "\xc3\x85ngstrom!", sizeof(myUTF)); -tb = AG_TextboxNew(win, AG_TEXTBOX_HFILL|AG_TEXTBOX_EXCL, "UTF-8 Buffer: "); +tb = AG_TextboxNew(win, AG_TEXTBOX_HFILL|AG_TEXTBOX_EXCL, + "UTF-8 Buffer: \n(%lu bytes)", sizeof(myUTF)); AG_TextboxBindUTF8(tb, myUTF, sizeof(myUTF)); +AG_TextboxSizeHintLines(tb, 2); /* Bind to a C string in any iconv-supported encoding */ #ifdef HAVE_ICONV AG_Strlcpy(myLat1, "Overv\xE5knign for feils\xF8king!", sizeof(myLat1)); -tb = AG_TextboxNew(win, AG_TEXTBOX_HFILL|AG_TEXTBOX_EXCL, "LATIN-1 Buffer: "); +tb = AG_TextboxNew(win, AG_TEXTBOX_HFILL|AG_TEXTBOX_EXCL, + "LATIN-1 Buffer: \n(%lu bytes)", sizeof(myLat1)); AG_TextboxBindEncoded(tb, "ISO-8859-1", myLat1, sizeof(myLat1)); +AG_TextboxSizeHintLines(tb, 2); +AG_LabelNewS(win, 0, "iconv support: YES"); #else -AG_LabelNewS(win, 0, "(Agar was not compiled with iconv support)"); +AG_LabelNewS(win, 0, + "iconv support: NO.\n" + "Available encodings: ASCII, UTF-8, UCS-4"); #endif +AG_SeparatorNewHoriz(win); /* Bind to a multilingual AG_Text(3) element. */ myTxt = AG_TextNew(0); AG_TextSetEnt(myTxt, AG_LANG_FR, "Fran\xc3\xa7\x61is!"); AG_TextSetEnt(myTxt, AG_LANG_EN, "English!"); AG_TextSetEnt(myTxt, AG_LANG_NO, "Norsk!"); -AG_TextSetLangISO(myTxt, "fr"); -tb = AG_TextboxNew(win, AG_TEXTBOX_HFILL, "AG_Text Buffer: "); +AG_LabelNewS(win, 0, "Multilingual AG_Text(3) buffer:"); +tb = AG_TextboxNewS(win, + AG_TEXTBOX_MULTILINGUAL|AG_TEXTBOX_EXPAND|AG_TEXTBOX_MULTILINE, + NULL); AG_TextboxBindText(tb, myTxt); +AG_TextboxSetLang(tb, AG_LANG_FR); +AG_TextboxSizeHint(tb, "XXXXXXXXXXXXXXXXXXXXXXXXX"); +AG_TextboxSizeHintLines(tb, 5); +AG_TextboxSetCursorPos(tb, -1);/* End of string */ return (0); } [Less]
Posted almost 11 years ago by Agar-SVN
Author: vedge Date: 2014-08-05 07:48:45 -0400 (Tue, 05 Aug 2014) New Revision: 9715 Modified: trunk/gui/AG_Tlist.3 trunk/gui/tlist.c trunk/gui/tlist.h Log: add AG_TlistSort() Modified: trunk/gui/AG_Tlist.3 ... [More] =================================================================== --- trunk/gui/AG_Tlist.32014-08-05 11:37:07 UTC (rev 9714) trunk/gui/AG_Tlist.32014-08-05 11:48:45 UTC (rev 9715) < at >< at > -1,4 1,4 < at >< at > -.\" Copyright (c) 2002-2007 Hypertriton, Inc. <http://hypertriton.com/> .\" Copyright (c) 2002-2014 Hypertriton, Inc. <http://hypertriton.com/> .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without < at >< at > -247,6 247,9 < at >< at > .Ft "void" .Fn AG_TlistDel "AG_Tlist *tlist" "AG_TlistItem *item" .Pp .Ft "int" .Fn AG_TlistSort "AG_Tlist *tlist" .Pp .Ft "void" .Fn AG_TlistUniq "AG_Tlist *tlist" .Pp < at >< at > -336,10 339,16 < at >< at > from its parent .Nm tlist . .Pp The .Fn AG_TlistSort routine lexicographically sorts the items in the list. The function returns 0 on success or -1 if insufficient memory is available for the sort. .Pp .Fn AG_TlistUniq scans the list for duplicates (by comparing items using the current comparison routine as configured by -.Fn AG_TlistSetCompareFn ), .Fn AG_TlistSetCompareFn ) , and removes all duplicate items. .Pp .Fn AG_TlistClear Modified: trunk/gui/tlist.c =================================================================== --- trunk/gui/tlist.c2014-08-05 11:37:07 UTC (rev 9714) trunk/gui/tlist.c2014-08-05 11:48:45 UTC (rev 9715) < at >< at > -37,7 37,6 < at >< at > static void FreeItem(AG_Tlist *, AG_TlistItem *); static void SelectItem(AG_Tlist *, AG_TlistItem *); static void DeselectItem(AG_Tlist *, AG_TlistItem *); -static void PopupMenu(AG_Tlist *, AG_TlistPopup *, int, int); static void UpdateItemIcon(AG_Tlist *, AG_TlistItem *, AG_Surface *); AG_Tlist * < at >< at > -939,6 938,23 < at >< at > } static void PopupMenu(AG_Tlist *tl, AG_TlistPopup *tp, int x, int y) { AG_Menu *m = tp->menu; #if 0 if (AG_ParentWindow(tl) == NULL) AG_FatalError("AG_Tlist: %s is unattached", OBJECT(tl)->name); #endif if (tp->panel != NULL) { AG_MenuCollapse(tl, tp->item); tp->panel = NULL; } m->itemSel = tp->item; tp->panel = AG_MenuExpand(tl, tp->item, x 4, y 4); } static void MouseButtonDown(AG_Event *event) { AG_Tlist *tl = AG_SELF(); < at >< at > -1423,21 1439,35 < at >< at > AG_Redraw(tl); } -static void -PopupMenu(AG_Tlist *tl, AG_TlistPopup *tp, int x, int y) static int CompareText(const void *p1, const void *p2) { -AG_Menu *m = tp->menu; - -#if 0 -if (AG_ParentWindow(tl) == NULL) -AG_FatalError("AG_Tlist: %s is unattached", OBJECT(tl)->name); -#endif -if (tp->panel != NULL) { -AG_MenuCollapse(tl, tp->item); -tp->panel = NULL; const AG_TlistItem *it1 = *(const AG_TlistItem **)p1; const AG_TlistItem *it2 = *(const AG_TlistItem **)p2; return strcoll(it1->text, it2->text); } int AG_TlistSort(AG_Tlist *tl) { AG_TlistItem *it, **items; Uint i = 0; if ((items = TryMalloc(tl->nitems*sizeof(AG_TlistItem *))) == NULL) { return (-1); } -m->itemSel = tp->item; -tp->panel = AG_MenuExpand(tl, tp->item, x 4, y 4); TAILQ_FOREACH(it, &tl->items, items) { items[i ] = it; } qsort(items, tl->nitems, sizeof(AG_TlistItem *), CompareText); TAILQ_INIT(&tl->items); for (i = 0; i < tl->nitems; i ) { TAILQ_INSERT_TAIL(&tl->items, items[i], items); } free(items); AG_Redraw(tl); return (0); } AG_WidgetClass agTlistClass = { Modified: trunk/gui/tlist.h =================================================================== --- trunk/gui/tlist.h2014-08-05 11:37:07 UTC (rev 9714) trunk/gui/tlist.h2014-08-05 11:48:45 UTC (rev 9715) < at >< at > -41,7 41,7 < at >< at > AG_TAILQ_ENTRY(ag_tlist_item) selitems;/* Saved selection state */ } AG_TlistItem; -AG_TAILQ_HEAD(ag_tlist_itemq, ag_tlist_item); typedef AG_TAILQ_HEAD(ag_tlist_itemq, ag_tlist_item) AG_TlistItemQ; typedef struct ag_tlist { struct ag_widget wid; < at >< at > -64,8 64,8 < at >< at > int item_h;/* Item height */ int icon_w;/* Item icon width */ void *dblClicked;/* Used by double click */ -struct ag_tlist_itemq items;/* Current Items */ -struct ag_tlist_itemq selitems;/* Saved item state */ AG_TlistItemQ items;/* Current Items */ AG_TlistItemQ selitems;/* Saved item state */ int nitems;/* Current item count */ int nvisitems;/* Visible item count */ AG_Scrollbar *sbar;/* Vertical scrollbar */ < at >< at > -149,6 149,7 < at >< at > int AG_TlistCompareStrings(const AG_TlistItem *, const AG_TlistItem *); int AG_TlistComparePtrs(const AG_TlistItem *, const AG_TlistItem *); int AG_TlistComparePtrsAndClasses(const AG_TlistItem *, const AG_TlistItem *); int AG_TlistSort(AG_Tlist *); #define AG_TlistBegin AG_TlistClear #define AG_TlistEnd AG_TlistRestore [Less]
Posted almost 11 years ago by Agar-SVN
Author: vedge Date: 2014-08-05 07:37:07 -0400 (Tue, 05 Aug 2014) New Revision: 9714 Modified: trunk/gui/font_selector.c trunk/gui/text.c Log: implement fontconfig support in AG_FontSelector Modified: trunk/gui/font_selector.c ... [More] =================================================================== --- trunk/gui/font_selector.c2014-08-02 13:07:59 UTC (rev 9713) trunk/gui/font_selector.c2014-08-05 11:37:07 UTC (rev 9714) < at >< at > -31,6 31,12 < at >< at > #include <string.h> #include <agar/config/have_fontconfig.h> #ifdef HAVE_FONTCONFIG #include <fontconfig/fontconfig.h> extern int agFontconfigInited;/* text.c */ #endif AG_FontSelector * AG_FontSelectorNew(void *parent, Uint flags) { < at >< at > -63,10 69,10 < at >< at > Strlcpy(fs->curFace, OBJECT(*pFont)->name, sizeof(fs->curFace)); fs->curSize = (*pFont)->spec.size; fs->curStyle = (*pFont)->flags; - #if 0 fs->tlFaces->flags |= AG_TLIST_SCROLLTOSEL; fs->tlSizes->flags |= AG_TLIST_SCROLLTOSEL; - #endif AG_ObjectUnlock(fs); } < at >< at > -139,42 145,74 < at >< at > ti->selected ; } -AG_GetString(AG_ConfigObject(), "font-path", fontPath, sizeof(fontPath)); -while ((s = AG_Strsep(&pFontPath, AG_PATHSEPMULTI)) != NULL) { -AG_Dir *dir; -int i; #ifdef HAVE_FONTCONFIG if (agFontconfigInited) { FcObjectSet *os; FcFontSet *fset; FcPattern *pat; -if ((dir = AG_OpenDir(s)) == NULL) { -AG_Verbose(_("Ignoring: %s\n"), AG_GetError()); -continue; pat = FcPatternCreate(); os = FcObjectSetBuild(FC_FAMILY, (char *)0); fset = FcFontList(NULL, pat, os); if (fset != NULL) { for (i = 0; i < fset->nfont; i ) { FcPattern *font = fset->fonts[i]; FcChar8 *fam; if (FcPatternGetString(font, FC_FAMILY, 0, &fam) == FcResultMatch) { ti = AG_TlistAddS(fs->tlFaces, NULL, (char *)fam); if (*pFont != NULL && strcmp((char *)fam, OBJECT(*pFont)->name) == 0) ti->selected ; } } FcFontSetDestroy(fset); } -for (i = 0; i < dir->nents; i ) { -char path[AG_FILENAME_MAX]; -AG_FileInfo info; -char *file = dir->ents[i], *pExt; AG_TlistSort(fs->tlFaces); } else #endif /* HAVE_FONTCONFIG */ -if (file[0] == '.' || - (pExt = strrchr(file, '.')) == NULL) { { AG_GetString(AG_ConfigObject(), "font-path", fontPath, sizeof(fontPath)); while ((s = AG_Strsep(&pFontPath, AG_PATHSEPMULTI)) != NULL) { AG_Dir *dir; int i; if ((dir = AG_OpenDir(s)) == NULL) { AG_Verbose(_("Ignoring: %s\n"), AG_GetError()); continue; } -if (strcmp(pExt, ".ttf") != 0 && - strcmp(pExt, ".TTF") != 0) -continue; for (i = 0; i < dir->nents; i ) { char path[AG_FILENAME_MAX]; AG_FileInfo info; char *file = dir->ents[i], *pExt; -Strlcpy(path, s, sizeof(path)); -Strlcat(path, AG_PATHSEP, sizeof(path)); -Strlcat(path, file, sizeof(path)); if (file[0] == '.' || (pExt = strrchr(file, '.')) == NULL) { continue; } if (Strcasecmp(pExt, ".ttf") != 0) /* XXX */ continue; -if (AG_GetFileInfo(path, &info) == -1 || - info.type != AG_FILE_REGULAR) { -continue; Strlcpy(path, s, sizeof(path)); Strlcat(path, AG_PATHSEP, sizeof(path)); Strlcat(path, file, sizeof(path)); if (AG_GetFileInfo(path, &info) == -1 || info.type != AG_FILE_REGULAR) { continue; } ti = AG_TlistAddS(fs->tlFaces, NULL, file); if (*pFont != NULL && strcmp(file, OBJECT(*pFont)->name) == 0) ti->selected ; } -ti = AG_TlistAddS(fs->tlFaces, NULL, file); -if (*pFont != NULL && - strcmp(file, OBJECT(*pFont)->name) == 0) -ti->selected ; AG_CloseDir(dir); } -AG_CloseDir(dir); } /* XXX */ Modified: trunk/gui/text.c =================================================================== --- trunk/gui/text.c2014-08-02 13:07:59 UTC (rev 9713) trunk/gui/text.c2014-08-05 11:37:07 UTC (rev 9714) < at >< at > -341,14 341,19 < at >< at > if (agFontconfigInited) { FcPattern *pattern, *fpat; FcResult fres = FcResultMatch; char *nameIn; FcChar8 *filename; FcMatrix *mat; -if ((pattern = FcNameParse((const FcChar8 *)name)) == NULL || Asprintf(&nameIn, "%s-%u", name, ptsize); if ((pattern = FcNameParse((FcChar8 *)nameIn)) == NULL || !FcConfigSubstitute(NULL, pattern, FcMatchPattern)) { AG_SetError(_("Fontconfig failed to parse: %s"), name); free(nameIn); goto fail; } free(nameIn); FcDefaultSubstitute(pattern); if ((fpat = FcFontMatch(NULL, pattern, &fres)) == NULL || fres != FcResultMatch) { [Less]
Posted almost 11 years ago by Agar-SVN
Author: vedge Date: 2014-08-02 09:07:59 -0400 (Sat, 02 Aug 2014) New Revision: 9713 Modified: trunk/gui/drv_glx.c Log: fix integer scaling in SetOpacity() Modified: trunk/gui/drv_glx.c ... [More] =================================================================== --- trunk/gui/drv_glx.c2014-07-30 00:48:17 UTC (rev 9712) +++ trunk/gui/drv_glx.c2014-08-02 13:07:59 UTC (rev 9713) < at >< at > -1933,7 +1933,7 < at >< at > GLX_SetOpacity(AG_Window *win, float f) { AG_DriverGLX *glx = (AG_DriverGLX *)WIDGET(win)->drv; -unsigned long opacity = (f > 0.99) ? 0xffffffff : f*0xffffffff; +Ulong opacity = (f > 0.99) ? (Ulong) 0xffffffff : (Ulong)(f*0xffffffff); if (wmNetWmWindowOpacity != None) { XChangeProperty(agDisplay, glx->w, [Less]