1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php 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 package com.android.ide.common.layout; 18 19 import com.android.annotations.NonNull; 20 import com.android.ide.common.api.DrawingStyle; 21 import com.android.ide.common.api.IColor; 22 import com.android.ide.common.api.IGraphics; 23 import com.android.ide.common.api.Point; 24 import com.android.ide.common.api.Rect; 25 26 import java.util.ArrayList; 27 import java.util.Collections; 28 import java.util.List; 29 30 // TODO: Create box of ascii art 31 32 public class TestGraphics implements IGraphics { 33 /** List of things we have drawn */ 34 private List<String> mDrawn = new ArrayList<String>(); 35 36 private IColor mBackground = new TestColor(0x000000); 37 38 private IColor mForeground = new TestColor(0xFFFFFF); 39 40 private int mAlpha = 128; 41 42 /** Return log of graphics calls */ 43 public List<String> getDrawn() { 44 return Collections.unmodifiableList(mDrawn); 45 } 46 47 /** Wipe out log of graphics calls */ 48 public void clear() { 49 mDrawn.clear(); 50 } 51 52 // ==== IGraphics ==== 53 54 @Override 55 public void drawBoxedStrings(int x, int y, @NonNull List<?> strings) { 56 mDrawn.add("drawBoxedStrings(" + x + "," + y + "," + strings + ")"); 57 } 58 59 @Override 60 public void drawLine(int x1, int y1, int x2, int y2) { 61 mDrawn.add("drawLine(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")"); 62 } 63 64 @Override 65 public void drawLine(@NonNull Point p1, @NonNull Point p2) { 66 mDrawn.add("drawLine(" + p1 + "," + p2 + ")"); 67 } 68 69 @Override 70 public void drawRect(int x1, int y1, int x2, int y2) { 71 mDrawn.add("drawRect(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")"); 72 } 73 74 @Override 75 public void drawRect(@NonNull Point p1, @NonNull Point p2) { 76 mDrawn.add("drawRect(" + p1 + "," + p2 + ")"); 77 } 78 79 @Override 80 public void drawRect(@NonNull Rect r) { 81 mDrawn.add("drawRect(" + rectToString(r) + ")"); 82 } 83 84 @Override 85 public void drawString(@NonNull String string, int x, int y) { 86 mDrawn.add("drawString(" + x + "," + y + "," + string + ")"); 87 } 88 89 @Override 90 public void drawString(@NonNull String string, @NonNull Point topLeft) { 91 mDrawn.add("drawString(" + string + "," + topLeft + ")"); 92 } 93 94 @Override 95 public void fillRect(int x1, int y1, int x2, int y2) { 96 mDrawn.add("fillRect(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")"); 97 } 98 99 @Override 100 public void fillRect(@NonNull Point p1, @NonNull Point p2) { 101 mDrawn.add("fillRect(" + p1 + "," + p2 + ")"); 102 } 103 104 @Override 105 public void fillRect(@NonNull Rect r) { 106 mDrawn.add("fillRect(" + rectToString(r) + ")"); 107 } 108 109 @Override 110 public int getAlpha() { 111 return mAlpha; 112 } 113 114 @Override 115 public @NonNull IColor getBackground() { 116 return mBackground; 117 } 118 119 @Override 120 public int getFontHeight() { 121 return 12; 122 } 123 124 @Override 125 public @NonNull IColor getForeground() { 126 return mForeground; 127 } 128 129 @Override 130 public @NonNull IColor registerColor(int rgb) { 131 mDrawn.add("registerColor(" + Integer.toHexString(rgb) + ")"); 132 return new TestColor(rgb); 133 } 134 135 @Override 136 public void setAlpha(int alpha) { 137 mAlpha = alpha; 138 mDrawn.add("setAlpha(" + alpha + ")"); 139 } 140 141 @Override 142 public void setBackground(@NonNull IColor color) { 143 mDrawn.add("setBackground(" + color + ")"); 144 mBackground = color; 145 } 146 147 @Override 148 public void setForeground(@NonNull IColor color) { 149 mDrawn.add("setForeground(" + color + ")"); 150 mForeground = color; 151 } 152 153 @Override 154 public void setLineStyle(@NonNull LineStyle style) { 155 mDrawn.add("setLineStyle(" + style + ")"); 156 } 157 158 @Override 159 public void setLineWidth(int width) { 160 mDrawn.add("setLineWidth(" + width + ")"); 161 } 162 163 @Override 164 public void useStyle(@NonNull DrawingStyle style) { 165 mDrawn.add("useStyle(" + style + ")"); 166 } 167 168 @Override 169 public void drawArrow(int x1, int y1, int x2, int y2, int size) { 170 mDrawn.add("drawArrow(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")"); 171 } 172 173 @Override 174 public void drawPoint(int x, int y) { 175 mDrawn.add("drawPoint(" + x + "," + y + ")"); 176 } 177 178 private static String rectToString(Rect rect) { 179 return "Rect[" + rect.x + "," + rect.y + "," + rect.w + "," + rect.h + "]"; 180 } 181 } 182