40 protected static final int POINTER_DRAG = 0x80; |
40 protected static final int POINTER_DRAG = 0x80; |
41 |
41 |
42 /** |
42 /** |
43 * If CustomItem is changed, reasons for Re-layouting. |
43 * If CustomItem is changed, reasons for Re-layouting. |
44 */ |
44 */ |
45 static final int UPDATE_REASON_REPAINT = UPDATE_ITEM_MAX << 1; |
45 static final int UPDATE_REASON_REPAINT = UPDATE_ITEM_MAX << 1; |
46 |
46 |
47 |
47 |
48 private boolean cleanupNeeded; |
|
49 private int contentWidth; |
48 private int contentWidth; |
50 private int contentHeight; |
49 private int contentHeight; |
51 |
50 |
52 private boolean repaintPending; |
51 private boolean repaintPending; |
53 private int repaintX1; |
52 private int repaintX1; |
54 private int repaintY1; |
53 private int repaintY1; |
55 private int repaintX2; |
54 private int repaintX2; |
56 private int repaintY2; |
55 private int repaintY2; |
57 private Object repaintLock; |
56 private Object repaintLock; |
58 private Object cleanupLock; |
|
59 private Object resizeLock; |
57 private Object resizeLock; |
60 |
58 |
61 // Flag for passing info between UI thread |
59 // Flag for passing info between UI thread |
62 // and Dispatcher thread |
60 // and Dispatcher thread |
63 private boolean widgetDisposed; |
61 private boolean widgetDisposed; |
93 } |
91 } |
94 } |
92 } |
95 } |
93 } |
96 }); |
94 }); |
97 repaintLock = new Object(); |
95 repaintLock = new Object(); |
98 cleanupLock = new Object(); |
|
99 resizeLock = new Object(); |
96 resizeLock = new Object(); |
100 setLabel(label); |
97 setLabel(label); |
101 } |
98 } |
102 |
99 |
103 /** |
100 /** |
104 * Get the game action associated with the key code. |
101 * Returns game action associated with key code. |
105 * |
102 * |
106 * @param keyCode key code |
103 * @param keyCode Key code to map to game action. |
107 * @return game action bound to the key |
104 * @return game action corresponding to key, or 0 if none |
108 */ |
105 * @throws IllegalArgumentException if keyCode is not a valid key code |
109 public int getGameAction(int keyCode) |
106 */ |
110 { |
107 public int getGameAction(int aKeyCode) |
111 return KeyTable.getGameAction(keyCode); |
108 { |
|
109 if (aKeyCode == 0) |
|
110 { |
|
111 throw new IllegalArgumentException( |
|
112 MsgRepository.CANVAS_EXCEPTION_INVALID_KEY_CODE); |
|
113 } |
|
114 return KeyTable.getGameAction(aKeyCode); |
112 } |
115 } |
113 |
116 |
114 /** |
117 /** |
115 * Get the interaction modes available on this device. |
118 * Get the interaction modes available on this device. |
116 * |
119 * |
307 } |
310 } |
308 EventDispatcher eventDispatcher = EventDispatcher.instance(); |
311 EventDispatcher eventDispatcher = EventDispatcher.instance(); |
309 LCDUIEvent event = eventDispatcher.newEvent(LCDUIEvent.CUSTOMITEM_SIZECHANGED, layouter.formLayouter.getForm()); |
312 LCDUIEvent event = eventDispatcher.newEvent(LCDUIEvent.CUSTOMITEM_SIZECHANGED, layouter.formLayouter.getForm()); |
310 event.item = this; |
313 event.item = this; |
311 eventDispatcher.postEvent(event); |
314 eventDispatcher.postEvent(event); |
312 synchronized(cleanupLock) |
|
313 { |
|
314 cleanupNeeded = true; |
|
315 } |
|
316 repaint(); |
315 repaint(); |
317 } |
316 } |
318 } |
317 } |
319 |
318 |
320 /* |
319 /* |
566 { |
565 { |
567 return; |
566 return; |
568 } |
567 } |
569 |
568 |
570 // Clean the background if dirty, buffer the operations. |
569 // Clean the background if dirty, buffer the operations. |
571 synchronized(cleanupLock) |
570 if(layouter.noBackground && event.type == LCDUIEvent.CUSTOMITEM_PAINT_NATIVE_REQUEST) |
572 { |
571 { |
573 if(cleanupNeeded && layouter.noBackground) |
572 customItemGraphics.setClip(event.x, event.y, event.width, event.height); |
574 { |
573 customItemGraphics.cleanBackground(new Rectangle(event.x, event.y, event.width, event.height)); |
575 // Must be made sure that size doesn't change between reading |
|
576 // the width and the height. |
|
577 int contentWidth, contentHeight; |
|
578 synchronized(resizeLock) |
|
579 { |
|
580 contentWidth = this.contentWidth; |
|
581 contentHeight = this.contentHeight; |
|
582 } |
|
583 |
|
584 customItemGraphics.setClip(0, 0, contentWidth, contentHeight); |
|
585 customItemGraphics.cleanBackground(new Rectangle(0, 0, contentWidth, contentHeight)); |
|
586 cleanupNeeded = false; |
|
587 } |
|
588 } |
574 } |
589 |
575 |
590 // Clip must define the invalid area |
576 // Clip must define the invalid area |
591 customItemGraphics.reset(); |
577 customItemGraphics.reset(); |
592 customItemGraphics.setClip(redrawNowX, redrawNowY, redrawNowW, redrawNowH); |
578 customItemGraphics.setClip(redrawNowX, redrawNowY, redrawNowW, redrawNowH); |