LRESULT WINAPI WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { if(g_WndProcContext == NULL) { return DefWindowProc( hWnd, msg, wParam, lParam ); } switch( msg ) { case WM_SYSCOMMAND: // Intercept System Commands { switch (wParam) // Check System Calls { case SC_SCREENSAVE: // Screensaver Trying To Start? case SC_MONITORPOWER: // Monitor Trying To Enter Powersave? return 0; // Prevent From Happening } break; // Exit } case WM_CLOSE: PostQuitMessage(0); //Kill the current window break; case WM_KEYDOWN: switch( wParam ) //key pressed { case VK_ESCAPE: //PostQuitMessage(0); //if escape pressed, exit break; default: g_WndProcContext->GetInputManager().SetKeyState(wParam, true); break; } break; case WM_KEYUP: g_WndProcContext->GetInputManager().SetKeyState(wParam, false); break; case WM_COMMAND: if ( 0 == HIWORD(wParam) ) { g_WndProcContext->GetInputManager().PushEvent(InputEvent(InputEventMenu, wParam)); //PostQuitMessage(0); } break; case WM_SIZE: g_WndProcContext->GetFrameTimer().Pause(); g_WndProcContext->QueueReSize(); break; case WM_SYSKEYDOWN: // Alt key pressed if ((TCHAR)wParam == KEY_ENTER) { g_WndProcContext->GetInputManager().SetKeyState(KEY_ALT_ENTER, true); return NULL; } break; case WM_SYSKEYUP: // Alt key pressed if ((TCHAR)wParam == KEY_ENTER) { g_WndProcContext->GetInputManager().SetKeyState(KEY_ALT_ENTER, false); return NULL; } break; case WM_LBUTTONDOWN: g_WndProcContext->GetInputManager().SetMouseState(MouseButtonLeft, true); break; case WM_LBUTTONUP: g_WndProcContext->GetInputManager().SetMouseState(MouseButtonLeft, false); break; case WM_RBUTTONDOWN: g_WndProcContext->GetInputManager().SetMouseState(MouseButtonRight, true); break; case WM_RBUTTONUP: g_WndProcContext->GetInputManager().SetMouseState(MouseButtonRight, false); break; case WM_MBUTTONDOWN: g_WndProcContext->GetInputManager().SetMouseState(MouseButtonMiddle, true); break; case WM_MBUTTONUP: g_WndProcContext->GetInputManager().SetMouseState(MouseButtonMiddle, false); break; case WM_MOUSEMOVE: { POINTS P = MAKEPOINTS(lParam); Vec2i NewPos(P.x, P.y); g_WndProcContext->GetInputManager().UpdateMousePos(NewPos); } break; case WM_MOUSEWHEEL: g_WndProcContext->GetInputManager().UpdateWheelState(GET_WHEEL_DELTA_WPARAM(wParam)); break; case WM_SIZING: { double Ratio = g_WndProcContext->GetWindowManager().CastWindows().FixedAspectRatio(); if(Ratio > 0.0) { RECT ScreenRect; GetWindowRect(GetDesktopWindow(), &ScreenRect); RECT *Rect = (RECT *)lParam; Vec2f BorderDimensions = g_WndProcContext->GetWindowManager().CastWindows().GetBorderDimensions(); //Console::WriteLine(BorderDimensions.CommaSeperatedString()); Vec2f ProposedDimensions = Vec2f(float(Rect->right - Rect->left), float(Rect->bottom - Rect->top)) - BorderDimensions; float NewWidth = float(ProposedDimensions.y / Ratio + BorderDimensions.x); float NewHeight = float(ProposedDimensions.x * Ratio + BorderDimensions.y); if(NewHeight > ScreenRect.bottom) { NewHeight = float(ScreenRect.bottom); NewWidth = float(ProposedDimensions.y / Ratio + BorderDimensions.x); Rect->right = Rect->left + Math::Round(NewWidth); } switch(wParam) { case WMSZ_BOTTOM: Rect->right = Rect->left + Math::Round(NewWidth); break; case WMSZ_LEFT: case WMSZ_TOPLEFT: case WMSZ_TOPRIGHT: Rect->top = Rect->bottom - Math::Round(NewHeight); break; case WMSZ_RIGHT: case WMSZ_BOTTOMRIGHT: case WMSZ_BOTTOMLEFT: Rect->bottom = Rect->top + Math::Round(NewHeight); break; case WMSZ_TOP: Rect->left = Rect->right - Math::Round(NewWidth); break; } return TRUE; } } break; //Console::WriteLine(String(wParam) + " " + String(lParam)); } return DefWindowProc( hWnd, msg, wParam, lParam ); //return handling of command to main }
bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_value) { if (p_name=="filter_count") { filters.resize(p_value); _change_notify(); ports_changed_notify(); return true; } if (String(p_name).begins_with("filter_")) { int idx = String(p_name).replace_first("filters_","").get_slice("/",0).to_int(); ERR_FAIL_INDEX_V(idx,filters.size(),false); String what = String(p_name).get_slice("/",1); if (what=="type") { filters[idx]=InputEvent(); filters[idx].type=InputEvent::Type(int(p_value)); if (filters[idx].type==InputEvent::JOYSTICK_MOTION) { filters[idx].joy_motion.axis_value=0.5; //for treshold } else if (filters[idx].type==InputEvent::KEY) { filters[idx].key.pressed=true; //put these as true to make it more user friendly } else if (filters[idx].type==InputEvent::MOUSE_BUTTON) { filters[idx].mouse_button.pressed=true; } else if (filters[idx].type==InputEvent::JOYSTICK_BUTTON) { filters[idx].joy_button.pressed=true; } else if (filters[idx].type==InputEvent::SCREEN_TOUCH) { filters[idx].screen_touch.pressed=true; } else if (filters[idx].type==InputEvent::ACTION) { filters[idx].action.pressed=true; } _change_notify(); ports_changed_notify(); return true; } if (what=="device") { filters[idx].device=p_value; ports_changed_notify(); return true; } switch(filters[idx].type) { case InputEvent::KEY: { if (what=="scancode") { String sc = p_value; if (sc==String()) { filters[idx].key.scancode=0; } else { filters[idx].key.scancode=find_keycode(p_value); } } else if (what=="unicode") { String uc = p_value; if (uc==String()) { filters[idx].key.unicode=0; } else { filters[idx].key.unicode=uc[0]; } } else if (what=="pressed") { filters[idx].key.pressed=p_value; } else if (what=="echo") { filters[idx].key.echo=p_value; } else if (what=="mod_alt") { filters[idx].key.mod.alt=p_value; } else if (what=="mod_shift") { filters[idx].key.mod.shift=p_value; } else if (what=="mod_ctrl") { filters[idx].key.mod.control=p_value; } else if (what=="mod_meta") { filters[idx].key.mod.meta=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::MOUSE_MOTION: { if (what=="button_mask") { filters[idx].mouse_motion.button_mask=p_value; } else if (what=="mod_alt") { filters[idx].mouse_motion.mod.alt=p_value; } else if (what=="mod_shift") { filters[idx].mouse_motion.mod.shift=p_value; } else if (what=="mod_ctrl") { filters[idx].mouse_motion.mod.control=p_value; } else if (what=="mod_meta") { filters[idx].mouse_motion.mod.meta=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::MOUSE_BUTTON: { if (what=="button_index") { filters[idx].mouse_button.button_index=p_value; } else if (what=="pressed") { filters[idx].mouse_button.pressed=p_value; } else if (what=="doubleclicked") { filters[idx].mouse_button.doubleclick=p_value; } else if (what=="mod_alt") { filters[idx].mouse_button.mod.alt=p_value; } else if (what=="mod_shift") { filters[idx].mouse_button.mod.shift=p_value; } else if (what=="mod_ctrl") { filters[idx].mouse_button.mod.control=p_value; } else if (what=="mod_meta") { filters[idx].mouse_button.mod.meta=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::JOYSTICK_MOTION: { if (what=="axis") { filters[idx].joy_motion.axis=int(p_value)<<1|filters[idx].joy_motion.axis; } else if (what=="mode") { filters[idx].joy_motion.axis|=int(p_value); } else if (what=="treshold") { filters[idx].joy_motion.axis_value=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::JOYSTICK_BUTTON: { if (what=="button_index") { filters[idx].joy_button.button_index=p_value; } else if (what=="pressed") { filters[idx].joy_button.pressed=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::SCREEN_TOUCH: { if (what=="finger_index") { filters[idx].screen_touch.index=p_value; } else if (what=="pressed") { filters[idx].screen_touch.pressed=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::SCREEN_DRAG: { if (what=="finger_index") { filters[idx].screen_drag.index=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::ACTION: { if (what=="action_name") { List<PropertyInfo> pinfo; Globals::get_singleton()->get_property_list(&pinfo); int index=1; for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { const PropertyInfo &pi=E->get(); if (!pi.name.begins_with("input/")) continue; String name = pi.name.substr(pi.name.find("/")+1,pi.name.length()); if (name==String(p_value)) { filters[idx].action.action=index; ports_changed_notify(); return true; } index++; } filters[idx].action.action=0; ports_changed_notify(); return false; } else if (what=="pressed") { filters[idx].action.pressed=p_value; ports_changed_notify(); return true; } } break; } } return false; }