/***********************************************************************************
 *                                                                                 *
 * Voreen - The Volume Rendering Engine                                            *
 *                                                                                 *
 * Copyright (C) 2005-2012 University of Muenster, Germany.                        *
 * Visualization and Computer Graphics Group <http://viscg.uni-muenster.de>        *
 * For a list of authors please refer to the file "CREDITS.txt".                   *
 *                                                                                 *
 * This file is part of the Voreen software package. Voreen is free software:      *
 * you can redistribute it and/or modify it under the terms of the GNU General     *
 * Public License version 2 as published by the Free Software Foundation.          *
 *                                                                                 *
 * Voreen is distributed in the hope that it will be useful, but WITHOUT ANY       *
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR   *
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.      *
 *                                                                                 *
 * You should have received a copy of the GNU General Public License in the file   *
 * "LICENSE.txt" along with this file. If not, see <http://www.gnu.org/licenses/>. *
 *                                                                                 *
 * For non-commercial academic use see the license exception specified in the file *
 * "LICENSE-academic.txt". To get information about commercial licensing please    *
 * contact the authors.                                                            *
 *                                                                                 *
 ***********************************************************************************/

#ifndef TGT_GUITIMER_H_
#define TGT_GUITIMER_H_

#include "tgt/types.h"

namespace tgt {

class EventHandler;

/// This is the base class for all tgt timer classes.
/// Derived classes use its functionality to to initiate gui-toolkit
/// dependend timers which gui-toolkit events are then translated
/// into tgt::TimeEvent objects and passed to an tgt::EventHandler.
class TGT_API Timer {
public:
    /// A constructor.
    /// @param eh       EventHandler to pass tgt::TimeEvent objects to.
    Timer( EventHandler* eh );

    /// A destructor
    virtual ~Timer();

    /// This abstract method is use to start this Timer. It will pass a tgt::TimeEvent to the
    /// actually set tgt::EventHandler.
    /// @param msec     Event will be created after given period of time in msec.
    /// @param limit    How many events to launch. Default is 0 (= unlimited).
    virtual void start( const int msec, const int limit = 0 ) = 0;

    /// Abstract method. Used to stop the timer.
    virtual void stop() = 0;


    // * getter / setter *

    /// Adjust the timer period
    virtual int getTickTime() { return tickTime_; };
    virtual void setTickTime( const int msec ) = 0;

    /// Redjust the counter limit.
    virtual void setLimit( const int limit ) { limit_ = limit; };
    virtual int getLimit() { return limit_; };

    /// Get the number of time events since calling tgt::Timer::start().
    virtual int getCount() { return count_; };
    virtual void setCount( const int count ) { count_ = count; };

    virtual bool isStopped() { return stopped_; }

    /// Set the tgt::EventHandler used to send tgt::TimeEvent objects to.
    void setEventHandler( EventHandler* eh ) { eventHandler_ = eh; }
    EventHandler* getEventHandler() { return eventHandler_; }

protected:
    /// How many events to fire till we stop.
    int limit_;
    /// Counts events fired since last start.
    int count_;
    /// How much time between the events to fire in msec.
    int tickTime_;
    /// Holds the tgt::EventHandler in which the tgt::TimeEvent
    /// objects are broadcasted.
    EventHandler* eventHandler_;
    bool stopped_;
};

}

#endif //TGT_GUITIMER_H
