#include "asset.h" #include "editor.h" #include "gui.h" #include "map.h" #include "plat.h" #include "render.h" #define tile_display_size 32 static GUI_Scroll_State map_ss = { 0 }; void draw_map_scrollable( GUI* g, Renderer* r, const Rect* rect, const GUI_Scroll_State* ss ) { const Map* m = g->uptr; const Map_Tile* tiles = map_tilesc(m); int x, y; Rect re = { 0 }; re.w = tile_display_size; re.h = tile_display_size; for (y = 0; y < m->h; y++) { for (x = 0; x < m->w; x++) { re.x = rect->x + x * tile_display_size - ss->x; re.y = rect->y + y * tile_display_size - ss->y; if (tiles[x + y * m->w]) ren_texture( r, &re, get_texture(asset_id_brick_texture) ); else ren_rect( r, make_black(), &re ); } } x = (g->app->mx - rect->x) / tile_display_size; y = (g->app->my - rect->y) / tile_display_size; if ( x >= 0 && y >= 0 && x < m->w && y < m->h ) { re.x = x * tile_display_size + rect->x; re.y = y * tile_display_size + rect->y; ren_rect( r, make_colour(0xffffff, 120), &re ); } } void edit_map(Editor* e, GUI* g, Map* m) { Rect b = gui_viewport(g); Rect t = gui_cut_up(&b, gui_text_height() + 4); int mcs[2]; (void)e; mcs[0] = m->w * tile_display_size; mcs[1] = m->h * tile_display_size; gui_btn(g, gui_cut_left(&t, gui_text_width("Load", 4) + 4), "Save"); gui_btn(g, gui_cut_left(&t, gui_text_width("Save", 4) + 4), "Load"); if (gui_btn(g, gui_cut_left(&t, gui_text_width("Bake Lights", 11) + 4), "Bake Lights")) { bake_map(m); } g->uptr = m; gui_scrollable(g, b, mcs, &map_ss, draw_map_scrollable); }