-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDisplayHandler.cpp
50 lines (41 loc) · 1.34 KB
/
CDisplayHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "CDisplayHandler.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
CDisplayHandler* CDisplayHandler::theInstance = NULL;
CDisplayHandler::CDisplayHandler(int windowWidth, int windowHeigth, const char *windowName, IDisplayOwner* owner): m_mousePos(0,0)
{
m_owner = owner;
int nameLength = strlen(windowName);
m_windowName = new char[nameLength + 1];
strcpy(m_windowName, windowName);
namedWindow(windowName, WINDOW_AUTOSIZE);
setMouseCallback(windowName, MouseMoveCallback);
theInstance = this;
}
CDisplayHandler::~CDisplayHandler()
{
}
bool CDisplayHandler::Update(CBuffer<CRGB>& image)
{
Mat temp = Mat(image.getHeigth(), image.getWidth(), CV_8UC3, image.getBufferPointer());
imshow(m_windowName, temp);
int key = waitKey(1);
if(key >= 0 && key < 255){
//std::cout<<"key:"<<key<<std::endl;
if(m_owner != NULL)
m_owner->KeyPress(key, true);
}
return true;
}
void CDisplayHandler::MouseMoveCallback(int event, int x, int y, int flag, void *param){
//cout<<x<<' '<<y<<endl;
theInstance->m_mousePos = CPoint<int>(x,y);
if(theInstance->m_owner != NULL)
theInstance->m_owner->MouseMove(x, y);
}
CPoint<int> CDisplayHandler::getLastMousePos(){
return m_mousePos;
}