DPF Plugin examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.3KB

  1. /*
  2. * Author: Harry van Haaren 2013
  3. * harryhaaren@gmail.com
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. *
  20. */
  21. #ifndef AVTK_IMAGE_H
  22. #define AVTK_IMAGE_H
  23. #include <FL/Fl_Widget.H>
  24. #include <vector>
  25. #include <string>
  26. #include <iostream>
  27. #include <stdio.h>
  28. #include <FL/fl_draw.H>
  29. using namespace std;
  30. namespace Avtk
  31. {
  32. class Image : public Fl_Widget
  33. {
  34. public:
  35. Image(int _x, int _y, int _w, int _h, const char *_label=0 ):
  36. Fl_Widget(_x, _y, _w, _h, _label)
  37. {
  38. x = _x;
  39. y = _y;
  40. w = _w;
  41. h = _h;
  42. label = _label;
  43. bits = -1;
  44. imageDataPtr = 0;
  45. }
  46. void setPixbuf(const unsigned char* data, int b )
  47. {
  48. bits = b;
  49. imageDataPtr = data;
  50. }
  51. int x, y, w, h;
  52. const char* label;
  53. int bits;
  54. const unsigned char* imageDataPtr;
  55. void draw()
  56. {
  57. if ( damage() & FL_DAMAGE_ALL && imageDataPtr != 0 )
  58. {
  59. fl_draw_image((const uchar*)imageDataPtr, x, y, w, h, bits, w*bits);
  60. }
  61. }
  62. void resize(int X, int Y, int W, int H)
  63. {
  64. Fl_Widget::resize(X,Y,W,H);
  65. x = X;
  66. y = Y;
  67. w = W;
  68. h = H;
  69. redraw();
  70. }
  71. int handle(int event)
  72. {
  73. switch(event)
  74. {
  75. case FL_PUSH:
  76. do_callback();
  77. return 1;
  78. case FL_DRAG:
  79. return 1;
  80. case FL_RELEASE:
  81. return 1;
  82. case FL_SHORTCUT:
  83. if ( test_shortcut() )
  84. {
  85. do_callback();
  86. return 1;
  87. }
  88. return 0;
  89. default:
  90. return Fl_Widget::handle(event);
  91. }
  92. }
  93. };
  94. } // Avtk
  95. #endif