osdir.com
mailing list archive

Subject: Agar: r7652 - trunk/gui - msg#00045

List: lib.agar.scm

Date: Prev Next Index Thread: Prev Next Index
Author: vedge
Date: 2008-09-17 06:40:33 -0300 (Wed, 17 Sep 2008)
New Revision: 7652

Modified:
trunk/gui/AG_Pixmap.3
trunk/gui/pixmap.c
trunk/gui/pixmap.h
Log:
- fix documented prototypes for PixmapReplaceSurface(), etc.
- provide PixmapReplaceCurrentSurface(), etc. variants.


Modified: trunk/gui/AG_Pixmap.3
===================================================================
--- trunk/gui/AG_Pixmap.3 2008-09-17 03:07:21 UTC (rev 7651)
+++ trunk/gui/AG_Pixmap.3 2008-09-17 09:40:33 UTC (rev 7652)
@@ -69,12 +69,6 @@
.Ft "AG_Pixmap *"
.Fn AG_PixmapFromSurfaceScaled "AG_Widget *parent" "Uint flags" "AG_Surface
*src" "int width" "int height"
.Pp
-.Ft "AG_Pixmap *"
-.Fn AG_PixmapFromBMP "AG_Widget *parent" "Uint flags" "const char *path"
-.Pp
-.Ft "AG_Pixmap *"
-.Fn AG_PixmapFromXCF "AG_Widget *parent" "Uint flags" "const char *path"
-.Pp
.nr nS 0
The
.Fn AG_PixmapNew
@@ -106,12 +100,6 @@
that will be freed automatically along with the widget instance.
.Fn AG_PixmapFromSurfaceScaled
uses a rescaled copy of the given surface.
-.Pp
-Use
-.Fn AG_PixmapFromBMP
-to load the image from a Windows Bitmap file, or
-.Fn AG_PixmapFromXCF
-to load from a Gimp XCF file.
.Sh CHANGING SURFACES
.nr nS 1
.Ft "int"
@@ -127,15 +115,24 @@
.Fn AG_PixmapSetSurface "AG_Pixmap *pixmap" "int surface_name"
.Pp
.Ft "void"
-.Fn AG_PixmapReplaceSurface "AG_Pixmap *pixmap" "int surface_name"
+.Fn AG_PixmapReplaceSurface "AG_Pixmap *pixmap" "int surface_name" "AG_Surface
*surfaceNew"
.Pp
.Ft "void"
-.Fn AG_PixmapReplaceSurfaceScaled "AG_Pixmap *pixmap" "int surface_name" "Uint
width" "Uint height"
+.Fn AG_PixmapReplaceCurrentSurface "AG_Pixmap *pixmap" "AG_Surface *surfaceNew"
.Pp
.Ft "void"
-.Fn AG_PixmapUpdateSurface "AG_Pixmap *pixmap"
+.Fn AG_PixmapReplaceSurfaceScaled "AG_Pixmap *pixmap" "int surface_name"
"AG_Surface *surfaceNew" "Uint width" "Uint height"
.Pp
.Ft "void"
+.Fn AG_PixmapReplaceCurrentSurfaceScaled "AG_Pixmap *pixmap" "AG_Surface
*surfaceNew" "Uint width" "Uint height"
+.Pp
+.Ft "void"
+.Fn AG_PixmapUpdateSurface "AG_Pixmap *pixmap" "int surface_name"
+.Pp
+.Ft "void"
+.Fn AG_PixmapUpdateCurrentSurface "AG_Pixmap *pixmap"
+.Pp
+.Ft "void"
.Fn AG_PixmapSetCoords "AG_Pixmap *pixmap" "int s" "int t"
.Pp
.nr nS 0
@@ -161,11 +158,18 @@
If you need to modify the contents of a previously mapped surface, it is
necessary to call
.Fn AG_PixmapUpdateSurface
-when you're done.
+afterwards.
It has no effect in direct video mode, but it causes the texture to be
re-uploaded to the graphics hardware in OpenGL mode.
.Pp
The
+.Fn AG_PixmapReplaceCurrentSurface ,
+.Fn AG_PixmapReplaceCurrentSurfaceScaled
+and
+.Fn AG_PixmapUpdateCurrentSurface
+variants operate on the currently selected (visible) surface.
+.Pp
+The
.Fn AG_PixmapSetCoords
function changes the source coordinates of the active surface.
The default is [0,0].

