indent shift.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:50:00 -07:00
parent fee4c7ca44
commit e6a81956de

View file

@ -38,29 +38,25 @@
/* Our globals: */ /* Our globals: */
static int shift_x, shift_y; static int shift_x, shift_y;
static Mix_Chunk * shift_snd; static Mix_Chunk *shift_snd;
/* Local function prototypes: */ /* Local function prototypes: */
static void shift_doit(magic_api * api, int which, SDL_Surface * canvas, static void shift_doit(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect, int crosshairs);
SDL_Rect * update_rect, int crosshairs);
Uint32 shift_api_version(void); Uint32 shift_api_version(void);
int shift_init(magic_api * api); int shift_init(magic_api * api);
int shift_get_tool_count(magic_api * api); int shift_get_tool_count(magic_api * api);
SDL_Surface * shift_get_icon(magic_api * api, int which); SDL_Surface *shift_get_icon(magic_api * api, int which);
char * shift_get_name(magic_api * api, int which); char *shift_get_name(magic_api * api, int which);
char * shift_get_description(magic_api * api, int which, int mode); char *shift_get_description(magic_api * api, int which, int mode);
void shift_drag(magic_api * api, int which, SDL_Surface * canvas, void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void shift_click(magic_api * api, int which, int mode, void shift_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
int x, int y, SDL_Rect * update_rect);
void shift_release(magic_api * api, int which, void shift_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
int x, int y, SDL_Rect * update_rect);
void shift_shutdown(magic_api * api); void shift_shutdown(magic_api * api);
void shift_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void shift_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int shift_requires_colors(magic_api * api, int which); int shift_requires_colors(magic_api * api, int which);
@ -71,7 +67,10 @@ int shift_modes(magic_api * api, int which);
Uint32 shift_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 shift_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required: // No setup required:
@ -79,57 +78,54 @@ int shift_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/shift.ogg", snprintf(fname, sizeof(fname), "%s/sounds/magic/shift.ogg", api->data_directory);
api->data_directory);
shift_snd = Mix_LoadWAV(fname); shift_snd = Mix_LoadWAV(fname);
return(1); return (1);
} }
// We have multiple tools: // We have multiple tools:
int shift_get_tool_count(magic_api * api ATTRIBUTE_UNUSED) int shift_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{ {
return(1); return (1);
} }
// Load our icons: // Load our icons:
SDL_Surface * shift_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) SDL_Surface *shift_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/shift.png", snprintf(fname, sizeof(fname), "%s/images/magic/shift.png", api->data_directory);
api->data_directory);
return(IMG_Load(fname)); return (IMG_Load(fname));
} }
// Return our names, localized: // Return our names, localized:
char * shift_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) char *shift_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return(strdup(gettext_noop("Shift"))); return (strdup(gettext_noop("Shift")));
} }
// Return our descriptions, localized: // Return our descriptions, localized:
char * shift_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) char *shift_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{ {
return(strdup(gettext_noop("Click and drag to shift your picture around on the canvas."))); return (strdup(gettext_noop("Click and drag to shift your picture around on the canvas.")));
} }
// Affect the canvas on drag: // Affect the canvas on drag:
void shift_drag(magic_api * api, int which, SDL_Surface * canvas, void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
if (ox == x && oy == y) if (ox == x && oy == y)
return; /* No-op */ return; /* No-op */
shift_doit(api, which, canvas, last, ox, oy, x, y, update_rect, 1); shift_doit(api, which, canvas, last, ox, oy, x, y, update_rect, 1);
} }
static void shift_doit(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, static void shift_doit(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect, int crosshairs) SDL_Rect * update_rect, int crosshairs)
{ {
SDL_Rect dest; SDL_Rect dest;
int dx, dy; int dx, dy;
@ -159,123 +155,123 @@ static void shift_doit(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
if (dy > 0) if (dy > 0)
{
if (dx > 0)
{ {
/* Top Left */ if (dx > 0)
{
/* Top Left */
dest.x = dx - canvas->w; dest.x = dx - canvas->w;
dest.y = dy - canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest);
}
/* Top */
dest.x = dx;
dest.y = dy - canvas->h; dest.y = dy - canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest); SDL_BlitSurface(last, NULL, canvas, &dest);
if (dx < 0)
{
/* Top Right */
dest.x = dx + canvas->w;
dest.y = dy - canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest);
}
} }
/* Top */
dest.x = dx;
dest.y = dy - canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest);
if (dx < 0)
{
/* Top Right */
dest.x = dx + canvas->w;
dest.y = dy - canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest);
}
}
if (dx > 0) if (dx > 0)
{ {
/* Left */ /* Left */
dest.x = dx - canvas->w; dest.x = dx - canvas->w;
dest.y = dy; dest.y = dy;
SDL_BlitSurface(last, NULL, canvas, &dest); SDL_BlitSurface(last, NULL, canvas, &dest);
} }
if (dx < 0) if (dx < 0)
{ {
/* Right */ /* Right */
dest.x = dx + canvas->w; dest.x = dx + canvas->w;
dest.y = dy; dest.y = dy;
SDL_BlitSurface(last, NULL, canvas, &dest); SDL_BlitSurface(last, NULL, canvas, &dest);
} }
if (dy < 0) if (dy < 0)
{
if (dx > 0)
{ {
/* Bottom Left */ if (dx > 0)
{
/* Bottom Left */
dest.x = dx - canvas->w; dest.x = dx - canvas->w;
dest.y = dy + canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest);
}
/* Bottom */
dest.x = dx;
dest.y = dy + canvas->h; dest.y = dy + canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest); SDL_BlitSurface(last, NULL, canvas, &dest);
if (dx < 0)
{
/* Bottom Right */
dest.x = dx + canvas->w;
dest.y = dy + canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest);
}
} }
/* Bottom */
dest.x = dx;
dest.y = dy + canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest);
if (dx < 0)
{
/* Bottom Right */
dest.x = dx + canvas->w;
dest.y = dy + canvas->h;
SDL_BlitSurface(last, NULL, canvas, &dest);
}
}
if (crosshairs) if (crosshairs)
{ {
dest.x = (canvas->w / 2) - 1; dest.x = (canvas->w / 2) - 1;
dest.y = 0; dest.y = 0;
dest.w = 3; dest.w = 3;
dest.h = canvas->h; dest.h = canvas->h;
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 255, 255, 255)); SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 255, 255, 255));
dest.x = 0; dest.x = 0;
dest.y = (canvas->h / 2) - 1; dest.y = (canvas->h / 2) - 1;
dest.w = canvas->w; dest.w = canvas->w;
dest.h = 3; dest.h = 3;
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 255, 255, 255)); SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 255, 255, 255));
dest.x = canvas->w / 2; dest.x = canvas->w / 2;
dest.y = 0; dest.y = 0;
dest.w = 1; dest.w = 1;
dest.h = canvas->h; dest.h = canvas->h;
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0)); SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0));
dest.x = 0; dest.x = 0;
dest.y = canvas->h / 2; dest.y = canvas->h / 2;
dest.w = canvas->w; dest.w = canvas->w;
dest.h = 1; dest.h = 1;
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0)); SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0));
} }
/* Update everything! */ /* Update everything! */
@ -290,8 +286,7 @@ static void shift_doit(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
// Affect the canvas on click: // Affect the canvas on click:
void shift_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, void shift_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
int x, int y, SDL_Rect * update_rect)
{ {
shift_x = x; shift_x = x;
shift_y = y; shift_y = y;
@ -301,8 +296,7 @@ void shift_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release: // Affect the canvas on release:
void shift_release(magic_api * api, int which, void shift_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
int x, int y, SDL_Rect * update_rect)
{ {
shift_doit(api, which, canvas, last, x, y, x, y, update_rect, 0); shift_doit(api, which, canvas, last, x, y, x, y, update_rect, 0);
api->stopsound(); api->stopsound();
@ -318,7 +312,7 @@ void shift_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint: // Record the color from Tux Paint:
void shift_set_color(magic_api * api ATTRIBUTE_UNUSED, void shift_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED) Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
{ {
} }
@ -328,15 +322,17 @@ int shift_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 0; return 0;
} }
void shift_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void shift_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void shift_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void shift_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
int shift_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) int shift_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return(MODE_PAINT_WITH_PREVIEW); return (MODE_PAINT_WITH_PREVIEW);
} }