PDA

View Full Version : mouse/stylus position


Heinz
11-13-2006, 12:30 PM
I want to check the Position of the stylus/mouse and if I use the wParam$/lParam$ in the func mainproc(hWnd$, Msg$, wParam$, lParam$) everything is fine.
However if I define for the gameloop a different function with

InitGameAPIEx(h$, &GameProc, 240, 320, false, 0, 0);

and use then the wParam$/lParam$ of the

func GameProc(hWnd$, Msg$, wParam$, lParam$)

both variables are always 0 independent of the position of the stylus. Has anybody an idea, why the GameProc version doesn't work?

thanks,
Heinz

Solonn
11-13-2006, 12:40 PM
I'm not sure if I understood completely the problem, but I'm using this function to initialize my engine:
G_INIT (hWnd, DrawProc, Width, Height, Orientation, AISpeed, FPSSpeed, FullScreen)
It's old school, but seems to work for me even for changing the reference procedure; "DrawProc" is the Pointer to a custom drawing routine; if NULL, PPL will do all the drawing for you, but you will have no control over it.
You may also consider checking this: G_SETPROC (ProcAddr),
Everything related to those two procedures can be found in the ppl help file.

Heinz
11-13-2006, 01:22 PM
Hi Solonn,

thanks for the quick reply and the suggestions. My problem is actually to get the position where the user touches the screen with the stylus (respectively the mouse position in the desktop version). If I use just the default mainproc I have the required cordinates in the varaiables wParam$/lParam$ (but for some reason he don't accepts game-API commands like g_line etc. in that procedure). If I define a separate function for the game-loop (as described above) all the game API commands work properly, but somehow the wParam$/lParam$ are always 0. Do you have an idea how to get the mouse position and beeing able to use the game API-functions in the same procedure (preferably something like the above defined GameProc)?

thanks a lot,
Heinz

kornalius
11-13-2006, 03:54 PM
Example please, this sounds really strange to my hears! ;)

Heinz
11-13-2006, 04:16 PM
Somewhere in the GameProc I make a mistake. I actually would like to use wParam$/lParam$ to get the position of the mouse/stylus, but they are alway 0 (however in the mainproc they have the proper values). The Code is:

// Default Advanced Game API skeleton
#include "GameAPI.ppl"

func mainproc(hWnd$, Msg$, wParam$, lParam$)
ok$ = true;
case (Msg$)
WM_CLOSE:
// Shutdown the GameAPI.
Free(z$);
ShutGameAPI(hWnd$);
WM_KEYDOWN:
PostMessage(hWnd$, WM_CLOSE, 0, 0);
end;
return (ok$);
end;

func GameProc(hWnd$, Msg$, wParam$, lParam$)
case (Msg$)
WM_PAINT:
// Clear screen first
G_Clear(0);
g_textout(NULL, wParam$, DVT_CENTER, 0, 2, g_rgb(255, 255, 255));
g_textout(NULL, lParam$, DVT_CENTER, 0, 22, g_rgb(255, 255, 255));
step$ = 10; // stepsize for calculation grid
for (xt$, 0, 240, step$)
for (yt$, 0, 320, step$)
if ((abs(wParam$ - xt$) < 20) and (abs(lParam$ - yt$) < 20))
z$[xt$, yt$] = step$ / 1.5;
else
z$[xt$, yt$] = z$[xt$, yt$] * 0.5;
end;
end;
end;
for (x$, 0, 239, step$)
for (y$, 0, 319, step$)
g_line(x$ + z$[x$, y$], y$, x$ + z$[x$, y$ + step$], y$ + step$, g_rgb(0, 150, 255));
g_line(x$, y$ + z$[x$, y$], x$ + step$, y$ + z$[x$ + step$, y$], g_rgb(0, 150, 255));
end;
end;
end;
return (true);
end;

func WinMain
// Create a new form that will hold the GAPI.
h$ = newform({GAPI}, {GAPIClass}, &mainproc);
ShowWindow(h$, SW_SHOW);
// Initialize GameAPI.
InitGameAPIEx(h$, &GameProc, 240, 320, false, 0, 0);
Dim(z$, 241, 321);
Global(z$);
for (xt$, 0, 240)
for (yt$, 0, 320)
z$[xt$, yt$] = 0;
end;
end;
return (true);
end;

PointOfLight
11-13-2006, 04:25 PM
wParam$ and lParam$ have different meanings depending on the event being trapped. I don't think they mean anything in the WM_PAINT event. What you will need to do is trap either the WM_LBUTTONDOWN or WM_LBUTTONUP events (depending on preference) in the MainProc. At that point, store those values in global variables, say CurX$ and CurY$. In the WM_PAINT event, just refer to CurX$ and CurY$ when doing your calculations. Hope that makes sense.

kornalius
11-13-2006, 06:12 PM
ditto ^

Heinz
11-15-2006, 09:35 AM
Thanks a lot for the hint. Everything works fine now.
I wasn't aware that the meaning of lParam$/wParam$ dependet on the trapped event.

dennishea
11-15-2006, 10:58 AM
Is there somewhere that tells which trapped events work with wparam$/lparam$ and which don't.

dennishea

PointOfLight
11-15-2006, 01:04 PM
The easiest place to find that information is MSDN. Just look up the event in question (ex: WM_PAINT), and it will tell you the meaning of the wParam$ and lParam$ parameters.

dennishea
11-15-2006, 02:23 PM
Thank you Eric.

dennishea