From: gautam AT interlog DOT com (Gautam N. Lad) Newsgroups: comp.os.msdos.djgpp Subject: Re: Mouse Controlling with Allegro.... Date: Sat, 04 Oct 97 17:42:26 GMT Organization: InterLog Internet Services Lines: 85 Message-ID: <615urv$lk$1@news.interlog.com> References: <01bcd0d8$f5d324a0$5d3e63c3 AT rossa> NNTP-Posting-Host: ip220-138.cc.interlog.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hi, "Ross Boast" wrote: > I am working on a GUI atm, it's very simple i have drawn a box with >shadows and a caption using allegro. What i am having problems with is >this: i can't get a routine going which will work when the mouse is over >the button and the left mouse button is hit. If you're using C++, and have made a Button class, it's real easy. Here's what you do (here's the scenario using C++): // This is our function to draw a button (let's assume that this function draws all // the rectangles, borders, and puts's the text in the center, and stores the x, y, // width, and height values): class Button { public: void Draw_Button(int x, int y, int width, int height, char *Text); int IsClicked(); private: int bx, by, bwidth, bheight; // Private members for other function like // IsClicked() to use. }; void Button :: Draw_Button(int x, int y, int width, int height, char *Text) { // store x,y,width,height in the b? variables. bx = x; by = y; bwidth = width; bheight = height; /* routines to draw button go here */ } // The first if statement checks if the left-button was pressed on the mouse. // if one was pressed, the next if statement checks if the mouse_x and mouse_y // are in the button's region. The reason bx+bwidth and by+bheight are used is, // if your button was drawn at (10, 10) with width and height being (5, 2), then // the button/rectangle would be drawn from (10, 10, 10+5, 10+2). Understand? // If mouse_x and mouse_y are in the button's region, it will return TRUE. int Button :: IsClicked() { if(mouse_b & 1) if(mouse_x > bx && mouse_y > by && mouse_x < bx+bwidth && y < by+bheight) return TRUE; return FALSE; } // a simple example: void main() { /* Initialize graphics system */ Button b; // Our button object b.Draw_Button(20, 30, 80, 20, "OK"); // Draw a button // Do a forever loop. If button get's pressed, break out of the loop, and quit for(;;) { if(b.IsClicked()) break; } } I hope this helps. If you want me to send you a working example (SRC + EXE), please let me know. If you don't understand C++, I will make one for you using C. Wait till you get into Entryfields, Radio Buttons, Check Boxes, List Boxes, etc. They are NOT THAT HARD, but it might give you some trouble. If it does, let me know (By E-mail). Good luck! Bye! ------------------------------------------------------------- Gautam N. Lad ------------------------------------------------------------- E-Mail: gautam AT interlog DOT com Website: http://www.interlog.com/~gautam POV-Ray Software, Gallery, and Links! -------------------------------------------------------------