/******************************************************************** * * _Explain * * Purpose: * Shows a text to give a short explanation of the sample program */ static void _Explain(void) { _DispStringCentered("At first time, you need to\n" "calibrate the Touch screen\n" "Please press the touch\n" "screen to continue..."); GUI_DispStringHCenterAt("Touch screen Calibration", LCD_GetXSize() / 2, 5); _WaitForPressedState(1); _WaitForPressedState(0); }
/******************************************************************** * * _Explain * * Funtion description * Shows a text to give a short explanation of the sample program */ static void _Explain(void) { _DispStringCentered("This sample shows how\n" "a touch screen can be\n" "calibrated at run time.\n" "Please press the touch\n" "screen to continue..."); GUI_DispStringHCenterAt("TOUCH_Calibrate", LCD_GetXSize() / 2, 5); _WaitForPressedState(1); _WaitForPressedState(0); }
/********************************************************************* * * _GetPhysValues * * Function description * Asks the user to press the touch screen at the given position * and returns the physical A/D values */ static void _GetPhysValues(int LogX, int LogY, int * pPhysX, int * pPhysY, const char * pString) { char acText[] = "Press here"; GUI_RECT Rect; int FontSizeY; int Align; FontSizeY = GUI_GetFontSizeY(); GUI_Clear(); GUI_SetColor(GUI_BLACK); _DispStringCentered("Runtime calibration,\n" "please touch the screen\n" "at the center of the ring."); /* Ask user to press the touch */ // // Calculate the rectangle for the string // Rect.y0 = LogY - FontSizeY; Rect.y1 = LogY + FontSizeY; if (LogX < LCD_GetXSize() / 2) { Rect.x0 = LogX + 15; Rect.x1 = LCD_GetXSize(); Align = GUI_TA_LEFT; } else { Rect.x0 = 0; Rect.x1 = LogX - 15; Align = GUI_TA_RIGHT; } // // Show the text nearby the ring // GUI_DispStringInRect(acText, &Rect, Align | GUI_TA_TOP); GUI_DispStringInRect(pString, &Rect, Align | GUI_TA_BOTTOM); // // Draw the ring // GUI_FillCircle(LogX, LogY, 10); GUI_SetColor(GUI_WHITE); GUI_FillCircle(LogX, LogY, 5); GUI_SetColor(GUI_BLACK); // // Wait until touch is pressed // _WaitForPressedState(1); *pPhysX = GUI_TOUCH_GetxPhys(); *pPhysY = GUI_TOUCH_GetyPhys(); // // Wait until touch is released // _WaitForPressedState(0); }
/********************************************************************* * * _GetPhysValues * * Purpose: * Asks the user to press the touch screen at the given position * and returns the physical pixels(A/D) values */ static void _GetPhysValues(int LogX, int LogY, int * pPhysX, int * pPhysY, const char * pString) { char acText[] = "Press here"; GUI_RECT Rect; GUI_PID_STATE State; int FontSizeY, Align; FontSizeY = GUI_GetFontSizeY(); /*获取字体的高度*/ GUI_Clear(); GUI_SetColor(GUI_BLACK); _DispStringCentered("Runtime calibration,\n" "please touch the corners of the screen\n" "at the center of the rings."); /* Ask user to press the touch */ /* Calculate the rectangle for the string(根据触摸点的位置,设置文字显示的区域) */ if (LogX < LCD_GetXSize() / 2) {/*判断是左上角的点,还是有下角的点*/ Rect.x0 = LogX + 25; Rect.x1 = LCD_GetXSize(); Rect.y0 = LogY - FontSizeY + 5; /*设置大小能显示两行字符*/ Rect.y1 = LogY + FontSizeY + 5; Align = GUI_TA_LEFT; } else { Rect.x0 = 0; Rect.x1 = LogX - 25; Rect.y0 = LogY - FontSizeY - 5; Rect.y1 = LogY + FontSizeY - 5; Align = GUI_TA_RIGHT; } /* Show the text nearby the ring */ GUI_DispStringInRect(acText, &Rect, Align | GUI_TA_TOP); GUI_DispStringInRect(pString, &Rect, Align | GUI_TA_BOTTOM); /* Draw the ring */ GUI_FillCircle(LogX, LogY, 10); GUI_SetColor(GUI_WHITE); GUI_FillCircle(LogX, LogY, 7); GUI_SetColor(GUI_BLACK); /* Wait until touch is pressed */ _WaitForPressedState(1); /*得到触摸点的值*/ GUI_TOUCH_GetState(&State); *pPhysX = State.x; *pPhysY = State.y; /* Wait until touch is released */ _WaitForPressedState(0); }