forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Best way to catch mouse cursor leaving %gr?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Mon Jul 30, 2012 12:48 pm    Post subject: Best way to catch mouse cursor leaving %gr? Reply with quote

Hi all,

I am writing a minesweeper game using clearwin+. I currently use %gr with full mouse input to get mouse state and for drawing the game board. Game board is drawn by drawing buffer to %gr and then board tile below mouse cursor is highlighted by drawing correct highlighted board tile image on top of it.

I would like to remove tile highlighting from game board when mouse cursor leaves %gr. What is the best way to catch when that happens?

Some simple example code would be nice... Smile
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: Düsseldorf, Germany

PostPosted: Mon Jul 30, 2012 2:58 pm    Post subject: Reply with quote

Just stop highlighting when the cursor co-ordinates are outside the graphics windows? Here is some example code:

Code:
winapp
program my_game
implicit none
include <windows.ins>

external    display
integer*4   j,ptr

j = winio@('%`^gr[user_surface,full_mouse_input]',200L,200L,ptr,1L,display)
end

integer function display()
implicit none
include <windows.ins>

integer*4   mouse_x,mouse_y,x1,x2,y1,y2

mouse_x = CLEARWIN_INFO@('GRAPHICS_MOUSE_X')
mouse_y = CLEARWIN_INFO@('GRAPHICS_MOUSE_Y')

x1 = 20*int(mouse_x/20.)
x2 = x1+19
y1 = 20*int(mouse_y/20.)
y2 = y1+19

call draw_filled_rectangle@(0,0,200,200,255)
if (mouse_x > 5 .and. mouse_x < 195 .and. mouse_y > 5 .and. mouse_y < 195) then
  call draw_filled_rectangle@(x1,y1,x2,y2,10)
end if

display = 1
end


Regards - Wilfried
Back to top
View user's profile Send private message
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Mon Jul 30, 2012 7:33 pm    Post subject: Re: Reply with quote

Wilfried Linder wrote:
Just stop highlighting when the cursor co-ordinates are outside the graphics windows?

Thanks,

I used cursor_monitor@() for this purpose. One problem however remains: it's possible to move mouse cursor outside the program window so fast that %gr or cursor monitor callbacks don't get launched. Any way for fixing this behaviour?

My original minesweeper game written in Hollywood is available here There are sources and binaries for some operating systems.
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Mon Jul 30, 2012 8:49 pm    Post subject: Reply with quote

If I understand Wilfried correctly, he has a border round the gameplay (board) area that the mouse pointer has to cross to exit. You could put something in this area so it wasn't obvious that the board didn't fill all the %gr area - something like a 3D or decorative border. If the mouse coordinates were in the border then you could un-highlight all the gameplay squares.

You may need to experiment on how big the border has to be to let you catch the mouse on its way off the play area. You could do all your highlighting etc in the graphics callback without needing to use ADD_CURSOR_MONITOR@.

I do something similar in one of my programs, and I use IMPORT_IMAGE@ a lot. I never buffer the graphics, but just keep overlaying the squares with new graphics. The screen is the buffer. You just need to draw bitmaps for each of the possible states of a square to use with IMPORT_IMAGE@. If you are doing it for your own entertainment, you can grab images from other programs using SHIFT-PrtSc and then paste the picture into paint. Then you can cut out and use the bit(s) you want. (My application isn't a game, it is a repositionable toolbar - I have bitmaps for each state each button can be in. I solved the problem of detecting mouse exit from a button by only selecting the middle 10x10 of a 16x16 button as its active area, in other words a 3 pixel border was enough to catch the mouse on its way out).

Eddie
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: Düsseldorf, Germany

PostPosted: Tue Jul 31, 2012 7:36 am    Post subject: Reply with quote

According to Eddie's remarks I added a 20-pixels border, then it runs better:

Code:
winapp
program my_game
implicit none
include <windows.ins>

external    display
integer*4   j,ptr

j = winio@('%ww[no_border]&')  ! added
j = winio@('%`^gr[user_surface,full_mouse_input]',240L,240L,ptr,1L,display)  ! expanded to 240x240 pixels
end

integer function display()
implicit none
include <windows.ins>

integer*4   mouse_x,mouse_y,x1,y1

mouse_x = CLEARWIN_INFO@('GRAPHICS_MOUSE_X')
mouse_y = CLEARWIN_INFO@('GRAPHICS_MOUSE_Y')

call draw_filled_rectangle@(0,0,240,240,255)
if (mouse_x > 25 .and. mouse_x < 215 .and. mouse_y > 25 .and. mouse_y < 215) then
  x1 = 20*int(mouse_x/20.)
  y1 = 20*int(mouse_y/20.)
  call draw_filled_rectangle@(x1,y1,x1+19,y1+19,10)
end if

display = 1
end


Regards - Wilfried
Back to top
View user's profile Send private message
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Tue Jul 31, 2012 8:06 am    Post subject: Reply with quote

Ok, I added a small border around the %gr area and things works quite well now.

Thanks for help, I will probably return with more questions later.

EDIT:

Ended up using timer callback for monitoring mouse cursor position using:
GetCursorPos() - Get mouse cursor position relative to screen coordinates
ScreenToClient() - Convert mouse cursor coordinates relative to client window
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group