Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Issue #6: Support smaller displays such as the PiTFT #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;

public interface IPiPlugUITheme {

Expand Down Expand Up @@ -54,4 +55,43 @@ public interface IPiPlugUITheme {
* @return the font.
*/
public Font getSubtitleFont();

/**
* Returns a layout margin to use in the application selection section of
* the dashboard.
*
* @return the margin width and height
*/
public int getMargin();

/**
* Returns a layout spacing to use in the application selection section of
* the dashboard.
*
* @return the spacing width and height
*/
public int getSpacing();

/**
* Returns the maximum number of columns to use for the application
* selection section of the dashboard.
*
* @return the maximum number of columns
*/
public int getMaximumColumns();

/**
* Returns the image to use in the quit button displayed in the dashboard.
*
* @return the quit button image
*/
public Image getQuitIconImage();

/**
* Returns the size to use for application icons in the dashboard.
*
* @return the application icon size
*/
public Point getAppIconSize();

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added com.genuitec.piplug.ui/images/icon-quit12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added com.genuitec.piplug.ui/images/icon-quit24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,28 @@ public Object start(IApplicationContext context) throws Exception {
Display display = new Display();
Rectangle bounds = display.getBounds();
final Shell shell = new Shell(display, SWT.NO_TRIM);
int width = bounds.width;
int height = bounds.height;
String[] arguments = (String[]) context.getArguments().get(
"application.args");
for (int i = 0; i < arguments.length; i++) {
String string = arguments[i];
if (string.equals("-width")) {
width = Integer.valueOf(arguments[i + 1]);
}
if (string.equals("-height")) {
height = Integer.valueOf(arguments[i + 1]);
}
}
shell.setBounds(0, 0, width, height);
shell.setText("PiPlug: Plug in Apps to your Pi");
IPiPlugUITheme theme = new PiPlugUITheme(shell);
IPiPlugUITheme theme = null;
if (shell.getSize().x == 320) {
theme = new QVGAPiPlugUITheme(shell);
} else {
theme = new PiPlugUITheme(shell);
}
PiPlugServices services = new PiPlugServices(theme);
shell.setBounds(0, 0, bounds.width, bounds.height);
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = layout.marginHeight = 0;
shell.setLayout(layout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
Expand Down Expand Up @@ -88,22 +90,25 @@ public PiPlugDashboardComposite(PiPlugAppContainer container,
this.container = container;

IPiPlugUITheme theme = container.getTheme();

// Create the logo section
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = 48;
layout.marginHeight = 48;
layout.marginWidth = theme.getMargin();
layout.marginHeight = theme.getMargin();
setLayout(layout);
setBackground(theme.getBackgroundColor());
Label label = new Label(this, SWT.CENTER);
label.setImage(theme.getHeaderLogoImage());
label.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false));
label.setBackground(theme.getBackgroundColor());

// Create the buttons section
buttonsArea = new Composite(this, SWT.NONE);
buttonsArea.setBackground(theme.getBackgroundColor());
buttonsAreaLayout = new GridLayout(1, false);
buttonsAreaLayout.marginWidth = buttonsAreaLayout.marginHeight = 0;
buttonsAreaLayout.horizontalSpacing = 40;
buttonsAreaLayout.verticalSpacing = 40;
buttonsAreaLayout.horizontalSpacing = theme.getSpacing();
buttonsAreaLayout.verticalSpacing = theme.getSpacing();
buttonsArea.setLayout(buttonsAreaLayout);
buttonsAreaGD = new GridData(SWT.CENTER, SWT.CENTER, true, true);
buttonsArea.setLayoutData(buttonsAreaGD);
Expand All @@ -115,39 +120,30 @@ public PiPlugDashboardComposite(PiPlugAppContainer container,
next.getKey());
sortApps();

// Create the buttons section
Label quit = new Label(this, SWT.NONE);
GridData gd = new GridData(SWT.RIGHT, SWT.BOTTOM, true, false);
gd.widthHint = 48;
gd.heightHint = 48;
gd.widthHint = theme.getMargin();
gd.heightHint = theme.getMargin();
quit.setLayoutData(gd);
quit.setImage(PiPlugUIActivator.loadImage("images/icon-quit48.png"));
quit.setImage(theme.getQuitIconImage());
quit.addMouseListener(new CloseShellListener());
quit.setBackground(theme.getBackgroundColor());
}

private boolean updateButtonsLayout(
Map<BundleDescriptor, IPiPlugApplication> applications) {
int maxColumns = getMaximumColumns();
IPiPlugUITheme theme = container.getTheme();
int maxColumns = theme.getMaximumColumns();
int newColumns = Math.min(maxColumns, applications.size());
if (newColumns == buttonsAreaLayout.numColumns)
return false;
buttonsAreaLayout.numColumns = newColumns;
buttonsAreaGD.widthHint = (newColumns * 256) + ((newColumns - 1) * 40);
buttonsAreaGD.widthHint = (newColumns * theme.getAppIconSize().x)
+ ((newColumns - 1) * theme.getSpacing());
return true;
}

private int getMaximumColumns() {
int maxColumns;
int shellWidth = getShell().getBounds().width;
if (shellWidth > 1800)
maxColumns = 5;
else if (shellWidth > 1200)
maxColumns = 4;
else
maxColumns = 3;
return maxColumns;
}

private void sortApps() {
List<Control> children = Arrays.asList(buttonsArea.getChildren());
if (children.isEmpty())
Expand Down Expand Up @@ -221,6 +217,7 @@ public void run() {
private Composite child;
private BundleDescriptor descriptor;
private Label button;
private Image icon;

public PiPlugAppHandle(Composite parent, IPiPlugApplication app,
IPiPlugUITheme theme, BundleDescriptor descriptor) {
Expand All @@ -238,32 +235,37 @@ public IPiPlugApplication getApp() {
private void createControls(IPiPlugUITheme theme) {
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = layout.marginHeight = 0;
layout.verticalSpacing = 10;
layout.verticalSpacing = theme.getSpacing();
setLayout(layout);
button = new Label(this, SWT.PUSH);
button.setBackground(theme.getBackgroundColor());
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.heightHint = 256;
gd.widthHint = 166;
gd.heightHint = theme.getAppIconSize().x;
gd.widthHint = theme.getAppIconSize().y;
button.setLayoutData(gd);
button.addMouseListener(this);
label = new Label(this, SWT.CENTER);
label.setFont(theme.getTitleFont());
label.setForeground(theme.getTitleColor());
label.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
label.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true,
false));
label.addMouseListener(this);
label.setBackground(theme.getBackgroundColor());
addMouseListener(this);
gd = new GridData(SWT.FILL, SWT.FILL);
gd.widthHint = 256;
gd.heightHint = 206;
gd.widthHint = theme.getAppIconSize().x;
gd.heightHint = theme.getAppIconSize().y + 30;
setLayoutData(gd);
this.setBackground(theme.getBackgroundColor());
ImageData original = app.getBranding().getImage().getImageData();
ImageData scaled = original.scaledTo(theme.getAppIconSize().x,
theme.getAppIconSize().y);
icon = new Image(container.getDisplay(), scaled);
updateAppBranding();
}

private void updateAppBranding() {
button.setImage(app.getBranding().getImage());
button.setImage(icon);
label.setText(app.getBranding().getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.genuitec.piplug.api.IPiPlugUITheme;

public class PiPlugUITheme implements IPiPlugUITheme {

private Color backgroundColor;
private Font titleFont, subtitleFont;
private Color titleColor, subtitleColor;
protected Color backgroundColor;
protected Font titleFont, subtitleFont;
protected Color titleColor, subtitleColor;
protected Point screenSize;
protected Point appIconSize;

public PiPlugUITheme(Shell shell) {
backgroundColor = new Color(Display.getDefault(), 0, 0, 0);
Expand All @@ -25,6 +28,40 @@ public PiPlugUITheme(Shell shell) {
subtitleFont = new Font(Display.getDefault(), fontBase.getName(),
fontBase.getHeight() + 5, SWT.NONE);
subtitleColor = new Color(Display.getDefault(), 160, 160, 160);
screenSize = shell.getSize();
appIconSize = new Point(256, 166);
}

@Override
public Point getAppIconSize() {
return appIconSize;
}

@Override
public Color getBackgroundColor() {
return backgroundColor;
}

@Override
public Image getHeaderLogoImage() {
return PiPlugUIActivator.loadImage("images/PiPlug-wText-50h.png");
}

@Override
public int getMargin() {
return 48;
}

@Override
public int getMaximumColumns() {
int shellWidth = screenSize.x;
int iconWidth = appIconSize.x;
return shellWidth / iconWidth;
}

@Override
public Image getQuitIconImage() {
return PiPlugUIActivator.loadImage("images/icon-quit48.png");
}

@Override
Expand All @@ -39,32 +76,28 @@ public Image[] getShellImages() {
}

@Override
public Image getHeaderLogoImage() {
return PiPlugUIActivator.loadImage("images/PiPlug-wText-50h.png");
public int getSpacing() {
return 40;
}

@Override
public Color getBackgroundColor() {
return backgroundColor;
public Color getSubtitleColor() {
return subtitleColor;
}

@Override
public Color getTitleColor() {
return titleColor;
public Font getSubtitleFont() {
return subtitleFont;
}

@Override
public Color getSubtitleColor() {
return subtitleColor;
public Color getTitleColor() {
return titleColor;
}

@Override
public Font getTitleFont() {
return titleFont;
}

@Override
public Font getSubtitleFont() {
return subtitleFont;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.genuitec.piplug.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.genuitec.piplug.api.IPiPlugUITheme;

/**
* A PiPlug theme for supporting quarter size VGA screens (320x240 pixels).
*
* @author Torkild U. Resheim
*/
public class QVGAPiPlugUITheme extends PiPlugUITheme implements IPiPlugUITheme {

public QVGAPiPlugUITheme(Shell shell) {
super(shell);
appIconSize = new Point(98, 48);
FontData fontBase = shell.getFont().getFontData()[0];
titleFont = new Font(Display.getDefault(), fontBase.getName(),
fontBase.getHeight() + 2, SWT.NONE);
subtitleFont = new Font(Display.getDefault(), fontBase.getName(),
fontBase.getHeight() + 1, SWT.NONE);
}

@Override
public Image getHeaderLogoImage() {
return PiPlugUIActivator.loadImage("images/PiPlug-wText-25h.png");
}

@Override
public int getMargin() {
return 8;
}

@Override
public int getMaximumColumns() {
return 3;
}

@Override
public Image getQuitIconImage() {
return PiPlugUIActivator.loadImage("images/icon-quit48.png");
}

@Override
public int getSpacing() {
return 8;
}

}