Scale device image to preferred size

Scale the device image to the preferred size of the frame, and
translate the mouse events before sending them to the device.
Added a license header.
Some general cleanup and formatting.