diff --git a/pui/pui.cpp b/pui/pui.cpp index 68ffcb7..bf2025d 100644 --- a/pui/pui.cpp +++ b/pui/pui.cpp @@ -12,7 +12,7 @@ void PUi::OnReshape(int w, int h) glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, w, h); - glOrtho(0, w, h, 0, 0, 1); + glOrtho(0, w * scale, h * scale, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glDisable(GL_DEPTH_TEST); glLoadIdentity(); @@ -26,8 +26,52 @@ void PUi::OnDisplay() this->widget->OnPaint(); } +void PUi::OnKeyboard(bool press, uint32_t key) +{ + printf("keyboard %d %X\n", press, key); +} + +void PUi::OnSpecial(bool press, PuglKey key) +{ + if (press) { + uint32_t port = (this->active ? this->active->port : 0); + uint32_t newport = port; + + switch (key) { + case PUGL_KEY_LEFT: newport--; break; + case PUGL_KEY_RIGHT: newport++; break; + + case PUGL_KEY_PAGE_UP: this->OnScroll(0, 2.5f); return; + case PUGL_KEY_PAGE_DOWN: this->OnScroll(0, -2.5f); return; + case PUGL_KEY_UP: this->OnScroll(0, 1); return; + case PUGL_KEY_DOWN: this->OnScroll(0, -1); return; + + case PUGL_KEY_SHIFT: this->mm |= 1; break; + case PUGL_KEY_CTRL: this->mm |= 2; break; + default: break; + } + + if (port != newport) { + if (this->active) this->active->active = false; + this->active = this->widget->GetWidget(newport); + if (this->active) this->active->active = true; + this->Repaint(); + } + } else { + switch (key) { + case PUGL_KEY_SHIFT: this->mm &= ~1; break; + case PUGL_KEY_CTRL: this->mm &= ~2; break; + default: break; + } + } + printf("special %d %X\n", press, key); +} + void PUi::OnMotion(int x, int y) { + x *= scale; + y *= scale; + if (!this->mb) { /* No button */ Widget *w = this->widget->GetWidget(x, y); @@ -52,6 +96,9 @@ void PUi::OnMotion(int x, int y) void PUi::OnMouse(int button, bool press, int x, int y) { + x *= scale; + y *= scale; + /* Keep track of button state */ if (press) { this->mb |= (1 << button); @@ -84,7 +131,10 @@ void PUi::OnMouse(int button, bool press, int x, int y) void PUi::OnScroll(float dx, float dy) { if (this->active) { - float value = this->active->value + (dy * .1f); + dy *= .1f; + if (this->mm & 1) dy *= .1f; + if (this->mm & 2) dy *= .01f; + float value = this->active->value + dy; if (this->active->SetValue(value)) { this->ParameterChanged(this->active); this->Repaint(); @@ -106,12 +156,14 @@ static void onDisplay(PuglView *view) static void onKeyboard(PuglView *view, bool press, uint32_t key) { - printf("keyboard %d %X\n", press, key); + PUi *pui = (PUi *)puglGetHandle(view); + pui->OnKeyboard(press, key); } static void onSpecial(PuglView *view, bool press, PuglKey key) { - printf("special %d %X\n", press, key); + PUi *pui = (PUi *)puglGetHandle(view); + pui->OnSpecial(press, key); } static void onMotion(PuglView *view, int x, int y) diff --git a/pui/pui.h b/pui/pui.h index 8185722..6bf6e71 100644 --- a/pui/pui.h +++ b/pui/pui.h @@ -13,6 +13,7 @@ struct PUi : PTextures { Widget *active; int mx, my, mb, mm; + float scale; virtual ~PUi(); @@ -22,6 +23,10 @@ struct PUi : PTextures { void OnDisplay(); + virtual void OnKeyboard(bool press, uint32_t key); + + virtual void OnSpecial(bool press, PuglKey key); + void OnMotion(int x, int y); void OnMouse(int button, bool press, int x, int y);