New magic tool: Pixels
Suitable for simple 'pixel art'. Draws 8x8 pixel rectangles on a grid across the canvas. Sound effect created via a small Atari BASIC program sampled in the open source 'Atari800' emulator (emulating the POKEY sound chip), and trimmed in Audacity.
This commit is contained in:
parent
0bb663de04
commit
4049b6cbbc
8 changed files with 239 additions and 6 deletions
|
|
@ -2,13 +2,17 @@ CHANGES.txt for Tux Paint
|
|||
|
||||
Tux Paint - A simple drawing program for children.
|
||||
|
||||
Copyright (c) 2002-2020
|
||||
Copyright (c) 2002-2021
|
||||
Various contributors (see below, and AUTHORS.txt)
|
||||
http://www.tuxpaint.org/
|
||||
|
||||
$Id$
|
||||
|
||||
2020.December.27 (0.9.26)
|
||||
2021.January.6 (0.9.26)
|
||||
* New Magic Tools:
|
||||
----------------
|
||||
* Pixels
|
||||
|
||||
* Documentation updates
|
||||
---------------------
|
||||
* Expanded the steps for making and posting releases.
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
A simple drawing program for children
|
||||
|
||||
Copyright 2002-2020 by various contributors; see AUTHORS.txt
|
||||
Copyright 2002-2021 by various contributors; see AUTHORS.txt
|
||||
http://www.tuxpaint.org/
|
||||
|
||||
June 14, 2002 - December 27, 2020
|
||||
June 14, 2002 - January 6, 2021
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@
|
|||
</h3>
|
||||
|
||||
<p>
|
||||
Copyright 2002-2020 by various contributors; see
|
||||
Copyright 2002-2021 by various contributors; see
|
||||
AUTHORS.txt<br>
|
||||
<a href=
|
||||
"http://www.tuxpaint.org/">http://www.tuxpaint.org/</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
June 14, 2002 - December 27, 2020
|
||||
June 14, 2002 - January 6, 2021
|
||||
</p>
|
||||
</center>
|
||||
|
||||
|
|
|
|||
BIN
magic/icons/pixels.png
Normal file
BIN
magic/icons/pixels.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
9
magic/magic-docs/en/html/pixels.html
Normal file
9
magic/magic-docs/en/html/pixels.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<body><html><head><title>Tux Paint "Magic" Tool: Pixels</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
|
||||
<h1 align="center">Tux Paint "Magic" Tool: Pixels</h1>
|
||||
<h2 align="center">By Bill Kendrick <<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>></h2>
|
||||
<p>This tool draws squares on the canvas in a grid, simulating large pixels seen on older computer displays, and allowing simple "pixel art" to be created in Tux Paint.</p>
|
||||
</body></html>
|
||||
7
magic/magic-docs/en/pixels.txt
Normal file
7
magic/magic-docs/en/pixels.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Tux Paint "Magic" Tool: Pixels
|
||||
|
||||
By Bill Kendrick <bill@newbreedsoftware.com>
|
||||
|
||||
This tool draws squares on the canvas in a grid, simulating large pixels
|
||||
seen on older computer displays, and allowing simple "pixel art" to be
|
||||
created in Tux Paint.
|
||||
BIN
magic/sounds/pixels.ogg
Normal file
BIN
magic/sounds/pixels.ogg
Normal file
Binary file not shown.
213
magic/src/pixels.c
Normal file
213
magic/src/pixels.c
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
pixels.c
|
||||
|
||||
Pixel art paintbrush Magic Tools Plugin
|
||||
Tux Paint - A simple drawing program for children.
|
||||
|
||||
Copyright (c) 2021 by Bill Kendrick and others; see AUTHORS.txt
|
||||
bill@newbreedsoftware.com
|
||||
http://www.tuxpaint.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
(See COPYING.txt)
|
||||
|
||||
Last updated: January 6, 2021
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum
|
||||
{
|
||||
TOOL_PIXELS,
|
||||
NUM_TOOLS
|
||||
};
|
||||
|
||||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk *pixel_snd;
|
||||
static Uint8 pixels_r, pixels_g, pixels_b;
|
||||
|
||||
|
||||
/* Local function prototype: */
|
||||
|
||||
int pixels_init(magic_api * api);
|
||||
Uint32 pixels_api_version(void);
|
||||
int pixels_get_tool_count(magic_api * api);
|
||||
SDL_Surface *pixels_get_icon(magic_api * api, int which);
|
||||
char *pixels_get_name(magic_api * api, int which);
|
||||
char *pixels_get_description(magic_api * api, int which, int mode);
|
||||
void pixels_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void pixels_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void pixels_release(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void pixels_shutdown(magic_api * api);
|
||||
void pixels_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int pixels_requires_colors(magic_api * api, int which);
|
||||
void pixels_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void pixels_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int pixels_modes(magic_api * api, int which);
|
||||
|
||||
// No setup required:
|
||||
int pixels_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/pixels.ogg", api->data_directory);
|
||||
pixel_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 pixels_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int pixels_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface *pixels_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/pixels.png", api->data_directory);
|
||||
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char *pixels_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* Both are named "Pixels", at the moment: */
|
||||
|
||||
return (strdup(gettext_noop("Pixels")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char *pixels_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (strdup(gettext_noop("Click and drag to draw large pixels.")));
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void do_pixels(void *ptr ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
SDL_Rect dest;
|
||||
int pixel_size;
|
||||
|
||||
pixel_size = 8;
|
||||
|
||||
dest.x = (x / pixel_size) * pixel_size;
|
||||
dest.y = (y / pixel_size) * pixel_size;
|
||||
dest.w = pixel_size;
|
||||
dest.h = pixel_size;
|
||||
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, pixels_r, pixels_g, pixels_b));
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void pixels_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_pixels);
|
||||
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = x - 64;
|
||||
update_rect->y = y - 64;
|
||||
update_rect->w = (ox + 128) - update_rect->x;
|
||||
update_rect->h = (oy + 128) - update_rect->h;
|
||||
|
||||
api->playsound(pixel_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
void pixels_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
pixels_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
void pixels_release(magic_api * api, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
api->stopsound();
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
void pixels_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (pixel_snd != NULL)
|
||||
Mix_FreeChunk(pixel_snd);
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void pixels_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
pixels_r = r;
|
||||
pixels_g = g;
|
||||
pixels_b = b;
|
||||
}
|
||||
|
||||
// Use colors:
|
||||
int pixels_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void pixels_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void pixels_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int pixels_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue