indent calligraphy.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:39:45 -07:00
parent 1ee28d1abd
commit 0a167dbc71

View file

@ -59,14 +59,11 @@ SDL_Surface * calligraphy_get_icon(magic_api * api, int which);
char *calligraphy_get_name(magic_api * api, int which); char *calligraphy_get_name(magic_api * api, int which);
char *calligraphy_get_description(magic_api * api, int which, int mode); char *calligraphy_get_description(magic_api * api, int which, int mode);
void calligraphy_drag(magic_api * api, int which, SDL_Surface * canvas, void calligraphy_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 calligraphy_click(magic_api * api, int which, int mode, void calligraphy_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 calligraphy_release(magic_api * api, int which, void calligraphy_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 calligraphy_shutdown(magic_api * api); void calligraphy_shutdown(magic_api * api);
void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int calligraphy_requires_colors(magic_api * api, int which); int calligraphy_requires_colors(magic_api * api, int which);
@ -79,13 +76,11 @@ int calligraphy_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/calligraphy.ogg", snprintf(fname, sizeof(fname), "%s/sounds/magic/calligraphy.ogg", api->data_directory);
api->data_directory);
calligraphy_snd = Mix_LoadWAV(fname); calligraphy_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy_brush.png", snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy_brush.png", api->data_directory);
api->data_directory);
calligraphy_brush = IMG_Load(fname); calligraphy_brush = IMG_Load(fname);
calligraphy_colored_brush = NULL; calligraphy_colored_brush = NULL;
@ -103,7 +98,10 @@ int calligraphy_init(magic_api * api)
return (1); return (1);
} }
Uint32 calligraphy_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 calligraphy_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// Only one tool: // Only one tool:
int calligraphy_get_tool_count(magic_api * api ATTRIBUTE_UNUSED) int calligraphy_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -116,8 +114,7 @@ SDL_Surface * calligraphy_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy.png", snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy.png", api->data_directory);
api->data_directory);
return (IMG_Load(fname)); return (IMG_Load(fname));
} }
@ -128,16 +125,15 @@ char * calligraphy_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
} }
// Return our description, localized: // Return our description, localized:
char * calligraphy_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) char *calligraphy_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{ {
return(strdup( return (strdup(gettext_noop("Click and drag the mouse around to draw in calligraphy.")));
gettext_noop("Click and drag the mouse around to draw in calligraphy.")));
} }
void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y, SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
Point2D *curve; Point2D *curve;
int i, n_points, thick, new_thick; int i, n_points, thick, new_thick;
@ -178,9 +174,7 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
calligraphy_control_points[2].x, calligraphy_control_points[2].x,
calligraphy_control_points[2].y) + calligraphy_control_points[2].y) +
calligraphy_dist(calligraphy_control_points[2].x, calligraphy_dist(calligraphy_control_points[2].x,
calligraphy_control_points[2].y, calligraphy_control_points[2].y, calligraphy_control_points[3].x, calligraphy_control_points[3].y);
calligraphy_control_points[3].x,
calligraphy_control_points[3].y);
if (n_points == 0) if (n_points == 0)
return; // No-op; not any points to plot return; // No-op; not any points to plot
@ -190,17 +184,13 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
calligraphy_ComputeBezier(calligraphy_control_points, n_points, curve); calligraphy_ComputeBezier(calligraphy_control_points, n_points, curve);
colr = SDL_MapRGB(canvas->format, colr = SDL_MapRGB(canvas->format, calligraphy_r, calligraphy_g, calligraphy_b);
calligraphy_r,
calligraphy_g,
calligraphy_b);
new_thick = 40 - min((n_points /* / 2 */ ), 32); new_thick = 40 - min((n_points /* / 2 */ ), 32);
for (i = 0; i < n_points - 1; i++) for (i = 0; i < n_points - 1; i++)
{ {
thick = ((new_thick * i) + thick = ((new_thick * i) + (calligraphy_old_thick * (n_points - i))) / n_points;
(calligraphy_old_thick * (n_points - i))) / n_points;
/* The new way, using an antialiased brush bitmap */ /* The new way, using an antialiased brush bitmap */
@ -253,8 +243,20 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x)
if (oy > y) { int tmp = oy; oy = y; y = tmp; } {
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = ox - 16; update_rect->x = ox - 16;
update_rect->y = oy - 16; update_rect->y = oy - 16;
@ -313,9 +315,7 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
Uint8 a; Uint8 a;
Uint32 amask; Uint32 amask;
if (calligraphy_r == r && if (calligraphy_r == r && calligraphy_g == g && calligraphy_b == b)
calligraphy_g == g &&
calligraphy_b == b)
return; return;
calligraphy_r = r; calligraphy_r = r;
@ -325,9 +325,7 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
if (calligraphy_colored_brush != NULL) if (calligraphy_colored_brush != NULL)
SDL_FreeSurface(calligraphy_colored_brush); SDL_FreeSurface(calligraphy_colored_brush);
amask = ~(calligraphy_brush->format->Rmask | amask = ~(calligraphy_brush->format->Rmask | calligraphy_brush->format->Gmask | calligraphy_brush->format->Bmask);
calligraphy_brush->format->Gmask |
calligraphy_brush->format->Bmask);
calligraphy_colored_brush = calligraphy_colored_brush =
SDL_CreateRGBSurface(SDL_SWSURFACE, SDL_CreateRGBSurface(SDL_SWSURFACE,
@ -335,8 +333,7 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
calligraphy_brush->h, calligraphy_brush->h,
calligraphy_brush->format->BitsPerPixel, calligraphy_brush->format->BitsPerPixel,
calligraphy_brush->format->Rmask, calligraphy_brush->format->Rmask,
calligraphy_brush->format->Gmask, calligraphy_brush->format->Gmask, calligraphy_brush->format->Bmask, amask);
calligraphy_brush->format->Bmask, amask);
if (calligraphy_colored_brush == NULL) if (calligraphy_colored_brush == NULL)
return; // FIXME: Error! return; // FIXME: Error!
@ -349,14 +346,10 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
{ {
for (x = 0; x < calligraphy_brush->w; x++) for (x = 0; x < calligraphy_brush->w; x++)
{ {
SDL_GetRGBA(api->getpixel(calligraphy_brush, x, y), SDL_GetRGBA(api->getpixel(calligraphy_brush, x, y), calligraphy_brush->format, &r, &g, &b, &a);
calligraphy_brush->format, &r, &g, &b, &a);
api->putpixel(calligraphy_colored_brush, x, y, api->putpixel(calligraphy_colored_brush, x, y,
SDL_MapRGBA(calligraphy_colored_brush->format, SDL_MapRGBA(calligraphy_colored_brush->format, calligraphy_r, calligraphy_g, calligraphy_b, a));
calligraphy_r,
calligraphy_g,
calligraphy_b, a));
} }
} }
@ -434,16 +427,19 @@ static void calligraphy_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D*
static float calligraphy_dist(float x1, float y1, float x2, float y2) static float calligraphy_dist(float x1, float y1, float x2, float y2)
{ {
float d; float d;
d = (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))); d = (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
return d; return d;
} }
void calligraphy_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void calligraphy_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void calligraphy_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void calligraphy_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }