C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-04-2008, 10:40 AM   #1
Registered User
 
Join Date: Apr 2008
Posts: 31
[C] drawing: drag GDI shapes

salutations,

we are beginners.
doubt: we would like to know what is the most convenient method to select and drag a shape drawn with Windows GDI (rectangles, ellipses, polygons...) inside a window or dialog box. for example, if we have drawn several ellipses (Ellipse() function) in a window's client area, we should be able to click one of the ellipses and drag it without affecting the other ellipses.
we have thought of a (naïve) solution, but we don't know if it is correct, and it seems a little complicated to implement:
to have a (dynamic?) array of structs in which every struct has all the informations necessary to draw one polygon (type, position, color, whether it's selected or not etc.). when the user clicks the window, the program loops through the array of structs until it finds a struct where the cursor's position is inside a shape's limits. if it does, it selects it. when the user drags the cursor, the position information in the struct of the selected shape is continually changed according to the cursor's position (maybe inside WM_MOUSEMOVE). then we should program WM_PAINT to draw each shape from the array of structs and redraw the window each time positions change.
thus, the act of clicking and moving changes information inside an array of structs which is used by WM_PAINT to draw shapes on the window. thus, the user is able to add more objects to the screen by adding more structs to the array.
what do you think? is there a better way?

thank you in advance.
pc2-brazil is offline   Reply With Quote
Old 10-05-2008, 04:17 AM   #2
Registered User
 
valaris's Avatar
 
Join Date: Jun 2008
Location: RING 0
Posts: 462
There was a section on this in pertzold's book. The general gist of it was to draw your objects and on WM_LBUTTONDOWN hit test your object by seeing if the coordinates were in the RECT coords of your shape, then draw the shape and update its coordinates on the WM_LBUTTONUP new mouse coordinates. This will only draw it after the mouse button is lifted though, constantly redrawing it on WM_MOUSEMOVE could be an option too.
valaris is offline   Reply With Quote
Old 10-05-2008, 06:35 AM   #3
Registered User
 
Join Date: Apr 2008
Posts: 31
Quote:
Originally Posted by valaris View Post
There was a section on this in pertzold's book. The general gist of it was to draw your objects and on WM_LBUTTONDOWN hit test your object by seeing if the coordinates were in the RECT coords of your shape, then draw the shape and update its coordinates on the WM_LBUTTONUP new mouse coordinates. This will only draw it after the mouse button is lifted though, constantly redrawing it on WM_MOUSEMOVE could be an option too.
thank you for the response.
but, to see if the coordinates are in the RECT coordinates of our shape, we would have to store those coordinates somewhere, right? like an array, like we told, or maybe a vector in C++.
because, as far as we know, when a shape is drawn in the window, it "merges" with the window, thus it's not a "separate" object anymore... if you understand what we meant. so, the whole image has to be redrawn so that one object can be moved.
is that right?
thank you in advance.
pc2-brazil is offline   Reply With Quote
Old 10-05-2008, 02:06 PM   #4
Registered User
 
valaris's Avatar
 
Join Date: Jun 2008
Location: RING 0
Posts: 462
Yes you must store the coordinates of each shape. If you know how many you are going to have use an array, otherwise yah throw them in a vector. Most people just create a static array/vector in the winProc that it will be drawn.

The shape doesn't become "part" of the window, its simply drawn inside the client area usually.
valaris is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[C] GDI: how to erase material drawn at an entire screen DC pc2-brazil Windows Programming 3 01-24-2009 07:24 PM
[C] Drag and drop controls pc2-brazil Windows Programming 1 09-02-2008 02:41 AM
GDI - Drawing to the screen correctly Tonto Windows Programming 1 06-24-2006 09:53 PM
GDI Drawing Help The Brain Windows Programming 3 10-20-2005 02:01 AM
drawing sprites with the windows gdi lambs4 Game Programming 10 08-14-2003 09:06 AM


All times are GMT -6. The time now is 12:04 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22