Results 1 to 8 of 8

Thread: Get the doughnut..

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    australia
    Posts
    94

    Get the doughnut..

    I've just understand how to use bitblt to put non-rect objects into a picture box. This put my headache of pic update speed to and end but ... another problem arise :

    How can I detect, when I click a point in a picture box area, that which object I'm clicking at? Like if I put a doughnut and say, detect if the clicked point is on the doughnut, not in the inner hole or ouside spaces? It is simple when I was using .click method before, but what should I do for this now? for bitblted object's click detection?

  2. #2
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Well, a "simple" solution would be to create another invisible picture where you draw the outlines (masks, whatever) in different colors for each object in the same order you draw them on the visible picture. You can then simply determine what object you clicked by checking the pixel color at that location...

    Don't have a clue on how to draw the masks in different colors though (at least not a fast way)...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  3. #3
    Zaei
    Guest
    Assign a RECT type to each image you Blt. Then, when the user clicks, find out if the user clicked inside one of the RECTs (inside one of the pictures), and if, so, find the offset from the top-left coordinates of the RECT. When you find those, use GetPixel() on the MASK image, and if the is the color of the mask(the doughnut part of it, it may be black or white, depending on the method you are using for Bltting), you hit the object.

    Z.

  4. #4
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Mhh.....sounds like a good idea, but what if two objects overlap and the point is in two rectangles at the same time?


    Mhhhh, my brain just started , you can just create a new type which holds not only the coordinates, but also the Z-index, so you can compare both when you find a point in two objects at the same time...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    australia
    Posts
    94
    sorry, I don't understand, can u write me a line of code or two for example? THX...

    I don't even know how to use getpixel & RECT, seems I need to work a lot harder

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    australia
    Posts
    94
    alright.. I just learn how to use getpixel, still figuring out how to use the method u 2 mention above, will be appreciate if i can get some example thankx

  7. #7
    Zaei
    Guest
    Or, instead of having a ZOrder, you could do a GetPixel on the final screen image, and test that against each of the original images (not the masks) to see which it belongs to. Then check the cooresponding mask.

    dimsum, check out the PtInRect API. A RECT just stores the left, right, top and bottom coordinates of an area.

    Z.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    australia
    Posts
    94
    Thx Zaei, I'm trying your method.

    I just wrote something like using two identical picture box( pic1 & pic 2 ), one is invisible( pic1 ) which I draw a mask ( the one to identify BLTed object's ID ) in the same x,y with the one in the picture box visible ( pic 2 ). And then when I clicked on the visible one ( pic 2 ), I getPixel on the invisibled one to get the mask. It will looks like one picture box (pic2) contain some good looking pictures BLTed, and the other (pic1) look like shot by paint guns

    It works fine, but I worry maybe there're some problem for this approach. I'm not experienced enough.

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