mwheeltonumericpropertyeventhandler.cpp 1.73 KB
Newer Older
1
2
#include "mwheeltonumericpropertyeventhandler.h"
#include "tgt/assert.h"
schultezub's avatar
schultezub committed
3
#include "tgt/event/mouseevent.h"
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

namespace TUMVis {
    const std::string MWheelToNumericPropertyEventHandler::loggerCat_ = "TUMVis.core.eventhandler.MWheelToNumericPropertyEventHandler";

    MWheelToNumericPropertyEventHandler::MWheelToNumericPropertyEventHandler(INumericProperty* property)
        : AbstractEventHandler()
        , _prop(property)
    {
        tgtAssert(_prop != 0, "Assigned property must not be 0.");
    }

    MWheelToNumericPropertyEventHandler::~MWheelToNumericPropertyEventHandler() {

    }

    bool MWheelToNumericPropertyEventHandler::accept(tgt::Event* e) {
        if (tgt::MouseEvent* me = dynamic_cast<tgt::MouseEvent*>(e)) {
            return me->action() == tgt::MouseEvent::WHEEL;
        }
        return false;
    }

    void MWheelToNumericPropertyEventHandler::execute(tgt::Event* e) {
        tgtAssert(dynamic_cast<tgt::MouseEvent*>(e) != 0, "Given event has wrong type. Check if the event is accepted by this event handler before executing it!");

        // this is only to be executed when the event was accepted, so the static cast is safe.
        tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
        tgtAssert(me->action() == tgt::MouseEvent::WHEEL, "Given event has wrong type. Check if the event is accepted by this event handler before executing it!");
        switch (me->button()) {
            case tgt::MouseEvent::MOUSE_WHEEL_UP:
                _prop->increment();
                e->ignore();
                break;
            case tgt::MouseEvent::MOUSE_WHEEL_DOWN:
                _prop->decrement();
                e->ignore();
                break;
        }
    }

}