home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / applications / xlispstat / src / src1.lzh / Amiga / amiresizebrush.c < prev    next >
C/C++ Source or Header  |  1990-10-11  |  5KB  |  129 lines

  1. /* AmiResizeBrush.c - Low Level Objects for Amiga                      */
  2. /* Copyright (c) 1990 by J.K. Lindsey                                  */
  3. /* Additions to XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney     */
  4. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  5. /* You may give out copies of this software; for conditions see the    */
  6. /* file COPYING included with this distribution.                       */
  7.  
  8. #define _IVIEWWINDOW_
  9. #include <proto/intuition.h>
  10. #include <proto/exec.h>
  11. #include <proto/graphics.h>
  12. #include <graphics/gfxmacros.h>
  13. #include "autil2.h"
  14. #include "xlisp.h"
  15. #include "osdef.h"
  16. #include "xlproto.h"
  17. #include "xlsproto.h"
  18. #include "iviewproto.h"
  19. #include "amivar.h"
  20.  
  21. #define WW 350
  22. #define WH 300
  23.  
  24. static struct {
  25.    int left,width;
  26.    int top,height;}
  27. oldBrush,brush;
  28. static short xy[18]={2,-2,78,-2,82,2,82,18,78,22,2,22,-2,18,-2,2,2,-2};
  29. static struct Border bd1={0,0,BLACK,WHITE,JAM1,9,xy,0},
  30.                      bd2={0,0,BLACK,WHITE,JAM1,9,xy,0};
  31. static struct IntuiText itext1={BLACK,WHITE,JAM1, 32,6,0,"OK",0},
  32.                         itext2={BLACK,WHITE,JAM1, 16,6,0,"Cancel",0},
  33.                         rmess2={BLACK,WHITE,JAM1, 59,25,0,"click in this window and drag",0},
  34.                         rmess1={BLACK,WHITE,JAM1,115,15,0,"To resize brush",&rmess2};
  35. static struct Gadget CancelButton={
  36.    0            ,230,WH-30,80,20,GADGHCOMP,RELVERIFY,BOOLGADGET,(APTR)&bd2,0,&itext2,0,0,1,0},
  37.                      OKButton={
  38.    &CancelButton, 40,WH-30,80,20,GADGHCOMP,RELVERIFY,BOOLGADGET,(APTR)&bd1,0,&itext1,0,0,0,0};
  39. static struct Window *wind;
  40. static struct RastPort *rp;
  41.  
  42. static void setup_window(void){
  43.    wind=MakeWind(150,50,WW,WH,WHITE,BLACK,MOUSEBUTTONS|GADGETUP,WINDOWDRAG
  44.    |SMART_REFRESH|ACTIVATE|WINDOWDEPTH|NOCAREREFRESH|SIZEBBOTTOM,
  45.    &OKButton,0,"Brush Resizer",screen,0,0,0,0,0,screentype);
  46.    if(!wind)xlfail("window creation failed");
  47.    rp=wind->RPort;
  48.    PrintIText(rp,&rmess1,0,0);
  49.    SetAPen(rp,BLACK);
  50.    SetDrMd(rp,COMPLEMENT);
  51.    SetDrPt(wind->RPort,0x5555);
  52.    RefreshGList(&OKButton,wind,0,-1);}
  53.  
  54. static void DrawBrush(void){
  55.    static short xy[10]={0,0,0,0,0,0,0,0,0,0};
  56.    static struct Border bd={0,0,BLACK,WHITE,COMPLEMENT,5,xy,0};
  57.    xy[2]=xy[4]=brush.width;
  58.    xy[5]=xy[7]=brush.height;
  59.    bd.TopEdge=brush.top;
  60.    bd.LeftEdge=brush.left;
  61.    DrawBorder(rp,&bd,0,0);}
  62.  
  63. static int event_loop(void){
  64.    int done=0,x,y,ox,oy;
  65.    unsigned long class;
  66.    unsigned short code;
  67.    struct Gadget *address;
  68.    struct IntuiMessage *message;
  69.    int cancelled;
  70.    cancelled=1;
  71.    do {
  72.       Wait(1<<wind->UserPort->mp_SigBit);
  73.       if(message=(struct IntuiMessage *)GetMsg(wind->UserPort)){
  74.          class=message->Class;
  75.          code=message->Code;
  76.          address=(struct Gadget *)message->IAddress;
  77.          ReplyMsg((struct Message *)message);
  78.          ox=wind->MouseX;
  79.          oy=wind->MouseY;
  80.          switch(class) {
  81.             case MOUSEBUTTONS: {
  82.                if(code==SELECTDOWN&&ox>3+brush.width&&ox<347&&oy>35+brush.height&&oy<WH-30){
  83.                   if(cancelled)cancelled=0;
  84.                   else DrawBrush();           /* if old brush, erase */
  85.                   brush.left=ox-brush.width;
  86.                   brush.top=oy-brush.height;
  87.                   DrawBrush();
  88.                   for(;;){
  89.                      if(message=(struct IntuiMessage *)GetMsg(wind->UserPort)){
  90.                         class=message->Class;
  91.                         code=message->Code;
  92.                         ReplyMsg((struct Message *)message);
  93.                         if(class==MOUSEBUTTONS&&code==SELECTUP)break;}
  94.                      x=wind->MouseX;
  95.                      y=wind->MouseY;
  96.                      if(x<=0||x>=wind->Width||y<=0||y>=wind->Height)break;
  97.                      if(x>3&&x<347&&y>35&&y<WH-30){
  98.                         DrawBrush();                /* to erase */
  99.                         brush.width+=x-ox;
  100.                         brush.height+=y-oy;
  101.                         DrawBrush();                /* to redraw */
  102.                         ox=x;
  103.                         oy=y;}}}
  104.                break;}
  105.             case GADGETUP: {
  106.                if(address->GadgetID){
  107.                   brush=oldBrush;
  108.                   cancelled=1;}
  109.                done=TRUE;
  110.                break;}}}}
  111.    while(!done);
  112.    return(cancelled);}
  113.  
  114. IViewGetNewBrushSize(IVIEW_WINDOW w,int *new_width,int *new_height){
  115.    int left,top,width,height,cancelled;
  116.    IViewGetBrush(w,&left,&top,&width,&height);
  117.    oldBrush.left=left;
  118.    oldBrush.top=top;
  119.    oldBrush.width=width;
  120.    oldBrush.height=height;
  121.    brush.width=width;
  122.    brush.height=height;
  123.    setup_window();
  124.    cancelled=event_loop();
  125.    CloseWindow(wind);
  126.    if(new_width)*new_width=brush.width;
  127.    if(new_height)*new_height=brush.height;
  128.    return(!cancelled);}
  129.