/android/Android(LGame-0.3.2&LAE-1.1)/LAE-1.1(Canvas)/src/core/org/loon/framework/android/game/core/graphics/component/LPaper.java

http://loon-simple.googlecode.com/ · Java · 174 lines · 121 code · 33 blank · 20 comment · 16 complexity · c9480eaebd0dffa21667d8b79bb712ff MD5 · raw file

  1. package org.loon.framework.android.game.core.graphics.component;
  2. import org.loon.framework.android.game.action.sprite.Animation;
  3. import org.loon.framework.android.game.action.sprite.SpriteImage;
  4. import org.loon.framework.android.game.core.graphics.LComponent;
  5. import org.loon.framework.android.game.core.graphics.LContainer;
  6. import org.loon.framework.android.game.core.graphics.LImage;
  7. import org.loon.framework.android.game.core.graphics.device.LGraphics;
  8. import org.loon.framework.android.game.utils.GraphicsUtils;
  9. /**
  10. * Copyright 2008 - 2010
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  13. * use this file except in compliance with the License. You may obtain a copy of
  14. * the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  21. * License for the specific language governing permissions and limitations under
  22. * the License.
  23. *
  24. * @project loonframework
  25. * @author chenpeng
  26. * @email??šceponline@yahoo.com.cn
  27. * @version 0.1.1
  28. */
  29. public class LPaper extends LContainer {
  30. private Animation animation = new Animation();
  31. public LPaper(LImage background, int x, int y) {
  32. super(x, y, background.getWidth(), background.getHeight());
  33. this.customRendering = true;
  34. this.setBackground(background);
  35. this.setElastic(true);
  36. this.setLocked(true);
  37. this.setLayer(100);
  38. }
  39. public LPaper(LImage background) {
  40. this(background, 0, 0);
  41. }
  42. public LPaper(String fileName, int x, int y) {
  43. this(GraphicsUtils.loadImage(fileName), x, y);
  44. }
  45. public LPaper(String fileName) {
  46. this(fileName, 0, 0);
  47. }
  48. public LPaper(int x, int y, int w, int h) {
  49. this(LImage.createImage(w < 1 ? w = 1 : w, h < 1 ? h = 1 : h, true), x,
  50. y);
  51. }
  52. public Animation getAnimation() {
  53. return this.animation;
  54. }
  55. public void setAnimation(Animation animation) {
  56. this.animation = animation;
  57. }
  58. public void addAnimationFrame(SpriteImage image, long timer) {
  59. animation.addFrame(image, timer);
  60. }
  61. public void addAnimationFrame(String fileName, long timer) {
  62. animation.addFrame(fileName, timer);
  63. }
  64. public void addAnimationFrame(LImage image, long timer) {
  65. animation.addFrame(image, timer);
  66. }
  67. public void doClick() {
  68. }
  69. public void downClick() {
  70. }
  71. public void upClick() {
  72. }
  73. protected void processTouchClicked() {
  74. if (!input.isMoving()) {
  75. this.doClick();
  76. }
  77. }
  78. protected void processKeyPressed() {
  79. if (this.isSelected()) {
  80. this.doClick();
  81. }
  82. }
  83. protected void createCustomUI(LGraphics g, int x, int y, int w, int h) {
  84. if (visible) {
  85. if (animation.getSpriteImage() != null) {
  86. g.drawImage(animation.getSpriteImage().getImage(), x, y);
  87. }
  88. if (x != 0 && y != 0) {
  89. g.translate(x, y);
  90. paint(g);
  91. g.translate(-x, -y);
  92. } else {
  93. paint(g);
  94. }
  95. }
  96. }
  97. public void paint(LGraphics g) {
  98. }
  99. public void update(long elapsedTime) {
  100. if (visible) {
  101. super.update(elapsedTime);
  102. animation.update(elapsedTime);
  103. }
  104. }
  105. protected void processTouchDragged() {
  106. if (!locked) {
  107. if (getContainer() != null) {
  108. getContainer().sendToFront(this);
  109. }
  110. this.move(this.input.getTouchDX(), this.input.getTouchDY());
  111. }
  112. }
  113. protected void processTouchPressed() {
  114. if (!input.isMoving()) {
  115. this.downClick();
  116. }
  117. }
  118. protected void processTouchReleased() {
  119. if (!input.isMoving()) {
  120. this.upClick();
  121. }
  122. }
  123. public boolean isLocked() {
  124. return locked;
  125. }
  126. public void setLocked(boolean locked) {
  127. this.locked = locked;
  128. }
  129. protected void validateSize() {
  130. super.validateSize();
  131. }
  132. public String getUIName() {
  133. return "Paper";
  134. }
  135. public String toString() {
  136. return getUIName();
  137. }
  138. public void createUI(LGraphics g, int x, int y, LComponent component,
  139. LImage[] buttonImage) {
  140. }
  141. }