Date:2013-08-11 00:05:18 (4 years 11 months ago)
Author:Maarten ter Huurne
Commit:f414ce4685122cd264dea18c7a5939259801efe3
Message:Allow layers to play animations

Files: src/gmenu2x.cpp (2 diffs)
src/helppopup.cpp (1 diff)
src/inputmanager.h (2 diffs)
src/layer.h (2 diffs)

Change Details

src/gmenu2x.cpp
596596
597597    bool quit = false;
598598    while (!quit) {
599        // Check whether any layers are animating and remove dismissed layers
600        // from the stack.
601        bool animating = false;
602        for (auto it = layers.begin(); it != layers.end(); ) {
603            auto layer = *it;
604            switch (layer->getStatus()) {
605                case Layer::Status::DISMISSED:
606                    it = layers.erase(it);
607                    break;
608                case Layer::Status::ANIMATING:
609                    animating = true;
610                    // fall through
611                case Layer::Status::PASSIVE:
612                    ++it;
613                    break;
614            }
615        }
616
599617        // Paint layers.
600618        for (auto layer : layers) {
601619            layer->paint(*s);
...... 
613631        }
614632
615633        // Handle other input events.
616        InputManager::Button button = input.waitForPressedButton();
617        for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
618            if ((*it)->handleButtonPress(button)) {
619                break;
620            }
621        }
622
623        // Remove dismissed layers from the stack.
624        for (auto it = layers.begin(); it != layers.end(); ) {
625            auto layer = *it;
626            if (layer->wasDismissed()) {
627                it = layers.erase(it);
628            } else {
629                ++it;
634        InputManager::ButtonEvent event;
635        bool gotEvent;
636        const bool wait = !animating;
637        do {
638            do {
639                gotEvent = input.getEvent(&event, wait);
640            } while (gotEvent && event.state != InputManager::PRESSED);
641        } while (wait && !gotEvent);
642        if (gotEvent) {
643            for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
644                if ((*it)->handleButtonPress(event.button)) {
645                    break;
646                }
630647            }
631648        }
632649    }
src/helppopup.cpp
3232
3333bool HelpPopup::handleButtonPress(InputManager::Button button) {
3434    if (button == InputManager::CANCEL) {
35        dismissed = true;
35        dismiss();
3636    }
3737    return true;
3838}
3939
4040bool HelpPopup::handleTouchscreen(Touchscreen &ts) {
4141    if (ts.pressed()) {
42        dismissed = true;
42        dismiss();
4343        ts.setHandled();
4444    }
4545    return true;
src/inputmanager.h
5858    bool waitForEvent(ButtonEvent *event);
5959    Button waitForPressedButton();
6060    bool pollEvent(ButtonEvent *event);
61    bool getEvent(ButtonEvent *bevent, bool wait);
6162
6263private:
6364    enum ButtonSource { UNMAPPED, KEYBOARD, JOYSTICK };
...... 
6970    Menu *menu;
7071
7172    void readConfFile(const std::string &conffile);
72    bool getEvent(ButtonEvent *bevent, bool wait);
7373
7474    ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
7575#ifndef SDL_JOYSTICK_DISABLED
src/layer.h
1616 */
1717class Layer {
1818public:
19    enum class Status { PASSIVE, ANIMATING, DISMISSED };
20
1921    virtual ~Layer() {}
2022
2123    /**
...... 
3638     */
3739    virtual bool handleTouchscreen(Touchscreen &ts) = 0;
3840
39    bool wasDismissed() { return dismissed; }
41    Status getStatus() { return status; }
4042
4143protected:
4244    /**
43     * Set this to true to request the layer to be removed from the stack.
45     * Request the Layer to be removed from the stack.
46     * There could be a few more calls to the Layer before it is actually
47     * removed, so be prepared to handle those.
48     */
49    void dismiss() {
50        status = Status::DISMISSED;
51    }
52
53    /**
54     * Request that this layer be repainted every frame.
4455     */
45    bool dismissed = false;
56    void startAnimating() {
57        if (status == Status::PASSIVE) status = Status::ANIMATING;
58    }
59
60    /**
61     * Request that this layer be repainted only after an event.
62     */
63    void stopAnimating() {
64        if (status == Status::ANIMATING) status = Status::PASSIVE;
65    }
66
67private:
68    Status status = Status::PASSIVE;
4669};
4770
4871#endif // LAYER_H

Archive Download the corresponding diff file



interactive