Beispiel #1
1
/* Ôóíêöèÿ îáðàáîòêè ñîîáùåíèÿ îêíà.
 * ÀÐÃÓÌÅÍÒÛ:
 *   - äåñêðèïòîð îêíà:
 *       HWND hWnd;
 *   - íîìåð ñîîáùåíèÿ (ñì. WM_***):
 *       UINT Msg;
 *   - ïàðàìåòð ñîîáøåíèÿ ('word parameter'):
 *       WPARAM wParam;
 *   - ïàðàìåòð ñîîáøåíèÿ ('long parameter'):
 *       LPARAM lParam;
 * ÂÎÇÂÐÀÙÀÅÌÎÅ ÇÍÀ×ÅÍÈÅ:
 *   (LRESULT) - â çàâèñèìîñòè îò ñîîáùåíèÿ.
 */
LRESULT CALLBACK MyWindowFunc( HWND hWnd, UINT Msg,
                               WPARAM wParam, LPARAM lParam )
{
  HDC hDC;   
  CREATESTRUCT *cs;    
  SYSTEMTIME st;
  CHAR Buf[100];
  HFONT hFnt, hOldFnt; 
 /* HPEN hPen; */
 /* HBRUSH hBrush, hOldBr;*/
  static INT xx[100], yy[100];
  static BITMAP bm;
  static HBITMAP hBm, hBmLogo;
  static HDC hMemDC, hMemDCLogo;
  static INT w, h;
  

  switch (Msg)
  {
  case WM_CREATE:
    cs = (CREATESTRUCT *)lParam;
    SetTimer(hWnd, 111, 50, NULL);     

    hBmLogo = LoadImage(NULL, "clock.bmp", IMAGE_BITMAP, w, h, LR_LOADFROMFILE);  
    GetObject(hBmLogo, sizeof(bm), &bm);   

    /* ñîçäàåì êîíòåêñò â ïàìÿòè */
    hDC = GetDC(hWnd);
    hMemDC = CreateCompatibleDC(hDC);
    hMemDCLogo = CreateCompatibleDC(hDC);
    ReleaseDC(hWnd, hDC);

    SelectObject(hMemDCLogo, hBmLogo);     
    return 0;

  case WM_SIZE:
    w = LOWORD(lParam);
    h = HIWORD(lParam);

    /* ñîçäàåì êàðòèíêó ðàçìåðîì ñ îêíî */
    if (hBm != NULL)
      DeleteObject(hBm);

    hDC = GetDC(hWnd);                                                                            
    hBm = CreateCompatibleBitmap(hDC, w, h); 
    
    ReleaseDC(hWnd, hDC);

    SelectObject(hMemDC, hBm);
    SendMessage(hWnd, WM_TIMER, 111, 0);
    return 0;

  case WM_TIMER:
    /* Clear Background */
    SelectObject(hMemDC, GetStockObject(NULL_PEN));
    SelectObject(hMemDC, GetStockObject(DC_BRUSH));
    SetDCBrushColor(hMemDC, RGB(0, 0, 0));   
    Rectangle(hMemDC, 0, 0, w, h);

    StretchBlt(hMemDC, w / 2 - bm.bmWidth / 2, h / 2 - bm.bmHeight / 2, bm.bmWidth, bm.bmHeight,
      hMemDCLogo, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);    

    GetLocalTime(&st); 
    DrawHand(hMemDC, w / 2, h / 2, 160, 5, (st.wSecond * 6 + 180) * PI / 180);
    DrawHand(hMemDC, w / 2, h / 2, 130, 10, (st.wMinute * 6 + 180) * PI / 180);
    DrawHand(hMemDC, w / 2, h / 2, 130, 10, (st.wHour % 12 * 30 + 180) * PI / 180);
    SelectObject(hMemDC, GetStockObject(NULL_PEN));
    SelectObject(hMemDC, GetStockObject(NULL_BRUSH));

    hFnt = CreateFont(h / 8 , 0, 0, 0, FW_BOLD, FALSE, FALSE,
      FALSE, RUSSIAN_CHARSET, OUT_DEFAULT_PRECIS,
      CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
      VARIABLE_PITCH | FF_ROMAN, "");     
   
    hOldFnt = SelectObject(hMemDC, hFnt);
    GetLocalTime(&st);
    SetTextColor(hMemDC, RGB(255, 255, 255));
    SetBkColor(hMemDC, RGB(12, 24, 200));
    SetBkMode(hMemDC, TRANSPARENT);
    TextOut(hMemDC, w / 4, h / 6, Buf,
      sprintf(Buf, "%02d:%02d:%02d (%02d.%02d.%d)",
        st.wHour, st.wMinute, st.wSecond,
        st.wDay, st.wMonth, st.wYear)); 

    DeleteObject(hFnt);  

    InvalidateRect(hWnd, NULL, TRUE);
    return 0;      

  case WM_ERASEBKGND:
    BitBlt((HDC)wParam, 0, 0, w, h, hMemDC, 0, 0, SRCCOPY);
    return 0;

  case WM_DESTROY:
    DeleteDC(hMemDC);
    DeleteObject(hBm);
    DeleteDC(hMemDCLogo);
    DeleteObject(hBmLogo);
    KillTimer(hWnd, 111);
    PostQuitMessage(0);
    return 0;
  }
  return DefWindowProc(hWnd, Msg, wParam, lParam);
} /* End of 'MyWindowFunc' function */
void TimeFace::OnPaintAll(Bitmap *destination)
{
	int w = destination->Width();
	int h = destination->Height();
	int cx = w / 2;
	int cy = h / 2;

	destination->FillRect(0, 0, w, h, false);

	{
		char buf[10];
		int y = cy + 10;
		MetaWatch_Combined_8pt.Print(destination, 20, y, daysOfWeek[GetRTCDOW()]);
		goodsprintf(buf, "%i/%2i",
				GetRTCDAY(),
				GetRTCMON()
				);
		y += MetaWatch_Combined_8pt.Height();
		MetaWatch_Small_8pt.Print(destination, 20, y, buf);
		goodsprintf(buf, "%4i",
				GetRTCYEAR()
				);
		y += MetaWatch_Small_8pt.Height();
		MetaWatch_Small_8pt.Print(destination, 20, y, buf);
	}

	// Clock markings
	for (int i = 0; i < 12; i++)
		DrawHand(destination, cx, cy, htTick, GetRadians(i, 12));

	int hour = GetRTCHOUR() % 12;
	int minute = GetRTCMIN();
	int second = GetRTCSEC();

	// Hour
	int hourFull = (hour * 60) + minute;
	DrawHand(destination, cx, cy, htHour, GetRadians(hourFull, 12 * 60));

	// Minute
	int minuteFull = (minute * 60) + second;
	DrawHand(destination, cx, cy, htMinute, GetRadians(minuteFull, 60 * 60));

	// Second
	DrawHand(destination, cx, cy, htSecond, GetRadians(second, 60));
}
Beispiel #3
0
void MainWindow::goto_State(GameState state)
{
    m_gamestate = state;
    switch (m_gamestate) {
    case Login:
        ui->tableName->setEnabled(false);
        break;
    case Pick:
        bet = BetAmount();
        ui->instructions->setText("Select cards to discard then press Draw");
        ui->action->setText("Draw!");
        ui->result_msg->setText("");
        DrawHand();
        DisplayHand();
        EnableCards(true);
        break;
    case Results:
        ui->instructions->setText("");
        DisplayHand();
        //EnableCards(false);
        ui->action->setText("Play Again");
        break;
    case Start:
        ui->instructions->setText("Select a bet amount.\nPayoff shows the fixed payoff plus any additional progressive jackpot.");
        ui->action->setText("Bet!");
        ui->result_msg->setText("");
        clearCards();
        ClearCelebrate();
        break;
    case Bankrupt:
        DisplayHand();
        ui->instructions->setText("You ran out of money.\nYou must admit you are a loser,\nbut then you'll get another $1000");
        ui->action->setText("I'm a loser.\r\nHelp me.");
        break;
    }
}
Beispiel #4
0
/// <summary>
/// Handle new body data
/// <param name="nTime">timestamp of frame</param>
/// <param name="nBodyCount">body data count</param>
/// <param name="ppBodies">body data in frame</param>
/// </summary>
void CBodyBasics::ProcessBody(INT64 nTime, int nBodyCount, IBody** ppBodies)
{
    if (m_hWnd)
    {
        HRESULT hr = EnsureDirect2DResources();

        DetectionResult nEngaged[6] = { DetectionResult_Unknown };

        int width = 0;
        int height = 0;
        if (SUCCEEDED(hr) && m_pRenderTarget && m_pCoordinateMapper)
        {
            m_pRenderTarget->BeginDraw();
            m_pRenderTarget->Clear();

            RECT rct;
            GetClientRect(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), &rct);
            width = rct.right;
            height = rct.bottom;

            for (int i = 0; i < nBodyCount; ++i)
            {
                nEngaged[i] = DetectionResult_Maybe;

                IBody* pBody = ppBodies[i];
                if (pBody)
                {
                    BOOLEAN bTracked = false;
                    hr = pBody->get_IsTracked(&bTracked);

                    // Engaged()は使えるみたい。これは、視野に入ってきた人を認識するものだろう。
                    hr = pBody->get_Engaged( &nEngaged[i] );
                    // 以下はまだ使えないようだ
                    //hr = pBody->GetAppearanceDetectionResults((UINT)i, &nEngaged[i]);

                    if (SUCCEEDED(hr) && bTracked)
                    {
                        Joint joints[JointType_Count];
                        D2D1_POINT_2F jointPoints[JointType_Count];
                        HandState leftHandState = HandState_Unknown;
                        HandState rightHandState = HandState_Unknown;

                        pBody->get_HandLeftState(&leftHandState);
                        pBody->get_HandRightState(&rightHandState);

                        hr = pBody->GetJoints(_countof(joints), joints);
                        if (SUCCEEDED(hr))
                        {
                            for (int j = 0; j < _countof(joints); ++j)
                            {
                                jointPoints[j] = BodyToScreen(joints[j].Position, width, height);
                            }

                            DrawBody(joints, jointPoints);

                            // ここに頭部に丸を描いて、ボディ番号を表示
                            DrawHead(jointPoints[JointType_Head], i, nEngaged[i]);

                            DrawHand(leftHandState, jointPoints[JointType_HandLeft]);
                            DrawHand(rightHandState, jointPoints[JointType_HandRight]);
                        }
                    }
                }
            }

            hr = m_pRenderTarget->EndDraw();

            // Device lost, need to recreate the render target
            // We'll dispose it now and retry drawing
            if (D2DERR_RECREATE_TARGET == hr)
            {
                hr = S_OK;
                DiscardDirect2DResources();
            }
        }

        if (!m_nStartTime)
        {
            m_nStartTime = nTime;
        }

        double fps = 0.0;

        LARGE_INTEGER qpcNow = {0};
        if (m_fFreq)
        {
            if (QueryPerformanceCounter(&qpcNow))
            {
                if (m_nLastCounter)
                {
                    m_nFramesSinceUpdate++;
                    fps = m_fFreq * m_nFramesSinceUpdate / double(qpcNow.QuadPart - m_nLastCounter);
                }
            }
        }

        WCHAR szStatusMessage[128] ;
        StringCchPrintf( szStatusMessage, _countof(szStatusMessage),
                         L" FPS = %0.2f  Time = %I64d width:%d height:%d",
                         fps, (nTime - m_nStartTime), width, height);

        if (SetStatusMessage(szStatusMessage, 1000, false))
        {
            m_nLastCounter = qpcNow.QuadPart;
            m_nFramesSinceUpdate = 0;
        }
    }
}
Beispiel #5
0
/* Функция обработки сообщения окна.
 * АРГУМЕНТЫ:
 *   - дескриптор окна:
 *       HWND hWnd;
 *   - номер сообщения (см. WM_***):
 *       UINT Msg;
 *   - параметр сообшения ('word parameter'):
 *       WPARAM wParam;
 *   - параметр сообшения ('long parameter'):
 *       LPARAM lParam;
 * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ:
 *   (LRESULT) - в зависимости от сообщения.
 */
