Added grid support

master
bzt 2019-12-08 04:08:12 +01:00
parent 239cfc1ff0
commit c1d032d77a
9 changed files with 35 additions and 5 deletions

View File

@ -111,6 +111,7 @@ Main editor window:
| <kbd>Shift</kbd> + <kbd>V</kbd> | duplicate current Z layer |
| <kbd>Ctrl</kbd> + <kbd>V</kbd> | remove current Z layer |
| <kbd>B</kbd> | select brush (use geometric objects) |
| <kbd>N</kbd> | toggle grid |
| <kbd>M</kbd> / <kbd>Tab</kbd> | open block map, search all available blocks |
| <kbd>,</kbd> / <kbd>&lt;</kbd> | zoom out |
| <kbd>.</kbd> / <kbd>&gt;</kbd> | zoom in |

Binary file not shown.

Binary file not shown.

View File

@ -29,7 +29,7 @@
#include "main.h"
int dx = 0, dz = 0, cx = 0, cz = 0, ox = 0, oy = 0, up = 0, zoom = 128, zz = 0, zx = 0, zs = 0;
int dx = 0, dz = 0, cx = 0, cz = 0, ox = 0, oy = 0, up = 0, zoom = 128, zz = 0, zx = 0, zs = 0, grid = 1;
char dstr[32];
/**
@ -143,6 +143,24 @@ void edit_redraw(int full)
}
}
}
/* draw grid */
if(grid && zz > 4) {
k = (x0 * zoom / 128);
y = (y3 * zoom / 128);
for(z = -mx; z < mx; z++) {
for(x = -mx; x < mx; x++) {
dst.x = sx + zx * (x - z) + k;
dst.y = sy + zz * (z + x) + y;
for(i = 0; i < zx; i++) {
l = dst.y + ((i+1) * zz) / zx;
if(dst.x + i > 0 && dst.x + zl+zx < bg->w && l > 0 && l < bg->h) {
*((uint32_t*)((uint8_t*)bg->pixels + (dst.x + i)*4 + l * bg->pitch)) = theme[THEME_INPBG];
*((uint32_t*)((uint8_t*)bg->pixels + (dst.x + zl+zx-i+1)*4 + l * bg->pitch)) = theme[THEME_INPBG];
}
}
}
}
}
/* foreground, layers above */
memset(fg->pixels, 0, fg->pitch * fg->h);
mts_getbounds(0, NULL, NULL);
@ -313,6 +331,7 @@ void edit_key(SDL_Event *event)
status = blocks[nodes[currlayer][cz][cx].param0].name;
}
break;
case SDLK_n: grid ^= 1; break;
case SDLK_PLUS: case SDLK_EQUALS: mts_layerprob(+1); break;
case SDLK_MINUS: mts_layerprob(-1); break;
case SDLK_PAGEUP: if(currlayer < 255) currlayer++; break;

View File

@ -105,6 +105,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Flood fill",
"Paint with block",
"Scroll",
"Toggle grid",
"(for all the shortcuts, read docs/usage.md)"
},
{
@ -179,6 +180,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Kitöltés",
"Rajzolás",
"Szkrollozás",
"Rácsháló ki/be",
"(az összes gyorsbillentyűt lásd a docs/usage.md fájlban)"
},
{
@ -253,6 +255,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Inundación con bloque",
"Pintar con bloque",
"Voluta",
"Activar/deactivar cuadrícula",
"para todos los accesos directos, lea docs/usage.md",
},
{
@ -327,6 +330,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Remplir inondé avec un bloc",
"Peindre avec un bloc",
"Faire défiler",
"Basculer la grille",
"pour tous les raccourcis, lisez docs/usage.md",
},
{
@ -401,6 +405,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Fülle es mit Block",
"Malen Sie mit Block",
"Scrollen",
"Gitter umschalten",
"Lesen Sie für alle Verknüpfungen docs/usage.md",
},
{
@ -475,6 +480,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Wypełnienie blokiem",
"Maluj blokiem",
"Zwój",
"Przełącz siatkę",
"dla wszystkich skrótów przeczytaj docs/usage.md",
},
{
@ -549,6 +555,7 @@ char *dict[NUMLANGS][NUMTEXTS + 1] = {
"Заливка с блоком",
"Краска с блоком",
"Манускрипт",
"Переключить сетку",
"для всех ярлыков, прочитайте docs/usage.md",
}

View File

@ -98,6 +98,7 @@ enum {
FILL,
PAINT,
SCROLL,
GRID,
HELP,
/* must be the last */

View File

@ -100,8 +100,8 @@ typedef struct {
} mtsblock_t;
extern int numpalettes, lenpalettes, palette[16], strmaxw, strsep, savelen, savepos, savepal, savebiome, numresults, *results;
extern int currlayer, gndlayer, mts_x, mts_y, mts_z, mix, miy, miz, max, may, maz, bound_valid, dx, dz, cx, cz, ox, oy, up;
extern int zx, zz, zs, shift, ctrl, activetool, activeblock, quitting, verbose, x0, x1, y0, y1, brush_type, brush_hollow, zoom;
extern int currlayer, gndlayer, mts_x, mts_y, mts_z, mix, miy, miz, max, may, maz, bound_valid, dx, dz, cx, cz, ox, oy, up, zoom;
extern int zx, zz, zs, shift, ctrl, activetool, activeblock, quitting, verbose, x0, x1, y0, y1, y3, brush_type, brush_hollow;
extern char **palettes, layerprob[256];
extern int numblocks;
extern mtsblock_t *blocks;

View File

@ -69,6 +69,7 @@ help_t helpkeys[] = {
{ UNDO, " Z " },
{ REDO, " Y " },
{ BRUSH, " B " },
{ GRID, " N " },
{ GROUNDLEVEL, " G " },
{ LAYERUP, " PgUp " },
{ LAYERDOWN, " PgDn " },
@ -125,6 +126,7 @@ void sdlhelp()
rect.h = ((int)(sizeof(helpkeys)/sizeof(helpkeys[0])) + 1) * (font->height + 4) + 8;
rect.x = (screen->w - rect.w)/2;
rect.y = (screen->h - rect.h)/2;
if(rect.x < 0 || rect.y < 0) { help = 0; return; }
SDL_FillRect(screen, &rect, theme[THEME_BG]);
rect.x += 4; rect.y += 4; strmaxw = rect.x + rect.w - 8;
@ -423,7 +425,7 @@ int sdlmain(int opt)
/* mouse events */
case SDL_MOUSEMOTION:
i = j = -1; status = NULL;
i = j = -1; status = NULL; help = 0;
if(event.motion.x >= 36 && event.motion.y < screen->h - (int)font->height &&
activetool == -1 && SDL_GetCursor() != working) {
if(systemcursor) SDL_ShowCursor(0);

View File

@ -680,7 +680,7 @@ int savepng(char *name, int num, SDL_Surface *src)
free(say);
/* save png */
#if 1
#if 0
img = (unsigned char *)stbi_write_png_to_mem(src->pixels, src->pitch, src->w, src->h, 4, &l);
#else
img = (unsigned char *)stbi_write_png_to_mem(dst->pixels, dst->pitch, dst->w, dst->h, 4, &l);