Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2015-01-06 18:51:37 +0000
committerStijn Buys <ingar@osirion.org>2015-01-06 18:51:37 +0000
commit72ee43e9470c6fdbc6ed7ff92b85dfa5062c5762 (patch)
tree6474fa59066d5212dcd40e3d76652dce35565280 /src/ui/console.cc
parent57d958d40af061e83aa99ca12e375e5345836ecd (diff)
Added separate event handlers for mouse button clicks and mouse wheel movement.
Diffstat (limited to 'src/ui/console.cc')
-rw-r--r--src/ui/console.cc36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/ui/console.cc b/src/ui/console.cc
index 3799392..b683778 100644
--- a/src/ui/console.cc
+++ b/src/ui/console.cc
@@ -25,6 +25,8 @@ namespace ui
const float DEFAULT_CONSOLE_HEIGHT = 0.7f;
const size_t DEFAULT_MAX_HISTO_LINES = 512;
+// number of lines to scroll
+const size_t SCROLL_LINES = 3;
// the global console buffer object
ConsoleBuffer Console::con_buffer;
@@ -87,8 +89,8 @@ void Console::show()
{
ui::Window::show();
raise();
- SDL_WM_GrabInput(SDL_GRAB_OFF);
- SDL_ShowCursor(SDL_ENABLE);
+
+ SDL_SetRelativeMouseMode(SDL_FALSE);
console_scrollpane->set_scroll(0);
console_scrollpane->set_offset(3);
@@ -106,12 +108,10 @@ void Console::hide()
ui::Window::hide();
core::Cvar *input_grab = core::Cvar::find("input_grab");
- if (!input_grab || input_grab->value()) {
- SDL_WM_GrabInput(SDL_GRAB_ON);
- SDL_ShowCursor(SDL_DISABLE);
+ if (input_grab && input_grab->value()) {
+ SDL_SetRelativeMouseMode(SDL_TRUE);
} else {
- SDL_WM_GrabInput(SDL_GRAB_OFF);
- SDL_ShowCursor(SDL_ENABLE);
+ SDL_SetRelativeMouseMode(SDL_FALSE);
}
audio::play("ui/console");
@@ -139,9 +139,6 @@ bool Console::on_emit(Widget *sender, const Event event, void *data)
bool Console::on_keypress(const int key, const unsigned int modifier)
{
- // number of lines to scroll
- const size_t scroll_offset = 3;
-
ui::Text::reverse_iterator upit;
switch (key) {
@@ -191,14 +188,12 @@ bool Console::on_keypress(const int key, const unsigned int modifier)
}
return true;
break;
- case 512 + SDL_BUTTON_WHEELUP:
case SDLK_PAGEUP:
- console_scrollpane->inc_scroll(scroll_offset);
+ console_scrollpane->inc_scroll(SCROLL_LINES);
return true;
break;
- case 512 + SDL_BUTTON_WHEELDOWN:
case SDLK_PAGEDOWN:
- console_scrollpane->dec_scroll(scroll_offset);
+ console_scrollpane->dec_scroll(SCROLL_LINES);
return true;
break;
}
@@ -206,6 +201,19 @@ bool Console::on_keypress(const int key, const unsigned int modifier)
return false;
}
+bool Console::on_mousewheel(const math::Vector2f & direction)
+{
+ if (direction.y() > 0 )
+ {
+ console_scrollpane->inc_scroll(SCROLL_LINES);
+ return true;
+ } else if (direction.y() < 0) {
+ console_scrollpane->dec_scroll(SCROLL_LINES);
+ return true;
+ }
+ return false;
+}
+
void Console::draw()
{
console_scrollbar->set_range(0, (float) con_buffer.log().size());