mirror of https://git.sr.ht/~kikoodx/sle
Level edition, tile picking and misc.
This is the first usable version of the project!
This commit is contained in:
parent
29f8bf2578
commit
b433b09f75
|
@ -6,6 +6,7 @@ include_directories(include)
|
|||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
src/mouse.c
|
||||
src/editing_area/main.c
|
||||
src/editing_area/level.c
|
||||
src/editing_area/draw.c
|
||||
|
@ -17,6 +18,7 @@ set(FLAGS
|
|||
-Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum
|
||||
-Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes
|
||||
-Wold-style-definition -Werror-implicit-function-declaration
|
||||
-Wformat-pedantic
|
||||
-Werror -pedantic -std=c90
|
||||
-Os)
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ static const int editor_window_height = 224 * EDITOR_SCALE;
|
|||
static const int draw_offset_x = -2 * EDITOR_SCALE;
|
||||
static const int draw_offset_y = -8 * EDITOR_SCALE;
|
||||
|
||||
#define PICKER_SCALE 1 /* don't change this yet! */
|
||||
#define PICKER_PADDING 4
|
||||
static const int picker_window_width =
|
||||
(TILE_WIDTH + PICKER_PADDING) * TILESET_WIDTH + PICKER_PADDING;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
void update_mouse_position(int *mouse_x, int *mouse_y, int max_x,
|
||||
int max_y);
|
|
@ -4,6 +4,7 @@
|
|||
#include "conf.h"
|
||||
#include "editing_area/draw.h"
|
||||
#include "editing_area/level.h"
|
||||
#include "mouse.h"
|
||||
#include "shared_data.h"
|
||||
#include <raylib.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -90,17 +91,8 @@ 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);
|
||||
|
||||
/* update mouse position */
|
||||
*mouse_x = GetMouseX();
|
||||
*mouse_y = GetMouseY();
|
||||
if (*mouse_x < 0)
|
||||
*mouse_x = 0;
|
||||
if (*mouse_y < 0)
|
||||
*mouse_y = 0;
|
||||
if (*mouse_x >= level.width)
|
||||
*mouse_x = level.width - 1;
|
||||
if (*mouse_y >= level.height)
|
||||
*mouse_y = level.height - 1;
|
||||
update_mouse_position(mouse_x, mouse_y, level.width - 1,
|
||||
level.height - 1);
|
||||
|
||||
/* set tile */
|
||||
if (left_click) {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "mouse.h"
|
||||
#include <raylib.h>
|
||||
|
||||
void update_mouse_position(int *mouse_x, int *mouse_y, int max_x,
|
||||
int max_y)
|
||||
{
|
||||
*mouse_x = GetMouseX();
|
||||
*mouse_y = GetMouseY();
|
||||
if (*mouse_x < 0)
|
||||
*mouse_x = 0;
|
||||
if (*mouse_y < 0)
|
||||
*mouse_y = 0;
|
||||
if (*mouse_x >= max_x)
|
||||
*mouse_x = max_x;
|
||||
if (*mouse_y >= max_y)
|
||||
*mouse_y = max_y;
|
||||
}
|
|
@ -2,24 +2,39 @@
|
|||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "conf.h"
|
||||
#include "mouse.h"
|
||||
#include "shared_data.h"
|
||||
#include "tile_picker/draw.h"
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <raylib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void init_mouse(void);
|
||||
static void update_mouse(int *mouse_x, int *mouse_y,
|
||||
struct SharedData *shared_data);
|
||||
|
||||
int tile_picker_main(int argc, char **argv,
|
||||
struct SharedData *shared_data)
|
||||
{
|
||||
int mouse_x;
|
||||
int mouse_y;
|
||||
Texture2D tileset;
|
||||
|
||||
/* initialize raylib */
|
||||
InitWindow(picker_window_width, picker_window_height,
|
||||
"SLE secondary window");
|
||||
SetTargetFPS(picker_target_fps);
|
||||
init_mouse();
|
||||
/* load textures */
|
||||
const Texture2D tileset = LoadTexture(argv[1]);
|
||||
tileset = LoadTexture(argv[1]);
|
||||
|
||||
/* only proceed if tileset is well loaded */
|
||||
if (tileset.width > 0) {
|
||||
while (!shared_data->end_child) {
|
||||
/* update */
|
||||
update_mouse(&mouse_x, &mouse_y, shared_data);
|
||||
|
||||
/* draw */
|
||||
BeginDrawing();
|
||||
|
||||
|
@ -38,3 +53,27 @@ int tile_picker_main(int argc, char **argv,
|
|||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static void init_mouse(void)
|
||||
{
|
||||
SetMouseOffset(-PICKER_PADDING, -PICKER_PADDING);
|
||||
SetMouseScale(
|
||||
1.0 / ((TILE_WIDTH + PICKER_PADDING) * PICKER_SCALE),
|
||||
1.0 / ((TILE_HEIGHT + PICKER_PADDING) * PICKER_SCALE));
|
||||
}
|
||||
|
||||
static void update_mouse(int *mouse_x, int *mouse_y,
|
||||
struct SharedData *shared_data)
|
||||
{
|
||||
const bool left_click = IsMouseButtonDown(0);
|
||||
const bool right_click = IsMouseButtonDown(1);
|
||||
|
||||
update_mouse_position(
|
||||
mouse_x, mouse_y,
|
||||
TILESET_MIN_WIDTH_PX + TILESET_WIDTH * PICKER_PADDING,
|
||||
TILESET_MIN_HEIGHT_PX + TILESET_HEIGHT * PICKER_PADDING);
|
||||
|
||||
/* set left button tile */
|
||||
if (left_click)
|
||||
shared_data->selected_tile = *mouse_x + *mouse_y * TILESET_WIDTH;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue