1. RE: Mouse clicks on bitmaps

Are you using a bitmap control or are you using a pixmap?  Does your 
bitmap change size?  Does the origin of the bitmap/pixmap change?Writing 
a w32HMouse handler might be a better option since it's params include 
the mouse position.

-- Brian

Jonas Temple wrote:
> 
> 
> posted by: Jonas Temple <jtemple at yhti.net>
> 
> I know this question has been asked in the past and I searched the 
> archive
> for any related messages, but could not find the answer.
> 
> How do I get or simulate a left mouse click in a bitmap?  My current 
> attempt is to set a HClick handler for the main window and then try
> to determine if the click was in the bounds of the bitmap.
> 
> If this is the correct approach then question two is:
> How do I accurately determine if the mouse is in the bitmap regardless
> of the size of the window?  I've been experimenting with 
> getPointerPos(),
> getPointerRelPos() and isScreenPointIn() but I can't get consistent 
> results.
> 
> Well, it's late and I need sleep....
> 
> Jonas

new topic     » topic index » view message » categorize

2. RE: Mouse clicks on bitmaps

Does this demo help?

include win32lib.ew
without warning

constant
  X = 1,
  Y = 2,
  Size = 301,
  Orig = {75,75}

constant
  Win = create(Window,"test",0,Default,Default,500,500,0),
  Stat = create(StatusBar,"",Win,0,{.5,-1},0,0,0),
  Pix = create(Pixmap,"",Win,0,0,Size,Size,0)

  ------------------------------

function ptInRect( sequence pt, sequence rect )
  return pt[X]>=rect[1] and pt[Y]>=rect[2] and pt[X]<rect[3] and 
pt[Y]<rect[4]
end function

  ------------------------------

procedure redSquare( sequence pos )
  pos = floor(pos/10)*10
  drawRectangle(Pix,w32True,pos[X]+1,pos[Y]+1,pos[X]+10,pos[Y]+10)
  copyBlt( Win, Orig[X], Orig[Y], Pix )
end procedure

  ------------------------------

procedure mouse_handler(integer self, integer event, sequence params)--( 
int event, int x, int y, int shift )\
  sequence pos

  pos = params[2..3]

  setText( {Stat,1}, sprintf("Win: %d,%d",pos ) )

  if ptInRect( pos, Orig & Orig+Size ) then
    setText( {Stat,2}, sprintf("Bmp: %d,%d",pos-Orig ) )
    if params[1] = LeftUp then
      redSquare( pos-Orig )
    end if
  else
    setText( {Stat,2}, "Not in Bitmap" )
  end if
end procedure
setHandler( Win, w32HMouse, routine_id("mouse_handler"))

  ------------------------------

procedure paint(integer self, integer event, sequence params)
  copyBlt( Win, Orig[X], Orig[Y], Pix )
end procedure
setHandler( Win, w32HPaint, routine_id("paint"))

  ------------------------------

procedure init(integer self, integer event, sequence params)
  -- init pixmap
  setWindowBackColor( Pix, BrightWhite )
  clearWindow(Pix)
  setPenColor( Pix, Black )
  for i = 0 to Size by 10 do
    drawLine( Pix, 0, i, Size, i )
    drawLine( Pix, i, 0, i, Size )
  end for
  setPenColor( Pix, BrightRed )
end procedure
setHandler( Win, w32HOpen, routine_id("init"))

  ------------------------------

WinMain( Win, Normal )

  ------------------------------


new topic     » goto parent     » topic index » view message » categorize

3. RE: Mouse clicks on bitmaps

Brian Broker wrote:
> 
Brian,

Sorry that I didn't reply sooner...I've been pretty busy today.

I actually did come to the same code as your demo.  I created a mouse
handler for the main window and then checked to see if the point was in
the bounds of the bitmap.  That seemed to work.

Thanks for all the suggestions,

Jonas

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu