Light: Support sizes

This commit is contained in:
Bill Kendrick 2023-04-20 23:31:28 -07:00
parent b9eb81708a
commit 4e54ad7704
2 changed files with 35 additions and 11 deletions

View file

@ -23,7 +23,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: February 12, 2023
Last updated: April 20, 2023
*/
#include <stdio.h>
@ -39,8 +39,12 @@
static Mix_Chunk *light1_snd, *light2_snd;
static float light_h, light_s, light_v;
static int light_radius = 8;
/* Function prototypes: */
Uint32 light_api_version(void);
int light_init(magic_api * api);
int light_init(magic_api * api, Uint32 disabled_features);
int light_get_tool_count(magic_api * api);
SDL_Surface *light_get_icon(magic_api * api, int which);
char *light_get_name(magic_api * api, int which);
@ -64,6 +68,9 @@ void light_switchin(magic_api * api, int which, int mode,
void light_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
int light_modes(magic_api * api, int which);
Uint8 light_accepted_sizes(magic_api * api, int which, int mode);
Uint8 light_default_size(magic_api * api, int which, int mode);
void light_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
Uint32 light_api_version(void)
@ -73,7 +80,7 @@ Uint32 light_api_version(void)
// No setup required:
int light_init(magic_api * api)
int light_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
@ -142,17 +149,17 @@ static void do_light(void *ptr, int which ATTRIBUTE_UNUSED,
float h, s, v, new_h, new_s, new_v;
float adj;
for (yy = -8; yy < 8; yy++)
for (yy = -light_radius; yy < light_radius; yy++)
{
for (xx = -8; xx < 8; xx++)
for (xx = -light_radius; xx < light_radius; xx++)
{
if (api->in_circle(xx, yy, 8))
if (api->in_circle(xx, yy, light_radius))
{
pix = api->getpixel(canvas, x + xx, y + yy);
SDL_GetRGB(pix, canvas->format, &r, &g, &b);
adj = (7.99 - sqrt(abs(xx * yy))) / 128.0;
adj = (((float) light_radius - 0.01) - sqrt(abs(xx * yy))) / (16.0 * (float) light_radius);
api->rgbtohsv(r, g, b, &h, &s, &v);
@ -214,10 +221,10 @@ void light_drag(magic_api * api, int which, SDL_Surface * canvas,
y = tmp;
}
update_rect->x = ox - 8;
update_rect->y = oy - 8;
update_rect->w = (x + 8) - update_rect->x;
update_rect->h = (y + 8) - update_rect->y;
update_rect->x = ox - light_radius;
update_rect->y = oy - light_radius;
update_rect->w = (x + light_radius) - update_rect->x;
update_rect->h = (y + light_radius) - update_rect->y;
api->playsound(light1_snd, (x * 255) / canvas->w, 255);
}
@ -278,3 +285,19 @@ int light_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
Uint8 light_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 4;
}
Uint8 light_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 2;
}
void light_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
light_radius = size * 4;
}