Added "wheel actions". The new behavior for the mouse wheel is this:

wheel=zoom,
alt+wheel=change fg color,
ctrl+wheel=change frame.
This commit is contained in:
David Capello 2010-04-24 01:31:35 -03:00
parent c8436b73e3
commit 28074c0e0c

View File

@ -730,6 +730,14 @@ static bool editor_view_msg_proc(JWidget widget, JMessage msg)
/**********************************************************************/
/* message handler for the editor */
enum WHEEL_ACTION { WHEEL_NONE,
WHEEL_ZOOM,
WHEEL_VSCROLL,
WHEEL_HSCROLL,
WHEEL_FG,
WHEEL_BG,
WHEEL_FRAME };
bool Editor::msg_proc(JMessage msg)
{
assert((m_state == EDITOR_STATE_DRAWING && m_toolLoopManager != NULL) ||
@ -1178,15 +1186,69 @@ bool Editor::msg_proc(JMessage msg)
case JM_WHEEL:
if (m_state == EDITOR_STATE_STANDBY ||
m_state == EDITOR_STATE_DRAWING) {
/* there are and sprite in the editor, there is the mouse inside*/
if (m_sprite &&
jwidget_has_mouse(this)) {
// There are and sprite in the editor, there is the mouse inside
if (m_sprite && jwidget_has_mouse(this)) {
int dz = jmouse_z(1) - jmouse_z(0);
WHEEL_ACTION wheelAction = WHEEL_NONE;
bool scrollBigSteps = false;
// Without modifiers
if (!(msg->any.shifts & (KB_SHIFT_FLAG |
KB_ALT_FLAG |
KB_CTRL_FLAG))) {
if (!(msg->any.shifts & (KB_SHIFT_FLAG | KB_ALT_FLAG | KB_CTRL_FLAG))) {
wheelAction = WHEEL_ZOOM;
}
else {
#if 1 // TODO make it configurable
if (has_shifts(msg, KB_ALT_FLAG)) {
if (has_shifts(msg, KB_SHIFT_FLAG))
wheelAction = WHEEL_BG;
else
wheelAction = WHEEL_FG;
}
else if (has_shifts(msg, KB_CTRL_FLAG)) {
wheelAction = WHEEL_FRAME;
}
#else
if (has_shifts(msg, KB_CTRL_FLAG))
wheelAction = WHEEL_HSCROLL;
else
wheelAction = WHEEL_VSCROLL;
if (has_shifts(msg, KB_SHIFT_FLAG))
scrollBigSteps = true;
#endif
}
switch (wheelAction) {
case WHEEL_FG: {
int newIndex = 0;
if (color_type(app_get_colorbar()->getFgColor()) == COLOR_TYPE_INDEX) {
newIndex = color_get_index(app_get_colorbar()->getFgColor()) + dz;
newIndex = MID(0, newIndex, 255);
}
app_get_colorbar()->setFgColor(color_index(newIndex));
break;
}
case WHEEL_BG: {
int newIndex = 0;
if (color_type(app_get_colorbar()->getBgColor()) == COLOR_TYPE_INDEX) {
newIndex = color_get_index(app_get_colorbar()->getBgColor()) + dz;
newIndex = MID(0, newIndex, 255);
}
app_get_colorbar()->setBgColor(color_index(newIndex));
break;
}
case WHEEL_FRAME: {
Command* command = CommandsModule::instance()->get_command_by_name
((dz < 0) ? CommandId::goto_next_frame: CommandId::goto_previous_frame);
if (command)
UIContext::instance()->execute_command(command, NULL);
break;
}
case WHEEL_ZOOM: {
JWidget view = jwidget_get_view(this);
JRect vp = jview_get_viewport_position(view);
int x, y, zoom;
@ -1220,8 +1282,11 @@ bool Editor::msg_proc(JMessage msg)
}
jrect_free(vp);
break;
}
else {
case WHEEL_HSCROLL:
case WHEEL_VSCROLL: {
JWidget view = jwidget_get_view(this);
JRect vp = jview_get_viewport_position(view);
int scroll_x, scroll_y;
@ -1229,12 +1294,14 @@ bool Editor::msg_proc(JMessage msg)
int dy = 0;
int thick = m_cursor_thick;
if (has_shifts(msg, KB_CTRL_FLAG))
if (wheelAction == WHEEL_HSCROLL) {
dx = dz * jrect_w(vp);
else
}
else {
dy = dz * jrect_h(vp);
}
if (has_shifts(msg, KB_SHIFT_FLAG)) {
if (scrollBigSteps) {
dx /= 2;
dy /= 2;
}
@ -1254,6 +1321,9 @@ bool Editor::msg_proc(JMessage msg)
jmouse_show();
jrect_free(vp);
break;
}
}
}
}