Main Page | Alphabetical List | Class List | File List | Class Members | File Members

editor/edit.c

Go to the documentation of this file.
00001 #include "editor.h"
00002 
00003 //map_field clipboard;
00004 map_square clipboard[40][40]; // FIXMEFIXME: Needs to be variably sized
00005 int clipboard_x=0, clipboard_y=0;
00006 
00007 //{{{
00008 void get_selected_region(int *top, int *left, int *right, int *bottom)
00009 {
00010     if(cursor_x==select_x && cursor_y==select_y) // If no selection, operate
00011                                                  // on the whole map
00012     {
00013         *top = *left = 0;
00014         *right = FIELD_WIDTH-1;
00015         *bottom = FIELD_HEIGHT-1;
00016     } else {
00017         *top = min(cursor_y, select_y);
00018         *bottom = max(cursor_y, select_y);
00019         *left = min(cursor_x, select_x);
00020         *right = max(cursor_x, select_x);
00021     }
00022 }
00023 //}}}
00024 
00025 //{{{
00026 void edit_cut(void)
00027 {
00028     int top, bottom, left, right;
00029     int xi, yi;
00030     
00031     get_selected_region(&top, &left, &right, &bottom);
00032     
00033     clipboard_y = bottom-top+1;
00034     clipboard_x = right-left+1;
00035     for(yi=top; yi<=bottom; yi++)
00036     for(xi=left; xi<=right; xi++) {
00037         clipboard[yi-top][xi-left] = current_map->t[yi][xi];
00038         current_map->t[yi][xi] = TILE_EMPTY;
00039     }
00040 }
00041 //}}}
00042 //{{{
00043 void edit_copy(void)
00044 {
00045     int top, bottom, left, right;
00046     int xi, yi;
00047     
00048     get_selected_region(&top, &left, &right, &bottom);
00049     
00050     clipboard_y = bottom-top+1;
00051     clipboard_x = right-left+1;
00052     for(yi=top; yi<=bottom; yi++)
00053     for(xi=left; xi<=right; xi++)
00054         clipboard[yi-top][xi-left] = current_map->t[yi][xi];
00055 }
00056 //}}}
00057 //{{{
00058 void edit_paste(void)
00059 {
00060     int xi, yi;
00061     for(yi=0; yi<clipboard_y; yi++)
00062     for(xi=0; xi<clipboard_x; xi++)
00063     {
00064         if(yi+cursor_y>=FIELD_HEIGHT || xi+cursor_x>=FIELD_WIDTH)
00065             continue;
00066         current_map->t[yi+cursor_y][xi+cursor_x] = clipboard[yi][xi];
00067     }
00068 }
00069 //}}}
00070 //{{{
00071 void edit_clear(void)
00072 {
00073     int top, bottom, left, right;
00074     int xi, yi;
00075     
00076     get_selected_region(&top, &left, &right, &bottom);
00077     
00078     for(yi=top; yi<=bottom; yi++)
00079     for(xi=left; xi<=right; xi++)
00080         current_map->t[yi][xi] = TILE_EMPTY;
00081 }
00082 //}}}
00083 //{{{
00084 void edit_select_all(void)
00085 {
00086     select_x = select_y = 0;
00087     cursor_x = FIELD_WIDTH-1;
00088     cursor_y = FIELD_HEIGHT-1;
00089 }
00090 //}}}
00091 
00092 

Generated on Thu Apr 22 14:06:32 2004 for SKye by doxygen 1.3.6