Beispiel #1
0
LPTABLETDATA GetNextPacket( BOOL fRemove )
//  Gets next packet from the queue.
//  If fRemove == TRUE, the packet is removed from the queue.
//  Otherwise, it is only copied from the queue.  
//////////////////////////////////////////////////////////////////////////////
{
    PACKET Packet;
    int numpkts;

    memset( &TabletData, 0, sizeof( TABLETDATA ));

    // bring context to front
    WTOverlap( hContext, TRUE );    

    if( fRemove )
        numpkts = WTPacketsGet( hContext, 1, &Packet );
    else
        numpkts = WTPacketsPeek( hContext, 1, &Packet );

    if( numpkts )
        return( PrsAdjust( Packet ));   // return new pressure and position
    else
        return( &TabletData );
}
Beispiel #2
0
/* -------------------------------------------------------------------------- */
LRESULT FAR PASCAL RuleAppWndProc (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
	static int inMode = ID_CLICK;
	static LONG x1 = 0, x2 = 0, y1 = 0, y2 = 0;
	static HCTX hTab = NULL;

	static FIX32 scale[2];

	PAINTSTRUCT psPaint;
	HDC hDC;

	switch (wMsg) {

		case WM_CREATE:
			TabletScaling(scale);
			break;

		case WM_LBUTTONDOWN:
			if ((hTab = TabletInit(hWnd, scale)) != NULL) {
				PACKET pkt;

				inMode = ID_PRESS;
				InvalidateRect(hWnd, NULL, TRUE);
				UpdateWindow(hWnd);

				while (inMode != ID_CLICK) {

					/* poll */
					if (!WTPacketsGet(hTab, 1, &pkt))
						continue;

					/* handle it */
					if (inMode == ID_PRESS && pkt.pkButtons) {
						x1 = pkt.pkX;
						y1 = pkt.pkY;
						inMode = ID_RELEASE;
						InvalidateRect(hWnd, NULL, TRUE);
						UpdateWindow(hWnd);
					}
					if (inMode == ID_RELEASE && pkt.pkButtons == 0) {
						x2 = pkt.pkX;
						y2 = pkt.pkY;
						inMode = ID_CLICK;
						InvalidateRect(hWnd, NULL, TRUE);
						UpdateWindow(hWnd);
					}
				}
				WTClose(hTab);
			}
			break;

		case WM_PAINT:
			hDC = BeginPaint(hWnd, &psPaint);
			ShowWindow(GetDlgItem(hWnd, ID_CLICK), inMode == ID_CLICK);
			ShowWindow(GetDlgItem(hWnd, ID_PRESS), inMode == ID_PRESS);
			ShowWindow(GetDlgItem(hWnd, ID_RELEASE), inMode == ID_RELEASE);
			if (inMode == ID_CLICK) {
				LONG delta[3];	/* horz/vert/diag */
				int i;

				delta[0] = labs(x2 - x1);
				delta[1] = labs(y2 - y1);
				delta[2] = nsqrt(delta[0] * delta[0] + delta[1] * delta[1]);

				for (i = 0; i < 3; i++) {	 	/* direction */
					char buf[20];

					/* print result in cm */
					wsprintf(buf, "%d.%3.3d", (UINT)delta[i]/1000,
						(UINT)delta[i]%1000);
					SetWindowText(GetDlgItem(hWnd, ID_HC + i), buf);

					/* convert to inches */
					delta[i] = INT(delta[i] * Cm2Inch);

					/* print result in inches */
					wsprintf(buf, "%d.%3.3d", (UINT)delta[i]/1000,
						(UINT)delta[i]%1000);
					SetWindowText(GetDlgItem(hWnd, ID_HI + i), buf);
				}
			}
			EndPaint(hWnd, &psPaint);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;

		default:
			return DefWindowProc(hWnd, wMsg, wParam, lParam);
	}
	return (LRESULT)0;
}
Beispiel #3
0
void moTablet::Update(moEventList *Events)
{
    MOuint i;
    moEvent *actual,*tmp;
    int n, tabletcode;

    for(n = 0; n < ncodes; n++) Codes[n].Cleanup();

//#ifdef MO_LINUX
/**
        while (XPending(m_Disp)) // Event loop
            {
                XEvent Event;
                XNextEvent(m_Disp, &Event);

                if (EasyTab_HandleEvent(&Event) == EASYTAB_OK)          // Event
                {
                    MODebug2->Message("Tablet Event EASYTAB_OK");
                    MODebug2->Message("Pos X:"+IntToStr(EasyTab->PosX)
                    +" Pos Y:"+ IntToStr(EasyTab->PosY)
                    +" Pressure"+ FloatToStr(EasyTab->Pressure) );
                    continue; // Tablet event handled
                }

                switch (Event.type)
                {

                }

                MODebug2->Message("Tablet Event:");
            }*/

          if (Events==NULL) return;

          actual = Events->First;
          //recorremos todos los events y parseamos el resultado
          //borrando aquellos que ya usamos
          while(actual!=NULL) {
            //solo nos interesan los del mouse
						/*moDebugManager::Message("TBLevent: did: " + IntToStr(actual->deviceid)
                                  + " dcode:" + IntToStr(actual->devicecode)
                                + " v0:" + IntToStr(actual->reservedvalue0)
                              + " v1:" + IntToStr(actual->reservedvalue1)
                            + " v2:" + IntToStr(actual->reservedvalue2)
													+ "MO_IODEVICE_TABLET:"+IntToStr(MO_IODEVICE_TABLET) );*/
            if(actual->deviceid == MO_IODEVICE_TABLET) {
              /*MODebug2->Message("tablet: MO_IODEVICE_TABLET event! code:"+IntToStr(actual->devicecode)
              +" devcode:" + IntToStr(SDL_MOUSEMOTION));*/

              switch(actual->devicecode) {
                case SDL_MOUSEMOTION:
                  {
                    //MODebug2->Message("tablet: motion");
                    tabletcode = TABLET_PEN_MOTION_X;
                    Pen[tabletcode].Change(actual->reservedvalue0);
                    Codes[tabletcode].state = true;
                    Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);

                    tabletcode = TABLET_PEN_MOTION_Y;
                    Pen[tabletcode].Change(actual->reservedvalue1);
                    Codes[tabletcode].state = true;
                    Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);

                    tabletcode = TABLET_PEN_PRESSURE;
                    Pen[tabletcode].Change(actual->reservedvalue2);
                    Codes[tabletcode].state = true;
                    Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);
                  }
                  break;

                default:
                  break;
              }

              tmp = actual->next;
              //Events->Delete(actual);
              actual = tmp;
            } else {
              actual = actual->next;
            }
          }


