cv-buttons.cpp
上传用户:tqh2500
上传日期:2022-04-23
资源大小:1k
文件大小:2k
源码类别:

OpenCV

开发平台:

C/C++

  1. #include <highgui.h>
  2. #include "cv-buttons.h"
  3. void cvButtonsOnMouse( int e, int x, int y, int f, void* param ){
  4. ((CvButtons*)param)->setMouseState(e,x,y,f);
  5. }
  6. void CvButtons::paintButtons(IplImage *img){
  7. vector<PushButton>::iterator it = buttonList.begin();
  8. while (it != buttonList.end()) {
  9. // Grab button variables:
  10. int x = (*it).x_pos;
  11. int y = (*it).y_pos;
  12. int w = (*it).width;
  13. int h = (*it).height;
  14. int x2 = x+w;
  15. int y2 = y+h;
  16. // Highlight mouseover position:
  17. if( mx >= x && mx <= x2 && my >= y && my <= y2 ){
  18. cvRectangle( img, cvPoint(x-2,y-2), cvPoint(x2+2,y2+2), cvScalar(255,255,255),1,CV_AA );
  19. // Check for mouse pressed event:
  20. if( me == CV_EVENT_LBUTTONDOWN ){
  21. // Check if toggle button has to change state:
  22. if( (*it).toggle == 0 || (*it).toggle == 1 ) (*it).toggle = !(*it).toggle;
  23. // Call callback function:
  24. (*it).cb((*it).toggle);
  25. // Draw confirmation rectangle:
  26. cvRectangle( img, cvPoint(x,y), cvPoint(x2,y2), cvScalar(255,255,255),CV_FILLED,CV_AA );
  27. // Reset event (avoid flickering buttons):
  28. me = CV_EVENT_MOUSEMOVE;
  29. }
  30. }
  31. // Draw toggle state:
  32. if( (*it).toggle == 1 )
  33. cvRectangle( img, cvPoint(x,y), cvPoint(x2,y2), cvScalar(255,255,255),CV_FILLED,CV_AA );
  34. // Draw button with text:
  35. cvRectangle( img, cvPoint(x,y), cvPoint(x2,y2), cvScalar(255,255,255),1,CV_AA );
  36. if( (*it).toggle == 1 )
  37. cvPutText( img, (*it).text, cvPoint(x+10,y+15), &font, cvScalar(0,0,0) );
  38. else
  39. cvPutText( img, (*it).text, cvPoint(x+10,y+15), &font, cvScalar(255,255,255) );
  40.         
  41.         // Step to next button:
  42.         it++;
  43. }
  44. }