Fixed problem where controllers placed outside of the window didn't work - thanks to https://github.com/sojamo/controlp5/issues/26

This commit is contained in:
Sandy Noble 2015-10-25 01:29:40 +01:00
parent e84d027d43
commit 70eaae51bd
3 changed files with 42 additions and 117 deletions

View File

@ -24,7 +24,7 @@
sandy.noble@gmail.com
http://www.polargraph.co.uk/
http://code.google.com/p/polargraph/
https://github.com/euphy/polargraphcontroller
*/
class Panel
{
@ -120,9 +120,9 @@ class Panel
public void draw()
{
//stroke(outlineColour);
//strokeWeight(2);
//rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight());
// stroke(outlineColour);
// strokeWeight(2);
// rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight());
drawControls();
}
@ -200,8 +200,9 @@ class Panel
}
}
void setHeight(float h)
void setSizeByHeight(float h)
{
// println("Setting size for " + this.getName());
if (this.isResizable())
{
if (h <= getMinimumHeight())
@ -211,23 +212,15 @@ class Panel
setControlPositions(buildControlPositionsForPanel(this));
float left = 0.0;
String controlName = "";
for (String key : getControlPositions().keySet())
{
PVector pos = getControlPositions().get(key);
if (pos.x >= left)
if (pos.x > left)
{
left = pos.x;
controlName = key;
}
}
Map<String, PVector> map = getControlSizes();
// PVector size = getControlSizes().get(controlName);
// println("size: " + size);
float right = left + DEFAULT_CONTROL_SIZE.x;
this.getOutline().setWidth(right);
}
}

View File