LRESULT CALLBACK MyWindowFunc( HWND hWnd, UINT Msg,
                               WPARAM wParam, LPARAM lParam )
{
  HDC hDC;
  CREATESTRUCT *cs; 
  POINT pt;
  SYSTEMTIME st;
  CHAR Buf[100];
  HFONT hFnt;
  HPEN hPen;
  DOUBLE Angle;
  static BITMAP bm;
  static HBITMAP hBm, hBmLogo;
  static HDC hMemDC, hMemDCLogo;
  static INT w, h;


  switch (Msg)
  {
  case WM_CREATE:
    cs = (CREATESTRUCT *)lParam;
    SetTimer(hWnd, 111, 50, NULL);

    hDC = GetDC(hWnd);
    hBmLogo = LoadImage(NULL, "clock.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    GetObject(hBmLogo, sizeof(bm), &bm);

    /* создаем контекст в памяти */
    hMemDC = CreateCompatibleDC(hDC);
    hMemDCLogo = CreateCompatibleDC(hDC);
    ReleaseDC(hWnd, hDC);

    SelectObject(hMemDCLogo, hBmLogo);
    return 0;

  case WM_SIZE:
    w = LOWORD(lParam);
    h = HIWORD(lParam);

    /* создаем картинку размером с окно */
    if (hBm != NULL)
      DeleteObject(hBm);

    hDC = GetDC(hWnd);
    hBm = CreateCompatibleBitmap(hDC, w, h);
    ReleaseDC(hWnd, hDC);

    SelectObject(hMemDC, hBm);
    SendMessage(hWnd, WM_TIMER, 111, 0);
    return 0;

  case WM_TIMER:
    /* Clear Background */
    SelectObject(hMemDC, GetStockObject(NULL_PEN));
    SelectObject(hMemDC, GetStockObject(DC_BRUSH));
    SetDCBrushColor(hMemDC, RGB(0, 0, 0));
    Rectangle(hMemDC, 0, 0, w + 1, h + 1);

    SelectObject(hMemDC, hBm);
    BitBlt(hMemDC, w / 2 - 300, h / 2 - 300, 600, 600,
      hMemDCLogo, 0, 0, SRCCOPY);

    /* Draw picture */
    hFnt = CreateFont(100, 0, 0, 0, FW_BOLD, FALSE, FALSE,
      FALSE, RUSSIAN_CHARSET, OUT_DEFAULT_PRECIS,
      CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
      VARIABLE_PITCH | FF_ROMAN, "");
    hFnt = SelectObject(hMemDC, hFnt);
    GetLocalTime(&st);
    SetTextColor(hMemDC, RGB(0, 200, 200));
    SetBkColor(hMemDC, RGB(0, 0, 0));  
    SetBkMode(hMemDC, TRANSPARENT);
    TextOut(hMemDC, w / 2 - 165, h / 2 - 400, Buf,
      sprintf(Buf, "%02d:%02d:%02d",
        st.wHour, st.wMinute, st.wSecond));
    TextOut(hMemDC, w / 2 - 200, h / 2 + 300, Buf,
      sprintf(Buf, "%02d.%02d.%d",
        st.wDay, st.wMonth, st.wYear));

    DeleteObject(hFnt);

 //   Angle = st.wSecond / 30.0 * PI + PI / 2;

    hPen = CreatePen(PS_SOLID, 5, RGB(255, 255, 255));
    SelectObject(hMemDC, hPen);

/*    pt.x = cos(Angle) * 250;
    pt.y = sin(Angle) * 250;
    MoveToEx(hMemDC, w / 2, h / 2, NULL);
    LineTo(hMemDC, w / 2 - pt.x, h / 2 - pt.y);  */

    SetDCBrushColor(hMemDC, RGB(0, 200, 200)); 
    DrawHand(hMemDC, w / 2, h / 2, 150, 10, (int)(st.wHour) % 12 * PI / 180 + 0.25);
    DrawHand(hMemDC, w / 2, h / 2, 200, 10, st.wMinute * 6 * PI / 180 + PI);
    
    SetDCBrushColor(hMemDC, RGB(0, 0, 0));
    DrawHand(hMemDC, w / 2, h / 2, 250, 10, st.wSecond * 6 * PI / 180 + PI);

    DeleteObject(hPen);   
  
    InvalidateRect(hWnd, NULL, TRUE);
    return 0;

  case WM_CLOSE:
    break;

  case WM_ERASEBKGND:
    BitBlt((HDC)wParam, 0, 0, w, h, hMemDC, 0, 0, SRCCOPY);
    return 0;


  case WM_DESTROY:
    DeleteDC(hMemDC);
    DeleteObject(hBm);
    DeleteDC(hMemDCLogo);
    DeleteObject(hBmLogo);
    KillTimer(hWnd, 111);
    PostQuitMessage(0);
    return 0;
  }
  return DefWindowProc(hWnd, Msg, wParam, lParam);
} /* End of 'MyWindowFunc' function */
/// <summary>
/// Handle new body data
/// <param name="nTime">timestamp of frame</param>
/// <param name="nBodyCount">body data count</param>
/// <param name="ppBodies">body data in frame</param>
/// </summary>
void CBodyBasics::ProcessBody(INT64 nTime, int nBodyCount, IBody** ppBodies)
{
   
	//Declare a struct to collect data
	struct FRAME_RESUME actual_frame;
	
	if (m_hWnd)
    {
        HRESULT hr = EnsureDirect2DResources();

        if (SUCCEEDED(hr) && m_pRenderTarget && m_pCoordinateMapper)
        {
            m_pRenderTarget->BeginDraw();
            m_pRenderTarget->Clear();

            RECT rct;
            GetClientRect(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), &rct);
            int width = rct.right;
            int height = rct.bottom;

            for (int i = 0; i < nBodyCount; ++i)
            {
                IBody* pBody = ppBodies[i];
                if (pBody)
                {
                    BOOLEAN bTracked = false;
                    hr = pBody->get_IsTracked(&bTracked);

					//If the person is tracked we assign true '1', else we assign false '0'
					actual_frame.person[i].isTracked = bTracked;

					//If the person is tracked
                    if (SUCCEEDED(hr) && bTracked)
                    {
                        Joint joints[JointType_Count]; 
                        D2D1_POINT_2F jointPoints[JointType_Count];
                        HandState leftHandState = HandState_Unknown;
                        HandState rightHandState = HandState_Unknown;

                        pBody->get_HandLeftState(&leftHandState);
                        pBody->get_HandRightState(&rightHandState);

                        hr = pBody->GetJoints(_countof(joints), joints);
                        if (SUCCEEDED(hr))
                        {
                            
							for (int j = 0; j < _countof(joints); ++j)
                            {
                                jointPoints[j] = BodyToScreen(joints[j].Position, width, height);	

								//If current joint is not tracked
								if (joints[j].TrackingState == TrackingState_NotTracked)
								{
									actual_frame.person[i].body.joint[j].isTracked = 0;
									actual_frame.person[i].body.joint[j].coordinate3D.X = 0;
									actual_frame.person[i].body.joint[j].coordinate3D.Y = 0;
									actual_frame.person[i].body.joint[j].coordinate3D.Z = 0;
									actual_frame.person[i].body.joint[j].coordinate2D.X = 0;
									actual_frame.person[i].body.joint[j].coordinate2D.Y = 0;
								}

								else
								{
									if (joints[j].TrackingState == TrackingState_Tracked)
									{
										actual_frame.person[i].body.joint[j].isTracked = 1;
									}
									else
									{
										if (joints[j].TrackingState == TrackingState_Inferred)
										{
											actual_frame.person[i].body.joint[j].isTracked = 2;
										}
										else
										{
											actual_frame.person[i].body.joint[j].isTracked = 3;
										}
									}

									actual_frame.person[i].body.joint[j].coordinate3D.X = joints[j].Position.X;
									actual_frame.person[i].body.joint[j].coordinate3D.Y = joints[j].Position.Y;
									actual_frame.person[i].body.joint[j].coordinate3D.Z = joints[j].Position.Z;
									actual_frame.person[i].body.joint[j].coordinate2D.X = jointPoints[j].x;
									actual_frame.person[i].body.joint[j].coordinate2D.Y = jointPoints[j].y;
								}

                            }						
											
							
                            DrawBody(joints, jointPoints);

                            DrawHand(leftHandState, jointPoints[JointType_HandLeft]);
                            DrawHand(rightHandState, jointPoints[JointType_HandRight]);
                        }											

						//Gesture values

						//Get body gesture
						//BodyGestureIdentification(actual_frame.person[i], &actual_frame.person[i].bodyGesture.type, &actual_frame.person[i].bodyGesture.parameter1);
						BodyPoseIdentification(actual_frame.person[i], &actual_frame.person[i].bodyPose.type);
						//Get hand gestures
						actual_frame.person[i].leftHandGesture.type = leftHandState;
						actual_frame.person[i].leftHandGesture.parameter1 = 0;
						actual_frame.person[i].rightHandGesture.type = rightHandState;
						actual_frame.person[i].rightHandGesture.parameter1 = 0;


                    }

					//If the person is not tracked put all its values in cero
					else
					{
						//All joints go to zero
						for (int j = 0; j <25; j++)
						{
							actual_frame.person[i].body.joint[j].isTracked = 0;
							actual_frame.person[i].body.joint[j].coordinate3D.X = 0;
							actual_frame.person[i].body.joint[j].coordinate3D.Y = 0;
							actual_frame.person[i].body.joint[j].coordinate3D.Z = 0;
							actual_frame.person[i].body.joint[j].coordinate2D.X = 0;
							actual_frame.person[i].body.joint[j].coordinate2D.Y = 0;
						}

						//All gestures go to zero
						actual_frame.person[i].bodyPose.type = 0;
						actual_frame.person[i].bodyGesture.type = 0;
						actual_frame.person[i].bodyGesture.parameter1 = 0;
						actual_frame.person[i].leftHandGesture.type = 0;
						actual_frame.person[i].leftHandGesture.parameter1 = 0;
						actual_frame.person[i].rightHandGesture.type = 0;
						actual_frame.person[i].rightHandGesture.parameter1 = 0;

					}


                }

           }

		    hr = m_pRenderTarget->EndDraw();

			// Device lost, need to recreate the render target
            // We'll dispose it now and retry drawing
            if (D2DERR_RECREATE_TARGET == hr)
            {
                hr = S_OK;
                DiscardDirect2DResources();
            }
        }

        if (!m_nStartTime)
        {
            m_nStartTime = nTime;
        }

        double fps = 0.0;

        LARGE_INTEGER qpcNow = {0};
        if (m_fFreq)
        {
            if (QueryPerformanceCounter(&qpcNow))
            {
                if (m_nLastCounter)
                {
                    m_nFramesSinceUpdate++;
                    fps = m_fFreq * m_nFramesSinceUpdate / double(qpcNow.QuadPart - m_nLastCounter);
                }
            }
        }

        WCHAR szStatusMessage[64];
        StringCchPrintf(szStatusMessage, _countof(szStatusMessage), L" FPS = %0.2f    Time = %I64d", fps, (nTime - m_nStartTime));

        if (SetStatusMessage(szStatusMessage, 1000, false))
        {
            m_nLastCounter = qpcNow.QuadPart;
            m_nFramesSinceUpdate = 0;
        }
    }

	//Collected results are sent to a file
	write_a_frame_resume_in_file(actual_frame);

}
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     {
     static DATETIME   dtPrevious ;
     static HDC        hdc ;
     static LONG       xPixelsPerMeter, yPixelsPerMeter ;
     static POINTL     aptlHour   [5] = { 0,-15, 10,0, 0,60, -10,0, 0,-15 },
                       aptlMinute [5] = { 0,-20,  5,0, 0,80,  -5,0, 0,-20 },
                       aptlSecond [2] = { 0,  0,  0,80 } ;
     static WINDOWINFO wi ;
     DATETIME          dt ;
     HPS               hps ;
     INT               iDiamMM, iAngle ;
     POINTL            aptl [3] ;

     switch (msg)
          {
          case WM_CREATE:
               hdc = WinOpenWindowDC (hwnd) ;

               DevQueryCaps (hdc, CAPS_VERTICAL_RESOLUTION,
                                  1L, &yPixelsPerMeter) ;
               DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION,
                                  1L, &xPixelsPerMeter) ;

               DosGetDateTime (&dtPrevious) ;
               dtPrevious.hours = (dtPrevious.hours * 5) % 60 +
                                   dtPrevious.minutes / 12 ;
               return 0 ;

          case WM_SIZE:
               wi.cxClient = SHORT1FROMMP (mp2) ;
               wi.cyClient = SHORT2FROMMP (mp2) ;

               iDiamMM = min (wi.cxClient * 1000L / xPixelsPerMeter,
                              wi.cyClient * 1000L / yPixelsPerMeter) ;

               wi.cxPixelDiam = xPixelsPerMeter * iDiamMM / 1000 ;
               wi.cyPixelDiam = yPixelsPerMeter * iDiamMM / 1000 ;
               return 0 ;

          case WM_TIMER:
               DosGetDateTime (&dt) ;
               dt.hours = (dt.hours * 5) % 60 + dt.minutes / 12 ;

               hps = WinGetPS (hwnd) ;
               GpiSetColor (hps, CLR_BACKGROUND) ;

               DrawHand (hps, aptlSecond, 2, dtPrevious.seconds, &wi) ;

               if (dt.hours   != dtPrevious.hours ||
                   dt.minutes != dtPrevious.minutes)
                    {
                    DrawHand (hps, aptlHour,   5, dtPrevious.hours,   &wi) ;
                    DrawHand (hps, aptlMinute, 5, dtPrevious.minutes, &wi) ;
                    }

               GpiSetColor (hps, CLR_NEUTRAL) ;

               DrawHand (hps, aptlHour,   5, dt.hours,   &wi) ;
               DrawHand (hps, aptlMinute, 5, dt.minutes, &wi) ;
               DrawHand (hps, aptlSecond, 2, dt.seconds, &wi) ;

               WinReleasePS (hps) ;
               dtPrevious = dt ;
               return 0 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ;
               GpiErase (hps) ;

               for (iAngle = 0 ; iAngle < 60 ; iAngle++)
                    {
                    aptl[0].x = 0 ;
                    aptl[0].y = 90 ;

                    RotatePoint    (aptl, 1, iAngle) ;
                    ScalePoint     (aptl, 1, &wi) ;
                    TranslatePoint (aptl, 1, &wi) ;

                    aptl[2].x = aptl[2].y = iAngle % 5 ? 2 : 10 ;

                    ScalePoint (aptl + 2, 1, &wi) ;

                    aptl[0].x -= aptl[2].x / 2 ;
                    aptl[0].y -= aptl[2].y / 2 ;

                    aptl[1].x = aptl[0].x + aptl[2].x ;
                    aptl[1].y = aptl[0].y + aptl[2].y ;

                    GpiMove (hps, aptl) ;
                    GpiBox (hps, DRO_OUTLINEFILL, aptl + 1,
                                 aptl[2].x, aptl[2].y) ;
                    }
               DrawHand (hps, aptlHour,   5, dtPrevious.hours,   &wi) ;
               DrawHand (hps, aptlMinute, 5, dtPrevious.minutes, &wi) ;
               DrawHand (hps, aptlSecond, 2, dtPrevious.seconds, &wi) ;

               WinEndPaint (hps) ;
               return 0 ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }
