skin: set the text on HW key button
authorgiwoong.kim <giwoong.kim@samsung.com>
Fri, 30 Nov 2012 06:59:48 +0000 (15:59 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Fri, 30 Nov 2012 06:59:48 +0000 (15:59 +0900)
Since this commit, ImageButton can draw the text
on its surface.

Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/window/ControlPanel.java
tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java

index d36df3e3e45a084bed64fafbf98c55b83240d3bc..7be89e1b772c7bcac1e10aeacde0f4f189d6407c 100644 (file)
@@ -141,7 +141,7 @@ public class ControlPanel extends SkinWindow {
                        for (KeyMapType keyEntry : keyMapList) {
                                ImageButton HWKeyButton = new ImageButton(compositeBase, SWT.NONE,
                                                imageNormal, imageHover, imagePushed);
-                               //HWKeyButton.setText(keyEntry.getEventInfo().getKeyName());
+                               HWKeyButton.setText(keyEntry.getEventInfo().getKeyName());
                                //HWKeyButton.setToolTipText(keyEntry.getTooltip());
                                HWKeyButton.setBackground(colorFrame);
                                HWKeyButton.setLayoutData(new GridData(imageNormal.getImageData().width,
@@ -273,6 +273,11 @@ public class ControlPanel extends SkinWindow {
                                        shell.removeMouseListener(shellMouseListener);
                                }
 
+                               imageNormal.dispose();
+                               imageHover.dispose();
+                               imagePushed.dispose();
+                               colorFrame.dispose();
+
                                frameMaker.freePatches();
                        }
                };
index ccb65ccdd959cf90f3a02f34035a074d68e7b24f..f7502cb563640867f4a474bc85e6fc9a0a3f766d 100644 (file)
@@ -37,18 +37,29 @@ import org.eclipse.swt.events.MouseMoveListener;
 import org.eclipse.swt.events.MouseTrackAdapter;
 import org.eclipse.swt.events.PaintEvent;
 import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.widgets.Canvas;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
 
 public class ImageButton extends Canvas {
+       /* state */
        private int mouse = 0;
        private boolean hit = false;
 
-       /* 0 : normal, 1 : hover, 2 : pushed */
+       /* image - 0 : normal, 1 : hover, 2 : pushed */
        private Image imageButton[];
 
+       private String text;
+       private int textPositionX;
+       private int textPositionY;
+       private static Color white;
+       private static Color gray;
+
        public ImageButton(Composite parent, int style,
                        Image imageNormal, Image imageHover, Image imagePushed) {
                super(parent, style);
@@ -58,33 +69,51 @@ public class ImageButton extends Canvas {
                imageButton[1] = imageHover;
                imageButton[2] = imagePushed;
 
+               this.text = null;
+               textPositionX = imageNormal.getImageData().width / 2;
+               textPositionY = imageNormal.getImageData().height / 2;
+               white = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
+               gray = Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
+
                this.addPaintListener(new PaintListener() {
                        @Override
                        public void paintControl(PaintEvent e) {
                                switch (mouse) {
-                               case 0:
-                                       /* default state */
-                                       if (imageButton[0] == null) {
-                                               e.gc.drawString("Normal", 1, 1);
-                                       } else {
+                               case 0: /* default state */
+                                       if (imageButton[0] != null) {
                                                e.gc.drawImage(imageButton[0], 0, 0);
                                        }
+
+                                       if (text != null) {
+                                               e.gc.setForeground(white);
+                                               e.gc.drawText(text,
+                                                               textPositionX, textPositionY, true);
+                                       }
+
                                        break;
-                               case 1:
-                                       /* mouse over */
-                                       if (imageButton[0] == null) {
-                                               e.gc.drawString("Mouse over", 1, 1);
-                                       } else {
-                                               e.gc.drawImage(imageButton[1], 1, 1);
+                               case 1: /* mouse over */
+                                       if (imageButton[1] != null) {
+                                               e.gc.drawImage(imageButton[1], 0, 0);
                                        }
+
+                                       if (text != null) {
+                                               e.gc.setForeground(white);
+                                               e.gc.drawText(text,
+                                                               textPositionX, textPositionY, true);
+                                       }
+
                                        break;
-                               case 2:
-                                       /* mouse down */
-                                       if (imageButton[0] == null) {
-                                               e.gc.drawString("Hit", 1, 1);
-                                       } else {
-                                               e.gc.drawImage(imageButton[2], 1, 1);
+                               case 2: /* mouse down */
+                                       if (imageButton[2] != null) {
+                                               e.gc.drawImage(imageButton[2], 0, 0);
+                                       }
+
+                                       if (text != null) {
+                                               e.gc.setForeground(gray);
+                                               e.gc.drawText(text,
+                                                               textPositionX, textPositionY, true);
                                        }
+
                                        break;
                                default:
                                        break;
@@ -164,4 +193,30 @@ public class ImageButton extends Canvas {
                });
        }
 
+       public void setText(String text) {
+               if (text == null || text.isEmpty()) {
+                       return;
+               }
+
+               this.text = text;
+
+               GC gc = new GC(this);
+               Point textSize = gc.textExtent(text);
+
+               textPositionX -= textSize.x / 2;
+               if (textPositionX < 0) {
+                       textPositionX = 0;
+               }
+
+               textPositionY -= textSize.y / 2;
+               if (textPositionY < 0) {
+                       textPositionY = 0;
+               }
+
+               gc.dispose();
+       }
+
+       public String getText() {
+               return text;
+       }
 }
\ No newline at end of file