/* Blinker
   Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org>
   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
   a blinkenarea.org project */

#ifndef BLINKER_CANVASINPUT_H
#define BLINKER_CANVASINPUT_H

#include <string>

#include <BlinkenLib/BlinkenFrame.h>

#include "Canvas.h"
#include "Directory.h"
#include "File.h"
#include "InStreamFile.h"
#include "Position.h"
#include "PositionFile.h"
#include "Size.h"
#include "SizeFile.h"
#include "StreamMgr.h"
#include "StreamRecv.h"

namespace Blinker {

/// input to canvas
class Canvas::Input: public StreamRecv
{
public:
  /**
   * @brief constructor
   * @param[in] canvas owning canvas
   * @param[in] name name of input
   * @param[in] dirBase base directory
   */
  Input(Canvas &canvas, const std::string &name, const Directory &dirBase);

  /// virtual destructor
  virtual ~Input();

private:
  /// copy constructor disabled
  Input(const Input &that);

  /// assignment operator disabled
  const Input & operator=(const Input &that);

public:
  /// check for update of configuration
  void updateConfig();

  /**
   * @brief set current frame
   * @param[in] stream stream name
   * @param[in] pFrame current frame (NULL for none)
   */
  virtual void setFrame(const std::string &stream, stBlinkenFrame *pFrame);

  /**
   * @brief draw current frame to canvas
   * @return if a frame was available and it was drawn
   */
  bool draw();

protected:
  /// (re-)get position of area to copy from stream
  void getSrcPos();

  /// (re-)get size of area to copy from stream
  void getSize();

  /// (re-)get destination position on canvas
  void getDestPos();

protected:
  Canvas       &m_canvas;      ///< owning canvas
  std::string  m_name;         ///< name of input
  InStreamFile m_fileInStream; ///< input stream name file
  PositionFile m_fileSrcPos;   ///< source position file
  SizeFile     m_fileSize;     ///< size file
  PositionFile m_fileDestPos;  ///< destination position file
}; // class Canvas::Input

} // namespace Blinker

#endif // #ifndef BLINKER_CANVASINPUT_H

