0fee1b0dbe796d5c03abdc7b516de170331aed5b
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

1) /* Blinker
2)    Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org>
3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4)    a blinkenarea.org project */
5) 
6) #include <string>
7) 
8) #include <BlinkenLib/BlinkenFrame.h>
9) 
10) #include "Canvas.h"
11) #include "CanvasInput.h"
12) #include "Directory.h"
13) #include "File.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

14) #include "InStreamFile.h"
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

15) #include "Position.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

16) #include "PositionFile.h"
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

17) #include "Size.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

18) #include "SizeFile.h"
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

19) #include "StreamMgr.h"
20) #include "StreamRecv.h"
21) 
22) namespace Blinker {
23) 
24) /**
25)  * @brief constructor
26)  * @param[in] canvas owning canvas
27)  * @param[in] dirBase base directory
28)  */
29) Canvas::Input::Input(Canvas &canvas, const Directory &dirBase):
30)   m_canvas(canvas),
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

31)   m_fileInStream(dirBase.getFile("instream"), canvas.m_streamMgr),
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

32)   m_fileSrcPos(dirBase.getFile("srcpos")),
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

33)   m_fileSize(dirBase.getFile("size")),
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

34)   m_fileDestPos(dirBase.getFile("destpos"))
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

35) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

36)   // set up
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

37)   getSrcPos();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

38)   getSize();
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

39)   getDestPos();
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

40)   m_fileInStream.setStreamRecv(this);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

41) }
42) 
43) /// virtual destructor
44) Canvas::Input::~Input()
45) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

46)   // clean up
47)   m_fileInStream.setStreamRecv(NULL);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

48) }
49) 
50) /// check for update of configuration
51) void Canvas::Input::updateConfig()
52) {
53)   // input stream name file was modified -> re-get input stream
54)   if (m_fileInStream.checkModified()) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

55)     m_fileInStream.update();
56)     m_canvas.redraw(); // notify canvas to redraw
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

57)   }
58) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

59)   // position/size files were modified -> re-get position/size
60)   if (m_fileSrcPos.checkModified())
61)     getSrcPos();
62)   if (m_fileSize.checkModified())
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

63)     getSize();
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

64)   if (m_fileDestPos.checkModified())
65)     getDestPos();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

66) }
67) 
68) /**
69)  * @brief set current frame
70)  * @param[in] stream stream name
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

71)  * @param[in] pFrame current frame (NULL for none)
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

72)  */
73) void Canvas::Input::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
74) {
75)   // notify canvas to redraw
76)   m_canvas.redraw();
77) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

78)   (void)pFrame; // unused (frame fetched from stream when requested to draw)
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

79)   (void)stream; // unused
80) }
81) 
82) /**
83)  * @brief draw current frame to canvas
84)  * @return if a frame was available and it was drawn
85)  */
86) bool Canvas::Input::draw()
87) {
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

88)   stBlinkenFrame *pFrame;
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

89)   int destx, desty, srcx, srcy, width, height;
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

90) 
91)   // no destination position or no canvas -> leave
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

92)   if (!m_fileDestPos.m_valid || !m_canvas.m_pCanvas)
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

93)     return false;
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

94)   destx = m_fileDestPos.m_obj.m_x;
95)   desty = m_fileDestPos.m_obj.m_y;
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

96) 
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

97)   // get current frame from stream (leave if no stream or no frame)
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

98)   pFrame = m_fileInStream.getCurFrame();
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

99)   if (!pFrame)
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

100)     return false;
101) 
102)   // no source position -> use top left
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

103)   if (m_fileSrcPos.m_valid) {
104)     srcx = m_fileSrcPos.m_obj.m_x;
105)     srcy = m_fileSrcPos.m_obj.m_y;
106)   } else {
107)     srcx = 0;
108)     srcy = 0;
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

109)   }
110) 
111)   // no size -> use entire source frame
112)   //            (BlinkenLib will clip this if too large)
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

113)   if (m_fileSize.m_valid) {
114)     width = m_fileSize.m_obj.m_width;
115)     height = m_fileSize.m_obj.m_height;
116)   } else {
117)     width = BlinkenFrameGetWidth(pFrame);
118)     height = BlinkenFrameGetHeight(pFrame);
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

119)   }
120) 
121)   // draw rectangular area to canvas
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

122)   BlinkenFrameCopyRect(m_canvas.m_pCanvas, desty, destx,
123)                        pFrame, srcy, srcx, height, width);
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

124) 
125)   return true;
126) }
127) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

128) /// (re-)get position of area to copy from stream
129) void Canvas::Input::getSrcPos()
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

130) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

131)   // read source position from file
132)   m_fileSrcPos.update();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

133) 
134)   // notify canvas to redraw
135)   m_canvas.redraw();
136) }
137) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

138) /// (re-)get size of area to copy from stream
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

139) void Canvas::Input::getSize()
140) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

141)   // read size from file
142)   m_fileSize.update();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

143) 
144)   // notify canvas to redraw
145)   m_canvas.redraw();
146) }
147) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

148) /// (re-)get destination position on canvas
149) void Canvas::Input::getDestPos()
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

150) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

151)   // read destination position from file
152)   m_fileDestPos.update();
Stefan Schuermans first version of canvas mod...

Stefan Schuermans authored 12 years ago

153) 
Stefan Schuermans changed canvas to be able t...

Stefan Schuermans authored 12 years ago

154)   // notify canvas to redraw
155)   m_canvas.redraw();