DWORD CGUIPage::OnGetObjectInsideRect(DWORD size, void *params) { DWORD retVal; OBJECTLIST::iterator olIter; IGUIElement *object; OBJINRECT *data; VERIFY_MESSAGE_SIZE(size, sizeof(OBJINRECT)); data = (OBJINRECT*)params; int x1 = data->x1; int x2 = data->x2; int y1 = data->y1; int y2 = data->y2; POSITIONDATA pd; IHashString *guiName; for(olIter = m_ObjectList.begin(); olIter != m_ObjectList.end(); olIter++) { object = dynamic_cast<IGUIElement*>(*olIter); if(!object) { m_ToolBox->SetErrorValue(ERR_NULL_POINTER); m_ToolBox->Log(LOGERROR, _T("Could not grab IGUIElement from list of gui elements")); return MSG_ERROR; } guiName = object->GetName(); static DWORD msgHash_GetPosition = CHashString(_T("GetPosition")).GetUniqueID(); retVal = m_ToolBox->SendMessage(msgHash_GetPosition, sizeof(POSITIONDATA), &pd, guiName); if(retVal != MSG_HANDLED) { m_ToolBox->Log(LOGERROR, _T("Could not send GetPosition message to %s\n"), guiName->GetString()); return MSG_ERROR; } if( InsideRect((int)pd.m_fXPos, (int)pd.m_fYPos, data->x1, data->y1, data->x2, data->y2) ) { data->list.push_back(object); } } if (data->list.empty()) { return MSG_HANDLED_PROCEED; } else { return MSG_HANDLED_STOP; } }
VOID CMainWnd::OnLButtonDown(WPARAM wParam, LPARAM lParam) { int x, y; x = LOWORD(lParam); y = HIWORD(lParam);//获取所在棋盘窗体客户区的坐标,根据所选棋种执行对应棋种单击事件处理函数 if (InsideRect(&rtBoard, x, y))//棋盘内为有效输入 { Function::MoveStep(x, y); } return; }
/* --- Window processing module for MENUBAR window class --- */ int MenuBarProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2) { int rtn; switch (msg) { case CREATE_WINDOW: reset_menubar(wnd); break; case SETFOCUS: return SetFocusMsg(wnd, p1); case BUILDMENU: BuildMenuMsg(wnd, p1); break; case PAINT: if (!isVisible(wnd) || GetText(wnd) == NULL) break; PaintMsg(wnd); return FALSE; case BORDER: if (mwnd == NULL) SendMessage(wnd, PAINT, 0, 0); return TRUE; case KEYBOARD: KeyboardMsg(wnd, p1); return TRUE; case LEFT_BUTTON: LeftButtonMsg(wnd, p1); return TRUE; case MB_SELECTION: SelectionMsg(wnd, p1, p2); break; case COMMAND: CommandMsg(wnd, p1, p2); return TRUE; case INSIDE_WINDOW: return InsideRect(p1, p2, WindowRect(wnd)); case CLOSE_POPDOWN: ClosePopdownMsg(wnd); return TRUE; case CLOSE_WINDOW: rtn = BaseWndProc(MENUBAR, wnd, msg, p1, p2); CloseWindowMsg(wnd); return rtn; default: break; } return BaseWndProc(MENUBAR, wnd, msg, p1, p2); }
/* ----------- MOUSE_MOVED Message ---------- */ static int MouseMovedMsg(WINDOW wnd, PARAM p1, PARAM p2) { int MouseX = (int) p1 - GetClientLeft(wnd); int MouseY = (int) p2 - GetClientTop(wnd); RECT rc = ClientRect(wnd); if (!InsideRect(p1, p2, rc)) return FALSE; if (MouseY > wnd->wlines-1) return FALSE; if (ButtonDown) { SetAnchor(wnd, ButtonX+wnd->wleft, ButtonY+wnd->wtop); TextMarking = TRUE; rc = WindowRect(wnd); SendMessage(NULL,MOUSE_TRAVEL,(PARAM) &rc, 0); ButtonDown = FALSE; } if (TextMarking && !(WindowMoving || WindowSizing)) { ExtendBlock(wnd, MouseX, MouseY); return TRUE; } return FALSE; }
int wxPageContainer::HitTest(const wxPoint& pt, wxPageInfo& pageInfo, int &tabIdx) { wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() ); wxRect rect = GetClientRect(); int btnLeftPos = render->GetLeftButtonPos(this); int btnRightPos = render->GetRightButtonPos(this); int btnXPos =render->GetXPos(this); long style = GetParent()->GetWindowStyleFlag(); tabIdx = -1; if(m_pagesInfoVec.IsEmpty()) { return wxFNB_NOWHERE; } rect = wxRect(btnXPos, 8, 16, 16); if(InsideRect(rect, pt)) { return (style & wxFNB_NO_X_BUTTON) ? wxFNB_NOWHERE : wxFNB_X; } rect = wxRect(btnRightPos, 8, 16, 16); if( style & wxFNB_DROPDOWN_TABS_LIST ) { rect = wxRect(render->GetDropArrowButtonPos( this ), 8, 16, 16); if(InsideRect(rect, pt)) return wxFNB_DROP_DOWN_ARROW; } if(InsideRect(rect, pt)) { return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_RIGHT_ARROW; } rect = wxRect(btnLeftPos, 8, 16, 16); if(InsideRect(rect, pt)) { return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_LEFT_ARROW; } // Test whether a left click was made on a tab bool bFoundMatch = false; for(size_t cur=m_nFrom; cur<m_pagesInfoVec.GetCount(); cur++) { wxPageInfo pgInfo = m_pagesInfoVec[cur]; if(pgInfo.GetPosition() == wxPoint(-1, -1)) continue; // check for mouse over tab's x button if(style & wxFNB_X_ON_TAB && (int)cur == GetSelection()) { // 'x' button exists on a tab if(InsideRect(m_pagesInfoVec[cur].GetXRect(), pt)) { pageInfo = pgInfo; tabIdx = (int)cur; return wxFNB_TAB_X; } } if(style & wxFNB_VC8) { if(m_pagesInfoVec[cur].GetRegion().Contains(pt) == wxInRegion) { if(bFoundMatch || (int)cur == GetSelection()) { pageInfo = pgInfo; tabIdx = (int)cur; return wxFNB_TAB; } pageInfo = pgInfo; tabIdx = (int)cur; bFoundMatch = true; } } else { wxRect tabRect = wxRect(pgInfo.GetPosition().x, pgInfo.GetPosition().y, pgInfo.GetSize().x, pgInfo.GetSize().y); if(InsideRect(tabRect, pt)) { // We have a match pageInfo = pgInfo; tabIdx = (int)cur; return wxFNB_TAB; } } } if(bFoundMatch) return wxFNB_TAB; // Default return wxFNB_NOWHERE; }
BOOL CALLBACK NewWordDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static int left, top, szblength; const HWND hwndEdit = FindWindowEx(hDlg, 0, TEXT("edit"), 0); static TCHAR szBuffer[50], http[100], wstr[50]; static char charBuffer[50]; HFONT hFontNew; switch (message) { case WM_INITDIALOG: RECT rect, drect; GetWindowRect(Mhwnd, &rect); GetWindowRect(hDlg, &drect); left = (rect.right - rect.left)/2 - (drect.right - drect.left)/2 + rect.left; top = (rect.bottom - rect.top)/2 - (drect.bottom - drect.top)/2 + rect.top; if(left > GetSystemMetrics (SM_CXSCREEN) - 100) left = GetSystemMetrics (SM_CXSCREEN) - 100; if(top > GetSystemMetrics (SM_CYSCREEN) - 100) top = GetSystemMetrics (SM_CYSCREEN) - 100; SetWindowPos(hDlg, 0, left, top, 161, 87, SWP_NOSIZE); PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)hwndEdit, TRUE); hFontNew = CreateFont(36,0,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH,TEXT("MS Shell Dlg")); SendMessage (hwndEdit, WM_SETFONT, (WPARAM) hFontNew, 0) ; SendMessage (hDlg, WM_COMMAND, (WPARAM) IDC_BUTTON1, 0) ; return FALSE ; case WM_ACTIVATE: if(wParam != WA_INACTIVE){ POINT point; RECT New_Word_rect, GRect; GetWindowRect(FindWindowEx(hDlg, 0, TEXT("button"), TEXT("New Word")), &New_Word_rect); GetWindowRect(FindWindowEx(hDlg, 0, TEXT("button"), TEXT("Google Dictionary")), &GRect); GetCursorPos(&point); if(InsideRect(New_Word_rect, point) || InsideRect(GRect, point)) return FALSE; else PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)hwndEdit, TRUE); } return TRUE; case WM_COMMAND: switch (LOWORD (wParam)) { case IDOK: ZeroMemory(szBuffer, 50); *(WORD*) szBuffer = 50 ; szblength = SendMessage (hwndEdit, EM_GETLINE, 0, (LPARAM) szBuffer) ; //http://www.google.com.tw/dictionary?langpair=en%7Cen&q=apprehend&hl=en&aq=f LookUpGooDic(Googlehwnd, szBuffer, http, 100, szblength); (*lpDisplayHTMLPage)(Googlehwnd, http); ZeroMemory(szBuffer + szblength, 50 - szblength); WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR, szBuffer, -1, charBuffer, 50, 0, 0); if(!CheckRepititiveWord(charBuffer, ListBoxVec)){ ListBoxVec.push_back(charBuffer); if(ListBoxhwnd){ SendMessage (ListBoxhwnd, LB_INSERTSTRING, -1, (LPARAM) szBuffer) ; } } return TRUE ; case IDCANCEL: EnableMenuItem (hMenu, 65535, MF_ENABLED) ; DestroyWindow (hDlg) ; hDlgModeless = NULL ; return TRUE ; case IDC_BUTTON1: SYSTEMTIME SystemTime; FILETIME FileTime; GetSystemTime(&SystemTime); SystemTimeToFileTime(&SystemTime, &FileTime); srand(MAKELONG(FileTime.dwLowDateTime, FileTime.dwHighDateTime)); SendMessage (hwndEdit, EM_SETSEL, 0, -1) ; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, VocList[rand()%VocList.size()].c_str(), -1, wstr, 50); SendMessage (hwndEdit, EM_REPLACESEL, 0, (LPARAM) wstr) ; return TRUE; case IDC_BUTTON2: SendMessage(hDlg, WM_COMMAND, IDOK, lParam); return TRUE ; } break ; } return FALSE ; }
int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId) { int i; SDL_keysym keysym; if( !touchscreenKeyboardShown ) return 0; if( action == MOUSE_DOWN ) { if( InsideRect( &arrows, x, y ) ) { OldCoords[pointerId] = &arrows; i = ArrowKeysPressed(x, y); if( i & ARROW_UP ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(UP), &keysym) ); if( i & ARROW_DOWN ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(DOWN), &keysym) ); if( i & ARROW_LEFT ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(LEFT), &keysym) ); if( i & ARROW_RIGHT ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(RIGHT), &keysym) ); oldArrows = i; return 1; } for( i = 0; i < nbuttons; i++ ) { if( InsideRect( &buttons[i], x, y) ) { OldCoords[pointerId] = &buttons[i]; SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym(buttonKeysyms[i], &keysym) ); if( i < AutoFireButtonsNum ) { ButtonAutoFire[i] = 0; if(touchscreenKeyboardTheme == 0) { ButtonAutoFireX[i] = x; ButtonAutoFireRot[i] = 0; } else { ButtonAutoFireX[i*2] = 0; ButtonAutoFireX[i*2+1] = 0; ButtonAutoFireRot[i] = x; ButtonAutoFireDecay[i] = SDL_GetTicks(); } } return 1; } } } else if( action == MOUSE_UP ) { if( OldCoords[pointerId] == &arrows ) { OldCoords[pointerId] = NULL; SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) ); SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) ); SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) ); SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) ); oldArrows = 0; return 1; } for( i = 0; i < nbuttons; i++ ) { if( OldCoords[pointerId] == &buttons[i] ) { if( ! ( i < AutoFireButtonsNum && ButtonAutoFire[i] ) ) { SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) ); } else { ButtonAutoFire[i] = 2; } OldCoords[pointerId] = NULL; if(touchscreenKeyboardTheme == 0) { ButtonAutoFireX[i] = 0; } else { ButtonAutoFireX[i*2] = 0; ButtonAutoFireX[i*2+1] = 0; } return 1; } } } else if( action == MOUSE_MOVE ) { if( OldCoords[pointerId] && !InsideRect(OldCoords[pointerId], x, y) ) { SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_UP, pointerId); return SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId); } else if( OldCoords[pointerId] == &arrows ) { i = ArrowKeysPressed(x, y); if( i == oldArrows ) return 1; if( oldArrows & ARROW_UP && ! (i & ARROW_UP) ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) ); if( oldArrows & ARROW_DOWN && ! (i & ARROW_DOWN) ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) ); if( oldArrows & ARROW_LEFT && ! (i & ARROW_LEFT) ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) ); if( oldArrows & ARROW_RIGHT && ! (i & ARROW_RIGHT) ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) ); if( i & ARROW_UP ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(UP), &keysym) ); if( i & ARROW_DOWN ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(DOWN), &keysym) ); if( i & ARROW_LEFT ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(LEFT), &keysym) ); if( i & ARROW_RIGHT ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(RIGHT), &keysym) ); oldArrows = i; } else { for(i = 0; i < AutoFireButtonsNum; i++) if( OldCoords[pointerId] == &buttons[i] ) { if(touchscreenKeyboardTheme == 0) { ButtonAutoFire[i] = abs(ButtonAutoFireX[i] - x) > buttons[i].w / 2; if( !ButtonAutoFire[i] ) ButtonAutoFireRot[i] = ButtonAutoFireX[i] - x; } else { int coeff = (buttonAutoFireImages[i*2+1].w > buttons[i].w) ? buttonAutoFireImages[i*2+1].w / buttons[i].w + 1 : 1; if( ButtonAutoFireRot[i] < x ) ButtonAutoFireX[i*2+1] += (x - ButtonAutoFireRot[i]) * coeff; if( ButtonAutoFireRot[i] > x ) ButtonAutoFireX[i*2] += (ButtonAutoFireRot[i] - x) * coeff; ButtonAutoFireRot[i] = x; if( ButtonAutoFireX[i*2] < 0 ) ButtonAutoFireX[i*2] = 0; if( ButtonAutoFireX[i*2+1] < 0 ) ButtonAutoFireX[i*2+1] = 0; if( ButtonAutoFireX[i*2] > buttonAutoFireImages[i*2+1].w / 2 ) ButtonAutoFireX[i*2] = buttonAutoFireImages[i*2+1].w / 2; if( ButtonAutoFireX[i*2+1] > buttonAutoFireImages[i*2+1].w / 2 ) ButtonAutoFireX[i*2+1] = buttonAutoFireImages[i*2+1].w / 2; if( ButtonAutoFireX[i*2] == buttonAutoFireImages[i*2+1].w / 2 && ButtonAutoFireX[i*2+1] == buttonAutoFireImages[i*2+1].w / 2 ) { if( ! ButtonAutoFire[i] ) ButtonAutoFireDecay[i] = SDL_GetTicks(); ButtonAutoFire[i] = 1; } } } } if( OldCoords[pointerId] ) return 1; return SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId); } return 0; };
/* ----------- LEFT_BUTTON Message ---------- */ static int LeftButtonMsg(WINDOW wnd, PARAM p1, PARAM p2) { int MouseX = (int) p1 - GetClientLeft(wnd); int MouseY = (int) p2 - GetClientTop(wnd); RECT rc = ClientRect(wnd); char *lp; int len; if (KeyBoardMarking) return TRUE; if (WindowMoving || WindowSizing) return FALSE; if (isMultiLine(wnd)) { if (TextMarking) { if (!InsideRect(p1, p2, rc)) { int x = MouseX, y = MouseY; int dir; MESSAGE msg = 0; if ((int)p2 == GetTop(wnd)) y++, dir = FALSE, msg = SCROLL; else if ((int)p2 == GetBottom(wnd)) --y, dir = TRUE, msg = SCROLL; else if ((int)p1 == GetLeft(wnd)) --x, dir = FALSE, msg = HORIZSCROLL; else if ((int)p1 == GetRight(wnd)) x++, dir = TRUE, msg = HORIZSCROLL; if (msg != 0) { if (SendMessage(wnd, msg, dir, 0)) ExtendBlock(wnd, x, y); SendMessage(wnd, PAINT, 0, 0); } } return TRUE; } if (!InsideRect(p1, p2, rc)) return FALSE; if (TextBlockMarked(wnd)) { ClearTextBlock(wnd); SendMessage(wnd, PAINT, 0, 0); } if (wnd->wlines) { if (MouseY > wnd->wlines-1) return TRUE; lp = TextLine(wnd, MouseY+wnd->wtop); len = (int) (strchr(lp, '\n') - lp); MouseX = min(MouseX, len); if (MouseX < wnd->wleft) { MouseX = 0; SendMessage(wnd, KEYBOARD, HOME, 0); } ButtonDown = TRUE; ButtonX = MouseX; ButtonY = MouseY; } else MouseX = MouseY = 0; wnd->WndRow = MouseY; SetLinePointer(wnd, MouseY+wnd->wtop); } if (isMultiLine(wnd) || (!TextBlockMarked(wnd) && MouseX+wnd->wleft < strlen(wnd->text))) wnd->CurrCol = MouseX+wnd->wleft; SendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow); return TRUE; }
int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId) { int i; SDL_keysym keysym; int processed = 0; if( !touchscreenKeyboardShown ) return 0; if( action == MOUSE_DOWN ) { //__android_log_print(ANDROID_LOG_INFO, "libSDL", "touch %03dx%03d ptr %d action %d", x, y, pointerId, action); if( InsideRect( &arrows, x, y ) ) { processed = 1; if( pointerInButtonRect[MAX_BUTTONS] == -1 ) { pointerInButtonRect[MAX_BUTTONS] = pointerId; if( SDL_ANDROID_isJoystickUsed ) { if( SDL_ANDROID_CurrentJoysticks[0] != NULL ) { SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 0, -(x - arrows.x - arrows.w / 2) * 65534 / arrows.w ); SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 1, -(y - arrows.y - arrows.h / 2) * 65534 / arrows.h ); } } else { i = ArrowKeysPressed(x, y); if( i & ARROW_UP ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(UP), &keysym) ); if( i & ARROW_DOWN ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(DOWN), &keysym) ); if( i & ARROW_LEFT ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(LEFT), &keysym) ); if( i & ARROW_RIGHT ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(RIGHT), &keysym) ); oldArrows = i; } } } for( i = 0; i < MAX_BUTTONS; i++ ) { if( ! buttons[i].h || ! buttons[i].w ) continue; if( InsideRect( &buttons[i], x, y) ) { processed = 1; if( pointerInButtonRect[i] == -1 ) { pointerInButtonRect[i] = pointerId; if( i == BUTTON_TEXT_INPUT ) SDL_ANDROID_ToggleScreenKeyboardTextInput(); else SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym(buttonKeysyms[i], &keysym) ); if( i < AutoFireButtonsNum ) { ButtonAutoFire[i] = 0; if(touchscreenKeyboardTheme == 0) { ButtonAutoFireX[i] = x; ButtonAutoFireRot[i] = 0; } else { ButtonAutoFireX[i*2] = 0; ButtonAutoFireX[i*2+1] = 0; ButtonAutoFireRot[i] = x; ButtonAutoFireDecay[i] = SDL_GetTicks(); } } } } } } else if( action == MOUSE_UP ) { //__android_log_print(ANDROID_LOG_INFO, "libSDL", "touch %03dx%03d ptr %d action %d", x, y, pointerId, action); if( pointerInButtonRect[MAX_BUTTONS] == pointerId ) { processed = 1; pointerInButtonRect[MAX_BUTTONS] = -1; if( SDL_ANDROID_isJoystickUsed ) { if( SDL_ANDROID_CurrentJoysticks[0] ) { SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 0, 0 ); SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 1, 0 ); } } else { SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) ); SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) ); SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) ); SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) ); oldArrows = 0; } } for( i = 0; i < MAX_BUTTONS; i++ ) { if( ! buttons[i].h || ! buttons[i].w ) continue; if( pointerInButtonRect[i] == pointerId ) { processed = 1; pointerInButtonRect[i] = -1; if( i < AutoFireButtonsNum && ButtonAutoFire[i] ) { ButtonAutoFire[i] = 2; } else { if( i != BUTTON_TEXT_INPUT ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) ); } if( i < AutoFireButtonsNum ) { if(touchscreenKeyboardTheme == 0) { ButtonAutoFireX[i] = 0; } else { ButtonAutoFireX[i*2] = 0; ButtonAutoFireX[i*2+1] = 0; } } } } } else if( action == MOUSE_MOVE ) { // Process cases when pointer enters button area (it won't send keypress twice if button already pressed) processed = SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId); // Process cases when pointer leaves button area // TODO: huge code size, split it or somehow make it more readable if( pointerInButtonRect[MAX_BUTTONS] == pointerId ) { processed = 1; if( ! InsideRect( &arrows, x, y ) ) { pointerInButtonRect[MAX_BUTTONS] = -1; if( SDL_ANDROID_isJoystickUsed ) { if( SDL_ANDROID_CurrentJoysticks[0] ) { SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 0, 0 ); SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 1, 0 ); } } else { SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) ); SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) ); SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) ); SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) ); oldArrows = 0; } } else { if( SDL_ANDROID_isJoystickUsed ) { if( SDL_ANDROID_CurrentJoysticks[0] ) { SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 0, -(x - arrows.x - arrows.w / 2) * 65534 / arrows.w ); SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 1, -(y - arrows.y - arrows.h / 2) * 65534 / arrows.h ); } } else { i = ArrowKeysPressed(x, y); if( i != oldArrows ) { if( oldArrows & ARROW_UP && ! (i & ARROW_UP) ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) ); if( oldArrows & ARROW_DOWN && ! (i & ARROW_DOWN) ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) ); if( oldArrows & ARROW_LEFT && ! (i & ARROW_LEFT) ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) ); if( oldArrows & ARROW_RIGHT && ! (i & ARROW_RIGHT) ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) ); if( i & ARROW_UP ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(UP), &keysym) ); if( i & ARROW_DOWN ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(DOWN), &keysym) ); if( i & ARROW_LEFT ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(LEFT), &keysym) ); if( i & ARROW_RIGHT ) SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(RIGHT), &keysym) ); } oldArrows = i; } } } for( i = 0; i < AutoFireButtonsNum; i++ ) { if( pointerInButtonRect[i] == pointerId ) { processed = 1; if( ! InsideRect( &buttonsAutoFireRect[i], x, y ) ) { pointerInButtonRect[i] = -1; if( !ButtonAutoFire[i] ) { if( i != BUTTON_TEXT_INPUT ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) ); } else { ButtonAutoFire[i] = 2; } if(touchscreenKeyboardTheme == 0) { ButtonAutoFireX[i] = 0; } else { ButtonAutoFireX[i*2] = 0; ButtonAutoFireX[i*2+1] = 0; } } else { if(touchscreenKeyboardTheme == 0) { ButtonAutoFire[i] = abs(ButtonAutoFireX[i] - x) > buttons[i].w / 2; if( !ButtonAutoFire[i] ) ButtonAutoFireRot[i] = ButtonAutoFireX[i] - x; } else { int coeff = (buttonAutoFireImages[i*2+1].w > buttons[i].w) ? buttonAutoFireImages[i*2+1].w / buttons[i].w + 1 : 1; if( ButtonAutoFireRot[i] < x ) ButtonAutoFireX[i*2+1] += (x - ButtonAutoFireRot[i]) * coeff; if( ButtonAutoFireRot[i] > x ) ButtonAutoFireX[i*2] += (ButtonAutoFireRot[i] - x) * coeff; ButtonAutoFireRot[i] = x; if( ButtonAutoFireX[i*2] < 0 ) ButtonAutoFireX[i*2] = 0; if( ButtonAutoFireX[i*2+1] < 0 ) ButtonAutoFireX[i*2+1] = 0; if( ButtonAutoFireX[i*2] > buttonAutoFireImages[i*2+1].w / 2 ) ButtonAutoFireX[i*2] = buttonAutoFireImages[i*2+1].w / 2; if( ButtonAutoFireX[i*2+1] > buttonAutoFireImages[i*2+1].w / 2 ) ButtonAutoFireX[i*2+1] = buttonAutoFireImages[i*2+1].w / 2; if( ButtonAutoFireX[i*2] == buttonAutoFireImages[i*2+1].w / 2 && ButtonAutoFireX[i*2+1] == buttonAutoFireImages[i*2+1].w / 2 ) { if( ! ButtonAutoFire[i] ) ButtonAutoFireDecay[i] = SDL_GetTicks(); ButtonAutoFire[i] = 1; } } } } } for( i = AutoFireButtonsNum; i < MAX_BUTTONS; i++ ) { if( ! buttons[i].h || ! buttons[i].w ) continue; if( pointerInButtonRect[i] == pointerId ) { processed = 1; if( ! InsideRect( &buttons[i], x, y ) ) { pointerInButtonRect[i] = -1; if( i != BUTTON_TEXT_INPUT ) SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) ); } } } } return processed; };
int processTouchscreenKeyboard(int x, int y, int action, int pointerId) { int i; int keysym; extern clientStatic_t cls; if(!g_use_touchscreen_icon){ return 0; } if(cls.state != CA_ACTIVE) { return 0; } //LOGI("touch x:%d, y:%d, a:%d, id:%d", x, y, action, pointerId); if( action == MOUSE_DOWN ) { if( OldCoords[pointerId] ) { processTouchscreenKeyboard(x, y, MOUSE_UP, pointerId); } //do the move stuff if( InsideRect( &arrow, x, y ) ) { OldCoords[pointerId] = &arrow; //i = ArrowKeysPressed(x, y); i = ArrowKeysPressed(x, y); //reset_arrow_key(); if( i & ARROW_UP ) { Key_Event(arrowkeys[UP],SDL_PRESSED); } if( i & ARROW_DOWN ) { Key_Event(arrowkeys[DOWN],SDL_PRESSED); } if( i & ARROW_LEFT ) { Key_Event_Alt(arrowkeys[LEFT],SDL_PRESSED); } if( i & ARROW_RIGHT ) { Key_Event_Alt(arrowkeys[RIGHT],SDL_PRESSED); } oldArrows = i; //__android_log_print(ANDROID_LOG_INFO, "doom", "down arrow %d",pointerId); return 1; } if(show_gun) { int num = SDL_ANDROID_get_number(x, y); if (num > 0) { //change the gun pressed_num = num; OldCoords[pointerId] = (SDL_Rect * )&pressed_num; //__android_log_print(ANDROID_LOG_INFO, "libSDL", "pressed num:%d", pressed_num); keysym = '0'; keysym += num; Key_Event(keysym ,SDL_PRESSED); return 1; } } //process other touch icon:fire ,jump ,switch gun for( i = 0; i < nbuttons; i++) { if( InsideRect( &buttons[i], x, y) ) { OldCoords[pointerId] = &buttons[i]; button_pressed[i] = 1; //LOGI("button %d is settttttttttt", i); if (i == SWITCH_GUN) { //switch gun show_gun = show_gun==0 ? 1 : 0; return 1; } if( i == TURN) { //jump_press= 1; //Key_Event(SDL_PRESSED, buttonKeysyms[][]); if(x < buttons[i].x+buttons[i].w/2) { //SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(A), &keysym) ); Key_Event( turnKeysyms[DpadAsturn][LEFT], SDL_PRESSED); oldTurn = 1; } else { //SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(D), &keysym) ); Key_Event( turnKeysyms[DpadAsturn][RIGHT],SDL_PRESSED); oldTurn = 2; } return 1; } Key_Event(buttonKeysyms[i], SDL_PRESSED); return 1; } } } else if( action == MOUSE_UP ) { if( OldCoords[pointerId] == &arrow) { OldCoords[pointerId] = NULL; //we draw use arrow_move, when touch up.return to the center //arrow_move = arrow_cricle; i = oldArrows; //reset_arrow_key(); if( i & ARROW_UP ) { Key_Event(arrowkeys[UP],SDL_RELEASED); } if( i & ARROW_DOWN ) { Key_Event(arrowkeys[DOWN],SDL_RELEASED); } if( i & ARROW_LEFT ) { Key_Event_Alt(arrowkeys[LEFT],SDL_RELEASED); } if( i & ARROW_RIGHT ) { Key_Event_Alt(arrowkeys[RIGHT],SDL_RELEASED); } oldArrows = 0; //__android_log_print(ANDROID_LOG_INFO, "doom", "up arrow %d",pointerId); return 1; } for( i = 0; i < nbuttons; i++ ) { if( OldCoords[pointerId] == &buttons[i] ) { button_pressed[i] = 0; //LOGI("button %d is clear", i); OldCoords[pointerId] = NULL; if(i == SWITCH_GUN) { // OldCoords[pointerId] = NULL; //show_gun = 0; return 1; } if( i == TURN) { //jump_release= 1; oldTurn = 0; Key_Event( turnKeysyms[DpadAsturn][LEFT], SDL_RELEASED); Key_Event( turnKeysyms[DpadAsturn][RIGHT], SDL_RELEASED); return 1; } Key_Event(buttonKeysyms[i], SDL_RELEASED); return 1; } } //process the gun number if(show_gun && OldCoords[pointerId] == (SDL_Rect * )&pressed_num) { if (pressed_num>0) { keysym = '0'+pressed_num; Key_Event( keysym, SDL_RELEASED); //SDL_SendKeyboardKey(SDL_RELEASED, GetKeysym( SDL_KEY(0), &keysym)+pressed_num ); pressed_num = -1; OldCoords[pointerId] = NULL; return 1; } } } else if( action == MOUSE_MOVE ) { //finger slip to ohter place if( OldCoords[pointerId] && !InsideRect(OldCoords[pointerId], x, y) ) { processTouchscreenKeyboard(x, y, MOUSE_UP, pointerId); return processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId); } if( OldCoords[pointerId] == &arrow ) { i = ArrowKeysPressed(x, y); if( i == oldArrows ) return 1; if( oldArrows & ARROW_UP && ! (i & ARROW_UP) ) Key_Event(arrowkeys[UP],SDL_RELEASED); if( oldArrows & ARROW_DOWN && ! (i & ARROW_DOWN) ) Key_Event(arrowkeys[DOWN],SDL_RELEASED); if( oldArrows & ARROW_LEFT && ! (i & ARROW_LEFT) ) Key_Event_Alt(arrowkeys[LEFT],SDL_RELEASED); if( oldArrows & ARROW_RIGHT && ! (i & ARROW_RIGHT) ) Key_Event_Alt(arrowkeys[RIGHT],SDL_RELEASED); if( i & ARROW_UP ) Key_Event(arrowkeys[UP],SDL_PRESSED); if( i & ARROW_DOWN ) Key_Event(arrowkeys[DOWN],SDL_PRESSED); if( i & ARROW_LEFT ) Key_Event_Alt(arrowkeys[LEFT],SDL_PRESSED); if( i & ARROW_RIGHT ) Key_Event_Alt(arrowkeys[RIGHT],SDL_PRESSED); oldArrows = i; } else if(OldCoords[pointerId] == &buttons[TURN]){ i = TurnKeyPressed(x, y); if( i == oldTurn) return 1; if(oldTurn == 1 && i == 2) { Key_Event( turnKeysyms[DpadAsturn][LEFT], SDL_RELEASED); Key_Event( turnKeysyms[DpadAsturn][RIGHT], SDL_PRESSED); } else if(oldTurn == 2 && i == 1) { Key_Event( turnKeysyms[DpadAsturn][RIGHT], SDL_RELEASED); Key_Event( turnKeysyms[DpadAsturn][LEFT], SDL_PRESSED); } oldTurn = i; } if( OldCoords[pointerId] ) return 1; //return processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId); } return 0; }