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.

styles.cc 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // ----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2010-2014 Fons Adriaensen <fons@linuxaudio.org>
  4. // Modified by falkTX on Jan-Apr 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 "styles.h"
  22. #include "tmeter.h"
  23. #include "png2img.h"
  24. #include "CarlaString.hpp"
  25. #include <dlfcn.h>
  26. namespace AT1 {
  27. XftColor *XftColors [NXFTCOLORS];
  28. XftFont *XftFonts [NXFTFONTS];
  29. X_textln_style tstyle1;
  30. X_button_style bstyle1;
  31. XImage *notesect_img;
  32. XImage *ctrlsect_img;
  33. ButtonImg b_note_img;
  34. ButtonImg b_midi_img;
  35. RotaryGeom r_tune_geom;
  36. RotaryGeom r_filt_geom;
  37. RotaryGeom r_bias_geom;
  38. RotaryGeom r_corr_geom;
  39. RotaryGeom r_offs_geom;
  40. static CarlaString getResourceDir()
  41. {
  42. Dl_info exeInfo;
  43. dladdr((void*)getResourceDir, &exeInfo);
  44. CarlaString filename(exeInfo.dli_fname);
  45. return filename.truncate(filename.rfind("-ui"));
  46. }
  47. void styles_init (X_display *disp, X_resman *xrm)
  48. {
  49. CarlaString resourceDir(getResourceDir());
  50. XftColors [C_MAIN_BG] = disp->alloc_xftcolor (0.25f, 0.25f, 0.25f, 1.0f);
  51. XftColors [C_MAIN_FG] = disp->alloc_xftcolor (1.0f, 1.0f, 1.0f, 1.0f);
  52. XftColors [C_TEXT_BG] = disp->alloc_xftcolor (1.0f, 1.0f, 1.0f, 1.0f);
  53. XftColors [C_TEXT_FG] = disp->alloc_xftcolor (0.1f, 0.1f, 0.1f, 1.0f);
  54. XftFonts [F_TEXT] = disp->alloc_xftfont (xrm->get (".font.text", "luxi:bold::pixelsize=11"));
  55. XftFonts [F_BUTT] = disp->alloc_xftfont (xrm->get (".font.butt", "luxi:bold::pixelsize=11"));
  56. tstyle1.font = XftFonts [F_TEXT];
  57. tstyle1.color.normal.bgnd = XftColors [C_TEXT_BG]->pixel;
  58. tstyle1.color.normal.text = XftColors [C_TEXT_FG];
  59. bstyle1.font = XftFonts [F_BUTT];
  60. bstyle1.color.bg[0] = XftColors [C_MAIN_BG]->pixel;
  61. bstyle1.color.fg[0] = XftColors [C_MAIN_FG];
  62. bstyle1.type = X_button_style::PLAIN | X_button_style::ALEFT;
  63. notesect_img = png2img (resourceDir+"/notesect.png", disp, XftColors [C_MAIN_BG]);
  64. ctrlsect_img = png2img (resourceDir+"/ctrlsect.png", disp, XftColors [C_MAIN_BG]);
  65. Tmeter::_scale = png2img (resourceDir+"/hscale.png", disp, XftColors [C_MAIN_BG]);
  66. Tmeter::_imag0 = png2img (resourceDir+"/hmeter0.png", disp, XftColors [C_MAIN_BG]);
  67. Tmeter::_imag1 = png2img (resourceDir+"/hmeter1.png", disp, XftColors [C_MAIN_BG]);
  68. if ( !notesect_img || !ctrlsect_img
  69. || !Tmeter::_scale || !Tmeter::_imag0 || !Tmeter::_imag1)
  70. {
  71. fprintf (stderr, "Can't load images from '%s'.\n", resourceDir.buffer());
  72. exit (1);
  73. }
  74. b_midi_img._backg = XftColors [C_MAIN_BG];
  75. b_midi_img._ximage = png2img (resourceDir+"/midi.png", disp, XftColors [C_MAIN_BG]);
  76. b_midi_img._x0 = 0;
  77. b_midi_img._y0 = 0;
  78. b_midi_img._dx = 40;
  79. b_midi_img._dy = 24;
  80. b_note_img._backg = XftColors [C_MAIN_BG];
  81. b_note_img._ximage = png2img (resourceDir+"/note.png", disp, XftColors [C_MAIN_BG]);
  82. b_note_img._x0 = 0;
  83. b_note_img._y0 = 0;
  84. b_note_img._dx = 16;
  85. b_note_img._dy = 16;
  86. r_tune_geom._backg = XftColors [C_MAIN_BG];
  87. r_tune_geom._image [0] = ctrlsect_img;
  88. r_tune_geom._lncol [0] = 1;
  89. r_tune_geom._x0 = 26;
  90. r_tune_geom._y0 = 17;
  91. r_tune_geom._dx = 23;
  92. r_tune_geom._dy = 23;
  93. r_tune_geom._xref = 11.5;
  94. r_tune_geom._yref = 11.5;
  95. r_tune_geom._rad = 11;
  96. r_bias_geom._backg = XftColors [C_MAIN_BG];
  97. r_bias_geom._image [0] = ctrlsect_img;
  98. r_bias_geom._lncol [0] = 0;
  99. r_bias_geom._x0 = 86;
  100. r_bias_geom._y0 = 17;
  101. r_bias_geom._dx = 23;
  102. r_bias_geom._dy = 23;
  103. r_bias_geom._xref = 11.5;
  104. r_bias_geom._yref = 11.5;
  105. r_bias_geom._rad = 11;
  106. r_filt_geom._backg = XftColors [C_MAIN_BG];
  107. r_filt_geom._image [0] = ctrlsect_img;
  108. r_filt_geom._lncol [0] = 0;
  109. r_filt_geom._x0 = 146;
  110. r_filt_geom._y0 = 17;
  111. r_filt_geom._dx = 23;
  112. r_filt_geom._dy = 23;
  113. r_filt_geom._xref = 11.5;
  114. r_filt_geom._yref = 11.5;
  115. r_filt_geom._rad = 11;
  116. r_corr_geom._backg = XftColors [C_MAIN_BG];
  117. r_corr_geom._image [0] = ctrlsect_img;
  118. r_corr_geom._lncol [0] = 0;
  119. r_corr_geom._x0 = 206;
  120. r_corr_geom._y0 = 17;
  121. r_corr_geom._dx = 23;
  122. r_corr_geom._dy = 23;
  123. r_corr_geom._xref = 11.5;
  124. r_corr_geom._yref = 11.5;
  125. r_corr_geom._rad = 11;
  126. r_offs_geom._backg = XftColors [C_MAIN_BG];
  127. r_offs_geom._image [0] = ctrlsect_img;
  128. r_offs_geom._lncol [0] = 0;
  129. r_offs_geom._x0 = 266;
  130. r_offs_geom._y0 = 17;
  131. r_offs_geom._dx = 23;
  132. r_offs_geom._dy = 23;
  133. r_offs_geom._xref = 11.5;
  134. r_offs_geom._yref = 11.5;
  135. r_offs_geom._rad = 11;
  136. }
  137. void styles_fini (X_display *disp)
  138. {
  139. notesect_img->data = 0;
  140. ctrlsect_img->data = 0;
  141. b_midi_img._ximage->data = 0;
  142. b_note_img._ximage->data = 0;
  143. Tmeter::_scale->data = 0;
  144. Tmeter::_imag0->data = 0;
  145. Tmeter::_imag1->data = 0;
  146. XDestroyImage (notesect_img);
  147. XDestroyImage (ctrlsect_img);
  148. XDestroyImage (b_midi_img._ximage);
  149. XDestroyImage (b_note_img._ximage);
  150. XDestroyImage (Tmeter::_scale);
  151. XDestroyImage (Tmeter::_imag0);
  152. XDestroyImage (Tmeter::_imag1);
  153. }
  154. }