00001 #include "editor.h"
00002
00003 #define MIN_SIZE_X 5
00004 #define MIN_SIZE_Y 5
00005 #define MAX_SIZE_X 50 // Arbitrary, but to make sure it stays sane
00006 #define MAX_SIZE_Y 40
00007
00008 static long new_size_x, new_size_y;
00009
00010
00011 void enter_resize_state(void)
00012 {
00013 input_state = resize_state;
00014 new_size_x = current_map->width;
00015 new_size_y = current_map->height;
00016 draw_resize_dialog();
00017 }
00018
00019
00020 void draw_resize_dialog(void)
00021 {
00022 char buf[64];
00023 draw_rect(50, 30, 60, 15);
00024 sprintf(buf, "%lix%li", new_size_x, new_size_y);
00025 draw_string_font(buf, 80-DrawStrWidth(buf, F_8x10)/2, 32, F_8x10);
00026 }
00027
00028
00029 void resize_state(int key)
00030 {
00031 if(key == KEY_LEFT) {
00032 if(new_size_x > MIN_SIZE_X) {
00033 new_size_x--;
00034 draw_resize_dialog();
00035 }
00036 } else if(key == KEY_UP) {
00037 if(new_size_y > MIN_SIZE_Y) {
00038 new_size_y--;
00039 draw_resize_dialog();
00040 }
00041 } else if(key == KEY_RIGHT) {
00042 if(new_size_x < MAX_SIZE_X) {
00043 new_size_x++;
00044 draw_resize_dialog();
00045 }
00046 } else if(key == KEY_DOWN) {
00047 if(new_size_y < MAX_SIZE_Y) {
00048 new_size_y++;
00049 draw_resize_dialog();
00050 }
00051 } else if(key == KEY_ENTER) {
00052 adjust_map_size(new_size_x, new_size_y);
00053 enter_edit_state();
00054 } else if(key == KEY_ESC) {
00055 enter_edit_state();
00056 }
00057 }
00058
00059
00060 void adjust_map_size(int width, int height)
00061 {
00062 int xi, yi;
00063 int xmax, ymax;
00064
00065 map_square saved_data[current_map->height][current_map->width];
00066
00067 if(cursor_x >= width) move_cursor( width-cursor_x-1, 0, 0 );
00068 if(cursor_y >= height) move_cursor( 0, height-cursor_y-1, 0 );
00069
00070 xmax = current_map->width;
00071 ymax = current_map->height;
00072
00073 for(yi=0; yi<ymax; yi++)
00074 for(xi=0; xi<xmax; xi++) {
00075 saved_data[yi][xi] = current_map->t[yi][xi];
00076 }
00077
00078 if(xmax > width) xmax = width;
00079 if(ymax > height) ymax = height;
00080
00081 set_level_size(current_map_num, width, height);
00082
00083 for(yi=0; yi<ymax; yi++)
00084 for(xi=0; xi<xmax; xi++) {
00085 current_map->t[yi][xi] = saved_data[yi][xi];
00086 }
00087 }
00088
00089
00090 void clip_scroll_pos(void)
00091 {
00092 if(scroll_x + VIEWPORT_WIDTH >= current_map->width)
00093 scroll_x = current_map->width - VIEWPORT_WIDTH;
00094 if(scroll_y + VIEWPORT_HEIGHT >= current_map->height)
00095 scroll_y = current_map->height - VIEWPORT_HEIGHT;
00096 if(scroll_x < 0) scroll_x = 0;
00097 if(scroll_y < 0) scroll_y = 0;
00098 }