Handle some key presses. Support scaled UI.
parent
ec2f1ee970
commit
94b6ed53b6
60
pui/pui.cpp
60
pui/pui.cpp
|
@ -12,7 +12,7 @@ void PUi::OnReshape(int w, int h)
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glViewport(0, 0, w, h);
|
glViewport(0, 0, w, h);
|
||||||
glOrtho(0, w, h, 0, 0, 1);
|
glOrtho(0, w * scale, h * scale, 0, 0, 1);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
@ -26,8 +26,52 @@ void PUi::OnDisplay()
|
||||||
this->widget->OnPaint();
|
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)
|
void PUi::OnMotion(int x, int y)
|
||||||
{
|
{
|
||||||
|
x *= scale;
|
||||||
|
y *= scale;
|
||||||
|
|
||||||
if (!this->mb) {
|
if (!this->mb) {
|
||||||
/* No button */
|
/* No button */
|
||||||
Widget *w = this->widget->GetWidget(x, y);
|
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)
|
void PUi::OnMouse(int button, bool press, int x, int y)
|
||||||
{
|
{
|
||||||
|
x *= scale;
|
||||||
|
y *= scale;
|
||||||
|
|
||||||
/* Keep track of button state */
|
/* Keep track of button state */
|
||||||
if (press) {
|
if (press) {
|
||||||
this->mb |= (1 << button);
|
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)
|
void PUi::OnScroll(float dx, float dy)
|
||||||
{
|
{
|
||||||
if (this->active) {
|
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)) {
|
if (this->active->SetValue(value)) {
|
||||||
this->ParameterChanged(this->active);
|
this->ParameterChanged(this->active);
|
||||||
this->Repaint();
|
this->Repaint();
|
||||||
|
@ -106,12 +156,14 @@ static void onDisplay(PuglView *view)
|
||||||
|
|
||||||
static void onKeyboard(PuglView *view, bool press, uint32_t key)
|
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)
|
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)
|
static void onMotion(PuglView *view, int x, int y)
|
||||||
|
|
|
@ -13,6 +13,7 @@ struct PUi : PTextures {
|
||||||
|
|
||||||
Widget *active;
|
Widget *active;
|
||||||
int mx, my, mb, mm;
|
int mx, my, mb, mm;
|
||||||
|
float scale;
|
||||||
|
|
||||||
virtual ~PUi();
|
virtual ~PUi();
|
||||||
|
|
||||||
|
@ -22,6 +23,10 @@ struct PUi : PTextures {
|
||||||
|
|
||||||
void OnDisplay();
|
void OnDisplay();
|
||||||
|
|
||||||
|
virtual void OnKeyboard(bool press, uint32_t key);
|
||||||
|
|
||||||
|
virtual void OnSpecial(bool press, PuglKey key);
|
||||||
|
|
||||||
void OnMotion(int x, int y);
|
void OnMotion(int x, int y);
|
||||||
|
|
||||||
void OnMouse(int button, bool press, int x, int y);
|
void OnMouse(int button, bool press, int x, int y);
|
||||||
|
|
Loading…
Reference in New Issue