Modified: trunk/gui/pixmap.c
===================================================================
--- trunk/gui/pixmap.c 2008-09-17 03:07:21 UTC (rev 7651)
+++ trunk/gui/pixmap.c 2008-09-17 09:40:33 UTC (rev 7652)
@@ -127,44 +127,6 @@
return (px);
}

-#if 0
-AG_Pixmap *
-AG_PixmapFromXCF(void *parent, Uint flags, const char *path)
-{
- AG_Object tmpObj;
- AG_Pixmap *px;
- AG_Surface *su;
- AG_DataSource *ds;
- Uint i;
-
- if ((ds = AG_OpenFile(path, "rb")) == NULL) {
- AG_TextMsg(AG_MSG_ERROR, "%s: %s", path, AG_GetError());
- return (NULL);
- }
-
- /* XXX hack */
- AG_ObjectInit(&tmpObj, &agObjectClass);
- tmpObj.gfx = AG_GfxNew(&tmpObj);
- if (AG_XCFLoad(ds, 0, tmpObj.gfx) == -1)
- goto fail;
-
- px = Malloc(sizeof(AG_Pixmap));
- AG_ObjectInit(px, &agPixmapClass);
- px->flags |= flags;
- AG_ObjectAttach(parent, px);
- for (i = 0; i < tmpObj.gfx->nsprites; i++) {
- AG_WidgetMapSurface(px, AG_DupSurface(AG_SPRITE(&tmpObj,i).su));
- }
- AG_CloseFile(ds);
- AG_ObjectDestroy(&tmpObj);
- return (px);
-fail:
- AG_CloseFile(ds);
- AG_ObjectDestroy(&tmpObj);
- return (NULL);
-}
-#endif
-
/*
* Map an existing surface. Returned surface ID is valid as long as pixmap
* is locked.
@@ -235,9 +197,10 @@
return (name);
}

-/* Replace the current surface with a scaled version of a surface. */
+/* Replace the specified surface with a scaled version of another surface. */
void
-AG_PixmapReplaceSurfaceScaled(AG_Pixmap *px, AG_Surface *su, Uint w, Uint h)
+AG_PixmapReplaceSurfaceScaled(AG_Pixmap *px, int surface_name, AG_Surface *su,
+ Uint w, Uint h)
{
AG_Surface *scaled = NULL;

@@ -245,7 +208,7 @@
AG_FatalError(NULL);
}
AG_ObjectLock(px);
- AG_WidgetReplaceSurface(px, px->n, scaled);
+ AG_WidgetReplaceSurface(px, surface_name, scaled);
AG_ObjectUnlock(px);
}


Modified: trunk/gui/pixmap.h
===================================================================
--- trunk/gui/pixmap.h 2008-09-17 03:07:21 UTC (rev 7651)
+++ trunk/gui/pixmap.h 2008-09-17 09:40:33 UTC (rev 7652)
@@ -28,19 +28,24 @@
AG_Pixmap *AG_PixmapFromSurfaceCopy(void *, Uint, AG_Surface *);
AG_Pixmap *AG_PixmapFromSurfaceScaled(void *, Uint, AG_Surface *, Uint, Uint);
AG_Pixmap *AG_PixmapFromBMP(void *, Uint, const char *);
-#if 0
-AG_Pixmap *AG_PixmapFromXCF(void *, Uint, const char *);
-#endif

