cv-buttons.cpp
上传用户:tqh2500
上传日期:2022-04-23
资源大小:1k
文件大小:2k
- #include <highgui.h>
- #include "cv-buttons.h"
- void cvButtonsOnMouse( int e, int x, int y, int f, void* param ){
- ((CvButtons*)param)->setMouseState(e,x,y,f);
- }
- void CvButtons::paintButtons(IplImage *img){
- vector<PushButton>::iterator it = buttonList.begin();
- while (it != buttonList.end()) {
-
- // Grab button variables:
- int x = (*it).x_pos;
- int y = (*it).y_pos;
- int w = (*it).width;
- int h = (*it).height;
- int x2 = x+w;
- int y2 = y+h;
-
- // Highlight mouseover position:
- if( mx >= x && mx <= x2 && my >= y && my <= y2 ){
- cvRectangle( img, cvPoint(x-2,y-2), cvPoint(x2+2,y2+2), cvScalar(255,255,255),1,CV_AA );
-
- // Check for mouse pressed event:
- if( me == CV_EVENT_LBUTTONDOWN ){
-
- // Check if toggle button has to change state:
- if( (*it).toggle == 0 || (*it).toggle == 1 ) (*it).toggle = !(*it).toggle;
-
- // Call callback function:
- (*it).cb((*it).toggle);
-
- // Draw confirmation rectangle:
- cvRectangle( img, cvPoint(x,y), cvPoint(x2,y2), cvScalar(255,255,255),CV_FILLED,CV_AA );
-
- // Reset event (avoid flickering buttons):
- me = CV_EVENT_MOUSEMOVE;
- }
- }
-
- // Draw toggle state:
- if( (*it).toggle == 1 )
- cvRectangle( img, cvPoint(x,y), cvPoint(x2,y2), cvScalar(255,255,255),CV_FILLED,CV_AA );
-
- // Draw button with text:
- cvRectangle( img, cvPoint(x,y), cvPoint(x2,y2), cvScalar(255,255,255),1,CV_AA );
- if( (*it).toggle == 1 )
- cvPutText( img, (*it).text, cvPoint(x+10,y+15), &font, cvScalar(0,0,0) );
- else
- cvPutText( img, (*it).text, cvPoint(x+10,y+15), &font, cvScalar(255,255,255) );
-
- // Step to next button:
- it++;
- }
- }