Audio plugin host https://kx.studio/carla
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.

141 lines
2.8KB

  1. // ----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2010 Fons Adriaensen <fons@linuxaudio.org>
  4. // Modified by falkTX on Jan 2015 for inclusion in Carla
  5. //
  6. // This program is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. //
  20. // ----------------------------------------------------------------------
  21. #include <cairo/cairo.h>
  22. #include <cairo/cairo-xlib.h>
  23. #include <math.h>
  24. #include "button.h"
  25. namespace AT1 {
  26. int PushButton::_keymod = 0;
  27. int PushButton::_button = 0;
  28. PushButton::PushButton (X_window *parent,
  29. X_callback *cbobj,
  30. ButtonImg *image,
  31. int xp,
  32. int yp,
  33. int cbind) :
  34. X_window (parent,
  35. image->_x0 + xp, image->_y0 + yp,
  36. image->_dx, image->_dy,
  37. image->_backg->pixel),
  38. _cbobj (cbobj),
  39. _cbind (cbind),
  40. _image (image),
  41. _state (0)
  42. {
  43. x_add_events (ExposureMask | ButtonPressMask | ButtonReleaseMask);
  44. }
  45. PushButton::~PushButton (void)
  46. {
  47. }
  48. void PushButton::init (X_display *disp)
  49. {
  50. }
  51. void PushButton::fini (void)
  52. {
  53. }
  54. void PushButton::handle_event (XEvent *E)
  55. {
  56. switch (E->type)
  57. {
  58. case Expose:
  59. render ();
  60. break;
  61. case ButtonPress:
  62. bpress ((XButtonEvent *) E);
  63. break;
  64. case ButtonRelease:
  65. brelse ((XButtonEvent *) E);
  66. break;
  67. default:
  68. fprintf (stderr, "PushButton: event %d\n", E->type );
  69. }
  70. }
  71. void PushButton::bpress (XButtonEvent *E)
  72. {
  73. int r = 0;
  74. if (E->button < 4)
  75. {
  76. _keymod = E->state;
  77. _button = E->button;
  78. r = handle_press ();
  79. }
  80. render ();
  81. if (r) callback (r);
  82. }
  83. void PushButton::brelse (XButtonEvent *E)
  84. {
  85. int r = 0;
  86. if (E->button < 4)
  87. {
  88. _keymod = E->state;
  89. _button = E->button;
  90. r = handle_relse ();
  91. }
  92. render ();
  93. if (r) callback (r);
  94. }
  95. void PushButton::set_state (int s)
  96. {
  97. if (_state != s)
  98. {
  99. _state = s;
  100. render ();
  101. }
  102. }
  103. void PushButton::render (void)
  104. {
  105. XPutImage (dpy (), win (), dgc (), _image->_ximage,
  106. _image->_x0, _image->_y0 + _state * _image->_dy, 0, 0, _image->_dx, _image->_dy);
  107. }
  108. }