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