Browse Source

support for mouse button modifiers

pull/1/head
Leonard Ritter 10 years ago
parent
commit
254df0a563
2 changed files with 12 additions and 7 deletions
  1. +1
    -3
      example.cpp
  2. +11
    -4
      oui.h

+ 1
- 3
example.cpp View File

@@ -1140,12 +1140,11 @@ void errorcb(int error, const char* desc)


static void mousebutton(GLFWwindow *window, int button, int action, int mods) { static void mousebutton(GLFWwindow *window, int button, int action, int mods) {
NVG_NOTUSED(window); NVG_NOTUSED(window);
NVG_NOTUSED(mods);
switch(button) { switch(button) {
case 1: button = 2; break; case 1: button = 2; break;
case 2: button = 1; break; case 2: button = 1; break;
} }
uiSetButton(button, (action==GLFW_PRESS)?1:0);
uiSetButton(button, mods, (action==GLFW_PRESS)?1:0);
} }


static void cursorpos(GLFWwindow *window, double x, double y) { static void cursorpos(GLFWwindow *window, double x, double y) {
@@ -1166,7 +1165,6 @@ static void charevent(GLFWwindow *window, unsigned int value) {
static void key(GLFWwindow* window, int key, int scancode, int action, int mods) static void key(GLFWwindow* window, int key, int scancode, int action, int mods)
{ {
NVG_NOTUSED(scancode); NVG_NOTUSED(scancode);
NVG_NOTUSED(mods);
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE); glfwSetWindowShouldClose(window, GL_TRUE);
uiSetKey(key, mods, action); uiSetKey(key, mods, action);


+ 11
- 4
oui.h View File

@@ -474,13 +474,14 @@ OUI_EXPORT UIvec2 uiGetCursorStartDelta();
// sets a mouse or gamepad button as pressed/released // sets a mouse or gamepad button as pressed/released
// button is in the range 0..63 and maps to an application defined input // button is in the range 0..63 and maps to an application defined input
// source. // source.
// mod is an application defined set of flags for modifier keys
// enabled is 1 for pressed, 0 for released // enabled is 1 for pressed, 0 for released
OUI_EXPORT void uiSetButton(int button, int enabled);
OUI_EXPORT void uiSetButton(unsigned int button, unsigned int mod, int enabled);


// returns the current state of an application dependent input button // returns the current state of an application dependent input button
// as set by uiSetButton(). // as set by uiSetButton().
// the function returns 1 if the button has been set to pressed, 0 for released. // the function returns 1 if the button has been set to pressed, 0 for released.
OUI_EXPORT int uiGetButton(int button);
OUI_EXPORT int uiGetButton(unsigned int button);


// returns the number of chained clicks; 1 is a single click, // returns the number of chained clicks; 1 is a single click,
// 2 is a double click, etc. // 2 is a double click, etc.
@@ -671,7 +672,7 @@ OUI_EXPORT unsigned int uiGetFlags(int item);


// when handling a KEY_DOWN/KEY_UP event: the key that triggered this event // when handling a KEY_DOWN/KEY_UP event: the key that triggered this event
OUI_EXPORT unsigned int uiGetKey(); OUI_EXPORT unsigned int uiGetKey();
// when handling a KEY_DOWN/KEY_UP event: the key that triggered this event
// when handling a keyboard or mouse event: the active modifier keys
OUI_EXPORT unsigned int uiGetModifier(); OUI_EXPORT unsigned int uiGetModifier();


// returns the items layout rectangle in absolute coordinates. If // returns the items layout rectangle in absolute coordinates. If
@@ -862,6 +863,7 @@ struct UIcontext {
UIstage stage; UIstage stage;
unsigned int active_key; unsigned int active_key;
unsigned int active_modifier; unsigned int active_modifier;
unsigned int active_button_modifier;
int last_timestamp; int last_timestamp;
int last_click_timestamp; int last_click_timestamp;
int clicks; int clicks;
@@ -944,13 +946,14 @@ OUI_EXPORT UIcontext *uiGetContext() {
return ui_context; return ui_context;
} }


void uiSetButton(int button, int enabled) {
void uiSetButton(unsigned int button, unsigned int mod, int enabled) {
assert(ui_context); assert(ui_context);
unsigned long long mask = 1ull<<button; unsigned long long mask = 1ull<<button;
// set new bit // set new bit
ui_context->buttons = (enabled)? ui_context->buttons = (enabled)?
(ui_context->buttons | mask): (ui_context->buttons | mask):
(ui_context->buttons & ~mask); (ui_context->buttons & ~mask);
ui_context->active_button_modifier = mod;
} }


static void uiAddInputEvent(UIinputEvent event) { static void uiAddInputEvent(UIinputEvent event) {
@@ -1808,6 +1811,7 @@ void uiProcess(int timestamp) {


ui_context->last_click_timestamp = timestamp; ui_context->last_click_timestamp = timestamp;
ui_context->last_click_item = active_item; ui_context->last_click_item = active_item;
ui_context->active_modifier = ui_context->active_button_modifier;
uiNotifyItem(active_item, UI_BUTTON0_DOWN); uiNotifyItem(active_item, UI_BUTTON0_DOWN);
} }
ui_context->state = UI_STATE_CAPTURE; ui_context->state = UI_STATE_CAPTURE;
@@ -1816,6 +1820,7 @@ void uiProcess(int timestamp) {
hot = uiFindItem(0, ui_context->cursor.x, ui_context->cursor.y, hot = uiFindItem(0, ui_context->cursor.x, ui_context->cursor.y,
UI_BUTTON2_DOWN, UI_ANY); UI_BUTTON2_DOWN, UI_ANY);
if (hot >= 0) { if (hot >= 0) {
ui_context->active_modifier = ui_context->active_button_modifier;
uiNotifyItem(hot, UI_BUTTON2_DOWN); uiNotifyItem(hot, UI_BUTTON2_DOWN);
} }
} else { } else {
@@ -1825,6 +1830,7 @@ void uiProcess(int timestamp) {
case UI_STATE_CAPTURE: { case UI_STATE_CAPTURE: {
if (!uiGetButton(0)) { if (!uiGetButton(0)) {
if (active_item >= 0) { if (active_item >= 0) {
ui_context->active_modifier = ui_context->active_button_modifier;
uiNotifyItem(active_item, UI_BUTTON0_UP); uiNotifyItem(active_item, UI_BUTTON0_UP);
if (active_item == hot) { if (active_item == hot) {
uiNotifyItem(active_item, UI_BUTTON0_HOT_UP); uiNotifyItem(active_item, UI_BUTTON0_HOT_UP);
@@ -1834,6 +1840,7 @@ void uiProcess(int timestamp) {
ui_context->state = UI_STATE_IDLE; ui_context->state = UI_STATE_IDLE;
} else { } else {
if (active_item >= 0) { if (active_item >= 0) {
ui_context->active_modifier = ui_context->active_button_modifier;
uiNotifyItem(active_item, UI_BUTTON0_CAPTURE); uiNotifyItem(active_item, UI_BUTTON0_CAPTURE);
} }
if (hot == active_item) if (hot == active_item)


Loading…
Cancel
Save