added mousewheel scrolling to input manager + combobox scolling enabled

This commit is contained in:
turanszkij
2017-02-12 13:57:40 +01:00
parent d50ac2f75b
commit 36f012e7ea
6 changed files with 42 additions and 5 deletions
+7
View File
@@ -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)
{
+7 -2
View File
@@ -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)
{
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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()
+22
View File
@@ -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 (i<firstItemVisible || i>firstItemVisible + 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 (i<firstItemVisible || i>firstItemVisible + 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;
+3
View File
@@ -169,6 +169,8 @@ protected:
function<void(wiEventArgs args)> 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();