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个字符

56 行
1.5KB

  1. import Utils from "/app/js/Utils.js";
  2. import GlobalEvents from "/app/js/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(){
  20. console.log("DEBOUNCED");
  21. console.log(this.__canvas.width + ", " + this.__canvas.height);
  22. console.log(this.__canvas.clientWidth + ", " + this.__canvas.height);
  23. }).bind(this), 250);
  24. window.addEventListener("resize", handle_resize);
  25. }
  26. get scale(){
  27. return this.__scale;
  28. }
  29. set scale(s){
  30. if (typeof(s) !== 'number')
  31. throw new TypeError("Expected number value.");
  32. this.__scale = Math.max(0.1, Math.min(100.0, s));
  33. }
  34. scale_up(amount=1){
  35. this.scale = this.scale + (amount*0.1);
  36. }
  37. scale_down(amount=1){
  38. this.scale = this.scale - (amount*0.1);
  39. }
  40. }
  41. const instance = new CTRLPainter();
  42. export default instance;