16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński * Collection of shorthands to deal with GDK events.
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński * Krzysztof Kosiński <tweenk.pl@gmail.com>
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński * Copyright (C) 2009 Authors
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński * Released under GNU GPL, read the file 'COPYING' for more information
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool state_held_shift(unsigned state) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool state_held_control(unsigned state) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool state_held_alt(unsigned state) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool state_held_only_shift(unsigned state) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return (state & GDK_SHIFT_MASK) && !(state & (GDK_CONTROL_MASK | GDK_MOD1_MASK));
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool state_held_only_control(unsigned state) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return (state & GDK_CONTROL_MASK) && !(state & (GDK_SHIFT_MASK | GDK_MOD1_MASK));
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool state_held_only_alt(unsigned state) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return (state & GDK_MOD1_MASK) && !(state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK));
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool state_held_any_modifiers(unsigned state) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK);
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool state_held_no_modifiers(unsigned state) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool state_held_button(unsigned state) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return (button == 0 || button > 5) ? false : state & (GDK_BUTTON1_MASK << (button-1));
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński/** Checks whether Shift was held when the event was generated. */
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński/** Checks whether Control was held when the event was generated. */
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool held_control(E const &event) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński/** Checks whether Alt was held when the event was generated. */
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński/** True if from the set of Ctrl, Shift and Alt only Ctrl was held when the event
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński * was generated. */
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool held_only_control(E const &event) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return state_held_only_control(event.state);
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński/** True if from the set of Ctrl, Shift and Alt only Shift was held when the event
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński * was generated. */
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool held_only_shift(E const &event) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return state_held_only_shift(event.state);
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński/** True if from the set of Ctrl, Shift and Alt only Alt was held when the event
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński * was generated. */
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool held_only_alt(E const &event) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool held_no_modifiers(E const &event) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return state_held_no_modifiers(event.state);
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline bool held_any_modifiers(E const &event) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return state_held_any_modifiers(event.state);
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiinline Geom::Point event_point(E const &event) {
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński/** Use like this:
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński * @code if (held_button<2>(event->motion)) { ... @endcode */
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński return state_held_button<button>(event.state);
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiguint shortcut_key(GdkEventKey const &event);
bd80360f39d70d4a2622064a4fa0f29dd829d1edKrzysztof Kosińskiunsigned combine_key_events(guint keyval, gint mask);
bd80360f39d70d4a2622064a4fa0f29dd829d1edKrzysztof Kosińskiunsigned combine_motion_events(SPCanvas *canvas, GdkEventMotion &event, gint mask);
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosińskiunsigned state_after_event(GdkEvent *event);
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński} // namespace UI
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński} // namespace Inkscape
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński Local Variables:
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński c-file-style:"stroustrup"
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński indent-tabs-mode:nil
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński fill-column:99
a4030d5ca449e7e384bc699cd249ee704faaeab0Chris Morgan// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :