Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!hao!gatech!udel!princeton!phoenix!kenchiu From: kenchiu@phoenix.Princeton.EDU (Kenneth Chiu) Newsgroups: comp.sys.amiga Subject: Re: PropGadget usage Message-ID: <1950@phoenix.Princeton.EDU> Date: 4 Mar 88 17:00:03 GMT References: <208@xenlink.UUCP> Reply-To: kenchiu@phoenix.Princeton.EDU (Kenneth Chiu) Distribution: na Organization: Princeton University, NJ Lines: 92 Keywords: help superbitmapwindow movement drawing program Summary: Here's some code 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