Some data encapsulation stuff for tile managers. This one will

probably make everyone recompile AGAIN.  Ha ha ha.
This commit is contained in:
scott 1998-07-28 23:13:36 +00:00
parent 2f0efbca32
commit 7bcac06c7e
12 changed files with 204 additions and 80 deletions

View File

@ -636,3 +636,58 @@ tile_manager_get_tile_num (TileManager *tm,
return tile_num;
}
void
tile_manager_set_user_data (TileManager *tm,
void *user_data)
{
tm->user_data = user_data;
}
void *
tile_manager_get_user_data (TileManager *tm)
{
return tm->user_data;
}
int
tile_manager_level_width (TileManager *tm, int level)
{
return tm->levels[level].width;
}
int
tile_manager_level_height (TileManager *tm, int level)
{
return tm->levels[level].height;
}
int
tile_manager_level_bpp (TileManager *tm, int level)
{
return tm->levels[level].bpp;
}
void
tile_manager_get_tile_coordinates (TileManager *tm, Tile *tile, int *x, int *y)
{
TileLink *tl;
for (tl = tile->tlink; tl; tl = tl->next)
{
if (tl->tm == tm) break;
}
if (tl == NULL)
{
g_warning ("tile_manager_get_tile_coordinates: tile not attached to manager");
return;
}
*x = TILE_WIDTH * (tl->tile_num % tm->levels[0].ntile_cols);
*y = TILE_HEIGHT * (tl->tile_num / tm->levels[0].ntile_cols);
}

View File

@ -138,5 +138,16 @@ void tile_manager_update_tile (TileManager *tm,
Tile *toplevel_tile,
int level);
void tile_manager_set_user_data (TileManager *tm,
void *user_data);
void *tile_manager_get_user_data (TileManager *tm);
int tile_manager_level_width (TileManager *tm, int level);
int tile_manager_level_height (TileManager *tm, int level);
int tile_manager_level_bpp (TileManager *tm, int level);
void tile_manager_get_tile_coordinates (TileManager *tm, Tile *tile,
int *x, int *y);
#endif /* __TILE_MANAGER_H__ */

View File

