From 36ce965feb08ab65fa1952c619c4db47cd064a47 Mon Sep 17 00:00:00 2001 From: "giwoong.kim" Date: Fri, 30 Nov 2012 15:59:48 +0900 Subject: [PATCH] skin: set the text on HW key button Since this commit, ImageButton can draw the text on its surface. Signed-off-by: GiWoong Kim --- .../emulator/skin/window/ControlPanel.java | 7 +- .../emulator/skin/window/ImageButton.java | 91 +++++++++++++++---- 2 files changed, 79 insertions(+), 19 deletions(-) diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ControlPanel.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ControlPanel.java index d36df3e3e4..7be89e1b77 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ControlPanel.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ControlPanel.java @@ -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(); } }; diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java index ccb65ccdd9..f7502cb563 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java @@ -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 -- 2.34.1