BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
f8c42ee
Branches
Tags
master
Blinker
src
noarch
CanvasInput.cpp
typos in comments and documentation
Stefan Schuermans
commited
f8c42ee
at 2011-11-21 22:00:13
CanvasInput.cpp
Blame
History
Raw
/* Blinker Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #include <string> #include <BlinkenLib/BlinkenFrame.h> #include "Canvas.h" #include "CanvasInput.h" #include "Directory.h" #include "File.h" #include "Position.h" #include "SettingFile.h" #include "Size.h" #include "StreamMgr.h" #include "StreamRecv.h" namespace Blinker { /** * @brief constructor * @param[in] canvas owning canvas * @param[in] dirBase base directory */ Canvas::Input::Input(Canvas &canvas, const Directory &dirBase): m_canvas(canvas), m_fileInStream(dirBase.getFile("instream")), m_fileSrcPos(dirBase.getFile("srcpos")), m_fileSize(dirBase.getFile("size")), m_fileDestPos(dirBase.getFile("destpos")), m_pInStream(NULL), m_haveSrcPos(false), m_haveSize(false), m_haveDestPos(false) { // get settings and attach to input stream getSrcPos(); getSize(); getDestPos(); getInStream(); } /// virtual destructor Canvas::Input::~Input() { // detach from input stream and release it releaseInStream(); } /// check for update of configuration void Canvas::Input::updateConfig() { // input stream name file was modified -> re-get input stream if (m_fileInStream.checkModified()) { releaseInStream(); getInStream(); } // position/size files were modified -> re-get position/size if (m_fileSrcPos.checkModified()) getSrcPos(); if (m_fileSize.checkModified()) getSize(); if (m_fileDestPos.checkModified()) getDestPos(); } /** * @brief set current frame * @param[in] stream stream name * @param[in] pFrame current frame */ void Canvas::Input::setFrame(const std::string &stream, stBlinkenFrame *pFrame) { // notify canvas to redraw m_canvas.redraw(); (void)pFrame; // unused (frame fetched from stream when requested to draw) (void)stream; // unused } /** * @brief set current frame to none * @param[in] stream stream name */ void Canvas::Input::setNoFrame(const std::string &stream) { // notify canvas to redraw m_canvas.redraw(); (void)stream; // unused } /** * @brief draw current frame to canvas * @return if a frame was available and it was drawn */ bool Canvas::Input::draw() { stBlinkenFrame *pFrame; // no destination position or no canvas -> leave if (!m_haveDestPos || !m_canvas.m_pCanvas) return false; // get current frame from stream (levae if no stream or no frame) if (!m_pInStream || !m_pInStream->getCurFrame(pFrame)) return false; // no source position -> use top left if (!m_haveSrcPos) { m_srcPos.m_x = 0; m_srcPos.m_y = 0; } // no size -> use entire source frame // (BlinkenLib will clip this if too large) if (!m_haveSize) { m_size.m_width = BlinkenFrameGetWidth(pFrame); m_size.m_height = BlinkenFrameGetHeight(pFrame); } // draw rectangular area to canvas BlinkenFrameCopyRect(m_canvas.m_pCanvas, m_destPos.m_y, m_destPos.m_x, pFrame, m_srcPos.m_y, m_srcPos.m_x, m_size.m_height, m_size.m_width); return true; } /// get input stream and attach to it void Canvas::Input::getInStream() { // get input stream m_fileInStream.getStr(m_nameInStream); m_pInStream = &m_canvas.m_streamMgr.refStream(m_nameInStream); // attach to input stream if (m_pInStream) m_pInStream->attach(this); // redrawing canvas will happen automatically because stream will set frame } /// detach from input stream and release it void Canvas::Input::releaseInStream() { // detach from input stream if (m_pInStream) m_pInStream->detach(this); // unreference stream m_pInStream = NULL; m_canvas.m_streamMgr.unrefStream(m_nameInStream); // notify canvas to redraw m_canvas.redraw(); } /// (re-)get position of area to copy from stream void Canvas::Input::getSrcPos() { std::string strPos; // read source position from file and parse it m_haveSrcPos = m_fileSrcPos.getStr(strPos) && m_srcPos.fromStr(strPos); // notify canvas to redraw m_canvas.redraw(); } /// (re-)get size of area to copy from stream void Canvas::Input::getSize() { std::string strSize; // read size from file and parse it m_haveSize = m_fileSize.getStr(strSize) && m_size.fromStr(strSize); // notify canvas to redraw m_canvas.redraw(); } /// (re-)get destination position on canvas void Canvas::Input::getDestPos() { std::string strPos; // read destination position from file and parse it m_haveDestPos = m_fileDestPos.getStr(strPos) && m_destPos.fromStr(strPos); // notify canvas to redraw m_canvas.redraw(); } } // namespace Blinker