import com.tigervnc.rfb.Point;
import com.tigervnc.rfb.Rect;
-class ViewportFrame extends JFrame
+class ViewportFrame extends JFrame implements ComponentListener
{
public ViewportFrame(String name, CConn cc_) {
cc = cc_;
cc.close();
}
});
+ addComponentListener(this);
+ }
+
+ public void componentResized(ComponentEvent e) {
+ if (cc.options.autoScale || cc.options.fixedRatioScale) {
+ if (sp.getSize().width != cc.desktop.scaledWidth ||
+ sp.getSize().height != cc.desktop.scaledHeight) {
+ cc.reconfigureViewport();
+ if (cc.desktop.cursor != null) {
+ cc.setCursor(cc.desktop.cursor.width(),
+ cc.desktop.cursor.height(),
+ cc.desktop.cursor.hotspot,
+ cc.desktop.cursor.data,
+ cc.desktop.cursor.mask);
+ }
+ }
+ }
+ }
+
+ public void componentHidden(ComponentEvent e) {
+ }
+
+ public void componentShown(ComponentEvent e) {
+ }
+
+ public void componentMoved(ComponentEvent e) {
}
public void addChild(DesktopWindow child) {
} else {
setSize(w, h);
}
- setLocation(x, y);
+ if (!cc.options.autoScale && !cc.options.fixedRatioScale)
+ setLocation(x, y);
setBackground(Color.BLACK);
}
desktop.requestFocusInWindow();
}
- private void reconfigureViewport()
+ public void reconfigureViewport()
{
//viewport.setMaxSize(cp.width, cp.height);
boolean pack = true;
- int w = cp.width;
- int h = cp.height;
Dimension dpySize = viewport.getToolkit().getScreenSize();
desktop.setScaledSize();
- if (!options.autoScale && !options.fixedRatioScale) {
- w = (int)java.lang.Math.floor(cp.width*scaleFactor/100);
- h = (int)java.lang.Math.floor(cp.height*scaleFactor/100);
- }
+ int w = desktop.scaledWidth;
+ int h = desktop.scaledHeight;
if (fullScreen) {
viewport.setExtendedState(JFrame.MAXIMIZED_BOTH);
viewport.setGeometry(0, 0, dpySize.width, dpySize.height, false);
viewport.setExtendedState(JFrame.NORMAL);
viewport.setGeometry(x, y, w, h, pack);
}
+ viewport.update(viewport.g);
}
// autoSelectFormatAndEncoding() chooses the format and encoding appropriate
String scaleString = viewer.scalingFactor.getValue();
if (scaleString.equals("Auto")) {
options.autoScale = true;
+ // FIXME: set scaleFactor?
} else if( scaleString.equals("FixedRatio")) {
options.fixedRatioScale = true;
+ // FIXME: set scaleFactor?
} else {
digit = Integer.parseInt(scaleString);
if (digit >= 1 && digit <= 1000) {
viewer.acceptBell.setParam(options.acceptBell.isSelected());
if (options.autoScale) {
viewer.scalingFactor.setParam("Auto");
+ scaleFactor = -1;
+ if (desktop != null) {
+ reconfigureViewport();
+ viewport.update(viewport.g);
+ if (desktop.cursor != null)
+ setCursor(desktop.cursor.width(), desktop.cursor.height(), desktop.cursor.hotspot, desktop.cursor.data, desktop.cursor.mask);
+ }
} else if(options.fixedRatioScale) {
viewer.scalingFactor.setParam("FixedRatio");
+ scaleFactor = -1;
+ if (desktop != null) {
+ reconfigureViewport();
+ viewport.update(viewport.g);
+ if (desktop.cursor != null)
+ setCursor(desktop.cursor.width(), desktop.cursor.height(), desktop.cursor.hotspot, desktop.cursor.data, desktop.cursor.mask);
+ }
} else {
String scaleString =
options.scalingFactor.getSelectedItem().toString();
scaleFactor =
Integer.parseInt(scaleString.substring(0, scaleString.length()-1));
if (oldScaleFactor != scaleFactor && desktop != null) {
- //desktop.setScaledSize();
reconfigureViewport();
viewport.update(viewport.g);
+ if (desktop.cursor != null)
+ setCursor(desktop.cursor.width(), desktop.cursor.height(), desktop.cursor.hotspot, desktop.cursor.data, desktop.cursor.mask);
}
}
if (cp.width != desktop.scaledWidth ||
cp.height != desktop.scaledHeight) {
- int sx = (desktop.scaleWidthRatio == -1)
- ? ev.getX() : (int)java.lang.Math.floor(ev.getX()/desktop.scaleWidthRatio);
- int sy = (desktop.scaleHeightRatio == -1)
- ? ev.getY() : (int)java.lang.Math.floor(ev.getY()/desktop.scaleWidthRatio);
+ int sx = (desktop.scaleWidthRatio == 1.00)
+ ? ev.getX() : (int)Math.floor(ev.getX()/(float)desktop.scaleWidthRatio);
+ int sy = (desktop.scaleHeightRatio == 1.00)
+ ? ev.getY() : (int)Math.floor(ev.getY()/(float)desktop.scaleHeightRatio);
ev.translatePoint(sx - ev.getX(), sy - ev.getY());
writer().writePointerEvent(new Point(ev.getX(),ev.getY()), buttonMask);
} else {
buttonMask = 16;
}
writeModifiers(ev.getModifiers() & ~KeyEvent.ALT_MASK & ~KeyEvent.META_MASK);
- for (int i=0;i<java.lang.Math.abs(clicks);i++) {
+ for (int i=0;i<Math.abs(clicks);i++) {
x = ev.getX();
y = ev.getY();
writer().writePointerEvent(new Point(x, y), buttonMask);
boolean firstUpdate;
boolean pendingUpdate;
- int scaleFactor;
+ int scaleFactor = 100;
static LogWriter vlog = new LogWriter("CConn");
}
-/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
+/* Copyright (C) 2010 D. R. Commander. All Rights Reserved.
+ * Copyright (C) 2009 Paul Donohue. All Rights Reserved.
+ * Copyright (C) 2006 Constantin Kaplinsky. All Rights Reserved.
+ * Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
MemoryImageSource bitmap =
new MemoryImageSource(cursor.width(), cursor.height(), cursor.cm,
cursor.data, 0, cursor.width());
- softCursor =
- tk.createCustomCursor(tk.createImage(bitmap), new java.awt.Point(hotspot.x,hotspot.y), "Cursor");
+ int cw = (int)Math.floor((float)cursor.width() * scaleWidthRatio);
+ int ch = (int)Math.floor((float)cursor.height() * scaleHeightRatio);
+ int hint = java.awt.Image.SCALE_DEFAULT;
+ Image cursorImage = (cw <= 0 || ch <= 0) ? tk.createImage(bitmap) :
+ tk.createImage(bitmap).getScaledInstance(cw,ch,hint);
+ softCursor = (tk.createCustomCursor(cursorImage,
+ new java.awt.Point(hotspot.x,hotspot.y), "Cursor"));
}
if (softCursor != null) {
}
public void setScaledSize() {
- int w = (int)java.lang.Math.floor(cc.cp.width*cc.scaleFactor/100);
- int h = (int)java.lang.Math.floor(cc.cp.height*cc.scaleFactor/100);
- scaledWidth = w;
- scaledHeight = h;
- scaleWidthRatio = ((float)w/(float)cc.cp.width);
- scaleHeightRatio = ((float)h/(float)cc.cp.height);
+ if (!cc.options.autoScale && !cc.options.fixedRatioScale) {
+ scaledWidth = (int)Math.floor((float)cc.cp.width * (float)cc.scaleFactor/100.0);
+ scaledHeight = (int)Math.floor((float)cc.cp.height * (float)cc.scaleFactor/100.0);
+ } else {
+ if (cc.viewport == null) {
+ scaledWidth = cc.cp.width;
+ scaledHeight = cc.cp.height;
+ } else {
+ Dimension availableSize = cc.viewport.sp.getSize();
+ if (availableSize.width == 0 || availableSize.height == 0)
+ availableSize = new Dimension(cc.cp.width, cc.cp.height);
+ if (cc.options.fixedRatioScale) {
+ float widthRatio = (float)availableSize.width / (float)cc.cp.width;
+ float heightRatio = (float)availableSize.height / (float)cc.cp.height;
+ float ratio = Math.min(widthRatio, heightRatio);
+ scaledWidth = (int)Math.floor(cc.cp.width * ratio);
+ scaledHeight = (int)Math.floor(cc.cp.height * ratio);
+ } else {
+ scaledWidth = availableSize.width;
+ scaledHeight = availableSize.height;
+ }
+ }
+ }
+ scaleWidthRatio = (float)((float)scaledWidth / (float)cc.cp.width);
+ scaleHeightRatio = (float)((float)scaledHeight / (float)cc.cp.height);
}
synchronized public void paintComponent(Graphics g) {
acceptBell.addItemListener(this);
JLabel scalingFactorLabel = new JLabel("Scaling Factor");
Object[] scalingFactors = {
- //"50%", "75%", "95%", "100%", "105%",
"Auto", "Fixed Aspect Ratio", "50%", "75%", "95%", "100%", "105%",
"125%", "150%", "175%", "200%", "250%", "300%", "350%", "400%" };
- scalingFactor = new JComboBox(scalingFactors);
+ scalingFactor = new JComboBox(scalingFactors);
scalingFactor.setEditable(true);
scalingFactor.addItemListener(this);
addGBComponent(fullScreen,MiscPanel, 0, 0, 2, 1, 0, 0, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(4,4,0,4));
qualityLevel.setEnabled(noJpeg.isSelected());
defaults.setPref("noJpeg",(noJpeg.isSelected()) ? "on" : "off");
}
+ if (s instanceof JComboBox && (JComboBox)s == scalingFactor) {
+ autoScale = fixedRatioScale = false;
+ if (scalingFactor.getSelectedItem().equals("Auto")) {
+ autoScale = true;
+ } else if (scalingFactor.getSelectedItem().equals("Fixed Aspect Ratio")) {
+ fixedRatioScale = true;
+ }
+ }
if (s instanceof JCheckBox && (JCheckBox)s == sendLocalUsername) {
defaults.setPref("sendLocalUsername",(sendLocalUsername.isSelected()) ? "on" : "off");
}