/android/LGame-Android-0.2.94/LGame/org/loon/framework/android/game/core/graphics/window/LPaper.java

http://loon-simple.googlecode.com/ · Java · 154 lines · 105 code · 29 blank · 20 comment · 11 complexity · 199b7c75a3054eb7d7db85085087de2c MD5 · raw file

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