not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2 KiB

  1. // Class to load all game images in cache
  2. enyo.kind({
  3. name: "LcdDisplay",
  4. kind: enyo.Control,
  5. classes: "lcd-border",
  6. published: { size: 3, value: "" },
  7. components: [
  8. // Value
  9. {name: "digits", components: [
  10. ]},
  11. // Preload image
  12. {kind: "Image", id:"led_nums", src:"images/led_values.png", classes: "image-preload", showing: false }
  13. ],
  14. // Constructor
  15. create: function() {
  16. this.inherited(arguments);
  17. this.sizeChanged();
  18. this.valueChanged();
  19. },
  20. // Size changed, reinit
  21. sizeChanged: function() {
  22. // Resize
  23. var wsize = window.innerWidth;
  24. var digitwidth;
  25. var digitheight;
  26. var zoom;
  27. if (wsize <= 480) {
  28. digitwidth = 20;
  29. digitheight = 32;
  30. } else {
  31. digitwidth = 30;
  32. digitheight = 48;
  33. }
  34. this.applyStyle("width", (digitwidth*this.size)+"px");
  35. this.applyStyle("height", digitheight+"px");
  36. // Clean digits
  37. var items = [];
  38. enyo.forEach(this.$.digits.getControls(), function(item) { items.push(item); });
  39. for (var i = 0 ; i < items.length ; i++) { items[i].destroy(); };
  40. // Create digits
  41. for (var i = 0 ; i < this.size ; i++) {
  42. this.$.digits.createComponent({ classes: "lcd-num lcd-image-empty" }, {owner: this}).render();
  43. }
  44. },
  45. // Value changed
  46. valueChanged: function() {
  47. // Get digit value
  48. var getDigitValue = function(valueto, index) {
  49. if (index >= valueto.length)
  50. return '';
  51. return valueto[index];
  52. };
  53. // Get matching class for the digit
  54. var getMatchingClass = function(digit) {
  55. var prefix = "lcd-image-";
  56. if (digit >= '0' && digit <= '9')
  57. prefix += digit;
  58. else if (digit == '-')
  59. prefix += "dash";
  60. else
  61. prefix += "empty";
  62. return prefix;
  63. };
  64. // Align to number of digits to size
  65. var complete = this.size - this.value.length;
  66. for (var i = 0 ; i < complete ; i++)
  67. this.value = ' '+this.value;
  68. // Set each digit value using the right class
  69. var digits = this.$.digits.getControls();
  70. for (var i = 0 ; i < this.size ; i++) {
  71. var newdigit = getDigitValue(this.value, i);
  72. var classes = digits[i].getClassAttribute();
  73. digits[i].addRemoveClass(classes.substr(classes.indexOf("lcd-image-")), false);
  74. digits[i].addRemoveClass(getMatchingClass(newdigit), true);
  75. }
  76. }
  77. });