Color.hx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package h2d.comp;
  2. class Color extends Component {
  3. var input : h2d.Interactive;
  4. public var value(default, set) : Int;
  5. public function new(?parent) {
  6. super("color", parent);
  7. input = new h2d.Interactive(0, 0, bg);
  8. var active = false;
  9. input.onPush = function(_) {
  10. active = true;
  11. };
  12. input.onOver = function(_) {
  13. addClass(":hover");
  14. };
  15. input.onOut = function(_) {
  16. active = false;
  17. removeClass(":hover");
  18. };
  19. input.onRelease = function(_) {
  20. if( active ) selectColor();
  21. };
  22. value = 0;
  23. }
  24. function set_value(v) {
  25. needRebuild = true;
  26. return value = v;
  27. }
  28. override function resize( ctx : Context ) {
  29. super.resize(ctx);
  30. if( !ctx.measure ) {
  31. input.width = width - (style.marginLeft + style.marginRight);
  32. input.height = height - (style.marginTop + style.marginBottom);
  33. bg.fillRectColor(extLeft() - style.marginLeft, extTop() - style.marginTop, contentWidth, contentHeight, 0xFF000000 | value);
  34. }
  35. }
  36. function selectColor() {
  37. var p : Component = this;
  38. while( p.parentComponent != null )
  39. p = p.parentComponent;
  40. var b = new Box(p);
  41. b.toggleClass("modal", true);
  42. var pick = new ColorPicker(b);
  43. pick.color = value;
  44. pick.addStyleString("dock:full");
  45. pick.onChange = function(c) {
  46. value = c;
  47. onChange(c);
  48. };
  49. pick.onClose = function() {
  50. b.remove();
  51. };
  52. }
  53. public dynamic function onChange( color : Int ) {
  54. }
  55. }