~kikoodx/sle

ab6ae281f88d40e4fee34298f8b97cff918265e0 — KikooDX 2 years ago 118d976 0.5.0
feature: rectangle fill
3 files changed, 39 insertions(+), 10 deletions(-)

M README
M meson.build
M src/editing_area/main.c
M README => README +3 -0
@@ 40,6 40,9 @@ Left click: draw with selected tile
Right click: erase (tile 0)
Middle click: pick a tile

Click on a first tile while holding nothing, then click on another tile
holding Left Control and the area between the two points will be filled.

Secondary window - Tile Picker
------------------------------
Left click on the tile you want to select.

M meson.build => meson.build +2 -4
@@ 1,11 1,9 @@
project('sle', 'c',
	version : '0.4.0',
	license : 'GPL-3.0-or-later')
raylibdep = dependency('raylib', version: '>=3.5.0')
raylibdep = dependency('raylib', version: '>=4.0.0')

cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required: true)
dl_dep = cc.find_library('dl', required: true)

inc = include_directories('include')



@@ 43,6 41,6 @@ c_flags = [
executable('sle',
	sources,
	include_directories : inc,
	dependencies : [raylibdep, dl_dep, m_dep],
	dependencies : [raylibdep],
	install : true,
	c_args : c_flags)

M src/editing_area/main.c => src/editing_area/main.c +34 -6
@@ 16,9 16,13 @@
#include <stdlib.h>
#include <sys/wait.h>

static int mark_x = -1;
static int mark_y = -1;

static void init_mouse(struct Options options);
static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
                         struct SharedData *shared_data);
static void set_tile(struct Level, int x, int y, int v);

int editing_area_main(struct Options options,
                      struct SharedData *shared_data)


@@ 129,17 133,36 @@ static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
	const bool left_click = IsMouseButtonDown(0);
	const bool right_click = IsMouseButtonDown(1);
	const bool middle_click = IsMouseButtonPressed(2);
	const bool k_lctrl = IsKeyDown(KEY_LEFT_CONTROL);

	update_mouse_position(mouse_x, mouse_y, level.width - 1,
	                      level.height - 1);

	/* set tile */
	if (left_click)
		level.data[*mouse_x + *mouse_y * level.width] =
		    shared_data->selected_tile;
	/* remove tile */
	if (right_click)
		level.data[*mouse_x + *mouse_y * level.width] = 0;
	if ((left_click || right_click) && k_lctrl && mark_x != -1) {
		const int x1 = (mark_x < *mouse_x) ? mark_x : *mouse_x;
		const int y1 = (mark_y < *mouse_y) ? mark_y : *mouse_y;
		const int x2 = (mark_x > *mouse_x) ? mark_x : *mouse_x;
		const int y2 = (mark_y > *mouse_y) ? mark_y : *mouse_y;
		const int v =
		    left_click ? shared_data->selected_tile : 0;
		int x, y;
		for (x = x1; x <= x2; x++)
			for (y = y1; y <= y2; y++)
				set_tile(level, x, y, v);
		mark_x = *mouse_x;
		mark_y = *mouse_y;
	} else if (left_click) {
		mark_x = *mouse_x;
		mark_y = *mouse_y;
		set_tile(level, *mouse_x, *mouse_y,
		         shared_data->selected_tile);
	} else if (right_click) {
		mark_x = *mouse_x;
		mark_y = *mouse_y;
		set_tile(level, *mouse_x, *mouse_y, 0);
	}

	/* set tile to pointed cell (pick tile) */
	if (middle_click) {
		INFO_VAR("%d",


@@ 148,3 171,8 @@ static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
		    level.data[*mouse_x + *mouse_y * level.width];
	}
}

static void set_tile(struct Level l, int x, int y, int v)
{
	l.data[x + y * l.width] = v;
}