From 36f012e7eafa4ed2c97ea824a09a0ddec9103904 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 12 Feb 2017 13:57:40 +0100 Subject: [PATCH] added mousewheel scrolling to input manager + combobox scolling enabled --- WickedEngine/WickedEngineEditor.cpp | 7 +++++++ WickedEngine/wiInputManager.cpp | 9 +++++++-- WickedEngine/wiInputManager.h | 4 ++-- WickedEngine/wiVersion.cpp | 2 +- WickedEngine/wiWidget.cpp | 22 ++++++++++++++++++++++ WickedEngine/wiWidget.h | 3 +++ 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/WickedEngine/WickedEngineEditor.cpp b/WickedEngine/WickedEngineEditor.cpp index 18f672a68..05a75c348 100644 --- a/WickedEngine/WickedEngineEditor.cpp +++ b/WickedEngine/WickedEngineEditor.cpp @@ -206,6 +206,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_MBUTTONUP: ShowCursor(true); break; + case WM_MOUSEWHEEL: + { + XMFLOAT4 pointer = wiInputManager::GetInstance()->getpointer(); + float delta = GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA; + wiInputManager::GetInstance()->setpointer(XMFLOAT4(pointer.x, pointer.y, delta, 0)); + } + break; case WM_KEYDOWN: switch (wParam) { diff --git a/WickedEngine/wiInputManager.cpp b/WickedEngine/wiInputManager.cpp index 61cc1202a..91def0277 100644 --- a/WickedEngine/wiInputManager.cpp +++ b/WickedEngine/wiInputManager.cpp @@ -13,6 +13,7 @@ #define KEY_TOGGLE(vk_code) (((int)Windows::UI::Core::CoreWindow::GetForCurrentThread()->GetAsyncKeyState((Windows::System::VirtualKey)vk_code) & 1) != 0) #endif //WINSTORE_SUPPORT #define KEY_UP(vk_code) (!KEY_DOWN(vk_code)) +static float mousewheel_scrolled = 0.0f; wiInputManager::wiInputManager() { @@ -101,6 +102,8 @@ void wiInputManager::Update() touches.clear(); + mousewheel_scrolled = 0.0f; + UNLOCK(); } @@ -185,10 +188,10 @@ XMFLOAT4 wiInputManager::getpointer() POINT p; GetCursorPos(&p); ScreenToClient(wiWindowRegistration::GetInstance()->GetRegisteredWindow(), &p); - return XMFLOAT4((float)p.x, (float)p.y, 0, 0); + return XMFLOAT4((float)p.x, (float)p.y, mousewheel_scrolled, 0); #else auto& p = Windows::UI::Core::CoreWindow::GetForCurrentThread()->PointerPosition; - return XMFLOAT4(p.X, p.Y, 0, 0); + return XMFLOAT4(p.X, p.Y, mousewheel_scrolled, 0); #endif } void wiInputManager::setpointer(const XMFLOAT4& props) @@ -200,6 +203,8 @@ void wiInputManager::setpointer(const XMFLOAT4& props) ClientToScreen(wiWindowRegistration::GetInstance()->GetRegisteredWindow(), &p); SetCursorPos(p.x, p.y); #endif + + mousewheel_scrolled = props.z; } void wiInputManager::hidepointer(bool value) { diff --git a/WickedEngine/wiInputManager.h b/WickedEngine/wiInputManager.h index 67ee22823..e9e1d6f46 100644 --- a/WickedEngine/wiInputManager.h +++ b/WickedEngine/wiInputManager.h @@ -60,9 +60,9 @@ public: bool press(DWORD button, InputType inputType = InputType::KEYBOARD, short playerindex = 0); //check if a button is held down bool hold(DWORD button, DWORD frames = 30, bool continuous = false, InputType inputType = InputType::KEYBOARD, short playerIndex = 0); - //get pointer position (eg. mouse pointer) + 2 unused + //get pointer position (eg. mouse pointer) (.xy) + scroll delta (.z) + 1 unused (.w) XMFLOAT4 getpointer(); - //set pointer position (eg. mouse pointer) + //set pointer position (eg. mouse pointer) + scroll delta (.z) void setpointer(const XMFLOAT4& props); //hide pointer void hidepointer(bool value); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 92fa007c2..558c3a141 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -7,7 +7,7 @@ namespace wiVersion // minor features, major updates const int minor = 9; // minor bug fixes, alterations, refactors, updates - const int revision = 63; + const int revision = 64; long GetVersion() diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index 220279ec3..c65441517 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -669,6 +669,8 @@ wiComboBox::wiComboBox(const string& name) :wiWidget() SetText(fastName.GetString()); OnSelect([](wiEventArgs args) {}); SetSize(XMFLOAT2(100, 20)); + SetMaxVisibleItemCount(8); + firstItemVisible = 0; } wiComboBox::~wiComboBox() { @@ -676,6 +678,7 @@ wiComboBox::~wiComboBox() } const float wiComboBox::_GetItemOffset(int index) const { + index = max(firstItemVisible, index) - firstItemVisible; return scale.y * (index + 1) + 1; } void wiComboBox::Update(wiGUI* gui) @@ -757,9 +760,18 @@ void wiComboBox::Update(wiGUI* gui) } else { + int scroll = (int)wiInputManager::GetInstance()->getpointer().z; + firstItemVisible -= scroll; + firstItemVisible = max(0, min((int)items.size() - maxVisibleItemCount, firstItemVisible)); + hovered = -1; for (size_t i = 0; i < items.size(); ++i) { + if (ifirstItemVisible + maxVisibleItemCount) + { + continue; + } + Hitbox2D itembox; itembox.pos.x = Transform::translation.x; itembox.pos.y = Transform::translation.y + _GetItemOffset((int)i); @@ -826,6 +838,12 @@ void wiComboBox::Render(wiGUI* gui) int i = 0; for (auto& x : items) { + if (ifirstItemVisible + maxVisibleItemCount) + { + i++; + continue; + } + wiColor col = colors[IDLE]; if (hovered == i) { @@ -886,6 +904,10 @@ void wiComboBox::ClearItems() selected = -1; } +void wiComboBox::SetMaxVisibleItemCount(int value) +{ + maxVisibleItemCount = value; +} void wiComboBox::SetSelected(int index) { selected = index; diff --git a/WickedEngine/wiWidget.h b/WickedEngine/wiWidget.h index b27782adf..163071a0b 100644 --- a/WickedEngine/wiWidget.h +++ b/WickedEngine/wiWidget.h @@ -169,6 +169,8 @@ protected: function onSelect; Hitbox2D hitBox; int selected; + int maxVisibleItemCount; + int firstItemVisible; // While the widget is active (rolled down) these are the inner states that control behaviour enum COMBOSTATE @@ -193,6 +195,7 @@ public: void AddItem(const string& item); void RemoveItem(int index); void ClearItems(); + void SetMaxVisibleItemCount(int value); void SetSelected(int index); int GetSelected();