///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <litec.h>
//#include <default.c>
#include <extra.h>
#include <windows.h>
#include <stdio.h>
#define NID_READY 0x80
#define NID_INTEGRATED_TOUCH 0x01
#define NID_MULTI_INPUT 0x40
#define WM_TOUCH 0x0240
#define TWF_FINETOUCH (0x00000001)
#define TWF_WANTPALM (0x00000002)
/*
* Conversion of touch input coordinates to pixels
*/
#define TOUCH_COORD_TO_PIXEL(l) ((l) / 100)
/*
* Touch input flag values (TOUCHINPUT.dwFlags)
*/
#define TOUCHEVENTF_MOVE 0x0001
#define TOUCHEVENTF_DOWN 0x0002
#define TOUCHEVENTF_UP 0x0004
#define TOUCHEVENTF_INRANGE 0x0008
#define TOUCHEVENTF_PRIMARY 0x0010
#define TOUCHEVENTF_NOCOALESCE 0x0020
#define TOUCHEVENTF_PEN 0x0040
#define TOUCHEVENTF_PALM 0x0080
/*
* Touch input mask values (TOUCHINPUT.dwMask)
*/
#define TOUCHINPUTMASKF_TIMEFROMSYSTEM 0x0001 // the dwTime field contains a system generated value
#define TOUCHINPUTMASKF_EXTRAINFO 0x0002 // the dwExtraInfo field is valid
#define TOUCHINPUTMASKF_CONTACTAREA 0x0004 // the cxContact and cyContact fields are valid
///////////////////////////////
//long WINAPI GetOpenClipboardWindow(long);
BOOL WINAPI RegisterTouchWindow(HWND,long ulFlags);
#define PRAGMA_API RegisterTouchWindow;user32!RegisterTouchWindow
#define PRAGMA_ZERO // initialize variables
typedef struct _TOUCHINPUT {
LONG x;
LONG y;
HANDLE hSource;
DWORD dwID;
DWORD dwFlags;
DWORD dwMask;
DWORD dwTime;
LONG dwExtraInfo;
DWORD cxContact;
DWORD cyContact;
} TOUCHINPUT;
typedef struct _ID {
int x;
int y;
} POINT_ID;
POINT_ID pID[100];
BOOL WINAPI GetTouchInputInfo(HANDLE hTouchInput,UINT cInputs,long pInputs,int cbSize);
#define PRAGMA_API GetTouchInputInfo;user32!GetTouchInputInfo
BOOL WINAPI GetTouchInputInfo(HANDLE hTouchInput,UINT cInputs,long pInputs,int cbSize);
#define PRAGMA_API GetTouchInputInfo;user32!GetTouchInputInfo
BOOL WINAPI CloseTouchInputHandle(HANDLE hTouchInput);
#define PRAGMA_API CloseTouchInputHandle;user32!CloseTouchInputHandle
function exits(){
sys_exit("wuit");
}
///GLOBAL VAR:
TOUCHINPUT pInputs[100];
var val_11=0;
var val_12=0;
var val_13=0;
var val_21=0;
var val_22=0;
var val_23=0;
var val_31=0;
var val_32=0;
var val_33=0;
var c_id=0;
var c_id2=0;
PANEL* stats={
digits(10,30,"id:%.0f",*,1,val_11);
digits(10,40,"x: %.0f",*,1,val_12);
digits(10,50,"y: %.0f",*,1,val_13);
digits(80,30,"id:%.0f",*,1,val_21);
digits(80,40,"x: %.0f",*,1,val_22);
digits(80,50,"y: %.0f",*,1,val_23);
digits(180,30,"id:%.0f",*,1,val_31);
digits(180,40,"x: %.0f",*,1,val_32);
digits(180,50,"y: %.0f",*,1,val_33);
//digits(10,35,4,*,1,pInputs[1].dwID);
flags=SHOW;
}
function touched(PANEL* o);
PANEL* t1={
bmap="quad2.png";
flags=SHOW | TRANSLUCENT | LIGHT;
pos_x=100;
pos_y=200;
event=touched;
}
PANEL* t2={
bmap="quad2.png";
flags=SHOW | TRANSLUCENT | LIGHT;
pos_x=300;
pos_y=200;
event=touched;
}
function touched(PANEL* o){
if(o==t1){o.blue=222;o.red=2; o.pos_y-=40;}
if(o==t2){o.blue=222;o.red=2; o.pos_y-=40;}
}
function object_ontouch(PANEL* p,TOUCHINPUT* ti){
//ONLY TOUCHES DOWN ONCE!!
//TODO: IF Skill_x is busy, add the skill_y for secundary two points manipulation
p.skill_x=ti.dwID;
STRING* debug_str4="#10";
//PANEL is attached with the ID, that will follow move
while(p.skill_x>0){
if(ti.dwFlags & TOUCHEVENTF_UP){break;}
str_for_num(debug_str4,ti.dwID);
str_cat(debug_str4," is attached to this entity");
draw_text(debug_str4,(p.pos_x)+10,(p.pos_y+10),vector(0,100,255)); // bright red text
p.pos_x=pID[ti.dwID].x;
p.pos_y=pID[ti.dwID].y;
wait(1);
}
//Loop breaked, because finger released by flag touch_up
//Break atachment to finger on skill_x
p.skill_x=-3;
}
function object_release(PANEL* p){
p.skill_x=-1;
}
function check_detection(PANEL* p, TOUCHINPUT* ti){
//further check or alpha pixel
if((p.pos_x<ti.x && p.pos_x+p.size_x>ti.x) && (p.pos_y<ti.y && p.pos_y+p.size_y>ti.y)){
//that px,py cursor is on the panel area. Activate detection..
object_ontouch(p, ti);
}
}
function detection_list(TOUCHINPUT* ti){
//all object that recieve clicks.
check_detection(t1,ti);
check_detection(t2,ti);
}
void init_vals(){
while(1){
val_11=pInputs[0].dwID;
val_12=pInputs[0].x;
val_13=pInputs[0].y;
val_21=pInputs[1].dwID;
val_21=pInputs[1].x;
val_23=pInputs[1].y;
wait(1);}
}
function touch_object(PANEL* p, TOUCHINPUT* a){
p.skill_x=a.dwID+10;
beep();
}
void OnTouchDownHandler(TOUCHINPUT* ti)
{//POINT p = GetTouchPoint(hWnd, ti);
detection_list(ti); //send pointer to detection
// t1.skill_x=-1;
// t2.skill_x=-1;
STRING* debug_str4="#10";
while(ti.dwFlags & TOUCHEVENTF_DOWN){
str_for_num(debug_str4,ti.dwID);
str_cat(debug_str4," DOWN");
draw_quad(NULL,vector(ti.x+10,ti.y+10,0),NULL,vector(10,10,0),vector(1,1,0),vector(100,222,0),100,0);
draw_text(debug_str4,(ti.x)+10,(ti.y),vector(100,100,255)); // bright red text
//if(mouse_left==1 && mouse_panel!=NULL){mouse_panel.skill_x=10;beep();}
wait(1);}
//draw_quad(NULL,vector(dx+120,dy,0),NULL,vector(random(ti.dwID),random(ti.dwID),random(ti.dwID)),vector(1,1,0),vector(0,222,0),100,0);
}
//Global var defining moving touched at the same time.. to avoid calling move handles, every time the same id is detected as moving..
int touch_initialized[100]; //100 touches
//// activate sonar detector when mouse down and move... dispatch each object handle.
//detect the size by their pixel position.. in between the touch area, if yes, attribute it an action.
void OnTouchMoveHandler_o(TOUCHINPUT* ti)
{
if( touch_initialized[ti.dwID]==1){return;}
STRING* debug_str4="#10";
touch_initialized[ti.dwID]=1;
while( touch_initialized[ti.dwID]==1){
str_for_num(debug_str4,ti.dwID);
str_cat(debug_str4," MOVE");
draw_quad(NULL,vector(ti.x+10,ti.y+10,0),NULL,vector(10,10,0),vector(1,1,0),vector(100,222,0),100,0);
draw_text(debug_str4,(ti.x)+10,(ti.y-10),vector(0,100,255)); // bright red text
wait(1);}
}
void OnTouchUpHandler(TOUCHINPUT* ti)
{//POINT p = GetTouchPoint(hWnd, ti);
//t1.skill_x=-2;
//t2.skill_x=-2;
//touch_initialized[ti.dwID]=0;
//object_release() //TODO.. COMO associar o retirar do dedo ao entity corresponte sem interferir com outro point k ja esteja la regiastado?
}
LRESULT OnTouch(HWND hWnd, WPARAM wParam, LPARAM lParam ){
BOOL bHandled = FALSE;
UINT cInputs = LOWORD(wParam); //numberof active inputs
//PTOUCHINPUT* pInputs;
// TOUCHINPUT* PTOUCHINPUT = malloc(sizeof(TOUCHINPUT)); // creates a new SPOT struct at runtime
// memset(PTOUCHINPUT,0,sizeof(TOUCHINPUT)); // set the struct content to zero (it's undefined after malloc)
/// OBSERVA o NUMERO DE INPUTS NO ECRAN, E GERA 1 STRUCT para cada um dos inputs.
//
//TOUCHINPUT* pInputs = malloc(cInputs*sizeof(TOUCHINPUT)); // creates a new SPOT struct at runtime
//pInputs = malloc(cInputs*sizeof(TOUCHINPUT)); // creates a new SPOT struct at runtime
//zero(pInputs);
//if (cInputs!=NULL){
//print2("exists");
if (cInputs>0){
if (GetTouchInputInfo(lParam, cInputs, pInputs, sizeof(TOUCHINPUT))){
int i;
c_id=cInputs;
c_id2=sizeof(pInputs)*cInputs;
for(i=0; i<cInputs; ++i)
{
//Unit conversion
pInputs[i].x/=100;
pInputs[i].y/=100;
pInputs[i].x-=window_pos.x;
pInputs[i].y-=window_pos.y;
pID[pInputs[i].dwID].x=pInputs[i].x;
pID[pInputs[i].dwID].y=pInputs[i].y;
//////////////////////////////
if(pInputs[i].dwFlags & TOUCHEVENTF_MOVE){OnTouchMoveHandler_o(pInputs[i]);}else{
if(pInputs[i].dwFlags & TOUCHEVENTF_DOWN){OnTouchDownHandler(pInputs[i]);}else{
if(pInputs[i].dwFlags & TOUCHEVENTF_UP){ OnTouchUpHandler(pInputs[i]);}}}
}
bHandled = TRUE;
if (bHandled){
// if you handled the message, close the touch input handle and return
CloseTouchInputHandle(lParam);
return;
}else{return DefWindowProc(hWnd, WM_TOUCH, wParam, lParam);}
}
}}
//recieve messages
LRESULT CALLBACK OriginalHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MyMessageHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
// pass touch messages to the touch handler
case WM_TOUCH:
//error("touch");
OnTouch(hWnd, wParam, lParam);
break;
}
return OriginalHandler(hwnd,message,wParam,lParam);
}
function draw_cursor(){while(1){draw_quad(NULL,vector(110,210,0),NULL,vector(10,10,0),vector(1,1,0),vector(100,222,0),100,0);wait(1);}}
function main()
{
vec_set(screen_size,vector(800,400,0));
//vec_set(screen_color,vector(50,1,1)); // dark blue
vec_set(sky_color,vector(50,1,1)); // dark blue
video_window(NULL,NULL,0,"My New Game");
on_esc = exits;
level_load(NULL);
wait(1);
reset(camera,SHOW);
mouse_mode=3;
wait(1);
//vec_set(camera.x,vector(-250,0,50));
//vec_set(camera.pan,vector(0,-15,0));
int value = GetSystemMetrics(94);
if (value & NID_READY){
//error("ready");/* stack ready */
print2("ready");
}
if (value & NID_MULTI_INPUT){
/* digitizer is multitouch */
//error("Multitouch found");
}
if (value & NID_INTEGRATED_TOUCH){
//error("integrated touch");/* Integrated touch */
}
BYTE
digitizerStatus = GetSystemMetrics(94);
if ((digitizerStatus & (0x80 + 0x40)) == 0) //Stack Ready + MultiTouch
{
error("no multitouch");
return;
}
var nInputs = GetSystemMetrics(95);
//printf("number of touches= %.0f",(double)nInputs);
if (!RegisterTouchWindow(hWnd,0))
{error("error");}
OriginalHandler = on_message; // store the original message loop
on_message = MyMessageHandler; // and replace it by your own
init_vals();
}