@ -95,9 +95,9 @@ Map<String, Panel> buildPanels() {
Map<String, Panel> panels = new HashMap<String, Panel>();
float panelHeight = frame.getHeight() - getMainPanelPosition().y - (DEFAULT_CONTROL_SIZE.y*3);
Rectangle panelOutline = new Rectangle(getMainPanelPosition(),
Rectangle panelOutlineInput = new Rectangle(getMainPanelPosition(),
new PVector((DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x)*2, panelHeight));
Panel inputPanel = new Panel(PANEL_NAME_INPUT, panelOutline);
Panel inputPanel = new Panel(PANEL_NAME_INPUT, panelOutlineInput);
inputPanel.setResizable(true);
inputPanel.setOutlineColour(color(200, 200, 200));
// get controls
@ -107,7 +107,9 @@ Map<String, Panel> buildPanels() {
inputPanel.setControlSizes(buildControlSizesForPanel(inputPanel));
panels.put(PANEL_NAME_INPUT, inputPanel);
Panel rovingPanel = new Panel(PANEL_NAME_ROVING, panelOutline);
Rectangle panelOutlineRoving = new Rectangle(getMainPanelPosition(),
new PVector((DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x)*2, panelHeight));
Panel rovingPanel = new Panel(PANEL_NAME_ROVING, panelOutlineRoving);
rovingPanel.setOutlineColour(color(100,200,200));
// get controls
rovingPanel.setResizable(true);
@ -117,7 +119,9 @@ Map<String, Panel> buildPanels() {
rovingPanel.setControlSizes(buildControlSizesForPanel(rovingPanel));
panels.put(PANEL_NAME_ROVING, rovingPanel);
Panel tracePanel = new Panel(PANEL_NAME_TRACE, panelOutline);
Rectangle panelOutlineTrace = new Rectangle(getMainPanelPosition(),
new PVector((DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x)*2, panelHeight));
Panel tracePanel = new Panel(PANEL_NAME_TRACE, panelOutlineTrace);
tracePanel.setOutlineColour(color(200,255,200));
// get controls
tracePanel.setResizable(true);
@ -127,7 +131,9 @@ Map<String, Panel> buildPanels() {
tracePanel.setControlSizes(buildControlSizesForPanel(tracePanel));
panels.put(PANEL_NAME_TRACE, tracePanel);
Panel detailsPanel = new Panel(PANEL_NAME_DETAILS, panelOutline);
Rectangle panelOutlineDetails = new Rectangle(getMainPanelPosition(),
new PVector((DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x)*2, panelHeight));
Panel detailsPanel = new Panel(PANEL_NAME_DETAILS, panelOutlineDetails);
detailsPanel.setOutlineColour(color(200, 200, 255));
// get controls
detailsPanel.setResizable(true);
@ -137,7 +143,9 @@ Map<String, Panel> buildPanels() {
detailsPanel.setControlSizes(buildControlSizesForPanel(detailsPanel));
panels.put(PANEL_NAME_DETAILS, detailsPanel);
Panel queuePanel = new Panel(PANEL_NAME_QUEUE, panelOutline);
Rectangle panelOutlineQueue = new Rectangle(getMainPanelPosition(),
new PVector((DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x)*2, panelHeight));
Panel queuePanel = new Panel(PANEL_NAME_QUEUE, panelOutlineQueue);
queuePanel.setOutlineColour(color(200, 200, 50));
// get controls
queuePanel.setResizable(true);
@ -147,10 +155,10 @@ Map<String, Panel> buildPanels() {
queuePanel.setControlSizes(buildControlSizesForPanel(queuePanel));
panels.put(PANEL_NAME_QUEUE, queuePanel);
panelOutline = new Rectangle(
Rectangle panelOutlineGeneral = new Rectangle(
new PVector(getMainPanelPosition().x, getMainPanelPosition().y-((DEFAULT_CONTROL_SIZE.y+CONTROL_SPACING.y)*2)),
new PVector((DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x)*2, (DEFAULT_CONTROL_SIZE.y+CONTROL_SPACING.y)*2));
Panel generalPanel = new Panel(PANEL_NAME_GENERAL, panelOutline);
Panel generalPanel = new Panel(PANEL_NAME_GENERAL, panelOutlineGeneral);
generalPanel.setResizable(false);
generalPanel.setOutlineColour(color(200, 50, 200));
// get controls
@ -568,6 +576,7 @@ Map<String, PVector> buildControlPositionsForPanel(Panel panel)
int row = 0;
for (Controller controller : panel.getControls())
{
if (controller.getName().startsWith("minitoggle_"))
{
PVector p = new PVector(col*(DEFAULT_CONTROL_SIZE.x+CONTROL_SPACING.x), row*(DEFAULT_CONTROL_SIZE.y+CONTROL_SPACING.y));

View File

@ -528,6 +528,7 @@ static PApplet parentPapplet = null;
void setup()
{
size(windowWidth, windowHeight);
println("Running polargraph controller");
frame.setResizable(true);
initLogging();
@ -545,11 +546,7 @@ void setup()
e.printStackTrace();
}
loadFromPropertiesFile();
// size(400, 400, JAVA2D );
// surface.setResizable(true);
// surface.setSize(windowWidth, windowHeight);
size(windowWidth, windowHeight, JAVA2D);
this.cp5 = new ControlP5(this);
initTabs();
@ -635,57 +632,50 @@ void preLoadCommandQueue()
void windowResized()
{
println("Window resized.");
windowWidth = frame.getWidth();
windowHeight = frame.getHeight();
for (String key : getPanels().keySet())
{
println("Panel: " + key);
Panel p = getPanels().get(key);
p.setHeight(frame.getHeight() - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2));
p.setSizeByHeight(frame.getHeight() - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2));
}
cp5.setGraphics(this,0,0);
}
void draw()
{
if (getCurrentTab() == TAB_NAME_INPUT)
{
if (getCurrentTab() == TAB_NAME_INPUT) {
drawImagePage();
}
else if (getCurrentTab() == TAB_NAME_QUEUE)
{
else if (getCurrentTab() == TAB_NAME_QUEUE) {
drawCommandQueuePage();
}
else if (getCurrentTab() == TAB_NAME_DETAILS)
{
else if (getCurrentTab() == TAB_NAME_DETAILS) {
drawDetailsPage();
}
else if (getCurrentTab() == TAB_NAME_ROVING)
{
else if (getCurrentTab() == TAB_NAME_ROVING) {
drawRovingPage();
}
else if (getCurrentTab() == TAB_NAME_TRACE)
{
else if (getCurrentTab() == TAB_NAME_TRACE) {
drawTracePage();
}
else
{
else {
drawDetailsPage();
}
if (isShowingSummaryOverlay())
{
if (isShowingSummaryOverlay()) {
drawSummaryOverlay();
}
if (isShowingDialogBox())
{
if (isShowingDialogBox()) {
drawDialogBox();
}
if (drawbotReady)
{
if (drawbotReady) {
dispatchCommandQueue();
}
}
String getCurrentTab()
@ -1640,10 +1630,6 @@ void keyPressed()
getDisplayMachine().getOffset().x = getDisplayMachine().getOffset().x - 10;
else if (checkKey(KeyEvent.VK_ESCAPE))
key = 0;
// if (checkKey(CONTROL) && checkKey(KeyEvent.VK_G))
// println("CTRL+G");
else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_G))
{
Toggle t = (Toggle) getAllControls().get(MODE_SHOW_GUIDES);
@ -1677,60 +1663,6 @@ void keyPressed()
{
displayingInfoTextOnInputPage = (displayingInfoTextOnInputPage) ? false : true;
}
// else if (key == '+')
// {
// currentMachineMaxSpeed = currentMachineMaxSpeed+MACHINE_MAXSPEED_INCREMENT;
// currentMachineMaxSpeed = Math.round(currentMachineMaxSpeed*100.0)/100.0;
// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
// DecimalFormat df = (DecimalFormat)nf;
// df.applyPattern("###.##");
// addToRealtimeCommandQueue(CMD_SETMOTORSPEED+df.format(currentMachineMaxSpeed)+",END");
// }
// else if (key == '-')
// {
// currentMachineMaxSpeed = currentMachineMaxSpeed+(0.0 - MACHINE_MAXSPEED_INCREMENT);
// currentMachineMaxSpeed = Math.round(currentMachineMaxSpeed*100.0)/100.0;
// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
// DecimalFormat df = (DecimalFormat)nf;
// df.applyPattern("###.##");
// addToRealtimeCommandQueue(CMD_SETMOTORSPEED+df.format(currentMachineMaxSpeed)+",END");
// }
// else if (key == '*')
// {
// currentMachineAccel = currentMachineAccel+MACHINE_ACCEL_INCREMENT;
// currentMachineAccel = Math.round(currentMachineAccel*100.0)/100.0;
// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
// DecimalFormat df = (DecimalFormat)nf;
// df.applyPattern("###.##");
// addToRealtimeCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",END");
// }
// else if (key == '/')
// {
// currentMachineAccel = currentMachineAccel+(0.0 - MACHINE_ACCEL_INCREMENT);
// currentMachineAccel = Math.round(currentMachineAccel*100.0)/100.0;
// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
// DecimalFormat df = (DecimalFormat)nf;
// df.applyPattern("###.##");
// addToRealtimeCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",END");
// }
// else if (key == ']')
// {
// currentPenWidth = currentPenWidth+penIncrement;
// currentPenWidth = Math.round(currentPenWidth*100.0)/100.0;
// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
// DecimalFormat df = (DecimalFormat)nf;
// df.applyPattern("###.##");
// addToRealtimeCommandQueue(CMD_CHANGEPENWIDTH+df.format(currentPenWidth)+",END");
// }
// else if (key == '[')
// {
// currentPenWidth = currentPenWidth-penIncrement;
// currentPenWidth = Math.round(currentPenWidth*100.0)/100.0;
// NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
// DecimalFormat df = (DecimalFormat)nf;
// df.applyPattern("###.##");
// addToRealtimeCommandQueue(CMD_CHANGEPENWIDTH+df.format(currentPenWidth)+",END");
// }
else if (key == '#' )
{
addToRealtimeCommandQueue(CMD_PENUP+"END");
@ -1748,15 +1680,6 @@ void keyPressed()
{
this.maxSegmentLength++;
}
// else if (key == ',')
// {
// if (this.minimumVectorLineLength > 0)
// this.minimumVectorLineLength--;
// }
// else if (key == '.')
// {
// this.minimumVectorLineLength++;
// }
}
void mouseDragged()
{
@ -1782,7 +1705,7 @@ void mouseClicked()
{
if (mouseOverPanel())
{ // changing mode
// panelClicked();
}
else
{