int AG_PixmapAddSurface(AG_Pixmap *, AG_Surface *);
int AG_PixmapAddSurfaceFromBMP(AG_Pixmap *, const char *);
int AG_PixmapAddSurfaceCopy(AG_Pixmap *, AG_Surface *);
int AG_PixmapAddSurfaceScaled(AG_Pixmap *, AG_Surface *, Uint, Uint);
-void AG_PixmapReplaceSurfaceScaled(AG_Pixmap *, AG_Surface *, Uint,
+#define AG_PixmapReplaceSurface(px,name,su) \
+ AG_WidgetReplaceSurface((px),(name),(su))
+#define AG_PixmapUpdateSurface(px,name) \
+ AG_WidgetUpdateSurface((px),(name))
+void AG_PixmapReplaceSurfaceScaled(AG_Pixmap *, int, AG_Surface *, Uint,
Uint);

-#define AG_PixmapReplaceSurface(px,su) AG_WidgetReplaceSurface((px),(px)->n,su)
-#define AG_PixmapUpdateSurface(px) AG_WidgetUpdateSurface((px),(px)->n)
+#define AG_PixmapReplaceCurrentSurface(px,su) \
+ AG_PixmapReplaceSurface((px),(px)->n,(su))
+#define AG_PixmapReplaceCurrentSurfaceScaled(px,su,w,h) \
+ AG_PixmapReplaceSurfaceScaled((px),(px)->n,(su),(w),(h))
+#define AG_PixmapUpdateCurrentSurface(px) \
+ AG_PixmapUpdateSurface((px),(px)->n)

static __inline__ int
AG_PixmapSetSurface(AG_Pixmap *px, int name)


Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Agar: r7650 - trunk/vg

Author: vedge Date: 2008-09-17 00:06:27 -0300 (Wed, 17 Sep 2008) New Revision: 7650 Modified: trunk/vg/vg_math.h trunk/vg/vg_view.c trunk/vg/vg_view.h Log: use rint() when computing the grid interval; this prevents numerical roundoff errors which could cause misalignment of multiple grids under some scale factors. Modified: trunk/vg/vg_math.h =================================================================== --- trunk/vg/vg_math.h 2008-09-16 16:04:43 UTC (rev 7649) +++ trunk/vg/vg_math.h 2008-09-17 03:06:27 UTC (rev 7650) @@ -14,6 +14,7 @@ # define VG_PI 3.14159265358979323846 #endif +/* XXX test in configure */ #if __STDC_VERSION__ >= 199901L # define VG_Sin(x) sinf(x) # define VG_Cos(x) cosf(x) @@ -25,6 +26,7 @@ # define VG_Ceil(x) ceilf(x) # define VG_Fabs(x) fabsf(x) # define VG_Hypot(x,y) hypotf((x),(y)) +# define VG_Rint(x) rintf(x) #else # define VG_Sin(x) ((float)sin((double)x)) # define VG_Cos(x) ((float)cos((double)x)) @@ -36,6 +38,7 @@ # define VG_Ceil(x) ((float)ceil((double)x)) # define VG_Fabs(x) ((float)fabs((double)x)) # define VG_Hypot(x,y) ((float)hypot((double)(x),(double)(y))) +# define VG_Rint(x) ((float)rint(x)) #endif /* C99 */ #define VG_Degrees(x) ((x)/(2.0*VG_PI)*360.0) Modified: trunk/vg/vg_view.c =================================================================== --- trunk/vg/vg_view.c 2008-09-16 16:04:43 UTC (rev 7649) +++ trunk/vg/vg_view.c 2008-09-17 03:06:27 UTC (rev 7650) @@ -43,14 +43,13 @@ #include "vg_tools.h" #include "tools.h" -static const float scaleFactors[28] = { - 1.0f, 1.25f, 1.5f, 1.75f, - 2.0f, 2.25f, 2.5f, 2.75f, - 3.0f, 3.25f, 3.5f, 3.75f, - 4.0f, 5.0f, 6.0f, 8.0f, 10.0f, 12.0f, 16.0f, 18.0f, - 20.0f, 22.0f, 24.0f, 32.0f, 34.0f, 36.0f, 38.0f, 40.0f +static const float scaleFactors[] = { + 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, + 10.0f, 12.0f, 14.0f, 16.0f, 18.0f, 20.0f, 22.0f, 24.0f, 26.0f, 28.0f, + 40.0f, 50.0f, 80.0f, 90.0f, 100.0f, 200.0f, 300.0f, + 400.0f, 600.0f, 700.0f, 800.0f, 900.0f }; -const int nScaleFactors = 28; +const int nScaleFactors = sizeof(scaleFactors)/sizeof(scaleFactors[0]); VG_View * VG_ViewNew(void *parent, VG *vg, Uint flags) @@ -139,13 +138,13 @@ case SDL_BUTTON_WHEELDOWN: if (vv->scaleIdx-1 >= 0) { VG_ViewSetScale(vv, --vv->scaleIdx); - VG_Status(vv, _("Scale: 1:%.0f"), vv->scale); + VG_Status(vv, _("Scale: 1:%f"), vv->scale); } return; case SDL_BUTTON_WHEELUP: if (vv->scaleIdx+1 < nScaleFactors) { VG_ViewSetScale(vv, ++vv->scaleIdx); - VG_Status(vv, _("Scale: 1:%.0f"), vv->scale); + VG_Status(vv, _("Scale: 1:%f"), vv->scale); } return; default: @@ -272,6 +271,7 @@ vv->y = AGWIDGET(vv)->h/2.0f; } +/* Update the point selection radius (dependent on scale factor). */ static void UpdatePointSelRadius(VG_View *vv) { @@ -279,6 +279,24 @@ } static void +UpdateGridIntervals(VG_View *vv) +{ + int i; + + for (i = 0; i < vv->nGrids; i++) { + VG_Grid *grid = &vv->grid[i]; + + grid->ival = (int)VG_Rint(((float)grid->ivalNom)/vv->wPixel); + + if (grid->ival < 6) { + grid->flags |= VG_GRID_UNDERSIZE; + } else { + grid->flags &= ~(VG_GRID_UNDERSIZE); + } + } +} + +static void Init(void *obj) { VG_View *vv = obj; @@ -374,7 +392,8 @@ AG_ObjectLock(vv); vv->grid[idx].type = type; - vv->grid[idx].ival = ival; + vv->grid[idx].ivalNom = ival; + vv->grid[idx].ival = 0; vv->grid[idx].color = color; if (idx == 0) { UpdatePointSelRadius(vv); @@ -382,6 +401,7 @@ if (idx >= vv->nGrids) { vv->nGrids = idx+1; } + UpdateGridIntervals(vv); AG_ObjectUnlock(vv); } @@ -474,14 +494,12 @@ static __inline__ void DrawGrid(VG_View *vv, const VG_Grid *grid) { - int x, x0, y; - int ival; + int x, x0, y, ival; - if (grid->ival <= 1) { + if (grid->flags & (VG_GRID_HIDE|VG_GRID_UNDERSIZE)) return; - } - ival = (int)(grid->ival/vv->wPixel); - + + ival = grid->ival; #ifdef HAVE_OPENGL if (agView->opengl) { x0 = WIDGET(vv)->cx + (int)(vv->x)%ival; @@ -740,15 +758,18 @@ AG_ObjectLock(vv); + /* Set the specified scaling factor. */ vv->scaleIdx = idx; vv->scale = scaleFactors[idx]; if (vv->scale < vv->scaleMin) { vv->scale = vv->scaleMin; } if (vv->scale > vv->scaleMax) { vv->scale = vv->scaleMax; } - + + /* Update all values dependent on VG's representation of a pixel. */ vv->wPixel = 1.0/vv->scale; vv->x *= (vv->scale/scalePrev); vv->y *= (vv->scale/scalePrev); UpdatePointSelRadius(vv); + UpdateGridIntervals(vv); AG_ObjectUnlock(vv); } Modified: trunk/vg/vg_view.h =================================================================== --- trunk/vg/vg_view.h 2008-09-16 16:04:43 UTC (rev 7649) +++ trunk/vg/vg_view.h 2008-09-17 03:06:27 UTC (rev 7650) @@ -21,8 +21,13 @@ typedef struct vg_grid { enum vg_grid_type type; - int ival; /* Interval (pixels, power of two) */ - VG_Color color; /* Display color */ + Uint flags; +#define VG_GRID_HIDE 0x01 /* Hide grid */ +#define VG_GRID_UNDERSIZE 0x02 /* Grid too small to display */ + + int ivalNom; /* Nominal pixel interval */ + int ival; /* Effective interval (dependent on wPixel) */ + VG_Color color; /* Display color */ } VG_Grid; typedef struct vg_view {

Next Message by Date: click to view message preview

Agar: r7654 - trunk/vg

Author: vedge Date: 2008-09-17 11:03:25 -0300 (Wed, 17 Sep 2008) New Revision: 7654 Modified: trunk/vg/vg_view.c trunk/vg/vg_view.h Log: precompute effective grid interval in pixels; fix default scale factors. Modified: trunk/vg/vg_view.c =================================================================== --- trunk/vg/vg_view.c 2008-09-17 10:27:46 UTC (rev 7653) +++ trunk/vg/vg_view.c 2008-09-17 14:03:25 UTC (rev 7654) @@ -44,10 +44,10 @@ #include "tools.h" static const float scaleFactors[] = { - 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, - 10.0f, 12.0f, 14.0f, 16.0f, 18.0f, 20.0f, 22.0f, 24.0f, 26.0f, 28.0f, - 40.0f, 50.0f, 80.0f, 90.0f, 100.0f, 200.0f, 300.0f, - 400.0f, 600.0f, 700.0f, 800.0f, 900.0f + 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, + 12.0f, 14.0f, 16.0f, 18.0f, 20.0f, 22.0f, 24.0f, 26.0f, 28.0f, + 30.0f, 40.0f, 50.0f, 60.0f, 70.0f, 80.0f, 90.0f, 100.0f, + 200.0f, 300.0f, 400.0f, 600.0f, 700.0f, 800.0f, 900.0f }; const int nScaleFactors = sizeof(scaleFactors)/sizeof(scaleFactors[0]); @@ -138,13 +138,13 @@ case SDL_BUTTON_WHEELDOWN: if (vv->scaleIdx-1 >= 0) { VG_ViewSetScale(vv, --vv->scaleIdx); - VG_Status(vv, _("Scale: 1:%f"), vv->scale); + VG_Status(vv, _("Scale: 1:%.0f"), vv->scale); } return; case SDL_BUTTON_WHEELUP: if (vv->scaleIdx+1 < nScaleFactors) { VG_ViewSetScale(vv, ++vv->scaleIdx); - VG_Status(vv, _("Scale: 1:%f"), vv->scale); + VG_Status(vv, _("Scale: 1:%.0f"), vv->scale); } return; default: @@ -286,9 +286,9 @@ for (i = 0; i < vv->nGrids; i++) { VG_Grid *grid = &vv->grid[i]; - grid->ival = (int)VG_Rint(((float)grid->ivalNom)/vv->wPixel); + grid->ivalView = (int)VG_Rint(((float)grid->ival)/vv->wPixel); - if (grid->ival < 6) { + if (grid->ivalView < 6) { grid->flags |= VG_GRID_UNDERSIZE; } else { grid->flags &= ~(VG_GRID_UNDERSIZE); @@ -321,10 +321,6 @@ vv->wPixel = 1.0f; vv->snap_mode = VG_GRID; vv->ortho_mode = VG_NO_ORTHO; - vv->grid[0].type = VG_GRID_POINTS; - vv->grid[0].ival = 8; - vv->grid[0].color = VG_GetColorRGB(100, 100, 100); - vv->nGrids = 1; vv->mouse.x = 0.0f; vv->mouse.y = 0.0f; vv->mouse.panning = 0; @@ -335,7 +331,9 @@ vv->editAreas = NULL; vv->nEditAreas = 0; TAILQ_INIT(&vv->tools); - UpdatePointSelRadius(vv); + + VG_ViewSetGrid(vv, 0, VG_GRID_POINTS, 8, VG_GetColorRGB(100,100,100)); + VG_ViewSetScale(vv, 0); AG_SetEvent(vv, "window-mousemotion", MouseMotion, NULL); AG_SetEvent(vv, "window-mousebuttondown", MouseButtonDown, NULL); @@ -392,8 +390,8 @@ AG_ObjectLock(vv); vv->grid[idx].type = type; - vv->grid[idx].ivalNom = ival; - vv->grid[idx].ival = 0; + vv->grid[idx].ival = ival; + vv->grid[idx].ivalView = 0; vv->grid[idx].color = color; if (idx == 0) { UpdatePointSelRadius(vv); @@ -499,7 +497,7 @@ if (grid->flags & (VG_GRID_HIDE|VG_GRID_UNDERSIZE)) return; - ival = grid->ival; + ival = grid->ivalView; #ifdef HAVE_OPENGL if (agView->opengl) { x0 = WIDGET(vv)->cx + (int)(vv->x)%ival; Modified: trunk/vg/vg_view.h =================================================================== --- trunk/vg/vg_view.h 2008-09-17 10:27:46 UTC (rev 7653) +++ trunk/vg/vg_view.h 2008-09-17 14:03:25 UTC (rev 7654) @@ -25,8 +25,8 @@ #define VG_GRID_HIDE 0x01 /* Hide grid */ #define VG_GRID_UNDERSIZE 0x02 /* Grid too small to display */ - int ivalNom; /* Nominal pixel interval */ - int ival; /* Effective interval (dependent on wPixel) */ + int ival; /* Nominal pixel interval */ + int ivalView; /* Effective interval (dependent on wPixel) */ VG_Color color; /* Display color */ } VG_Grid;

Previous Message by Thread: click to view message preview

Agar: r7650 - trunk/vg

Author: vedge Date: 2008-09-17 00:06:27 -0300 (Wed, 17 Sep 2008) New Revision: 7650 Modified: trunk/vg/vg_math.h trunk/vg/vg_view.c trunk/vg/vg_view.h Log: use rint() when computing the grid interval; this prevents numerical roundoff errors which could cause misalignment of multiple grids under some scale factors. Modified: trunk/vg/vg_math.h =================================================================== --- trunk/vg/vg_math.h 2008-09-16 16:04:43 UTC (rev 7649) +++ trunk/vg/vg_math.h 2008-09-17 03:06:27 UTC (rev 7650) @@ -14,6 +14,7 @@ # define VG_PI 3.14159265358979323846 #endif +/* XXX test in configure */ #if __STDC_VERSION__ >= 199901L # define VG_Sin(x) sinf(x) # define VG_Cos(x) cosf(x) @@ -25,6 +26,7 @@ # define VG_Ceil(x) ceilf(x) # define VG_Fabs(x) fabsf(x) # define VG_Hypot(x,y) hypotf((x),(y)) +# define VG_Rint(x) rintf(x) #else # define VG_Sin(x) ((float)sin((double)x)) # define VG_Cos(x) ((float)cos((double)x)) @@ -36,6 +38,7 @@ # define VG_Ceil(x) ((float)ceil((double)x)) # define VG_Fabs(x) ((float)fabs((double)x)) # define VG_Hypot(x,y) ((float)hypot((double)(x),(double)(y))) +# define VG_Rint(x) ((float)rint(x)) #endif /* C99 */ #define VG_Degrees(x) ((x)/(2.0*VG_PI)*360.0) Modified: trunk/vg/vg_view.c =================================================================== --- trunk/vg/vg_view.c 2008-09-16 16:04:43 UTC (rev 7649) +++ trunk/vg/vg_view.c 2008-09-17 03:06:27 UTC (rev 7650) @@ -43,14 +43,13 @@ #include "vg_tools.h" #include "tools.h" -static const float scaleFactors[28] = { - 1.0f, 1.25f, 1.5f, 1.75f, - 2.0f, 2.25f, 2.5f, 2.75f, - 3.0f, 3.25f, 3.5f, 3.75f, - 4.0f, 5.0f, 6.0f, 8.0f, 10.0f, 12.0f, 16.0f, 18.0f, - 20.0f, 22.0f, 24.0f, 32.0f, 34.0f, 36.0f, 38.0f, 40.0f +static const float scaleFactors[] = { + 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, + 10.0f, 12.0f, 14.0f, 16.0f, 18.0f, 20.0f, 22.0f, 24.0f, 26.0f, 28.0f, + 40.0f, 50.0f, 80.0f, 90.0f, 100.0f, 200.0f, 300.0f, + 400.0f, 600.0f, 700.0f, 800.0f, 900.0f }; -const int nScaleFactors = 28; +const int nScaleFactors = sizeof(scaleFactors)/sizeof(scaleFactors[0]); VG_View * VG_ViewNew(void *parent, VG *vg, Uint flags) @@ -139,13 +138,13 @@ case SDL_BUTTON_WHEELDOWN: if (vv->scaleIdx-1 >= 0) { VG_ViewSetScale(vv, --vv->scaleIdx); - VG_Status(vv, _("Scale: 1:%.0f"), vv->scale); + VG_Status(vv, _("Scale: 1:%f"), vv->scale); } return; case SDL_BUTTON_WHEELUP: if (vv->scaleIdx+1 < nScaleFactors) { VG_ViewSetScale(vv, ++vv->scaleIdx); - VG_Status(vv, _("Scale: 1:%.0f"), vv->scale); + VG_Status(vv, _("Scale: 1:%f"), vv->scale); } return; default: @@ -272,6 +271,7 @@ vv->y = AGWIDGET(vv)->h/2.0f; } +/* Update the point selection radius (dependent on scale factor). */ static void UpdatePointSelRadius(VG_View *vv) { @@ -279,6 +279,24 @@ } static void +UpdateGridIntervals(VG_View *vv) +{ + int i; + + for (i = 0; i < vv->nGrids; i++) { + VG_Grid *grid = &vv->grid[i]; + + grid->ival = (int)VG_Rint(((float)grid->ivalNom)/vv->wPixel); + + if (grid->ival < 6) { + grid->flags |= VG_GRID_UNDERSIZE; + } else { + grid->flags &= ~(VG_GRID_UNDERSIZE); + } + } +} + +static void Init(void *obj) { VG_View *vv = obj; @@ -374,7 +392,8 @@ AG_ObjectLock(vv); vv->grid[idx].type = type; - vv->grid[idx].ival = ival; + vv->grid[idx].ivalNom = ival; + vv->grid[idx].ival = 0; vv->grid[idx].color = color; if (idx == 0) { UpdatePointSelRadius(vv); @@ -382,6 +401,7 @@ if (idx >= vv->nGrids) { vv->nGrids = idx+1; } + UpdateGridIntervals(vv); AG_ObjectUnlock(vv); } @@ -474,14 +494,12 @@ static __inline__ void DrawGrid(VG_View *vv, const VG_Grid *grid) { - int x, x0, y; - int ival; + int x, x0, y, ival; - if (grid->ival <= 1) { + if (grid->flags & (VG_GRID_HIDE|VG_GRID_UNDERSIZE)) return; - } - ival = (int)(grid->ival/vv->wPixel); - + + ival = grid->ival; #ifdef HAVE_OPENGL if (agView->opengl) { x0 = WIDGET(vv)->cx + (int)(vv->x)%ival; @@ -740,15 +758,18 @@ AG_ObjectLock(vv); + /* Set the specified scaling factor. */ vv->scaleIdx = idx; vv->scale = scaleFactors[idx]; if (vv->scale < vv->scaleMin) { vv->scale = vv->scaleMin; } if (vv->scale > vv->scaleMax) { vv->scale = vv->scaleMax; } - + + /* Update all values dependent on VG's representation of a pixel. */ vv->wPixel = 1.0/vv->scale; vv->x *= (vv->scale/scalePrev); vv->y *= (vv->scale/scalePrev); UpdatePointSelRadius(vv); + UpdateGridIntervals(vv); AG_ObjectUnlock(vv); } Modified: trunk/vg/vg_view.h =================================================================== --- trunk/vg/vg_view.h 2008-09-16 16:04:43 UTC (rev 7649) +++ trunk/vg/vg_view.h 2008-09-17 03:06:27 UTC (rev 7650) @@ -21,8 +21,13 @@ typedef struct vg_grid { enum vg_grid_type type; - int ival; /* Interval (pixels, power of two) */ - VG_Color color; /* Display color */ + Uint flags; +#define VG_GRID_HIDE 0x01 /* Hide grid */ +#define VG_GRID_UNDERSIZE 0x02 /* Grid too small to display */ + + int ivalNom; /* Nominal pixel interval */ + int ival; /* Effective interval (dependent on wPixel) */ + VG_Color color; /* Display color */ } VG_Grid; typedef struct vg_view {

Next Message by Thread: click to view message preview

Agar: r7654 - trunk/vg

Author: vedge Date: 2008-09-17 11:03:25 -0300 (Wed, 17 Sep 2008) New Revision: 7654 Modified: trunk/vg/vg_view.c trunk/vg/vg_view.h Log: precompute effective grid interval in pixels; fix default scale factors. Modified: trunk/vg/vg_view.c =================================================================== --- trunk/vg/vg_view.c 2008-09-17 10:27:46 UTC (rev 7653) +++ trunk/vg/vg_view.c 2008-09-17 14:03:25 UTC (rev 7654) @@ -44,10 +44,10 @@ #include "tools.h" static const float scaleFactors[] = { - 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, - 10.0f, 12.0f, 14.0f, 16.0f, 18.0f, 20.0f, 22.0f, 24.0f, 26.0f, 28.0f, - 40.0f, 50.0f, 80.0f, 90.0f, 100.0f, 200.0f, 300.0f, - 400.0f, 600.0f, 700.0f, 800.0f, 900.0f + 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, + 12.0f, 14.0f, 16.0f, 18.0f, 20.0f, 22.0f, 24.0f, 26.0f, 28.0f, + 30.0f, 40.0f, 50.0f, 60.0f, 70.0f, 80.0f, 90.0f, 100.0f, + 200.0f, 300.0f, 400.0f, 600.0f, 700.0f, 800.0f, 900.0f }; const int nScaleFactors = sizeof(scaleFactors)/sizeof(scaleFactors[0]); @@ -138,13 +138,13 @@ case SDL_BUTTON_WHEELDOWN: if (vv->scaleIdx-1 >= 0) { VG_ViewSetScale(vv, --vv->scaleIdx); - VG_Status(vv, _("Scale: 1:%f"), vv->scale); + VG_Status(vv, _("Scale: 1:%.0f"), vv->scale); } return; case SDL_BUTTON_WHEELUP: if (vv->scaleIdx+1 < nScaleFactors) { VG_ViewSetScale(vv, ++vv->scaleIdx); - VG_Status(vv, _("Scale: 1:%f"), vv->scale); + VG_Status(vv, _("Scale: 1:%.0f"), vv->scale); } return; default: @@ -286,9 +286,9 @@ for (i = 0; i < vv->nGrids; i++) { VG_Grid *grid = &vv->grid[i]; - grid->ival = (int)VG_Rint(((float)grid->ivalNom)/vv->wPixel); + grid->ivalView = (int)VG_Rint(((float)grid->ival)/vv->wPixel); - if (grid->ival < 6) { + if (grid->ivalView < 6) { grid->flags |= VG_GRID_UNDERSIZE; } else { grid->flags &= ~(VG_GRID_UNDERSIZE); @@ -321,10 +321,6 @@ vv->wPixel = 1.0f; vv->snap_mode = VG_GRID; vv->ortho_mode = VG_NO_ORTHO; - vv->grid[0].type = VG_GRID_POINTS; - vv->grid[0].ival = 8; - vv->grid[0].color = VG_GetColorRGB(100, 100, 100); - vv->nGrids = 1; vv->mouse.x = 0.0f; vv->mouse.y = 0.0f; vv->mouse.panning = 0; @@ -335,7 +331,9 @@ vv->editAreas = NULL; vv->nEditAreas = 0; TAILQ_INIT(&vv->tools); - UpdatePointSelRadius(vv); + + VG_ViewSetGrid(vv, 0, VG_GRID_POINTS, 8, VG_GetColorRGB(100,100,100)); + VG_ViewSetScale(vv, 0); AG_SetEvent(vv, "window-mousemotion", MouseMotion, NULL); AG_SetEvent(vv, "window-mousebuttondown", MouseButtonDown, NULL); @@ -392,8 +390,8 @@ AG_ObjectLock(vv); vv->grid[idx].type = type; - vv->grid[idx].ivalNom = ival; - vv->grid[idx].ival = 0; + vv->grid[idx].ival = ival; + vv->grid[idx].ivalView = 0; vv->grid[idx].color = color; if (idx == 0) { UpdatePointSelRadius(vv); @@ -499,7 +497,7 @@ if (grid->flags & (VG_GRID_HIDE|VG_GRID_UNDERSIZE)) return; - ival = grid->ival; + ival = grid->ivalView; #ifdef HAVE_OPENGL if (agView->opengl) { x0 = WIDGET(vv)->cx + (int)(vv->x)%ival; Modified: trunk/vg/vg_view.h =================================================================== --- trunk/vg/vg_view.h 2008-09-17 10:27:46 UTC (rev 7653) +++ trunk/vg/vg_view.h 2008-09-17 14:03:25 UTC (rev 7654) @@ -25,8 +25,8 @@ #define VG_GRID_HIDE 0x01 /* Hide grid */ #define VG_GRID_UNDERSIZE 0x02 /* Grid too small to display */ - int ivalNom; /* Nominal pixel interval */ - int ival; /* Effective interval (dependent on wPixel) */ + int ival; /* Nominal pixel interval */ + int ivalView; /* Effective interval (dependent on wPixel) */ VG_Color color; /* Display color */ } VG_Grid;
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by