TextureSelect.hx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package hide.comp;
  2. class TextureSelect extends FileSelect {
  3. public var value(default, set) : h3d.mat.Texture;
  4. public var area(default, set) : { x : Int, y : Int, width : Int, height : Int };
  5. var preview : Element;
  6. public function new(?parent,?root) {
  7. preview = new Element("<div class='texture-preview'>");
  8. super(hide.Ide.IMG_EXTS, parent, root);
  9. preview.insertAfter(root);
  10. }
  11. override function remove() {
  12. super.remove();
  13. preview.remove();
  14. }
  15. function set_area(v) {
  16. area = v;
  17. this.path = path;
  18. return v;
  19. }
  20. override function set_path(p:String) {
  21. super.set_path(p);
  22. if( p == null )
  23. value = null;
  24. else if( value == null || value.name != p ) {
  25. var scene = Scene.getNearest(element);
  26. if( scene != null ) {
  27. scene.setCurrent();
  28. value = scene.loadTexture("", p);
  29. }
  30. }
  31. if( p == null )
  32. preview.hide();
  33. else {
  34. preview.show();
  35. preview.css("background-image", "url('file://" + ide.getPath(p) + "')");
  36. preview.css("background-size", area == null ? "15px 15px" : area.width + "px " + area.height + "px");
  37. preview.css("background-position", area == null ? "" : area.x + "px " + area.y + "px");
  38. }
  39. return p;
  40. }
  41. function set_value(t:h3d.mat.Texture) {
  42. value = t;
  43. var p = value == null ? null : value.name;
  44. if( p != path )
  45. this.path = p;
  46. return t;
  47. }
  48. }