//#endif


#ifdef MO_WIN32
	if (!t_hTablet) return;



	UINT nTabPressure = 0;	// 0 = nothing 255 = hardest
	int nTabAlt = 0;	    // Which way up for Wacom pens, negative = eraser, positive = normal tip
	int nTabTwist = 0;	    // Spin about x axis, I don't think this is used on Wacom pens
	int nTabCompass = 0;	// 0 = North, 900 = east etc.
	UINT nTabCursor = 0;	// A number for the selected cursor or pointer, Wacom 1=normal, 2=eraser

	UINT  		t_buttonNew;
	UINT  		prsOld;
	UINT  		curOld;
	ORIENTATION ortOld;

	LONG         pkXOld;
	LONG         pkYOld;
	LONG         pkZOld;

	PACKET* pkt;     // the current packet
#endif
	// Update codes.


#ifdef MO_WIN32
    // Polling the packets in the queue with
	// int WTPacketsGet(hCtx, cMaxPkts, lpPkts), where
	// Parameter	Type/Description
	// hCtx	HCTX  Identifies the context whose packets are being returned.
	// cMaxPkts	int  Specifies the maximum number of packets to return.
	// lpPkts	LPVOID  Points to a buffer to receive the event packets.
    // Return Value	The return value is the number of packets copied in the buffer.
	UINT cPkts = WTPacketsGet(t_hTablet, m_cMaxPkts, m_lpPkts);

    if (cPkts == 0)
	{
		// No events... setting pressure to zero.
		/*
		tabletcode = TABLET_PEN_PRESSURE;
        Pen[tabletcode].Change(0);
		if (Pen[tabletcode].change)
		{
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);

			MODebug2->Push( moText(" Tablet: ") + IntToStr(Pen[tabletcode].value) );
		}
		*/
	}

	for (i = 0; i < cPkts; i++)
	{
		pkt = &m_lpPkts[i];

		// Saving old data...
		prsOld = t_prsNew;
		curOld = t_curNew;
		ortOld = t_ortNew;

		pkXOld = t_pkXNew;
		pkYOld = t_pkYNew;
		pkZOld = t_pkZNew;

		t_pkXNew = m_pResourceManager->GetRenderMan()->RenderWidth() * ((float)pkt->pkX / (float)lcMine.lcOutExtX);
		t_pkYNew = m_pResourceManager->GetRenderMan()->RenderHeight() * ((float)pkt->pkY / (float)lcMine.lcOutExtY);
		t_pkZNew = pkt->pkZ;

		t_curNew = pkt->pkCursor;
		t_prsNew = pkt->pkNormalPressure;
		t_ortNew = pkt->pkOrientation;

		t_buttonNew = pkt->pkButtons;

		nTabPressure = t_prsNew;
		nTabCompass = t_ortNew.orAzimuth ;	//Clockwise rotation about z-azis, 0 is north, 900 is east, 1800 is south and 2700 is west, 3599 is nearly north again.
		nTabAlt = t_ortNew.orAltitude ;	    //Tilt.  If Wacom then Positive = normal tip, negative = eraser tip
		nTabTwist = t_ortNew.orTwist ;	    //I don't think it's used on Wacom pen tablets
		nTabCursor = t_curNew;	            //1=normal 2=eraser.

		tabletcode = -1;

		if (t_pkXNew != pkXOld)
		{
			tabletcode = TABLET_PEN_MOTION_X;
			Pen[tabletcode].Change(t_pkXNew);
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);

			//#ifdef MO_DEBUG
            //MODebug2->Push( moText(" motion x: ") + IntToStr(Pen[tabletcode].value) );
            //#endif
		}

		if (t_pkYNew != pkYOld)
		{
			tabletcode = TABLET_PEN_MOTION_Y;
			Pen[tabletcode].Change(t_pkYNew);
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);

			//#ifdef MO_DEBUG
			//MODebug2->Push( moText(" motion y: ") + IntToStr(Pen[tabletcode].value) );
			//#endif
		}

		if (t_pkZNew != pkZOld)
		{
			tabletcode = TABLET_PEN_MOTION_Z;
			Pen[tabletcode].Change(t_pkZNew);
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);
		}

		if (t_prsNew != prsOld)
		{
			tabletcode = TABLET_PEN_PRESSURE;
            Pen[tabletcode].Change(t_prsNew);
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);
			//MODebug->Push(moText("Pressure: ") + IntToStr(t_prsNew));
			#ifdef _DEBUG
			MODebug2->Message( moText(" pressure: ") + IntToStr(Pen[tabletcode].value) );
			#endif
		}

		if (t_ortNew.orAzimuth != ortOld.orAzimuth)
		{
			tabletcode = TABLET_PEN_AZIMUTH;
            Pen[tabletcode].Change(t_ortNew.orAzimuth);
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);

			//MODebug2->Push( moText(" azimuth: ") + IntToStr(Pen[tabletcode].value) );
		}

		if (t_ortNew.orAltitude != ortOld.orAltitude)
		{
			tabletcode = TABLET_PEN_TILT;
            Pen[tabletcode].Change(t_ortNew.orAltitude);
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);
		}

		if (t_ortNew.orTwist != ortOld.orTwist)
		{
			tabletcode = TABLET_PEN_TWIST;
            Pen[tabletcode].Change(t_ortNew.orTwist);
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);
		}

		if (t_curNew != curOld)
		{
			tabletcode = TABLET_PEN_CURSOR;
            Pen[tabletcode].Change(MOCursorCode(t_curNew));
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);
		}

		/*
		if ((TABLET_PEN_MOTION_X <= tabletcode) && (tabletcode <= TABLET_PEN_CURSOR))
			if (Pen[tabletcode].change)
			{
				Codes[tabletcode].state = true;
				Codes[tabletcode].AddValueToArray(Pen[tabletcode].value);
			}
			*/

		if (t_buttonNew > 1)
		{
			//MODebug->Push("Pressure when pressing button: " + IntToStr(t_prsNew));
			tabletcode = TABLET_PEN_BUTTON;
			Codes[tabletcode].state = true;
			Codes[tabletcode].AddValueToArray(t_buttonNew);
		}
	}
	#endif
}