Overview
Comment: | Add drawing ellipses into picture editor |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
38ac4dd10f9534e42b5958b9834a124c |
User & Date: | user on 2021-01-18 23:27:52 |
Other Links: | manifest | tags |
Context
2021-01-19
| ||
02:43 | Implement import/export in the picture editor. check-in: a5ef9613c5 user: user tags: trunk | |
2021-01-18
| ||
23:27 | Add drawing ellipses into picture editor check-in: 38ac4dd10f user: user tags: trunk | |
06:04 | Add rotation and add/delete pictures commands into the picture editor. Also correct the maximum number of picture variants. check-in: bf1d25458b user: user tags: trunk | |
Changes
Modified picedit.c from [665be25639] to [14fb1e6db2].
︙ | ︙ | |||
291 292 293 294 295 296 297 298 299 300 301 302 303 304 | static void fill_circle(Uint8*p,Uint8 s,Uint8 x0,Uint8 y0,Uint32 r,Uint8 c) { int x,y; for(y=0;y<s;y++) for(x=0;x<s;x++) { if((x-x0)*(x-x0)+(y-y0)*(y-y0)<=r) p[y*s+x]=c; } } static inline void edit_picture_1(Picture**pict,const char*name) { static const Uint8 shade[64]= "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | static void fill_circle(Uint8*p,Uint8 s,Uint8 x0,Uint8 y0,Uint32 r,Uint8 c) { int x,y; for(y=0;y<s;y++) for(x=0;x<s;x++) { if((x-x0)*(x-x0)+(y-y0)*(y-y0)<=r) p[y*s+x]=c; } } static void draw_ellipse(Uint8*p,Uint8 s,Uint8 x0,Uint8 y0,Uint8 x1,Uint8 y1,Uint8 c) { double cx,cy,rx,ry,v; int x,y; if(x1<x0) x=x1,x1=x0,x0=x; if(y1<y0) y=y1,y1=y0,y0=y; cx=0.5*(x1+x0); cy=0.5*(y1+y0); rx=0.5*(x1-x0); ry=0.5*(y1-y0); for(y=y0;y<=y1;y++) { v=(y-cy)/ry; v*=v; if(v>1.0) continue; v=rx*sqrt(1.0-v); x=round(cx-v); if(x>=0 && x<s) p[y*s+x]=c; x=round(cx+v); if(x>=0 && x<s) p[y*s+x]=c; } for(x=x0;x<=x1;x++) { v=(x-cx)/rx; v*=v; if(v>1.0) continue; v=ry*sqrt(1.0-v); y=round(cy-v); if(y>=0 && y<s) p[y*s+x]=c; y=round(cy+v); if(y>=0 && y<s) p[y*s+x]=c; } } static void fill_ellipse(Uint8*p,Uint8 s,Uint8 x0,Uint8 y0,Uint8 x1,Uint8 y1,Uint8 c) { double cx,cy,rx,ry; int x,y; if(x1<x0) x=x1,x1=x0,x0=x; if(y1<y0) y=y1,y1=y0,y0=y; cx=0.5*(x1+x0); cy=0.5*(y1+y0); rx=0.5*(x1-x0); ry=0.5*(y1-y0); for(y=y0;y<=y1;y++) for(x=x0;x<=x1;x++) { if(pow((x-cx)/rx,2.0)+pow((y-cy)/ry,2.0)<=1.0) p[y*s+x]=c; } } static inline void edit_picture_1(Picture**pict,const char*name) { static const Uint8 shade[64]= "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" |
︙ | ︙ | |||
487 488 489 490 491 492 493 | case 2: // Pick i=pict[sel]->data[(y+1)*pict[sel]->size+x]; goto pick; case 3: // Line if((i&2) && xx!=-1) draw_line(pict[sel]->data+pict[sel]->size,pict[sel]->size,x,y,xx,yy,cc); if(i&1) xx=x,yy=y; break; | | | | > > > > > > > > > > > > > > > | 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | case 2: // Pick i=pict[sel]->data[(y+1)*pict[sel]->size+x]; goto pick; case 3: // Line if((i&2) && xx!=-1) draw_line(pict[sel]->data+pict[sel]->size,pict[sel]->size,x,y,xx,yy,cc); if(i&1) xx=x,yy=y; break; case 4: // Rectangle if(i==1) { xx=x; yy=y; } else if(xx!=-1) { p=pict[sel]->data+(j=pict[sel]->size); if(xx<x) i=x,x=xx,xx=i; if(yy<y) i=y,y=yy,yy=i; memset(p+y*j+x,cc,xx+1-x); memset(p+yy*j+x,cc,xx+1-x); while(y<yy) p[y*j+x]=p[y*j+xx]=cc,y++; xx=yy=-1; } break; case 5: // Fill rectangle if(i==1) { xx=x; yy=y; } else if(xx!=-1) { p=pict[sel]->data+(j=pict[sel]->size); if(xx<x) i=x,x=xx,xx=i; if(yy<y) i=y,y=yy,yy=i; while(y<yy) memset(p+y*j+x,cc,xx+1-x),y++; xx=yy=-1; } break; case 6: // Circle if(i==1) { xx=x; yy=y; } else if(i==2) { draw_circle(pict[sel]->data+pict[sel]->size,pict[sel]->size,x,y,(x-xx)*(x-xx)+(y-yy)*(y-yy),cc); } else if(i==3) { draw_circle(pict[sel]->data+pict[sel]->size,pict[sel]->size,xx,yy,(x-xx)*(x-xx)+(y-yy)*(y-yy),cc); } break; case 7: // Fill circle if(i==1) { xx=x; yy=y; } else if(i==2) { fill_circle(pict[sel]->data+pict[sel]->size,pict[sel]->size,x,y,(x-xx)*(x-xx)+(y-yy)*(y-yy),cc); } else if(i==3) { fill_circle(pict[sel]->data+pict[sel]->size,pict[sel]->size,xx,yy,(x-xx)*(x-xx)+(y-yy)*(y-yy),cc); } break; case 8: // Ellipse if(i==1) { xx=x; yy=y; } else if(xx!=-1) { draw_ellipse(pict[sel]->data+pict[sel]->size,pict[sel]->size,x,y,xx,yy,cc); } break; case 9: // Fill ellipse if(i==1) { xx=x; yy=y; } else if(xx!=-1) { fill_ellipse(pict[sel]->data+pict[sel]->size,pict[sel]->size,x,y,xx,yy,cc); draw_ellipse(pict[sel]->data+pict[sel]->size,pict[sel]->size,x,y,xx,yy,cc); } break; } goto redraw; } break; case SDL_KEYDOWN: switch(ev.key.keysym.sym) { |
︙ | ︙ |
Modified picedit.doc from [47704e2e89] to [a51d4def0a].
︙ | ︙ | |||
142 143 144 145 146 147 148 | Filled circle (I) Click the left button at the centre of the circle and the right button at the radius, or you can click the left button at the radius and the middle button at the centre. Hollow ellipse (E) | | > | > | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | Filled circle (I) Click the left button at the centre of the circle and the right button at the radius, or you can click the left button at the radius and the middle button at the centre. Hollow ellipse (E) Click the left button on one corner of the bounding rectangle of the ellipse, and then click the middle or right button on the other side. Filled ellipse (S) Click the left button on one corner of the bounding rectangle of the ellipse, and then click the middle or right button on the other side. |