void MenuItemColour::ListUpdate(bool selected) { if(selected) { if(MFInput_WasPressed(Button_XB_A, IDD_Gamepad)) pCurrentMenu = this; if(MFInput_WasPressed(Button_DLeft, IDD_Gamepad)) { preset = preset <= 0 ? COLOUR_PRESETS-1 : preset-1; pData->FromPackedColour(presets[preset]); if(pCallback) pCallback(this, pUserData); } else if(MFInput_WasPressed(Button_DRight, IDD_Gamepad)) { preset = preset >= COLOUR_PRESETS-1 ? 0 : preset+1; pData->FromPackedColour(presets[preset]); if(pCallback) pCallback(this, pUserData); } } }
void MenuItemPosition2D::ListUpdate(bool selected) { if(selected) { MFVector t = *pData; float input; if(MFInput_WasPressed(Button_XB_B, IDD_Gamepad)) *pData = defaultValue; if(MFInput_WasPressed(Button_XB_X, IDD_Gamepad)) *pData = MakeVector(0.0f, 0.0f, 0.0f); if((input = MFInput_Read(Axis_RX, IDD_Gamepad))) { input = input < 0.0f ? -(input*input) : input*input; pData->x += input*increment*MFTimeDelta(); } if((input = MFInput_Read(Axis_RY, IDD_Gamepad))) { input = input < 0.0f ? -(input*input) : input*input; pData->y -= input*increment*MFTimeDelta(); } if(pCallback && t != *pData) pCallback(this, pUserData); } }
void MenuItemIntString::ListUpdate(bool selected) { if(selected) { if(MFInput_WasPressed(Button_DLeft, IDD_Gamepad)) { --data; if(data<0) while(ppValues[data+1]) data++; if(pCallback) pCallback(this, pUserData); } else if(MFInput_WasPressed(Button_DRight, IDD_Gamepad)) { ++data; if(!ppValues[data]) data = 0; if(pCallback) pCallback(this, pUserData); } else if(MFInput_WasPressed(Button_P2_Cross, IDD_Gamepad)) { if(pCallback) pCallback(this, pUserData); } } }
void MenuItemFloat::ListUpdate(bool selected) { if(selected) { float t = *pData; float input; if(MFInput_WasPressed(Button_XB_B, IDD_Gamepad)) *pData = defaultValue; if(MFInput_WasPressed(Button_XB_X, IDD_Gamepad)) *pData = 0.0f; if(MFInput_WasPressed(Button_DLeft, IDD_Gamepad)) { *pData -= increment; } else if(MFInput_WasPressed(Button_DRight, IDD_Gamepad)) { *pData += increment; } if((input = MFInput_Read(Axis_RX, IDD_Gamepad))) { input = input < 0.0f ? -(input*input) : input*input; *pData += input*increment*MFTimeDelta(); } if(*pData < minimumValue) *pData = maximumValue+(*pData-minimumValue); if(*pData > maximumValue) *pData = minimumValue+(*pData-maximumValue); if(pCallback && t != *pData) pCallback(this, pUserData); } }
void MenuItemInt::ListUpdate(bool selected) { if(selected) { int t = *pData; if(MFInput_WasPressed(Button_XB_B, IDD_Gamepad)) *pData = defaultValue; if(MFInput_WasPressed(Button_XB_X, IDD_Gamepad)) *pData = 0; if(MFInput_WasPressed(Button_DLeft, IDD_Gamepad)) { *pData -= increment; } else if(MFInput_WasPressed(Button_DRight, IDD_Gamepad)) { *pData += increment; } if(*pData < minimumValue) *pData = maximumValue+(*pData-minimumValue); if(*pData > maximumValue) *pData = minimumValue+(*pData-maximumValue); if(pCallback && t != *pData) pCallback(this, pUserData); } }
void MenuItemBool::ListUpdate(bool selected) { if(selected) { if(MFInput_WasPressed(Button_DLeft, IDD_Gamepad) || MFInput_WasPressed(Button_DRight, IDD_Gamepad) || MFInput_WasPressed(Button_XB_A, IDD_Gamepad)) { data = !data; if(pCallback) pCallback(this, pUserData); } } }
void Menu::ListUpdate(bool selected) { if(selected) { if(MFInput_WasPressed(Button_XB_A, IDD_Gamepad)) pCurrentMenu = this; } }
void Menu::Update() { static int gMenuHeld = 0; static float gHoldTimeout = 0.3f; // test controls and move cursor if(MFInput_WasPressed(Button_DUp, IDD_Gamepad) || (gMenuHeld == Button_DUp && gHoldTimeout<=0.0f)) { selection = selection > 0 ? selection-1 : numChildren-1; if(gMenuHeld) gHoldTimeout += 0.1f; else gMenuHeld = Button_DUp; } if(MFInput_WasPressed(Button_DDown, IDD_Gamepad) || (gMenuHeld == Button_DDown && gHoldTimeout<=0.0f)) { selection = selection < numChildren-1 ? selection+1 : 0; if(gMenuHeld) gHoldTimeout += 0.1f; else gMenuHeld = Button_DDown; } if(gMenuHeld) { gHoldTimeout -= MFTimeDelta(); if(!MFInput_Read(gMenuHeld, IDD_Gamepad)) { gMenuHeld = 0; gHoldTimeout = 0.3f; } } if(MFInput_WasPressed(Button_XB_Y, IDD_Gamepad) && pParent) pCurrentMenu = pParent; for(int a=0; a<numChildren; a++) { pChildren[a]->ListUpdate(a == selection); } }
MF_API bool MFInput_WasPressed(int button, int device, int deviceID) { MFDebug_Assert(device >= 0 && device < IDD_Max, "Invalid Input Device"); MFDebug_Assert(deviceID >= -1 && deviceID < MFInput_MaxInputID, "Invalid DeviceID"); if(deviceID == -1) { bool value = false; for(int a=0; a<MFInput_MaxInputID && !value; a++) { value = MFInput_WasPressed(button, device, a); } return value; } switch(device) { case IDD_Gamepad: { return gGamepadStates[deviceID].values[button] && !gPrevGamepadStates[deviceID].values[button]; } case IDD_Mouse: if(button < Mouse_MaxAxis) { return gMouseStates[deviceID].values[button] && !gPrevMouseStates[deviceID].values[button]; } else if(button < Mouse_Max) { return gMouseStates[deviceID].buttonState[button - Mouse_MaxAxis] && !gPrevMouseStates[deviceID].buttonState[button - Mouse_MaxAxis]; } break; case IDD_Keyboard: return gKeyStates[deviceID].keys[button] && !gPrevKeyStates[deviceID].keys[button]; default: break; } return false; }
void MenuItemColour::Update() { if(MFInput_WasPressed(Button_XB_Y, IDD_Gamepad)) pCurrentMenu = pParent; }
void MenuItemStatic::ListUpdate(bool selected) { if(selected) if(pCallback && MFInput_WasPressed(Button_XB_A, IDD_Gamepad)) pCallback(this, pUserData); }
void MenuObject::Update() { // allow back to parent if(MFInput_WasPressed(Button_XB_Y, IDD_Gamepad)) pCurrentMenu = pParent; }
void Game_Update() { if(!bShowModel) { if(MFInput_WasPressed(Key_Up, IDD_Keyboard) && menuIndex > 0) --menuIndex; else if(MFInput_WasPressed(Key_Down, IDD_Keyboard) && menuIndex < (int)models.size()-1) ++menuIndex; else if(MFInput_WasPressed(Key_Return, IDD_Keyboard) && models.size() > 0) { bShowModel = true; // load model pModel = MFModel_CreateWithAnimation(models[menuIndex].CStr()); } } else { if(MFInput_WasPressed(Key_Escape, IDD_Keyboard)) { if(pModel) { MFModel_Destroy(pModel); pModel = NULL; } models.clear(); Scan("data:"); if(models.size() <= (size_t)menuIndex) menuIndex = models.size() ? (int)models.size() - 1 : 0; bShowModel = false; return; } if(pModel) { if(MFInput_Read(Mouse_LeftButton, IDD_Mouse) > 0.f) { yaw += -MFInput_Read(Mouse_XDelta, IDD_Mouse) * 0.02f; pitch += -MFInput_Read(Mouse_YDelta, IDD_Mouse) * 0.015f; } if(MFInput_Read(Mouse_MiddleButton, IDD_Mouse) > 0.f) { zoom *= 1.f + -MFInput_Read(Mouse_YDelta, IDD_Mouse) * 0.02f; } // calculate a spinning world matrix MFMatrix world; world.SetTranslation(MakeVector(0, -0.25f, 1) * zoom); world.RotateY(yaw); world.RotateX(pitch); // set world matrix to the model MFModel_SetWorldMatrix(pModel, world); // advance the animation MFAnimation *pAnim = MFModel_GetAnimation(pModel); if(pAnim) { float start, end; MFAnimation_GetFrameRange(pAnim, &start, &end); static float time = 0.f; time += MFSystem_TimeDelta();// * 500; while(time >= end) time -= end; MFAnimation_SetFrame(pAnim, time); } } } }
void HKStringEntryLogic::Update() { bool shiftL = !!MFInput_Read(Key_LShift, IDD_Keyboard); bool shiftR = !!MFInput_Read(Key_RShift, IDD_Keyboard); bool ctrlL = !!MFInput_Read(Key_LControl, IDD_Keyboard); bool ctrlR = !!MFInput_Read(Key_RControl, IDD_Keyboard); int keyPressed = 0; bool shift = shiftL || shiftR; bool ctrl = ctrlL || ctrlR; #if defined(MF_WINDOWS) if(ctrl && MFInput_WasPressed(Key_C, IDD_Keyboard) && selectionStart != selectionEnd) { BOOL opened = OpenClipboard(apphWnd); if(opened) { int selMin = MFMin(selectionStart, selectionEnd); int selMax = MFMax(selectionStart, selectionEnd); int numChars = selMax-selMin; HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, numChars + 1); char *pString = (char*)GlobalLock(hData); MFString_Copy(pString, GetRenderString().SubStr(selMin, numChars).CStr()); GlobalUnlock(hData); EmptyClipboard(); SetClipboardData(CF_TEXT, hData); CloseClipboard(); } } else if(ctrl && MFInput_WasPressed(Key_X, IDD_Keyboard) && selectionStart != selectionEnd) { BOOL opened = OpenClipboard(apphWnd); if(opened) { int selMin = MFMin(selectionStart, selectionEnd); int selMax = MFMax(selectionStart, selectionEnd); int numChars = selMax-selMin; HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, numChars + 1); char *pString = (char*)GlobalLock(hData); MFString_Copy(pString, GetRenderString().SubStr(selMin, numChars).CStr()); GlobalUnlock(hData); EmptyClipboard(); SetClipboardData(CF_TEXT, hData); CloseClipboard(); ClearSelection(); } } else if(ctrl && MFInput_WasPressed(Key_V, IDD_Keyboard)) { BOOL opened = OpenClipboard(apphWnd); if(opened) { int selMin = MFMin(selectionStart, selectionEnd); int selMax = MFMax(selectionStart, selectionEnd); int numChars = selMax-selMin; HANDLE hData = GetClipboardData(CF_TEXT); MFString paste((const char*)GlobalLock(hData), true); buffer.Replace(selMin, numChars, paste); GlobalUnlock(hData); cursorPos = selMin + paste.NumBytes(); selectionStart = selectionEnd = cursorPos; GlobalUnlock(hData); CloseClipboard(); if((numChars || cursorPos != selMin) && changeCallback) changeCallback(buffer.CStr()); } } else #endif { // check for new keypresses for(int a=0; a<255; a++) { if(MFInput_WasPressed(a, IDD_Keyboard)) { keyPressed = a; holdKey = a; repeatDelay = gRepeatDelay; break; } } // handle repeat keys if(holdKey && MFInput_Read(holdKey, IDD_Keyboard)) { repeatDelay -= MFSystem_TimeDelta(); if(repeatDelay <= 0.f) { keyPressed = holdKey; repeatDelay += gRepeatRate; } } else holdKey = 0; // if there was a new key press if(keyPressed) { switch(keyPressed) { case Key_Backspace: case Key_Delete: { if(selectionStart != selectionEnd) { ClearSelection(); } else { if(keyPressed == Key_Backspace && cursorPos > 0) { buffer.ClearRange(--cursorPos, 1); selectionStart = selectionEnd = cursorPos; if(changeCallback) changeCallback(buffer.CStr()); } else if(keyPressed == Key_Delete && cursorPos < buffer.NumBytes()) { buffer.ClearRange(cursorPos, 1); selectionStart = selectionEnd = cursorPos; if(changeCallback) changeCallback(buffer.CStr()); } } break; } case Key_Left: case Key_Right: case Key_Home: case Key_End: { if(ctrl) { if(keyPressed == Key_Left) { while(cursorPos && MFIsWhite(buffer[cursorPos-1])) --cursorPos; if(MFIsAlphaNumeric(buffer[cursorPos-1])) { while(cursorPos && MFIsAlphaNumeric(buffer[cursorPos-1])) --cursorPos; } else if(cursorPos) { --cursorPos; while(cursorPos && buffer[cursorPos-1] == buffer[cursorPos]) --cursorPos; } } else if(keyPressed == Key_Right) { while(cursorPos < buffer.NumBytes() && MFIsWhite(buffer[cursorPos])) ++cursorPos; if(MFIsAlphaNumeric(buffer[cursorPos])) { while(cursorPos < buffer.NumBytes() && MFIsAlphaNumeric(buffer[cursorPos])) ++cursorPos; } else if(cursorPos < buffer.NumBytes()) { ++cursorPos; while(cursorPos < buffer.NumBytes() && buffer[cursorPos] == buffer[cursorPos-1]) ++cursorPos; } } else if(keyPressed == Key_Home) cursorPos = 0; else if(keyPressed == Key_End) cursorPos = buffer.NumBytes(); } else { if(keyPressed == Key_Left) cursorPos = (!shift && selectionStart != selectionEnd ? MFMin(selectionStart, selectionEnd) : MFMax(cursorPos-1, 0)); else if(keyPressed == Key_Right) cursorPos = (!shift && selectionStart != selectionEnd ? MFMax(selectionStart, selectionEnd) : MFMin(cursorPos+1, buffer.NumBytes())); else if(keyPressed == Key_Home) cursorPos = 0; // TODO: if multiline, go to start of line.. else if(keyPressed == Key_End) cursorPos = buffer.NumBytes(); // TODO: if multiline, go to end of line... } if(shift) selectionEnd = cursorPos; else selectionStart = selectionEnd = cursorPos; break; } default: { bool caps = MFInput_GetKeyboardStatusState(KSS_CapsLock); int ascii = MFInput_KeyToAscii(keyPressed, shift, caps); if(ascii && (!maxLen || buffer.NumBytes() < maxLen-1)) { // check character exclusions if(MFIsNewline(ascii) && type != ST_MultiLine) break; if(ascii == '\t' && type != ST_MultiLine) break; if(type == ST_Numeric && !MFIsNumeric(ascii)) break; if(include) { if(include.FindChar(ascii) < 0) break; } if(exclude) { if(exclude.FindChar(ascii) >= 0) break; } int selMin = MFMin(selectionStart, selectionEnd); int selMax = MFMax(selectionStart, selectionEnd); int selRange = selMax - selMin; const uint16 wstr[] = { (uint16)ascii, 0 }; char insert[5]; MFString_CopyUTF16ToUTF8(insert, wstr); buffer.Replace(selMin, selRange, insert); cursorPos = selMin + 1; selectionStart = selectionEnd = cursorPos; if(changeCallback) changeCallback(buffer.CStr()); } break; } } } } }