[comp.sys.amiga] PropGadget usage

theo@xenlink.UUCP (Theo deRaadt) (03/02/88)

I am in desperate need of a some source that will show me how to make
a SuperBitMap window move under the control of PropGadgets. I have
written the basis of my doodle program in assembly already, and would
really like to see some code of how to use these. All previous attempts
at handling these have done really weird things. All that I need is
to see how to read the values, set them correctly on a resize, and
move the SuperBitMap with the delta values set correctly.
Thanks a lot for any help.
 <tdr.

              -^-                  -^-
               O  _              _  O
               |==*              *==|
              /|  !              !  /\
==================!==============!====================================
======= Caution! Hard Hat Area. .signature under construction. =======
======================================================================

kenchiu@phoenix.Princeton.EDU (Kenneth Chiu) (03/05/88)

Someone wanted some code examples on using a SuperBitMap scrolled under
gadget control.  This is not *exactly* that, but is pretty close.  It is
called when you receive a select down message, or gadget hit message.  It
then responds to *relative* mouse move messages, until some other kind
of message is received.  It's in C, and the original author was using
assembly, but I assume this is just as good for illustration.

Trying to get all the signs right is very confusing, and it'll probably
be quicker to not try to figure out my signs, and just fix yours by
observation.

Note that for some reason Intuition doesn't seem to adjust the gadget
positions in respect to the scroll values.  So you have to do this yourself,
and that is what the function at the end does.

Also note that to permit resizing, you have to fiddle with the limits some
to make sure the user doesn't expand the window past the boundaries of the
bitmap.

Please report any problems you see with this code.


void
ShiftWin(w)
struct Window *w;
{
    struct IntuiMessage *m;
    struct Layer *l;
    int bm_width, bm_height;
    int dx, dy;
    int old_scroll_x, old_scroll_y;
    Boolean go;

    l = w->WLayer;
    bm_width = WD(w)->IntWidth;
    bm_height = WD(w)->IntHeight;
    old_scroll_x = l->Scroll_X;
    old_scroll_y = l->Scroll_Y;

    for (go = T; go;) {

        WaitPort(window_port);

        dx = dy = 0;

        /* collect as many mouse messages as we can get */

        while (go && (m = (struct IntuiMessage *) GetMsg(window_port))) {

            if (m->Class == MOUSEMOVE && m->IAddress == w) {

                dx -= m->MouseX;
                dy -= m->MouseY;
                ReplyMsg(m);

            } else {

                /* turn off mouse messages */
                Forbid(); w->Flags &= ~REPORTMOUSE; Permit();
                if ((m->Class & MOUSEBUTTONS) && m->Code == MENUUP)
                    ReplyMsg(m);
                else
                    AddHead(window_port->mp_MsgList, m);
                go = F;
            }
        }

        /* now process what we have received, I'm not sure if I need to
        disable multi-tasking, but just to be safe */

        Forbid();

        /* make sure didn't scroll off sideways */
        if (dx > 0)
            dx = MIN(bm_width - (w->GZZWidth + l->Scroll_X), dx);
        else
            dx = MAX(-l->Scroll_X, dx);

        /* make sure didn't scroll off vertically */
        if (dy > 0)
            dy = MIN(bm_height - (w->GZZHeight + l->Scroll_Y), dy);
        else
            dy = MAX(-l->Scroll_Y, dy);

        Permit();

        ScrollLayer(NULL, l, (long) dx, (long) dy);
    }

    UpdateGdgsPos(w, l->Scroll_X - old_scroll_x, l->Scroll_Y - old_scroll_y);
}

Ken Chiu