PolyUIColorBox.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. Copyright (C) 2012 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolySceneImage.h"
  22. #include "PolySceneLabel.h"
  23. #include "PolyScenePrimitive.h"
  24. #include "PolyEntity.h"
  25. #include "PolyUIEvent.h"
  26. #include "PolyUITextInput.h"
  27. #include "PolyUIWindow.h"
  28. #include "PolyUIHSlider.h"
  29. #include "PolyUIBox.h"
  30. #include "PolyUIElement.h"
  31. #include "PolyFont.h"
  32. namespace Polycode {
  33. class _PolyExport UIColorPicker : public UIWindow {
  34. public:
  35. UIColorPicker();
  36. virtual ~UIColorPicker();
  37. void updateSelectedColor(bool updateTextFields=true, bool updateHue = true, bool updateSV=true);
  38. void setHue(Number hueNum);
  39. void handleEvent(Event *event);
  40. void setSaturationAndValue(Number S, Number V);
  41. void updateColorFromMainSelector();
  42. void updateColorFromHueSelector();
  43. void rebuildFromTextInputs();
  44. void cancelColorListeners();
  45. void Update();
  46. void onClose();
  47. bool isContinuous();
  48. void setContinuous(bool _continuous);
  49. void setPickerColor(Color newColor);
  50. Color getSelectedColor();
  51. protected:
  52. Vector2 lastMainSelectorPosition;
  53. Number lastHueSelectorPosition;
  54. bool suppressTextChangeEvent;
  55. bool continuous;
  56. Color selectedColor;
  57. Number colorAlpha;
  58. Number currentH;
  59. Number currentS;
  60. Number currentV;
  61. UITextInput *rTextInput;
  62. UITextInput *gTextInput;
  63. UITextInput *bTextInput;
  64. UITextInput *aTextInput;
  65. UIImage *mainFrame;
  66. UIImage *mainBg;
  67. UIImage *hueFrame;
  68. UIImage *hueSelector;
  69. UIImage *mainSelector;
  70. UIHSlider *alphaSlider;
  71. SceneMesh *mainColorRect;
  72. vector<UILabel *> junkLabels; // Kept only to delete
  73. };
  74. class _PolyExport UIColorBox : public UIElement {
  75. public:
  76. UIColorBox(UIColorPicker *colorPicker, Color initialColor, Number width, Number height);
  77. virtual ~UIColorBox();
  78. Color getSelectedColor();
  79. void setBoxColor(Color newColor);
  80. void showColorPicker();
  81. void handleEvent(Event *event);
  82. protected:
  83. bool listeningToPicker;
  84. UIColorPicker *colorPicker;
  85. Color selectedColor;
  86. UIBox *frameImage;
  87. UIRect *bgImage;
  88. UIRect *colorShape;
  89. };
  90. }