Adding some button handling.
This commit is contained in:
@ -29,10 +29,13 @@
|
|||||||
\ last-key ( -- n )
|
\ last-key ( -- n )
|
||||||
\ last-keysym ( -- n )
|
\ last-keysym ( -- n )
|
||||||
\ last-keycode ( -- n )
|
\ last-keycode ( -- n )
|
||||||
|
\ pressed? ( k -- f )
|
||||||
\ event ( -- n )
|
\ event ( -- n )
|
||||||
\ Event constants:
|
\ Event constants:
|
||||||
\ UNKNOWN TIMEOUT RESIZED EXPOSED
|
\ UNKNOWN TIMEOUT RESIZED EXPOSED
|
||||||
\ MOTION PRESSED RELEASED FINISHED
|
\ MOTION PRESSED RELEASED FINISHED
|
||||||
|
\ Key/Button constants:
|
||||||
|
\ LEFT-BUTTON MIDDLE-BUTTON RIGHT-BUTTON
|
||||||
|
|
||||||
vocabulary grf grf definitions
|
vocabulary grf grf definitions
|
||||||
vocabulary internals
|
vocabulary internals
|
||||||
@ -46,6 +49,10 @@ vocabulary internals
|
|||||||
6 constant RELEASED
|
6 constant RELEASED
|
||||||
7 constant FINISHED
|
7 constant FINISHED
|
||||||
|
|
||||||
|
255 constant LEFT-BUTTON
|
||||||
|
254 constant MIDDLE-BUTTON
|
||||||
|
253 constant RIGHT-BUTTON
|
||||||
|
|
||||||
0 value mouse-x
|
0 value mouse-x
|
||||||
0 value mouse-y
|
0 value mouse-y
|
||||||
0 value last-key
|
0 value last-key
|
||||||
@ -59,10 +66,18 @@ internals definitions
|
|||||||
|
|
||||||
0 value backbuffer
|
0 value backbuffer
|
||||||
|
|
||||||
|
256 constant key-count
|
||||||
|
create key-state key-count allot
|
||||||
|
key-state key-count erase
|
||||||
|
|
||||||
|
: key-state! ( f k ) key-state + c! ;
|
||||||
|
|
||||||
grf definitions also internals
|
grf definitions also internals
|
||||||
|
|
||||||
: pixel ( w h -- a ) width * + 4* backbuffer + ;
|
: pixel ( w h -- a ) width * + 4* backbuffer + ;
|
||||||
|
|
||||||
|
: pressed? ( k -- f ) key-state + c@ 0<> ;
|
||||||
|
|
||||||
( Rest of the core definitions per platform. )
|
( Rest of the core definitions per platform. )
|
||||||
|
|
||||||
only forth definitions
|
only forth definitions
|
||||||
|
|||||||
@ -14,17 +14,13 @@
|
|||||||
|
|
||||||
grf
|
grf
|
||||||
|
|
||||||
0 value clicking
|
|
||||||
|
|
||||||
-1 -1 window
|
-1 -1 window
|
||||||
: run
|
: run
|
||||||
begin
|
begin
|
||||||
wait
|
wait
|
||||||
PRESSED event = if 1 to clicking then
|
|
||||||
RELEASED event = if 0 to clicking then
|
|
||||||
0 to color
|
0 to color
|
||||||
0 0 width height box
|
0 0 width height box
|
||||||
clicking if $ccccff else $ffccff then to color
|
LEFT-BUTTON pressed? if $ccccff else $ffccff then to color
|
||||||
mouse-x mouse-y height heart
|
mouse-x mouse-y height heart
|
||||||
flip
|
flip
|
||||||
event FINISHED = until
|
event FINISHED = until
|
||||||
|
|||||||
@ -44,6 +44,26 @@ cell allocate throw to backbuffer
|
|||||||
RESIZED to event
|
RESIZED to event
|
||||||
;
|
;
|
||||||
|
|
||||||
|
: msg>button ( n -- n )
|
||||||
|
dup WM_LBUTTONDOWN = over WM_LBUTTONUP = or if
|
||||||
|
drop LEFT-BUTTON exit
|
||||||
|
then
|
||||||
|
dup WM_MBUTTONDOWN = over WM_MBUTTONUP = or if
|
||||||
|
drop MIDDLE-BUTTON exit
|
||||||
|
then
|
||||||
|
dup WM_RBUTTONDOWN = over WM_RBUTTONUP = or if
|
||||||
|
drop RIGHT-BUTTON exit
|
||||||
|
then
|
||||||
|
drop 0
|
||||||
|
;
|
||||||
|
|
||||||
|
: msg>pressed ( n -- 0/1 )
|
||||||
|
dup WM_LBUTTONDOWN =
|
||||||
|
over WM_MBUTTONDOWN = or
|
||||||
|
over WM_RBUTTONDOWN = or if drop 1 exit then
|
||||||
|
drop 0
|
||||||
|
;
|
||||||
|
|
||||||
: GrfWindowProc { hwnd msg w l }
|
: GrfWindowProc { hwnd msg w l }
|
||||||
WM_QUIT msg = if
|
WM_QUIT msg = if
|
||||||
FINISHED to event
|
FINISHED to event
|
||||||
@ -72,15 +92,12 @@ cell allocate throw to backbuffer
|
|||||||
then
|
then
|
||||||
WM_CHAR msg = if
|
WM_CHAR msg = if
|
||||||
then
|
then
|
||||||
WM_LBUTTONDOWN msg = if
|
msg msg>button if
|
||||||
l GET_X_LPARAM to mouse-x
|
l GET_X_LPARAM to mouse-x
|
||||||
l GET_Y_LPARAM to mouse-y
|
l GET_Y_LPARAM to mouse-y
|
||||||
PRESSED to event
|
msg msg>pressed msg msg>button key-state!
|
||||||
then
|
msg msg>button to last-keycode
|
||||||
WM_LBUTTONUP msg = if
|
msg msg>pressed if PRESSED else RELEASED then to event
|
||||||
l GET_X_LPARAM to mouse-x
|
|
||||||
l GET_Y_LPARAM to mouse-y
|
|
||||||
RELEASED to event
|
|
||||||
then
|
then
|
||||||
WM_MOUSEMOVE msg = if
|
WM_MOUSEMOVE msg = if
|
||||||
l GET_X_LPARAM to mouse-x
|
l GET_X_LPARAM to mouse-x
|
||||||
|
|||||||
Reference in New Issue
Block a user