|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.mj.impl.nokialcdui; |
|
18 |
|
19 import javax.microedition.lcdui.*; |
|
20 |
|
21 import org.eclipse.swt.internal.qt.graphics.GraphicsContext; |
|
22 |
|
23 import com.nokia.mid.ui.DirectGraphics; |
|
24 |
|
25 /** |
|
26 * Abstract class providing the interface to internal LCDUI resources. |
|
27 */ |
|
28 public abstract class LCDUIInvoker { |
|
29 |
|
30 /** |
|
31 * Invoker instance. |
|
32 */ |
|
33 private static com.nokia.mj.impl.nokialcdui.LCDUIInvoker invokerInstance; |
|
34 |
|
35 /** |
|
36 * Method called at LCDUI initialization and setting the invoker. |
|
37 * |
|
38 * @param invoker In |
|
39 */ |
|
40 public static void setInvoker(LCDUIInvoker invoker) { |
|
41 invokerInstance = invoker; |
|
42 } |
|
43 |
|
44 /** |
|
45 * Synchronized execution of runnable with eSWT thread. |
|
46 * |
|
47 * @param runnable a runnable |
|
48 */ |
|
49 public static void eSWTUIThreadRunnerSyncExec(Runnable runnable) { |
|
50 invokerInstance.doESWTUIThreadRunnerSyncExec(runnable); |
|
51 } |
|
52 |
|
53 /** |
|
54 * Returns main eSWT Control that is used by LCDUI Displayable or Item. |
|
55 * |
|
56 * @param lcduiObject - LCDUI Displayable or Item. |
|
57 * @return eSWT Control that is used by Displayable/Item or null if no |
|
58 * Control is available. |
|
59 */ |
|
60 public static org.eclipse.swt.widgets.Control getEswtControl(Object lcduiObject) { |
|
61 return invokerInstance.doGetEswtControl(lcduiObject); |
|
62 } |
|
63 |
|
64 /** |
|
65 * Returns eSWT Display that is used by LCDUI. |
|
66 * |
|
67 * @return eSWT Display that is used by LCDUI. |
|
68 */ |
|
69 public static org.eclipse.swt.widgets.Display getEswtDisplay() { |
|
70 return invokerInstance.doGetEswtDisplay(); |
|
71 } |
|
72 |
|
73 public static org.eclipse.swt.graphics.Image getEswtImage(Image img) { |
|
74 return invokerInstance.doGetEswtImage(img); |
|
75 } |
|
76 |
|
77 /** |
|
78 * Get the DirectGraphics object associated with this Graphics object. |
|
79 * |
|
80 * @param g Graphics object |
|
81 * @return DirectGraphics object |
|
82 */ |
|
83 public static DirectGraphics getDirectGraphics(Graphics g) { |
|
84 return invokerInstance.doGetDirectGraphics(g); |
|
85 } |
|
86 |
|
87 public static GraphicsContext getGc(Graphics g) { |
|
88 return invokerInstance.doGetGc(g); |
|
89 } |
|
90 |
|
91 /** |
|
92 * Get a freely sized Font with the given parameters. |
|
93 * |
|
94 * @param face font face |
|
95 * @param style font style |
|
96 * @param height font height |
|
97 * @return the requested Font |
|
98 */ |
|
99 public static Font getFreeSizedFont(int face, int style, int height) { |
|
100 return invokerInstance.doGetFreeSizedFont(face, style, height); |
|
101 } |
|
102 |
|
103 /** |
|
104 * Init GameCanvas. |
|
105 * |
|
106 * @param canvas GameCanvas object |
|
107 * @param suppressKeys suppress game keys |
|
108 * @return framebuffer image |
|
109 */ |
|
110 public static void initGameCanvas(Object canvas, boolean suppressKeys) { |
|
111 invokerInstance.doInitGameCanvas(canvas, suppressKeys); |
|
112 } |
|
113 |
|
114 /** |
|
115 * Get the frameBuffer's Graphics object. |
|
116 * |
|
117 * @param canvas GameCanvas object |
|
118 * @return Graphics object |
|
119 */ |
|
120 public static Object getGraphics(Object canvas) { |
|
121 return invokerInstance.doGetGraphics(canvas); |
|
122 } |
|
123 |
|
124 public static Object getFlushLock(Object graphics) { |
|
125 return invokerInstance.doGetFlushLock(graphics); |
|
126 } |
|
127 |
|
128 /** |
|
129 * Get game key states. |
|
130 * |
|
131 * @param canvas GameCanvas object |
|
132 * @return key states |
|
133 */ |
|
134 public static int getKeyStates(Object canvas) { |
|
135 return invokerInstance.doGetKeyStates(canvas); |
|
136 } |
|
137 |
|
138 /** |
|
139 * Renders the GameCanvas's frameBuffer to the Graphics object at (0,0). |
|
140 * |
|
141 * @param canvas GameCanvas object |
|
142 * @param graphics Graphics object |
|
143 */ |
|
144 public static void renderGraphics(Object canvas, Object graphics) { |
|
145 invokerInstance.doRenderGraphics(canvas, graphics); |
|
146 } |
|
147 |
|
148 /** |
|
149 * Flushes the GameCanvas's frameBuffer to the display. |
|
150 * |
|
151 * @param canvas GameCanvas object |
|
152 * @param x clip X |
|
153 * @param y clip Y |
|
154 * @param width clip width |
|
155 * @param height clip height |
|
156 */ |
|
157 public static void flushGraphics(Object canvas, |
|
158 int x, int y, int width, int height) { |
|
159 invokerInstance.doFlushGraphics(canvas, x, y, width, height); |
|
160 } |
|
161 |
|
162 /** |
|
163 * Returns the dynamic property value. |
|
164 * |
|
165 * @param key property key |
|
166 * @return property value |
|
167 */ |
|
168 public static String getDynamicProperty(String key) { |
|
169 return invokerInstance.doGetDynamicProperty(key); |
|
170 } |
|
171 |
|
172 /** |
|
173 * Detect pixel level collision. |
|
174 */ |
|
175 public static boolean detectCollision(Image image1, int transform1, int p1x, int p1y, |
|
176 int r1x1, int r1y1, int r1x2, int r1y2, |
|
177 Image image2, int transform2, int p2x, int p2y, |
|
178 int r2x1, int r2y1, int r2x2, int r2y2) { |
|
179 return invokerInstance.doDetectCollision(image1, transform1, p1x, p1y, |
|
180 r1x1, r1y1, r1x2, r1y2, |
|
181 image2, transform2, p2x, p2y, |
|
182 r2x1, r2y1, r2x2, r2y2); |
|
183 } |
|
184 |
|
185 |
|
186 // MMAPI support |
|
187 |
|
188 protected abstract org.eclipse.swt.widgets.Control doGetEswtControl( |
|
189 Object lcduiObj); |
|
190 |
|
191 protected abstract org.eclipse.swt.widgets.Display doGetEswtDisplay(); |
|
192 |
|
193 protected abstract org.eclipse.swt.graphics.Image doGetEswtImage(Image img); |
|
194 |
|
195 |
|
196 // DirectGraphics support |
|
197 |
|
198 protected abstract DirectGraphics doGetDirectGraphics(Graphics g); |
|
199 |
|
200 protected abstract GraphicsContext doGetGc(Graphics g); |
|
201 |
|
202 protected abstract Font doGetFreeSizedFont(int face, int style, int height); |
|
203 |
|
204 // GameCanvas support |
|
205 |
|
206 protected abstract void doInitGameCanvas(Object canvas, |
|
207 boolean suppressKeys); |
|
208 |
|
209 protected abstract Object doGetGraphics(Object canvas); |
|
210 |
|
211 protected abstract Object doGetFlushLock(Object graphics); |
|
212 |
|
213 protected abstract int doGetKeyStates(Object canvas); |
|
214 |
|
215 protected abstract void doRenderGraphics(Object canvas, Object graphics); |
|
216 |
|
217 protected abstract void doFlushGraphics(Object canvas, |
|
218 int x, int y, int width, int height); |
|
219 |
|
220 protected abstract String doGetDynamicProperty(String key); |
|
221 |
|
222 protected abstract boolean doDetectCollision(Image image1, int transform1, int p1x, int p1y, |
|
223 int r1x1, int r1y1, int r1x2, int r1y2, |
|
224 Image image2, int transform2, int p2x, int p2y, |
|
225 int r2x1, int r2y1, int r2x2, int r2y2); |
|
226 |
|
227 // TactileFeedback support |
|
228 protected abstract void doESWTUIThreadRunnerSyncExec(Runnable runnable); |
|
229 |
|
230 |
|
231 } |