@ -26,7 +26,7 @@
#include "undo.h"
#include "gimpsignal.h"
#include "tile_manager_pvt.h" /* ick. */
#include "tile_manager.h" /* ick. */
#include "tile_pvt.h"
#include "layer_pvt.h"
#include "drawable_pvt.h" /* ick ick. */
@ -188,7 +188,7 @@ gimp_image_allocate_projection (GimpImage *gimage)
/* allocate the new projection */
gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes);
gimage->projection->user_data = (void *) gimage;
tile_manager_set_user_data (gimage->projection, (void *) gimage);
tile_manager_set_validate_proc (gimage->projection, gimp_image_validate);
}
@ -411,9 +411,9 @@ TileManager *
gimp_image_shadow (GimpImage *gimage, int width, int height, int bpp)
{
if (gimage->shadow &&
((width != gimage->shadow->levels[0].width) ||
(height != gimage->shadow->levels[0].height) ||
(bpp != gimage->shadow->levels[0].bpp)))
((width != tile_manager_level_width (gimage->shadow, 0)) ||
(height != tile_manager_level_height (gimage->shadow, 0)) ||
(bpp != tile_manager_level_bpp (gimage->shadow, 0))))
gimp_image_free_shadow (gimage);
else if (gimage->shadow)
return gimage->shadow;
@ -1283,11 +1283,10 @@ gimp_image_validate (TileManager *tm, Tile *tile, int level)
int w, h;
/* Get the gimage from the tilemanager */
gimage = (GimpImage *) tm->user_data;
gimage = (GimpImage *) tile_manager_get_user_data (tm);
/* Find the coordinates of this tile */
x = TILE_WIDTH * (tile->tlink->tile_num % tm->levels[0].ntile_cols);
y = TILE_HEIGHT * (tile->tlink->tile_num / tm->levels[0].ntile_cols);
tile_manager_get_tile_coordinates (tm, tile, &x, &y);
w = tile->ewidth;
h = tile->eheight;
@ -2576,8 +2575,8 @@ gimp_image_projection (GimpImage *gimage)
}
else
{
if ((gimage->projection->levels[0].width != gimage->width) ||
(gimage->projection->levels[0].height != gimage->height))
if ((tile_manager_level_width (gimage->projection, 0) != gimage->width) ||
(tile_manager_level_height (gimage->projection, 0) != gimage->height))
gimp_image_allocate_projection (gimage);
return gimage->projection;

View File

@ -26,7 +26,7 @@
#include "undo.h"
#include "gimpsignal.h"
#include "tile_manager_pvt.h" /* ick. */
#include "tile_manager.h" /* ick. */
#include "tile_pvt.h"
#include "layer_pvt.h"
#include "drawable_pvt.h" /* ick ick. */
@ -188,7 +188,7 @@ gimp_image_allocate_projection (GimpImage *gimage)
/* allocate the new projection */
gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes);
gimage->projection->user_data = (void *) gimage;
tile_manager_set_user_data (gimage->projection, (void *) gimage);
tile_manager_set_validate_proc (gimage->projection, gimp_image_validate);
}
@ -411,9 +411,9 @@ TileManager *
gimp_image_shadow (GimpImage *gimage, int width, int height, int bpp)
{
if (gimage->shadow &&
((width != gimage->shadow->levels[0].width) ||
(height != gimage->shadow->levels[0].height) ||
(bpp != gimage->shadow->levels[0].bpp)))
((width != tile_manager_level_width (gimage->shadow, 0)) ||
(height != tile_manager_level_height (gimage->shadow, 0)) ||
(bpp != tile_manager_level_bpp (gimage->shadow, 0))))
gimp_image_free_shadow (gimage);
else if (gimage->shadow)
return gimage->shadow;
@ -1283,11 +1283,10 @@ gimp_image_validate (TileManager *tm, Tile *tile, int level)
int w, h;
/* Get the gimage from the tilemanager */
gimage = (GimpImage *) tm->user_data;
gimage = (GimpImage *) tile_manager_get_user_data (tm);
/* Find the coordinates of this tile */
x = TILE_WIDTH * (tile->tlink->tile_num % tm->levels[0].ntile_cols);
y = TILE_HEIGHT * (tile->tlink->tile_num / tm->levels[0].ntile_cols);
tile_manager_get_tile_coordinates (tm, tile, &x, &y);
w = tile->ewidth;
h = tile->eheight;
@ -2576,8 +2575,8 @@ gimp_image_projection (GimpImage *gimage)
}
else
{
if ((gimage->projection->levels[0].width != gimage->width) ||
(gimage->projection->levels[0].height != gimage->height))
if ((tile_manager_level_width (gimage->projection, 0) != gimage->width) ||
(tile_manager_level_height (gimage->projection, 0) != gimage->height))
gimp_image_allocate_projection (gimage);
return gimage->projection;

View File

@ -26,7 +26,7 @@
#include "undo.h"
#include "gimpsignal.h"
#include "tile_manager_pvt.h" /* ick. */
#include "tile_manager.h" /* ick. */
#include "tile_pvt.h"
#include "layer_pvt.h"
#include "drawable_pvt.h" /* ick ick. */
@ -188,7 +188,7 @@ gimp_image_allocate_projection (GimpImage *gimage)
/* allocate the new projection */
gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes);
gimage->projection->user_data = (void *) gimage;
tile_manager_set_user_data (gimage->projection, (void *) gimage);
tile_manager_set_validate_proc (gimage->projection, gimp_image_validate);
}
@ -411,9 +411,9 @@ TileManager *
gimp_image_shadow (GimpImage *gimage, int width, int height, int bpp)
{
if (gimage->shadow &&
((width != gimage->shadow->levels[0].width) ||
(height != gimage->shadow->levels[0].height) ||
(bpp != gimage->shadow->levels[0].bpp)))
((width != tile_manager_level_width (gimage->shadow, 0)) ||
(height != tile_manager_level_height (gimage->shadow, 0)) ||
(bpp != tile_manager_level_bpp (gimage->shadow, 0))))
gimp_image_free_shadow (gimage);
else if (gimage->shadow)
return gimage->shadow;
@ -1283,11 +1283,10 @@ gimp_image_validate (TileManager *tm, Tile *tile, int level)
int w, h;
/* Get the gimage from the tilemanager */
gimage = (GimpImage *) tm->user_data;
gimage = (GimpImage *) tile_manager_get_user_data (tm);
/* Find the coordinates of this tile */
x = TILE_WIDTH * (tile->tlink->tile_num % tm->levels[0].ntile_cols);
y = TILE_HEIGHT * (tile->tlink->tile_num / tm->levels[0].ntile_cols);
tile_manager_get_tile_coordinates (tm, tile, &x, &y);
w = tile->ewidth;
h = tile->eheight;
@ -2576,8 +2575,8 @@ gimp_image_projection (GimpImage *gimage)
}
else
{
if ((gimage->projection->levels[0].width != gimage->width) ||
(gimage->projection->levels[0].height != gimage->height))
if ((tile_manager_level_width (gimage->projection, 0) != gimage->width) ||
(tile_manager_level_height (gimage->projection, 0) != gimage->height))
gimp_image_allocate_projection (gimage);
return gimage->projection;

View File

@ -26,7 +26,7 @@
#include "undo.h"
#include "gimpsignal.h"
#include "tile_manager_pvt.h" /* ick. */
#include "tile_manager.h" /* ick. */
#include "tile_pvt.h"
#include "layer_pvt.h"
#include "drawable_pvt.h" /* ick ick. */
@ -188,7 +188,7 @@ gimp_image_allocate_projection (GimpImage *gimage)
/* allocate the new projection */
gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes);
gimage->projection->user_data = (void *) gimage;
tile_manager_set_user_data (gimage->projection, (void *) gimage);
tile_manager_set_validate_proc (gimage->projection, gimp_image_validate);
}
@ -411,9 +411,9 @@ TileManager *
gimp_image_shadow (GimpImage *gimage, int width, int height, int bpp)
{
if (gimage->shadow &&
((width != gimage->shadow->levels[0].width) ||
(height != gimage->shadow->levels[0].height) ||
(bpp != gimage->shadow->levels[0].bpp)))
((width != tile_manager_level_width (gimage->shadow, 0)) ||
(height != tile_manager_level_height (gimage->shadow, 0)) ||
(bpp != tile_manager_level_bpp (gimage->shadow, 0))))
gimp_image_free_shadow (gimage);
else if (gimage->shadow)
return gimage->shadow;
@ -1283,11 +1283,10 @@ gimp_image_validate (TileManager *tm, Tile *tile, int level)
int w, h;
/* Get the gimage from the tilemanager */
gimage = (GimpImage *) tm->user_data;
gimage = (GimpImage *) tile_manager_get_user_data (tm);
/* Find the coordinates of this tile */
x = TILE_WIDTH * (tile->tlink->tile_num % tm->levels[0].ntile_cols);
y = TILE_HEIGHT * (tile->tlink->tile_num / tm->levels[0].ntile_cols);
tile_manager_get_tile_coordinates (tm, tile, &x, &y);
w = tile->ewidth;
h = tile->eheight;
@ -2576,8 +2575,8 @@ gimp_image_projection (GimpImage *gimage)
}
else
{
if ((gimage->projection->levels[0].width != gimage->width) ||
(gimage->projection->levels[0].height != gimage->height))
if ((tile_manager_level_width (gimage->projection, 0) != gimage->width) ||
(tile_manager_level_height (gimage->projection, 0) != gimage->height))
gimp_image_allocate_projection (gimage);
return gimage->projection;

View File

@ -26,7 +26,7 @@
#include "undo.h"
#include "gimpsignal.h"
#include "tile_manager_pvt.h" /* ick. */
#include "tile_manager.h" /* ick. */
#include "tile_pvt.h"
#include "layer_pvt.h"
#include "drawable_pvt.h" /* ick ick. */
@ -188,7 +188,7 @@ gimp_image_allocate_projection (GimpImage *gimage)
/* allocate the new projection */
gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes);
gimage->projection->user_data = (void *) gimage;
tile_manager_set_user_data (gimage->projection, (void *) gimage);
tile_manager_set_validate_proc (gimage->projection, gimp_image_validate);
}
@ -411,9 +411,9 @@ TileManager *
gimp_image_shadow (GimpImage *gimage, int width, int height, int bpp)
{
if (gimage->shadow &&
((width != gimage->shadow->levels[0].width) ||
(height != gimage->shadow->levels[0].height) ||
(bpp != gimage->shadow->levels[0].bpp)))
((width != tile_manager_level_width (gimage->shadow, 0)) ||
(height != tile_manager_level_height (gimage->shadow, 0)) ||
(bpp != tile_manager_level_bpp (gimage->shadow, 0))))
gimp_image_free_shadow (gimage);
else if (gimage->shadow)
return gimage->shadow;
@ -1283,11 +1283,10 @@ gimp_image_validate (TileManager *tm, Tile *tile, int level)
int w, h;
/* Get the gimage from the tilemanager */
gimage = (GimpImage *) tm->user_data;
gimage = (GimpImage *) tile_manager_get_user_data (tm);
/* Find the coordinates of this tile */
x = TILE_WIDTH * (tile->tlink->tile_num % tm->levels[0].ntile_cols);
y = TILE_HEIGHT * (tile->tlink->tile_num / tm->levels[0].ntile_cols);
tile_manager_get_tile_coordinates (tm, tile, &x, &y);
w = tile->ewidth;
h = tile->eheight;
@ -2576,8 +2575,8 @@ gimp_image_projection (GimpImage *gimage)
}
else
{
if ((gimage->projection->levels[0].width != gimage->width) ||
(gimage->projection->levels[0].height != gimage->height))
if ((tile_manager_level_width (gimage->projection, 0) != gimage->width) ||
(tile_manager_level_height (gimage->projection, 0) != gimage->height))
gimp_image_allocate_projection (gimage);
return gimage->projection;

View File

@ -26,7 +26,7 @@
#include "undo.h"
#include "gimpsignal.h"
#include "tile_manager_pvt.h" /* ick. */
#include "tile_manager.h" /* ick. */
#include "tile_pvt.h"
#include "layer_pvt.h"
#include "drawable_pvt.h" /* ick ick. */
@ -188,7 +188,7 @@ gimp_image_allocate_projection (GimpImage *gimage)
/* allocate the new projection */
gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes);
gimage->projection->user_data = (void *) gimage;
tile_manager_set_user_data (gimage->projection, (void *) gimage);
tile_manager_set_validate_proc (gimage->projection, gimp_image_validate);
}
@ -411,9 +411,9 @@ TileManager *
gimp_image_shadow (GimpImage *gimage, int width, int height, int bpp)
{
if (gimage->shadow &&
((width != gimage->shadow->levels[0].width) ||
(height != gimage->shadow->levels[0].height) ||
(bpp != gimage->shadow->levels[0].bpp)))
((width != tile_manager_level_width (gimage->shadow, 0)) ||
(height != tile_manager_level_height (gimage->shadow, 0)) ||
(bpp != tile_manager_level_bpp (gimage->shadow, 0))))
gimp_image_free_shadow (gimage);
else if (gimage->shadow)
return gimage->shadow;
@ -1283,11 +1283,10 @@ gimp_image_validate (TileManager *tm, Tile *tile, int level)
int w, h;
/* Get the gimage from the tilemanager */
gimage = (GimpImage *) tm->user_data;
gimage = (GimpImage *) tile_manager_get_user_data (tm);
/* Find the coordinates of this tile */
x = TILE_WIDTH * (tile->tlink->tile_num % tm->levels[0].ntile_cols);
y = TILE_HEIGHT * (tile->tlink->tile_num / tm->levels[0].ntile_cols);
tile_manager_get_tile_coordinates (tm, tile, &x, &y);
w = tile->ewidth;
h = tile->eheight;
@ -2576,8 +2575,8 @@ gimp_image_projection (GimpImage *gimage)
}
else
{
if ((gimage->projection->levels[0].width != gimage->width) ||
(gimage->projection->levels[0].height != gimage->height))
if ((tile_manager_level_width (gimage->projection, 0) != gimage->width) ||
(tile_manager_level_height (gimage->projection, 0) != gimage->height))
gimp_image_allocate_projection (gimage);
return gimage->projection;

View File

@ -26,7 +26,7 @@
#include "undo.h"
#include "gimpsignal.h"
#include "tile_manager_pvt.h" /* ick. */
#include "tile_manager.h" /* ick. */
#include "tile_pvt.h"
#include "layer_pvt.h"
#include "drawable_pvt.h" /* ick ick. */
@ -188,7 +188,7 @@ gimp_image_allocate_projection (GimpImage *gimage)
/* allocate the new projection */
gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes);
gimage->projection->user_data = (void *) gimage;
tile_manager_set_user_data (gimage->projection, (void *) gimage);
tile_manager_set_validate_proc (gimage->projection, gimp_image_validate);
}
@ -411,9 +411,9 @@ TileManager *
gimp_image_shadow (GimpImage *gimage, int width, int height, int bpp)
{
if (gimage->shadow &&
((width != gimage->shadow->levels[0].width) ||
(height != gimage->shadow->levels[0].height) ||
(bpp != gimage->shadow->levels[0].bpp)))
((width != tile_manager_level_width (gimage->shadow, 0)) ||
(height != tile_manager_level_height (gimage->shadow, 0)) ||
(bpp != tile_manager_level_bpp (gimage->shadow, 0))))
gimp_image_free_shadow (gimage);
else if (gimage->shadow)
return gimage->shadow;
@ -1283,11 +1283,10 @@ gimp_image_validate (TileManager *tm, Tile *tile, int level)
int w, h;
/* Get the gimage from the tilemanager */
gimage = (GimpImage *) tm->user_data;
gimage = (GimpImage *) tile_manager_get_user_data (tm);
/* Find the coordinates of this tile */
x = TILE_WIDTH * (tile->tlink->tile_num % tm->levels[0].ntile_cols);
y = TILE_HEIGHT * (tile->tlink->tile_num / tm->levels[0].ntile_cols);
tile_manager_get_tile_coordinates (tm, tile, &x, &y);
w = tile->ewidth;
h = tile->eheight;
@ -2576,8 +2575,8 @@ gimp_image_projection (GimpImage *gimage)
}
else
{
if ((gimage->projection->levels[0].width != gimage->width) ||
(gimage->projection->levels[0].height != gimage->height))
if ((tile_manager_level_width (gimage->projection, 0) != gimage->width) ||
(tile_manager_level_height (gimage->projection, 0) != gimage->height))
gimp_image_allocate_projection (gimage);
return gimage->projection;

View File

@ -26,7 +26,7 @@
#include "undo.h"
#include "gimpsignal.h"
#include "tile_manager_pvt.h" /* ick. */
#include "tile_manager.h" /* ick. */
#include "tile_pvt.h"
#include "layer_pvt.h"
#include "drawable_pvt.h" /* ick ick. */
@ -188,7 +188,7 @@ gimp_image_allocate_projection (GimpImage *gimage)
/* allocate the new projection */
gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes);
gimage->projection->user_data = (void *) gimage;
tile_manager_set_user_data (gimage->projection, (void *) gimage);
tile_manager_set_validate_proc (gimage->projection, gimp_image_validate);
}
@ -411,9 +411,9 @@ TileManager *
gimp_image_shadow (GimpImage *gimage, int width, int height, int bpp)
{
if (gimage->shadow &&
((width != gimage->shadow->levels[0].width) ||
(height != gimage->shadow->levels[0].height) ||
(bpp != gimage->shadow->levels[0].bpp)))
((width != tile_manager_level_width (gimage->shadow, 0)) ||
(height != tile_manager_level_height (gimage->shadow, 0)) ||
(bpp != tile_manager_level_bpp (gimage->shadow, 0))))
gimp_image_free_shadow (gimage);
else if (gimage->shadow)
return gimage->shadow;
@ -1283,11 +1283,10 @@ gimp_image_validate (TileManager *tm, Tile *tile, int level)
int w, h;
/* Get the gimage from the tilemanager */
gimage = (GimpImage *) tm->user_data;
gimage = (GimpImage *) tile_manager_get_user_data (tm);
/* Find the coordinates of this tile */
x = TILE_WIDTH * (tile->tlink->tile_num % tm->levels[0].ntile_cols);
y = TILE_HEIGHT * (tile->tlink->tile_num / tm->levels[0].ntile_cols);
tile_manager_get_tile_coordinates (tm, tile, &x, &y);
w = tile->ewidth;
h = tile->eheight;
@ -2576,8 +2575,8 @@ gimp_image_projection (GimpImage *gimage)
}
else
{
if ((gimage->projection->levels[0].width != gimage->width) ||
(gimage->projection->levels[0].height != gimage->height))
if ((tile_manager_level_width (gimage->projection, 0) != gimage->width) ||
(tile_manager_level_height (gimage->projection, 0) != gimage->height))
gimp_image_allocate_projection (gimage);
return gimage->projection;

View File

@ -636,3 +636,58 @@ tile_manager_get_tile_num (TileManager *tm,
return tile_num;
}
void
tile_manager_set_user_data (TileManager *tm,
void *user_data)
{
tm->user_data = user_data;
}
void *
tile_manager_get_user_data (TileManager *tm)
{
return tm->user_data;
}
int
tile_manager_level_width (TileManager *tm, int level)
{
return tm->levels[level].width;
}
int
tile_manager_level_height (TileManager *tm, int level)
{
return tm->levels[level].height;
}
int
tile_manager_level_bpp (TileManager *tm, int level)
{
return tm->levels[level].bpp;
}
void
tile_manager_get_tile_coordinates (TileManager *tm, Tile *tile, int *x, int *y)
{
TileLink *tl;
for (tl = tile->tlink; tl; tl = tl->next)
{
if (tl->tm == tm) break;
}
if (tl == NULL)
{
g_warning ("tile_manager_get_tile_coordinates: tile not attached to manager");
return;
}
*x = TILE_WIDTH * (tl->tile_num % tm->levels[0].ntile_cols);
*y = TILE_HEIGHT * (tl->tile_num / tm->levels[0].ntile_cols);
}

View File

@ -138,5 +138,16 @@ void tile_manager_update_tile (TileManager *tm,
Tile *toplevel_tile,
int level);
void tile_manager_set_user_data (TileManager *tm,
void *user_data);
void *tile_manager_get_user_data (TileManager *tm);
int tile_manager_level_width (TileManager *tm, int level);
int tile_manager_level_height (TileManager *tm, int level);
int tile_manager_level_bpp (TileManager *tm, int level);
void tile_manager_get_tile_coordinates (TileManager *tm, Tile *tile,
int *x, int *y);
#endif /* __TILE_MANAGER_H__ */