1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009, 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
28 import org.eclipse.swt.widgets.*; |
28 import org.eclipse.swt.widgets.*; |
29 import org.eclipse.swt.widgets.Display; |
29 import org.eclipse.swt.widgets.Display; |
30 import org.eclipse.swt.graphics.*; |
30 import org.eclipse.swt.graphics.*; |
31 import org.eclipse.swt.internal.extension.CompositeExtension; |
31 import org.eclipse.swt.internal.extension.CompositeExtension; |
32 import org.eclipse.swt.internal.qt.graphics.WindowSurface; |
32 import org.eclipse.swt.internal.qt.graphics.WindowSurface; |
|
33 import org.eclipse.swt.internal.extension.MobileShellExtension; |
|
34 import org.eclipse.swt.internal.qt.SymbianWindowVisibilityListener; |
33 |
35 |
34 |
36 |
35 /** |
37 /** |
36 * The abstract <code>Canvas</code> class is designed to handle low-level |
38 * The abstract <code>Canvas</code> class is designed to handle low-level |
37 * graphical operations as well as low-level key and pointer events. Canvas is |
39 * graphical operations as well as low-level key and pointer events. Canvas is |
170 new CanvasShellPaintListener(); |
172 new CanvasShellPaintListener(); |
171 |
173 |
172 private CanvasShellMouseListener mouseListener = |
174 private CanvasShellMouseListener mouseListener = |
173 new CanvasShellMouseListener(); |
175 new CanvasShellMouseListener(); |
174 |
176 |
|
177 private CanvasShellVisibilityListener shellVisibilityListener = |
|
178 new CanvasShellVisibilityListener(); |
|
179 |
175 // Canvas Graphics object passed to paint(Graphics g) |
180 // Canvas Graphics object passed to paint(Graphics g) |
176 private Graphics canvasGraphics; |
181 private Graphics canvasGraphics; |
177 |
182 |
178 // Graphics object for transferring return values |
183 // Graphics object for transferring return values |
179 // from UI thread |
184 // from UI thread |
180 private Graphics tempGraphics; |
185 private Graphics tempGraphics; |
181 |
186 |
182 // Graphics command buffer for this instance |
187 // Graphics command buffer for this instance |
183 Buffer graphicsBuffer; |
188 Buffer graphicsBuffer; |
184 |
189 |
185 //On Screen Keypad |
190 //On Screen Keypad |
186 //private Composite keypadComposite; |
191 //private Composite keypadComposite; |
187 private CanvasKeypad onScreenkeypad; |
192 private CanvasKeypad onScreenkeypad; |
188 private static CanvasKeypad sharedKeypad; |
193 private static CanvasKeypad sharedKeypad; |
189 private int oskHeight; |
194 private int oskHeight; |
315 |
318 |
316 // Make the Shell maximized. On Symbian it's automatically maximized |
319 // Make the Shell maximized. On Symbian it's automatically maximized |
317 // so this has no effect but on other platforms explicit maximizing |
320 // so this has no effect but on other platforms explicit maximizing |
318 // might be needed. |
321 // might be needed. |
319 mShell.setMaximized(true); |
322 mShell.setMaximized(true); |
320 |
323 |
321 return mShell; |
324 return mShell; |
322 } |
325 } |
323 |
326 |
324 /** |
327 /** |
325 * Sets ticker. If ticker is added already to other canvas(es), |
328 * Sets ticker. If ticker is added already to other canvas(es), |
427 setDefaultTapValues(); |
430 setDefaultTapValues(); |
428 } |
431 } |
429 |
432 |
430 canvasComp = super.eswtConstructContent(style); |
433 canvasComp = super.eswtConstructContent(style); |
431 canvasComp.setVisible(false); |
434 canvasComp.setVisible(false); |
432 |
435 |
433 createOnScreenKeypad(); |
436 createOnScreenKeypad(); |
434 |
437 |
435 return canvasComp; |
|
436 } |
|
437 |
|
438 void eswtInitGraphics() { |
|
439 // create graphics buffer |
438 // create graphics buffer |
440 graphicsBuffer = Buffer.createInstance(this, canvasComp); |
439 graphicsBuffer = Buffer.createInstance(this, canvasComp); |
441 } |
440 |
442 |
441 return canvasComp; |
443 /** |
442 } |
444 * Creates OSK(OnScreenKeypad), shared Keypad will be created for Canvas, |
443 |
|
444 /** |
|
445 * Creates OSK(OnScreenKeypad), shared Keypad will be created for Canvas, |
445 * seperate OSK will be created for each GameCanvas. |
446 * seperate OSK will be created for each GameCanvas. |
446 */ |
447 */ |
447 CanvasKeypad createOnScreenKeypad() |
448 CanvasKeypad createOnScreenKeypad() |
448 { |
449 { |
449 // Read the on screen keypad settings from the jad attribute |
450 // Read the on screen keypad settings from the jad attribute |
486 shellArea.width, shellArea.height - tickerHeight - oskHeight); |
486 shellArea.width, shellArea.height - tickerHeight - oskHeight); |
487 |
487 |
488 canvasComp.setFocus(); |
488 canvasComp.setFocus(); |
489 return canvasComp.getClientArea(); |
489 return canvasComp.getClientArea(); |
490 } |
490 } |
491 |
|
492 |
491 |
493 /* (non-Javadoc) |
492 /* (non-Javadoc) |
494 * @see Displayable#eswtHandleShowCurrentEvent() |
493 * @see Displayable#eswtHandleShowCurrentEvent() |
495 */ |
494 */ |
496 void eswtHandleShowCurrentEvent() |
495 void eswtHandleShowCurrentEvent() |
514 addCommands(); |
513 addCommands(); |
515 super.eswtHandleShowCurrentEvent(); |
514 super.eswtHandleShowCurrentEvent(); |
516 getContentComp().addPaintListener(paintListener); |
515 getContentComp().addPaintListener(paintListener); |
517 getContentComp().addMouseListener(mouseListener); |
516 getContentComp().addMouseListener(mouseListener); |
518 getContentComp().addMouseMoveListener(mouseListener); |
517 getContentComp().addMouseMoveListener(mouseListener); |
|
518 ((MobileShellExtension)getShell()).addSymbianWindowVisibilityListener(shellVisibilityListener); |
519 } |
519 } |
520 |
520 |
521 /* (non-Javadoc) |
521 /* (non-Javadoc) |
522 * @see Displayable#eswtHandleHideCurrentEvent() |
522 * @see Displayable#eswtHandleHideCurrentEvent() |
523 */ |
523 */ |
532 removeCommands(); |
532 removeCommands(); |
533 super.eswtHandleHideCurrentEvent(); |
533 super.eswtHandleHideCurrentEvent(); |
534 getContentComp().removePaintListener(paintListener); |
534 getContentComp().removePaintListener(paintListener); |
535 getContentComp().removeMouseListener(mouseListener); |
535 getContentComp().removeMouseListener(mouseListener); |
536 getContentComp().removeMouseMoveListener(mouseListener); |
536 getContentComp().removeMouseMoveListener(mouseListener); |
|
537 ((MobileShellExtension)getShell()).removeSymbianWindowVisibilityListener(shellVisibilityListener); |
537 } |
538 } |
538 |
539 |
539 /** |
540 /** |
540 * eSWT callback to add a Command. |
541 * eSWT callback to add a Command. |
541 */ |
542 */ |
649 { |
650 { |
650 tickerLabel.pack(); |
651 tickerLabel.pack(); |
651 tickerLabel.setLocation(Integer.MIN_VALUE, 0); |
652 tickerLabel.setLocation(Integer.MIN_VALUE, 0); |
652 } |
653 } |
653 |
654 |
654 if(isMode(CURRENTLY_VISIBLE)) |
655 if(isMode(CURRENTLY_VISIBLE)) |
655 { |
656 { |
656 tickerLabel.setVisible(!isMode(FULLSCREEN_MODE)); |
657 tickerLabel.setVisible(!isMode(FULLSCREEN_MODE)); |
657 } |
658 } |
658 } |
659 } |
659 |
660 |
660 if(isMode(CURRENTLY_VISIBLE)) |
661 if(isMode(CURRENTLY_VISIBLE)) |
661 { |
662 { |
662 ((MobileShell)mShell).setFullScreenMode(isMode(FULLSCREEN_MODE)); |
663 ((MobileShell)mShell).setFullScreenMode(isMode(FULLSCREEN_MODE)); |
887 final void initGameCanvas(boolean suppressKeys) |
887 final void initGameCanvas(boolean suppressKeys) |
888 { |
888 { |
889 setMode(SUPPRESS_GAMEKEYS, suppressKeys); |
889 setMode(SUPPRESS_GAMEKEYS, suppressKeys); |
890 } |
890 } |
891 |
891 |
892 |
|
893 /** |
892 /** |
894 * Gets composite that contains Canvas content. |
893 * Gets composite that contains Canvas content. |
895 * |
894 * |
896 * @return Composite. |
895 * @return Composite. |
897 */ |
896 */ |
898 Composite getContentComp() |
897 Composite getContentComp() |
899 { |
898 { |
900 return canvasComp; |
899 return canvasComp; |
901 } |
900 } |
902 |
901 |
903 |
|
904 /** |
902 /** |
905 * Get game canvas frame buffer graphics. |
903 * Get game canvas frame buffer graphics. |
906 */ |
904 */ |
907 final Graphics getGameBufferGraphics() |
905 final Graphics getGameBufferGraphics() |
908 { |
906 { |
909 tempGraphics = null; |
907 tempGraphics = null; |
910 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
908 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
911 { |
909 { |
912 public void run() |
910 public void run() |
913 { |
911 { |
914 tempGraphics = graphicsBuffer.getGraphics(); |
912 tempGraphics = graphicsBuffer.getGraphics(); |
915 } |
913 } |
956 * @param height |
954 * @param height |
957 */ |
955 */ |
958 void flushGameBuffer(final int x, final int y, final int width, |
956 void flushGameBuffer(final int x, final int y, final int width, |
959 final int height) |
957 final int height) |
960 { |
958 { |
961 // This is serialized with the |
959 // This is serialized with the |
962 // paint callback processing |
960 // paint callback processing |
963 synchronized(flushLock) |
961 synchronized(flushLock) |
964 { |
962 { |
965 synchronized(graphicsBuffer) |
963 synchronized(graphicsBuffer) |
966 { |
964 { |
967 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
965 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
968 { |
966 { |
969 public void run() |
967 public void run() |
970 { |
968 { |
971 graphicsBuffer.sync(); |
969 graphicsBuffer.sync(); |
972 graphicsBuffer.blitToDisplay(null, getContentComp()); |
970 graphicsBuffer.blitToDisplay(null, getContentComp()); |
973 } |
971 } |
974 }); |
972 }); |
975 } |
973 } |
976 } |
974 } |
977 } |
975 } |
978 |
976 |
979 /** |
977 /** |
980 * Called by ShellListener when shell gets activated. |
978 * Called by ShellListener when shell gets activated. |
981 */ |
979 */ |
982 void handleShellActivatedEvent() |
980 void handleShellActivatedEvent() |
1010 */ |
1008 */ |
1011 void eswtHandleResizeEvent(int width, int height) |
1009 void eswtHandleResizeEvent(int width, int height) |
1012 { |
1010 { |
1013 super.eswtHandleResizeEvent(width, height); |
1011 super.eswtHandleResizeEvent(width, height); |
1014 // update new bounds to graphicsBuffer |
1012 // update new bounds to graphicsBuffer |
1015 // this call must not be synchronized as we |
1013 // this call must not be synchronized as we |
1016 // cannot use locking in UI thread |
1014 // cannot use locking in UI thread |
1017 graphicsBuffer.setControlBounds(getContentComp()); |
1015 graphicsBuffer.setControlBounds(getContentComp()); |
1018 synchronized(cleanupLock) |
1016 synchronized(cleanupLock) |
1019 { |
1017 { |
1020 setMode(CLEANUP_NEEDED, true); |
1018 setMode(CLEANUP_NEEDED, true); |
1063 class CanvasShellPaintListener implements PaintListener |
1061 class CanvasShellPaintListener implements PaintListener |
1064 { |
1062 { |
1065 public void paintControl(PaintEvent pe) |
1063 public void paintControl(PaintEvent pe) |
1066 { |
1064 { |
1067 // Check if we got here from buffer flush |
1065 // Check if we got here from buffer flush |
1068 if(graphicsBuffer.isPaintingActive()) |
1066 if(graphicsBuffer.isPaintingActive()) |
1069 { |
1067 { |
1070 graphicsBuffer.blitToDisplay(pe.gc.getGCData().internalGc, null); |
1068 graphicsBuffer.blitToDisplay(pe.gc.getGCData().internalGc, null); |
1071 } |
1069 } |
1072 else |
1070 else |
1073 { |
1071 { |
1140 { |
1138 { |
1141 synchronized(flushLock) |
1139 synchronized(flushLock) |
1142 { |
1140 { |
1143 // It's possible that this Canvas is sent to background |
1141 // It's possible that this Canvas is sent to background |
1144 // right after the visibility is checked here, however |
1142 // right after the visibility is checked here, however |
1145 // it is okay as in such case we just do one extra paint |
1143 // it is okay as in such case we just do one extra paint |
1146 // callback. The visibility change cannot be synchronized with |
1144 // callback. The visibility change cannot be synchronized with |
1147 // this method, since it would expose implementation to deadlock |
1145 // this method, since it would expose implementation to deadlock |
1148 if(!isMode(CURRENTLY_VISIBLE)) |
1146 if(!isMode(CURRENTLY_VISIBLE)) |
1149 { |
1147 { |
1150 return; |
1148 return; |
1151 } |
1149 } |
1152 |
1150 |
1153 // Decide the area going to be painted by the callback. |
1151 // Decide the area going to be painted by the callback. |
1154 final int redrawNowX; |
1152 final int redrawNowX; |
1155 final int redrawNowY; |
1153 final int redrawNowY; |
1156 final int redrawNowW; |
1154 final int redrawNowW; |
1157 final int redrawNowH; |
1155 final int redrawNowH; |