Results 1 to 9 of 9

Thread: Selecting shapes drawn by GDI

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46

    Exclamation Selecting shapes drawn by GDI

    I have a picturebox in my form and GDI draws geometrical shapes (arc, ellipse,rectangle etc.) and when user clicks on one of them (but when clicks the bound of the shape not the area that located inside the bounds) like in AutoCAD. For example : clicks on an arc, my app gets it as selecteditem = arc1 .
    I can do that only with rectangle, line, triangle (shapes made by line/lines) But I can`t calculate an ellipse`s bounds cause it isn`t made with edges.
    Please share the ideas with me if you have about how to do ,
    Please help

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Tricky

    I'd pick a stretched transformation which nullifies the excentricity of the ellipse (making it a circle) and then test the distance's closeness to the border, however very excentric ellipses will have very excentric validation areas as well.
    using circle method on vb graphical objects you pass the excentricity but with ellipse api you pass the rect in which the ellipse is inscribed in. divide width by height to get excentricity.
    Transform clicked coordinates to non excentric coordinates (divide wither vertical or horizontal coord with e) after moving origo to ellipse center. then get the modulus squared with x*x+y*y. test if it is larger than inner radius squared and smaller than outher radius squared. That should do it.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46
    Thank you very much for your interests and sharing your ideas with me Kedaman and Chris. This is very important for me.

    And excuise me Kedaman, but I don`t understand the meaning of "e"
    Can you please explain the meaning of it.
    Thanks again.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Sorry, e stands for excentricity. The ratio between the height and width.
    Chris, he want's to click on the border of the ellipse but nice idea. I'm not sure but elliptical regions will consume a big load of memory and performance due to regions being groups of exclusive rectanges.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Oops... sorry for my misunderstand the question. Yes, I agree with you kedaman, those region will ate up lot memory especially when deal with a large amount of region For some instances, we also can use the Union to combine two region

    Meanwhile, I did wrote a program that will hold up 100-200 region handle at once in my GIS application and so far still able to survive and hope it won't kill my program.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    they're not at all bad, if they're used for the right purposes, especially clipping, but the areas better be not too complex. To combine,substract, or, and, xor regions you can use combinergn api
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46
    Hi again, after 6 days,
    I recently learnt that GetPath function of GDI "retrieves the coordinates defining the endpoints of lines and the control points of curves found in the current path". I think my app matches the mousedown coordinates with the modified value of GetPath function and checks if user clicked on a line, circle or rectangle. So may be it also solves my problem. But unfortunately I have found a little about it: only description and arguments. I tried to write a sample app but vb shows error messages because of I don`t understand how to use tagPOINT type which is one of its arguments. Would you please tell me how can I use it successfully. I really need it.

    All I know about it, is :

    Function GetPath(hdc As Long, lpPoints As Long, lpTypes As Byte, nSize As Long) As Long
    hdc

    hdc [in] Handle to a device context that contains a closed path.
    lpPoints
    lpPoints [out] Pointer to an array of POINT structures that receives the line endpoints and curve control points.
    lpTypes [out] Pointer to an array of bytes that receives the vertex types. This parameter can be one of the following values. Type Description
    PT_MOVETO Specifies that the corresponding point in the lpPoints parameter starts a disjoint figure.
    PT_LINETO Specifies that the previous point and the corresponding point in lpPoints are the endpoints of a line.
    PT_BEZIERTO Specifies that the corresponding point in lpPoints is a control point or ending point for a Bézier curve.
    PT_BEZIERTO values always occur in sets of three. The point in the path immediately preceding them defines the starting point for the Bézier curve. The first two PT_BEZIERTO points are the control points, and the third PT_BEZIERTO point is the ending (if hard-coded) point.

    And I don`t know but does GDI accept also lines, arcs, recantgles... as object. Would you please tell me.

    Thanks

  8. #8
    New Member
    Join Date
    May 2003
    Location
    argentina
    Posts
    2
    might
    I've the same problem.
    Did you solved it...
    could you help me...
    thanks...
    LUCAs

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Wouldn't hit testing with an ellipse be easier using the formular for an ellipse?

    My math has gone to hell since I left school, but I think it would be easier than keda's approach...

    Try asking in the math forum.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width