sle/src/editing_area/draw.c

56 lines
1.6 KiB
C

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#include "editing_area/draw.h"
#include "conf.h"
#include "editing_area/level.h"
#include "options.h"
#include <raylib.h>
#include <stdlib.h>
void level_draw(struct Level level, struct Options options,
Texture2D tileset)
{
int x;
int y;
for (x = 0; x < level.width; x += 1) {
for (y = 0; y < level.height; y += 1) {
const int tile_index = x + y * level.width;
/* if tile index is out of bound, skip */
if (tile_index >= level.width * level.height)
continue;
const Tile tile =
level.data[tile_index] - options.tile_first;
/* if tile is not in tileset, skip */
if ((!tile && !options.tile_first) ||
tile >= (Tile)options.tileset_width *
options.tileset_height)
continue;
const Rectangle tile_rect = {
(int)(tile % options.tileset_width) *
options.tile_width,
(int)(tile / options.tileset_width) *
options.tile_height,
options.tile_width, options.tile_height};
const Vector2 tile_pos = {
x * options.tile_width +
options.editor_draw_offset_x,
y * options.tile_height +
options.editor_draw_offset_y};
DrawTextureRec(tileset, tile_rect, tile_pos,
WHITE);
}
}
}
void editor_mouse_draw(struct Options options, int x, int y)
{
const int tx =
x * options.tile_width + options.editor_draw_offset_x;
const int ty =
y * options.tile_height + options.editor_draw_offset_y;
DrawRectangle(tx, ty, options.tile_width, options.tile_height,
OVERRING_TILE_COLOR);
}