1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18package com.replica.replicaisland;
19
20public final class DebugSystem extends BaseObject {
21	public static final int COLOR_RED = 0;
22	public static final int COLOR_BLUE = 1;
23	public static final int COLOR_OUTLINE = 2;
24	public static final int SHAPE_BOX = 0;
25	public static final int SHAPE_CIRCLE = 1;
26
27	private Texture mRedBoxTexture;
28	private Texture mBlueBoxTexture;
29	private Texture mOutlineBoxTexture;
30	private Texture mRedCircleTexture;
31	private Texture mBlueCircleTexture;
32	private Texture mOutlineCircleTexture;
33
34	private Vector2 mWorkVector;
35
36	public DebugSystem(TextureLibrary library) {
37		super();
38		if (library != null) {
39			mRedBoxTexture = library.allocateTexture(R.drawable.debug_box_red);
40			mBlueBoxTexture = library.allocateTexture(R.drawable.debug_box_blue);
41			mOutlineBoxTexture = library.allocateTexture(R.drawable.debug_box_outline);
42			mRedCircleTexture = library.allocateTexture(R.drawable.debug_circle_red);
43			mBlueCircleTexture = library.allocateTexture(R.drawable.debug_circle_blue);
44			mOutlineCircleTexture = library.allocateTexture(R.drawable.debug_circle_outline);
45
46		}
47
48		mWorkVector = new Vector2();
49	}
50
51	@Override
52	public void reset() {
53	}
54
55	public void drawShape(float x, float y, float width, float height, int shapeType, int colorType) {
56        final RenderSystem render = sSystemRegistry.renderSystem;
57        final DrawableFactory factory = sSystemRegistry.drawableFactory;
58        CameraSystem camera = sSystemRegistry.cameraSystem;
59        ContextParameters params = sSystemRegistry.contextParameters;
60        mWorkVector.set(x, y);
61        mWorkVector.x = (mWorkVector.x - camera.getFocusPositionX()
62                        + (params.gameWidth / 2));
63        mWorkVector.y = (mWorkVector.y - camera.getFocusPositionY()
64                        + (params.gameHeight / 2));
65
66        if (mWorkVector.x + width >= 0.0f && mWorkVector.x < params.gameWidth
67                && mWorkVector.y + height >= 0.0f && mWorkVector.y < params.gameHeight) {
68	        DrawableBitmap bitmap = factory.allocateDrawableBitmap();
69	        if (bitmap != null) {
70	        	Texture texture = getTexture(shapeType, colorType);
71	            bitmap.resize((int)texture.width, (int)texture.height);
72	            // TODO: scale stretch hack.  fix!
73	            bitmap.setWidth((int)width);
74	            bitmap.setHeight((int)height);
75	            bitmap.setTexture(texture);
76	            mWorkVector.set(x, y);
77
78	            render.scheduleForDraw(bitmap, mWorkVector, SortConstants.HUD, true);
79	        }
80        }
81	}
82
83	private final Texture getTexture(int shapeType, int colorType) {
84		Texture result = null;
85		if (shapeType == SHAPE_BOX) {
86			switch (colorType) {
87				case COLOR_RED:
88					result = mRedBoxTexture;
89					break;
90				case COLOR_BLUE:
91					result = mBlueBoxTexture;
92					break;
93				case COLOR_OUTLINE:
94					result = mOutlineBoxTexture;
95					break;
96			}
97		} else if (shapeType == SHAPE_CIRCLE) {
98			switch (colorType) {
99			case COLOR_RED:
100				result = mRedCircleTexture;
101				break;
102			case COLOR_BLUE:
103				result = mBlueCircleTexture;
104				break;
105			case COLOR_OUTLINE:
106				result = mOutlineCircleTexture;
107				break;
108			}
109		}
110		return result;
111	}
112
113
114}
115