Small OpenGL based c++ rendering library
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.

menuitem.cpp 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "menuitem.h"
  2. namespace segl {
  3. MenuItem::MenuItem(std::string c) {
  4. caption = c;
  5. fontsizeadd = 0;
  6. fontname = "menufont";
  7. usevalue = false;
  8. selectable = true;
  9. grey = false;
  10. novaluecenter = false;
  11. fontengine.fontSelect(fontname);
  12. }
  13. std::string MenuItem::getValue() {
  14. return value;
  15. }
  16. std::string MenuItem::getCaption() {
  17. return caption;
  18. }
  19. void MenuItem::setCaption(std::string str) {
  20. caption = str;
  21. }
  22. int MenuItem::getMaxValueLen() {
  23. return (int)value.length();
  24. }
  25. void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int capvallen, int maxlen) {
  26. fontengine.setSize(basefontsize+fontsizeadd);
  27. if(highlight)
  28. fontengine.setColor(1.0f, 0.0f, 0.0f);
  29. else if(grey)
  30. fontengine.setColor(0.8f, 0.8f, 0.8f);
  31. else
  32. fontengine.setColor(1.0f, 1.0f, 1.0f);
  33. if(!usevalue) {
  34. fontengine.renderLine(caption, (int)pos.x, (int)pos.y, center);
  35. } else {
  36. // center und position ggf. �berarbeiten..
  37. Punkt2D tmp = pos;
  38. // tmp.x = pos.x - (caplen+vallen+valuewidth)/2;
  39. tmp.x = pos.x - maxlen/2;
  40. // tmp.x = pos.x - valuewidth/2 - fontengine.getTextWidth(caption)/2;
  41. // tmp.x = pos.x - caplen - valuewidth/2;
  42. fontengine.renderLine(caption, (int)tmp.x, (int)tmp.y, false);
  43. tmp.x += capvallen+valuewidth;
  44. fontengine.renderLine(value, (int)tmp.x, (int)tmp.y, false);
  45. }
  46. }
  47. bool MenuItem::isSelectable() {
  48. return (!grey)&&selectable;
  49. }
  50. bool MenuItem::hasValue() {
  51. return usevalue;
  52. }
  53. void MenuItem::setFontSizeAdd(int fsa) {
  54. fontsizeadd = fsa;
  55. }
  56. int MenuItem::getFontSizeAdd() {
  57. return fontsizeadd;
  58. }
  59. void MenuItem::greyItem(bool _grey) {
  60. grey = _grey;
  61. }
  62. MenuItem::~MenuItem() {
  63. }
  64. } // namespace segl