diff options
| author | Cracker64 <cracker642@gmail.com> | 2010-12-16 05:17:08 (GMT) |
|---|---|---|
| committer | Cracker64 <cracker642@gmail.com> | 2010-12-16 05:17:08 (GMT) |
| commit | 327ccb7bbae1923b98ff8db8d87b2f649afd7d35 (patch) | |
| tree | 780474c5170c6ec2bb8e0aa921ec221be0da9f00 /src | |
| parent | 5b2c6893941cc04bbe80f74b8ea35a744b0164cc (diff) | |
| download | powder-327ccb7bbae1923b98ff8db8d87b2f649afd7d35.zip powder-327ccb7bbae1923b98ff8db8d87b2f649afd7d35.tar.gz | |
a rotate tool! ctrl-r, then select the area, it will rotate counterclockwise, no properties are saved right now, it deletes and recreates.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 26 | ||||
| -rw-r--r-- | src/powder.c | 55 |
2 files changed, 77 insertions, 4 deletions
@@ -1463,8 +1463,6 @@ int main(int argc, char *argv[]) } if(sdl_key=='d') DEBUG_MODE = !DEBUG_MODE; - if(sdl_key=='r') - GENERATION = 0; if(sdl_key=='i') { int nx, ny; @@ -1512,6 +1510,13 @@ int main(int argc, char *argv[]) } } } + if(sdl_key=='r'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))) + { + save_mode = 1; + copy_mode = 3;//rotate + } + else if(sdl_key=='r') + GENERATION = 0; if(sdl_key=='x'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))) { save_mode = 1; @@ -1868,6 +1873,14 @@ int main(int argc, char *argv[]) copy_mode = 0; clear_area(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); } + else if(copy_mode==3)//rotation + { + if(save_h>save_w) + save_w = save_h; + rotate_area(save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL);//just do squares for now + save_mode = 0; + copy_mode = 0; + } else { stamp_save(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); @@ -2148,7 +2161,14 @@ int main(int argc, char *argv[]) if(save_mode) { - xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); + if(copy_mode==3)//special drawing for rotate, can remove once it can do rectangles + { + if(save_h>save_w) + save_w = save_h; + xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL); + } + else + xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); da = 51; db = 269; } diff --git a/src/powder.c b/src/powder.c index 1ba31f9..be6735a 100644 --- a/src/powder.c +++ b/src/powder.c @@ -4918,6 +4918,56 @@ void update_particles(pixel *vid) } +void rotate_area(int area_x, int area_y, int area_w, int area_h) +{ + int cx = 0; + int cy = 0; + char tpmap[area_h][area_w]; + char rtpmap[area_w][area_h]; + unsigned char tbmap[area_h][area_w]; + unsigned char rtbmap[area_h][area_w]; + for(cy=0; cy<area_h; cy++) + { + for(cx=0; cx<area_w; cx++) + { + if(area_x + cx<XRES&&area_y + cy<YRES) + bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0; + //tbmap[cy][cx] = bmap[(cy+area_y)/CELL][(cx+area_x)/CELL];//does not do walls right now, very glitchy + } + } + for(cy=0; cy<area_h; cy++) + { + for(cx=0; cx<area_w; cx++) + { + if((area_x + cx<XRES&&area_y + cy<YRES) && !bmap[(cy+area_y)/CELL][(cx+area_x)/CELL]) + { + tpmap[cy][cx] = pmap[(int)(cy+area_y+0.5f)][(int)(cx+area_x+0.5f)]&0xFF; + delete_part(cx+area_x, cy+area_y); + } + else + tpmap[cy][cx] = 0; + } + } + for(cy=0; cy<area_w; cy++) + { + for(cx=0; cx<area_h; cx++) + { + //rtbmap[(area_h-1)-cx][cy] = tbmap[cy][cx]; + rtpmap[(area_h-1)-cx][cy] = tpmap[cy][cx]; + } + } + for(cy=0; cy<area_w; cy++) + { + for(cx=0; cx<area_h; cx++) + { + //bmap[area_y+cy][area_x+cx] = rtbmap[cy][cx]; + if(area_x + cx<XRES&&area_y + cy<YRES) + if(rtpmap[cy][cx]>0&&rtpmap[cy][cx]<PT_NUM) + create_part(-1,area_x + cx,area_y + cy,rtpmap[cy][cx]); + } + } +} + void clear_area(int area_x, int area_y, int area_w, int area_h) { int cx = 0; @@ -5152,7 +5202,10 @@ int create_parts(int x, int y, int rx, int ry, int c) for(j=-ry; j<=ry; j++) for(i=-rx; i<=rx; i++) if((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) - create_part(-2, x+i, y+j, c); + if(!REPLACE_MODE) + create_part(-2, x+i, y+j, c); + else if((pmap[y+j][x+i]&0xFF)==SLALT&&SLALT!=0) + create_part(-2, x+i, y+j, c); return 1; } |
