A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

61 line
1.7KB

  1. import Utils from "/app/js/common/Utils.js";
  2. import GlobalEvents from "/app/js/common/EventCaller.js";
  3. const EL_CANVAS_ID = "painter";
  4. // For reference...
  5. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/stroke
  6. class CTRLPainter {
  7. constructor(){
  8. this.__canvas = null;
  9. this.__context = null;
  10. this.__scale = 1.0; // This is the scale the painter will display source information.
  11. this.__offset = [0.0, 0.0]; // This is the X,Y offset from origin to display source information.
  12. this.__canvas = document.getElementById(EL_CANVAS_ID);
  13. if (!this.__canvas)
  14. throw new Error("Failed to obtain the canvas element.");
  15. this.__context = this.__canvas.getContext("2d");
  16. if (!this.__context)
  17. throw new Error("Failed to obtain canvas context.");
  18. //var imgdata = this.__context.getImageData();
  19. var handle_resize = Utils.debounce((function(e){
  20. console.log("DEBOUNCED");
  21. console.log(e);
  22. var w = this.__canvas.clientWidth;
  23. var h = this.__canvas.clientHeight;
  24. this.__canvas.width = w;
  25. this.__canvas.height = h;
  26. console.log(this.__canvas.width + ", " + this.__canvas.height);
  27. console.log(this.__canvas.clientWidth + ", " + this.__canvas.clientHeight);
  28. }).bind(this), 250);
  29. window.addEventListener("resize", handle_resize);
  30. }
  31. get scale(){
  32. return this.__scale;
  33. }
  34. set scale(s){
  35. if (typeof(s) !== 'number')
  36. throw new TypeError("Expected number value.");
  37. this.__scale = Math.max(0.1, Math.min(100.0, s));
  38. }
  39. scale_up(amount=1){
  40. this.scale = this.scale + (amount*0.1);
  41. }
  42. scale_down(amount=1){
  43. this.scale = this.scale - (amount*0.1);
  44. }
  45. }
  46. const instance = new CTRLPainter();
  47. export default instance;