|
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 javax.microedition.lcdui.game; |
|
18 |
|
19 import javax.microedition.lcdui.Graphics; |
|
20 |
|
21 import com.nokia.mj.impl.nokialcdui.LCDUIInvoker; |
|
22 |
|
23 /** |
|
24 * GameCanvas class. |
|
25 */ |
|
26 public abstract class GameCanvas extends javax.microedition.lcdui.Canvas |
|
27 { |
|
28 |
|
29 /** |
|
30 * Bit representing UP key. (1 << Canvas.UP) |
|
31 */ |
|
32 public static final int UP_PRESSED = 0x0002; |
|
33 |
|
34 /** |
|
35 * Bit representing DOWN key. (1 << Canvas.DOWN) |
|
36 */ |
|
37 public static final int DOWN_PRESSED = 0x0040; |
|
38 |
|
39 /** |
|
40 * Bit representing LEFT key. (1 << Canvas.LEFT) |
|
41 */ |
|
42 public static final int LEFT_PRESSED = 0x0004; |
|
43 |
|
44 /** |
|
45 * Bit representing RIGHT key. (1 << Canvas.RIGHT) |
|
46 */ |
|
47 public static final int RIGHT_PRESSED = 0x0020; |
|
48 |
|
49 /** |
|
50 * Bit representing FIRE key. (1 << Canvas.FIRE) |
|
51 */ |
|
52 public static final int FIRE_PRESSED = 0x0100; |
|
53 |
|
54 /** |
|
55 * Bit representing GAME_A key. (1 << Canvas.GAME_A) |
|
56 */ |
|
57 public static final int GAME_A_PRESSED = 0x0200; |
|
58 |
|
59 /** |
|
60 * Bit representing GAME_B key. (1 << Canvas.GAME_B) |
|
61 */ |
|
62 public static final int GAME_B_PRESSED = 0x0400; |
|
63 |
|
64 /** |
|
65 * Bit representing GAME_C key. (1 << Canvas.GAME_C) |
|
66 */ |
|
67 public static final int GAME_C_PRESSED = 0x0800; |
|
68 |
|
69 /** |
|
70 * Bit representing GAME_D key. (1 << Canvas.GAME_D) |
|
71 */ |
|
72 public static final int GAME_D_PRESSED = 0x1000; |
|
73 |
|
74 /** |
|
75 * Constructor. |
|
76 * |
|
77 * @param suppressKeyEvents supress game key events. |
|
78 */ |
|
79 protected GameCanvas(boolean suppressKeyEvents) |
|
80 { |
|
81 super(); |
|
82 LCDUIInvoker.initGameCanvas(this, suppressKeyEvents); |
|
83 } |
|
84 |
|
85 /** |
|
86 * Get frameBuffer's Graphics object. |
|
87 * |
|
88 * @return frameBuffer's Graphics |
|
89 */ |
|
90 protected Graphics getGraphics() |
|
91 { |
|
92 return (Graphics) LCDUIInvoker.getGraphics(this); |
|
93 } |
|
94 |
|
95 /** |
|
96 * Get game key states. |
|
97 * |
|
98 * @return game key states |
|
99 */ |
|
100 public int getKeyStates() |
|
101 { |
|
102 return LCDUIInvoker.getKeyStates(this); |
|
103 } |
|
104 |
|
105 /** |
|
106 * By default this renders the frameBuffer at (0,0). |
|
107 * |
|
108 * @param g Graphics object |
|
109 */ |
|
110 public void paint(javax.microedition.lcdui.Graphics g) |
|
111 { |
|
112 // If the Graphics doesn't belong to the frame buffer |
|
113 LCDUIInvoker.renderGraphics(this, g); |
|
114 } |
|
115 |
|
116 /** |
|
117 * Flushes the frameBuffer's region to the display. |
|
118 * |
|
119 * @param x clip X |
|
120 * @param y clip Y |
|
121 * @param w clip width |
|
122 * @param h clip height |
|
123 */ |
|
124 public void flushGraphics(int x, int y, int w, int h) |
|
125 { |
|
126 if(w > 0 && h > 0) |
|
127 { |
|
128 LCDUIInvoker.flushGraphics(this, x, y, w, h); |
|
129 } |
|
130 } |
|
131 |
|
132 /** |
|
133 * Flushes the frameBuffer to the display. |
|
134 */ |
|
135 public void flushGraphics() |
|
136 { |
|
137 LCDUIInvoker.flushGraphics(this, 0, 0, getWidth(), getHeight()); |
|
138 } |
|
139 |
|
140 } |