handle WM_MOUSEWHEEL and WM_POINTERUPDATE for the Windows Ink stylus driver
This commit is contained in:
@@ -623,20 +623,6 @@ bool App::mouse_down(int button, float x, float y)
|
||||
e.m_type = button ? kEventType::MouseDownR : kEventType::MouseDownL;
|
||||
e.m_pos = { x / zoom, y / zoom };
|
||||
auto ret = layout[main_id]->on_event(&e);
|
||||
//LOG("mouse click button%d pos %f %f", button, x, y);
|
||||
|
||||
// if (popup)
|
||||
// {
|
||||
// layout[main_id]->remove_child(popup);
|
||||
// popup = nullptr;
|
||||
// }
|
||||
// if (button == 1)
|
||||
// {
|
||||
// popup = (NodePopupMenu*)layout[const_hash("popup-menu")]->m_children[0]->clone();
|
||||
// popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
// popup->SetPosition(x / zoom, y / zoom);
|
||||
// layout[main_id]->add_child(popup);
|
||||
// }
|
||||
layout[main_id]->update();
|
||||
return ret == kEventResult::Consumed;
|
||||
}
|
||||
@@ -657,7 +643,16 @@ bool App::mouse_up(int button, float x, float y)
|
||||
e.m_pos = { x / zoom, y / zoom };
|
||||
auto ret = layout[main_id]->on_event(&e);
|
||||
layout[main_id]->update();
|
||||
//LOG("mouse up button%d pos %f %f", button, x, y);
|
||||
return ret == kEventResult::Consumed;
|
||||
}
|
||||
bool App::mouse_scroll(float x, float y, float delta)
|
||||
{
|
||||
MouseEvent e;
|
||||
e.m_type = kEventType::MouseScroll;
|
||||
e.m_pos = { x / zoom, y / zoom };
|
||||
e.m_scroll_delta = delta;
|
||||
auto ret = layout[main_id]->on_event(&e);
|
||||
layout[main_id]->update();
|
||||
return ret == kEventResult::Consumed;
|
||||
}
|
||||
bool App::key_down(int key)
|
||||
@@ -667,7 +662,6 @@ bool App::key_down(int key)
|
||||
e.m_key = key;
|
||||
auto ret = layout[main_id]->on_event(&e);
|
||||
layout[main_id]->update();
|
||||
//LOG("key down %d '%c'", key, key);
|
||||
return ret == kEventResult::Consumed;
|
||||
}
|
||||
bool App::key_up(int key)
|
||||
@@ -677,7 +671,6 @@ bool App::key_up(int key)
|
||||
e.m_key = key;
|
||||
auto ret = layout[main_id]->on_event(&e);
|
||||
layout[main_id]->update();
|
||||
//LOG("key up %d '%c'", key, key);
|
||||
return ret == kEventResult::Consumed;
|
||||
}
|
||||
bool App::key_char(int key)
|
||||
@@ -687,6 +680,5 @@ bool App::key_char(int key)
|
||||
e.m_key = key;
|
||||
auto ret = layout[main_id]->on_event(&e);
|
||||
layout[main_id]->update();
|
||||
//LOG("key up %d '%c'", key, key);
|
||||
return ret == kEventResult::Consumed;
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
bool mouse_down(int button, float x, float y);
|
||||
bool mouse_move(float x, float y);
|
||||
bool mouse_up(int button, float x, float y);
|
||||
bool mouse_scroll(float x, float y, float delta);
|
||||
bool key_down(int key);
|
||||
bool key_up(int key);
|
||||
bool key_char(int key);
|
||||
|
||||
@@ -197,17 +197,15 @@ void ui::Canvas::resize(int width, int height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
// m_tmp.create(width, height);
|
||||
// m_fb.create(width, height);
|
||||
// m_tex.create(width, height);
|
||||
// m_tex2.create(width, height);
|
||||
m_tmp.create(width, height);
|
||||
m_tex.create(width, height);
|
||||
m_tex2.create(width, height);
|
||||
}
|
||||
bool ui::Canvas::create(int width, int height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_tmp.create(width, height);
|
||||
//m_fb.create(width, height);
|
||||
m_tex.create(width, height);
|
||||
m_tex2.create(width, height); // TODO: destroy before recreating
|
||||
m_sampler.create();
|
||||
|
||||
@@ -105,6 +105,7 @@ enum class kEventType : uint8_t
|
||||
MouseUpR,
|
||||
MouseEnter,
|
||||
MouseLeave,
|
||||
MouseScroll,
|
||||
KeyDown,
|
||||
KeyUp,
|
||||
KeyChar,
|
||||
@@ -122,6 +123,7 @@ class MouseEvent : public Event
|
||||
public:
|
||||
MouseEvent() { m_cat = kEventCategory::MouseEvent; }
|
||||
glm::vec2 m_pos;
|
||||
float m_scroll_delta;
|
||||
};
|
||||
|
||||
class KeyEvent : public Event
|
||||
@@ -1873,6 +1875,7 @@ class NodeCanvas : public Node
|
||||
bool m_draggingR = false;
|
||||
glm::vec2 m_dragR_start;
|
||||
glm::vec2 m_pan_start;
|
||||
glm::vec2 m_pan;
|
||||
public:
|
||||
std::unique_ptr<ui::Canvas> m_canvas;
|
||||
ui::Brush m_brush;
|
||||
@@ -1886,9 +1889,9 @@ public:
|
||||
m_canvas->layer_add("asd");
|
||||
m_canvas->clear();
|
||||
m_sampler.create();
|
||||
SetPositioning(YGPositionTypeAbsolute);
|
||||
SetPosition(100, 100);
|
||||
SetSize({ 512, 512 });
|
||||
// SetPositioning(YGPositionTypeAbsolute);
|
||||
// SetPosition(100, 100);
|
||||
// SetSize({ 512, 512 });
|
||||
}
|
||||
virtual void draw() override
|
||||
{
|
||||
@@ -1904,14 +1907,14 @@ public:
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
float zoom = root()->m_zoom;
|
||||
auto box = m_clip_uncut * zoom;
|
||||
auto box = m_clip * zoom;
|
||||
glm::ivec4 c = (glm::ivec4)glm::vec4(box.x, (int)(vp[3] - box.y - box.w), box.z, box.w);
|
||||
glViewport(c.x, c.y, c.z, c.w);
|
||||
|
||||
glm::vec2 sz = { m_canvas->m_width, m_canvas->m_height };
|
||||
auto mvp = glm::ortho(0.f, box.z, 0.f, box.w, -1.f, 1.f) *
|
||||
//glm::translate(glm::vec3((m_size - sz) * 0.5f, 0)) * // center
|
||||
glm::translate(glm::vec3(0)) * // corner
|
||||
glm::translate(glm::vec3(m_pan, 0)) * // corner
|
||||
glm::scale(glm::vec3(sz * zoom, 1)) *
|
||||
glm::translate(glm::vec3(.5f, .5f, 0.f)); // pivot
|
||||
|
||||
@@ -1946,11 +1949,11 @@ public:
|
||||
}
|
||||
virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size) override
|
||||
{
|
||||
if (new_size.x > m_canvas->m_width)
|
||||
{
|
||||
m_canvas->resize((int)new_size.x, (int)new_size.y);
|
||||
m_canvas->clear();
|
||||
}
|
||||
// if (new_size.x > m_canvas->m_width)
|
||||
// {
|
||||
// m_canvas->resize((int)new_size.x, (int)new_size.y);
|
||||
// m_canvas->clear();
|
||||
// }
|
||||
}
|
||||
virtual kEventResult handle_event(Event* e) override
|
||||
{
|
||||
@@ -1975,7 +1978,7 @@ public:
|
||||
case kEventType::MouseDownR:
|
||||
m_draggingR = true;
|
||||
m_dragR_start = me->m_pos;
|
||||
m_pan_start = GetPosition();
|
||||
m_pan_start = m_pan;
|
||||
mouse_capture();
|
||||
break;
|
||||
case kEventType::MouseUpR:
|
||||
@@ -1986,7 +1989,7 @@ public:
|
||||
if (m_dragging)
|
||||
m_canvas->stroke_update(cur, 1.f);
|
||||
if (m_draggingR)
|
||||
SetPosition(m_pan_start + me->m_pos - m_dragR_start);
|
||||
m_pan = m_pan_start + (me->m_pos - m_dragR_start) * glm::vec2(1, -1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -597,20 +597,42 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
App::I.key_char((int)wp);
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
App::I.mouse_move(LOWORD(lp), HIWORD(lp));
|
||||
App::I.mouse_move((float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp));
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
App::I.mouse_down(0, LOWORD(lp), HIWORD(lp));
|
||||
App::I.mouse_down(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp));
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
App::I.mouse_up(0, LOWORD(lp), HIWORD(lp));
|
||||
App::I.mouse_up(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp));
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
App::I.mouse_down(1, LOWORD(lp), HIWORD(lp));
|
||||
App::I.mouse_down(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp));
|
||||
break;
|
||||
case WM_RBUTTONUP:
|
||||
App::I.mouse_up(1, LOWORD(lp), HIWORD(lp));
|
||||
App::I.mouse_up(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp));
|
||||
break;
|
||||
case WM_MOUSEWHEEL:
|
||||
App::I.mouse_scroll((float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp),
|
||||
(float)GET_WHEEL_DELTA_WPARAM(wp) / (float)WHEEL_DELTA);
|
||||
break;
|
||||
case WM_POINTERUPDATE:
|
||||
{
|
||||
POINTER_INFO pointerInfo;
|
||||
UINT32 pointerId = GET_POINTERID_WPARAM(wp);
|
||||
|
||||
// Retrieve common pointer information
|
||||
if (!GetPointerInfo(pointerId, &pointerInfo))
|
||||
{
|
||||
// failure, call GetLastError()
|
||||
}
|
||||
else
|
||||
{
|
||||
// success, process pointerInfo
|
||||
int i = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return DefWindowProc(hWnd, msg, wp, lp);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <gl\glew.h>
|
||||
#include <gl\wglew.h>
|
||||
#include <gl\GL.h>
|
||||
|
||||
Reference in New Issue
Block a user