Beispiel #8
0
void MainWindow::on_tester_clicked()
{
    static int tester = 200;
    tester++;

    if (tester == 1) {
        QPixmap pixmap(QString(":/images/celebrations/%1.jpg").arg(1));
        ui->celebrate_pic->setPixmap(pixmap);
        //ui->celebrate_pic->setMask(pixmap.mask());
        m_anim_celebrate->start();
        ui->celebrate_pic->show();
    }
    else if (tester == 2) {
        m_anim_celebrate_fade->start();
    }
    else if (tester == 13) {
        DrawHand();
        EnableCards(true);
        m_gamestate = Pick;
    }
    else if (tester == 13) {
        DrawHand();
        EnableCards(true);
        m_gamestate = Pick;
    }
    else if (tester == 14) {
        ReplenishHand();
    }
    else if (tester == 3) {
        DoCelebrate(Small);
    }
    else if (tester == 4) {
        ClearCelebrate();
    }
    else if (tester == 5) {
        DoCelebrate(Medium);
    }
    else if (tester == 6) {
        ClearCelebrate();
    }
    else if (tester == 7) {
        DoCelebrate(Large);
    }
    else if (tester == 8) {
        ClearCelebrate();
    }
    else if (tester == 7) {
        PlaySound("slide2.mp3");
    }
    else if (tester == 8) {
        PlaySound("slide3.mp3");
    }
    else if (tester == 9) {
        PlaySound("slide4.mp3");
    }
    else if (tester == 10) {
        PlaySound("slide5.mp3");
    }
    else if (tester == 7) {
        PlaySound("swing.wav");
    }
    else if (tester == 8) {
        PlaySound("whoosh.wav");
    }
    else if (tester == 9) {
        PlaySound("too bad.mp3");
    }
}
Beispiel #9
0
int main ( int argc, char *argv[] )
{

    if ( SDL_Init(SDL_INIT_EVERYTHING) != 0)
    {
        std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
        return 2;
    }

    if(TTF_Init() == -1)
    {
        std::cout << "TTF_Init: " << TTF_GetError() << std::endl;
        return 7;
    }

    SDL_Window *window = SDL_CreateWindow("SDL_TEST", 80, 80, WIDTH, HEIGHT, SDL_WINDOW_SHOWN);
    if (window == NULL)
    {
        std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
        return 3;
    }

    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    if(renderer == NULL)
    {
        std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
        return 4;
    }
    SDL_RenderClear(renderer);

    SYSTEMTIME t;

    SDL_Surface *ClockPlate = SDL_CreateRGBSurface(0, WIDTH, HEIGHT, 32, 0, 0, 0, 0);
    SDL_Renderer *PlateRender = SDL_CreateSoftwareRenderer(ClockPlate);
    DrawPlate(PlateRender);
    SDL_Texture *TexturePlate = SDL_CreateTextureFromSurface(renderer, ClockPlate);
    SDL_DestroyRenderer(PlateRender);
    SDL_FreeSurface(ClockPlate);

    SDL_Color LogoColor = { 255, 0, 0, 255 };
    SDL_Rect LogoXY = { WIDTH/2-80, 70, 160, 40 };
    TTF_Font *LogoFont = TTF_OpenFont("C:/Windows/Fonts/KhmerUIb.ttf", 30);
    SDL_Surface *Logo = TTF_RenderUTF8_Blended(LogoFont, "HAMILTON", LogoColor);
    SDL_Texture *TextureLogo = SDL_CreateTextureFromSurface(renderer, Logo);
    SDL_FreeSurface(Logo);
    TTF_CloseFont(LogoFont);

    SDL_Color NumColor = { 0, 255, 255, 255 };
    SDL_Rect NumXY = { WIDTH/2-80, 280, 160, 40 };
    TTF_Font *NumFont = TTF_OpenFont("C:/Windows/Fonts/DIGITAL-Regular.ttf", 32);
    SDL_Surface *NumClock = NULL;
    SDL_Texture *TextureNum = NULL;
    char Num[8];

    SDL_Color DayColor = { 255, 0, 255, 255 };
    SDL_Rect DayXY = { WIDTH/2+75, HEIGHT/2-18, 80, 36 };
    TTF_Font *DayFont = TTF_OpenFont("C:/Windows/Fonts/DIGITAL-Regular.ttf", 60);
    SDL_Surface *SurfaceDay = NULL;
    SDL_Texture *TextureDay = NULL;
    char Day[6];

    bool Quit = false;
    SDL_Event event;
    while(!Quit)
    {
        while(SDL_PollEvent(&event))
            switch(event.type)
            {
                case SDL_KEYDOWN:
                    if(event.key.keysym.sym == SDLK_ESCAPE)
                        Quit = true;
                    break;
                case SDL_QUIT:
                    Quit = true;
                    break;
                default:
                    break;
            }
        GetLocalTime(&t);
        SDL_RenderCopy(renderer, TexturePlate, NULL, NULL);
        SDL_RenderCopy(renderer, TextureLogo, NULL, &LogoXY);

        sprintf(Day, "%.2d  %s", t.wDay, Week(t.wDayOfWeek));
        SurfaceDay = TTF_RenderUTF8_Blended(DayFont, Day, DayColor);
        TextureDay = SDL_CreateTextureFromSurface(renderer, SurfaceDay);
        SDL_FreeSurface(SurfaceDay);
        SDL_RenderCopy(renderer, TextureDay, NULL, &DayXY);
        SDL_DestroyTexture(TextureDay);

        sprintf(Num, "%.2d:%.2d:%.2d", t.wHour, t.wMinute, t.wSecond);
        NumClock = TTF_RenderUTF8_Blended(NumFont, Num, NumColor);
        TextureNum = SDL_CreateTextureFromSurface(renderer, NumClock);
        SDL_FreeSurface(NumClock);
        SDL_RenderCopy(renderer, TextureNum, NULL, &NumXY);
        SDL_DestroyTexture(TextureNum);

        DrawHand(renderer, t.wHour, t.wMinute, t.wSecond);

        SDL_RenderPresent(renderer);
    }
    SDL_DestroyTexture(TextureLogo);
    SDL_DestroyTexture(TexturePlate);
    TTF_CloseFont(NumFont);

    return 0;
}
Beispiel #10
0
/*-------------------------------------------------------------
**	ClockTick
**		Clock timeout.
*/
static void 
ClockTick(
        XtPointer client_data,
        XtIntervalId *id )
{
	DtClockGadget		w = 	(DtClockGadget)client_data;	
	struct tm *	localtime ();
	struct tm 	tm; 
	time_t		time_value;
	char *		time_ptr;
	register Display *	dpy = XtDisplay (w);
	register Window		win = XtWindow (w);

	if (id || !w->clock.interval_id)
		w->clock.interval_id =
			XtAppAddTimeOut (
				XtWidgetToApplicationContext ((Widget) w),
				G_ClockInterval (w)*1000, ClockTick,
				(XtPointer)w );
	(void) time (&time_value);
	tm = *localtime (&time_value);

	if (! XtIsManaged ((Widget)w))
	{
		w->clock.otm = tm;
		return;
	}

/*	Beep on the half hour; double-beep on the hour.
*/
	if (w->clock.chime == TRUE)
	{
		if (w->clock.beeped && (tm.tm_min != 30) &&
		    (tm.tm_min != 0))
			w->clock.beeped = FALSE;
		if (((tm.tm_min == 30) || (tm.tm_min == 0)) 
		    && (!w->clock.beeped))
		{
			w->clock.beeped = TRUE;
			XBell (dpy, 50);	
			if (tm.tm_min == 0)
				XBell (dpy, 50);
		}
	}

/* remove this when clipping added to gcs */
	if ((G_Width (w) <
                   (Dimension)((G_ClockWidth (w) / 2) + w->clock.centerX)) ||
	    (G_Height (w) <
                   (Dimension)((G_ClockHeight (w) / 2) + w->clock.centerY)))
		return;

/*	The second (or minute) hand is sec (or min) sixtieths around the
*	clock face. The hour hand is (hour + min/60) twelfths of the way
*	around the clock-face.
*/
	if (tm.tm_hour > 12)
		tm.tm_hour -= 12;

	EraseHands (w, &tm);

	w->clock.segbuffptr = w->clock.segbuff;
	w->clock.numseg = 0;

/*	Calculate the hour hand, fill it in with its color.
*/
	DrawHand (w, w->clock.minute_hand_length, w->clock.hand_width,
				((double) tm.tm_min)/60.0);
	XDrawLines (dpy, win, G_ClockHandGC (w), w->clock.segbuff,
			VERTICES_IN_HANDS, CoordModeOrigin);
	XFillPolygon (dpy, win, G_ClockHandGC (w), w->clock.segbuff,
			VERTICES_IN_HANDS, Convex, CoordModeOrigin);

	w->clock.hour = w->clock.segbuffptr;

	DrawHand (w, w->clock.hour_hand_length, w->clock.hand_width,
			 ((((double)tm.tm_hour) + 
				(((double)tm.tm_min)/60.0)) / 12.0));
	XFillPolygon (dpy, win, G_ClockHandGC (w), w->clock.hour,
			VERTICES_IN_HANDS, Convex, CoordModeOrigin);
	XDrawLines (dpy, win, G_ClockHandGC (w), w->clock.hour,
			VERTICES_IN_HANDS, CoordModeOrigin);

	w->clock.sec = w->clock.segbuffptr;
	w->clock.otm = tm;
}
/// <summary>
/// Handle new body data
/// <param name="nTime">timestamp of frame</param>
/// <param name="nBodyCount">body data count</param>
/// <param name="ppBodies">body data in frame</param>
/// </summary>
void CBodyBasics::ProcessBody(INT64 nTime, int nBodyCount, IBody** ppBodies)
{
    if (m_hWnd)
    {
        HRESULT hr = EnsureDirect2DResources();

        if (SUCCEEDED(hr) && m_pRenderTarget && m_pCoordinateMapper)
        {
            m_pRenderTarget->BeginDraw();
            m_pRenderTarget->Clear();

            RECT rct;
            GetClientRect(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), &rct);
            int width = rct.right;
            int height = rct.bottom;

            for (int i = 0; i < nBodyCount; ++i)
            {
                IBody* pBody = ppBodies[i];
                if (pBody)
                {
                    BOOLEAN bTracked = false;
                    hr = pBody->get_IsTracked(&bTracked);

                    if (SUCCEEDED(hr) && bTracked)
                    {
                        Joint joints[JointType_Count]; 
                        D2D1_POINT_2F jointPoints[JointType_Count];
                        HandState leftHandState = HandState_Unknown;
                        HandState rightHandState = HandState_Unknown;

                        pBody->get_HandLeftState(&leftHandState);
                        pBody->get_HandRightState(&rightHandState);

                        hr = pBody->GetJoints(_countof(joints), joints);
                        if (SUCCEEDED(hr))
                        {
                            for (int j = 0; j < _countof(joints); ++j)
                            {
                                jointPoints[j] = BodyToScreen(joints[j].Position, width, height);
                            }

                            DrawBody(joints, jointPoints);

                            DrawHand(leftHandState, jointPoints[JointType_HandLeft]);
                            DrawHand(rightHandState, jointPoints[JointType_HandRight]);
                        }
						
                    }
                }
            }

            hr = m_pRenderTarget->EndDraw();

            // Device lost, need to recreate the render target
            // We'll dispose it now and retry drawing
            if (D2DERR_RECREATE_TARGET == hr)
            {
                hr = S_OK;
                DiscardDirect2DResources();
            }
        }
		FILE *fp;
		if ((fp = fopen("C:\\Users\\tuchiyama\\Desktop\\SpeechBasics-D2D\\speech.txt", "r")) != NULL) {
			if ((fp = fopen("body.txt", "r")) != NULL) {
				std::ifstream ifsa("C:\\Users\\tuchiyama\\Desktop\\SpeechBasics-D2D\\speech.txt");
				std::string linea;
				int si = 0;
				while (std::getline(ifsa, linea)) {
					si++;
				}
				std::ifstream ifsb("body.txt");
				std::string lineb;
				int bi = 0;
				while (std::getline(ifsb, lineb)) {
					bi++;
				}
				if (si > bi) {
					isWrite = true;
					std::ofstream ofs("body.txt", std::ios::app);
					for (int j = 0; j < si - bi; j++) {
						ofs << "start" << std::endl;
					}
				}
			}
		}
		if ((fp = fopen("C:\\Users\\tuchiyama\\Desktop\\SpeechBasics-D2D\\delete.txt", "r")) != NULL) {
			if ((fp = fopen("delete.txt", "r")) != NULL) {
				std::ifstream ifsa("C:\\Users\\tuchiyama\\Desktop\\SpeechBasics-D2D\\delete.txt");
				std::string linea;
				int si = 0;
				while (std::getline(ifsa, linea)) {
					si++;
				}
				std::ifstream ifsb("delete.txt");
				std::string lineb;
				int bi = 0;
				while (std::getline(ifsb, lineb)) {
					bi++;
				}
				if (si > bi) {
					system("ruby C:\\Users\\tuchiyama\\Documents\\odorimming\\make_html.rb undo");
					std::ofstream ofs("delete.txt", std::ios::app);
					for (int j = 0; j < si - bi; j++) {
						ofs << "delete" << std::endl;
					}
				}
			}
		}

        if (!m_nStartTime)
        {
            m_nStartTime = nTime;
        }

        double fps = 0.0;

        LARGE_INTEGER qpcNow = {0};
        if (m_fFreq)
        {
            if (QueryPerformanceCounter(&qpcNow))
            {
                if (m_nLastCounter)
                {
                    m_nFramesSinceUpdate+=1;
                    fps = m_fFreq * m_nFramesSinceUpdate / double(qpcNow.QuadPart - m_nLastCounter);
                }
            }
        }

        WCHAR szStatusMessage[64];
        StringCchPrintf(szStatusMessage, _countof(szStatusMessage), L" FPS = %0.2f    Time = %I64d", fps, (nTime - m_nStartTime));

        if (SetStatusMessage(szStatusMessage, 1000, false))
        {
            m_nLastCounter = qpcNow.QuadPart ;
            m_nFramesSinceUpdate = 0;
        }
    }
}