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

View File

@ -95,9 +95,9 @@ Map<String, Panel> buildPanels() {
Map<String, Panel> panels = new HashMap<String, Panel>(); Map<String, Panel> panels = new HashMap<String, Panel>();
float panelHeight = frame.getHeight() - getMainPanelPosition().y - (DEFAULT_CONTROL_SIZE.y*3); 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)); 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.setResizable(true);
inputPanel.setOutlineColour(color(200, 200, 200)); inputPanel.setOutlineColour(color(200, 200, 200));
// get controls // get controls
@ -107,7 +107,9 @@ Map<String, Panel> buildPanels() {
inputPanel.setControlSizes(buildControlSizesForPanel(inputPanel)); inputPanel.setControlSizes(buildControlSizesForPanel(inputPanel));
panels.put(PANEL_NAME_INPUT, 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)); rovingPanel.setOutlineColour(color(100,200,200));
// get controls // get controls
rovingPanel.setResizable(true); rovingPanel.setResizable(true);
@ -117,7 +119,9 @@ Map<String, Panel> buildPanels() {
rovingPanel.setControlSizes(buildControlSizesForPanel(rovingPanel)); rovingPanel.setControlSizes(buildControlSizesForPanel(rovingPanel));
panels.put(PANEL_NAME_ROVING, 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)); tracePanel.setOutlineColour(color(200,255,200));
// get controls // get controls
tracePanel.setResizable(true); tracePanel.setResizable(true);
@ -127,7 +131,9 @@ Map<String, Panel> buildPanels() {
tracePanel.setControlSizes(buildControlSizesForPanel(tracePanel)); tracePanel.setControlSizes(buildControlSizesForPanel(tracePanel));
panels.put(PANEL_NAME_TRACE, 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)); detailsPanel.setOutlineColour(color(200, 200, 255));
// get controls // get controls
detailsPanel.setResizable(true); detailsPanel.setResizable(true);
@ -137,7 +143,9 @@ Map<String, Panel> buildPanels() {
detailsPanel.setControlSizes(buildControlSizesForPanel(detailsPanel)); detailsPanel.setControlSizes(buildControlSizesForPanel(detailsPanel));
panels.put(PANEL_NAME_DETAILS, 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)); queuePanel.setOutlineColour(color(200, 200, 50));
// get controls // get controls
queuePanel.setResizable(true); queuePanel.setResizable(true);
@ -147,10 +155,10 @@ Map<String, Panel> buildPanels() {
queuePanel.setControlSizes(buildControlSizesForPanel(queuePanel)); queuePanel.setControlSizes(buildControlSizesForPanel(queuePanel));
panels.put(PANEL_NAME_QUEUE, 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(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)); 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.setResizable(false);
generalPanel.setOutlineColour(color(200, 50, 200)); generalPanel.setOutlineColour(color(200, 50, 200));
// get controls // get controls
@ -568,6 +576,7 @@ Map<String, PVector> buildControlPositionsForPanel(Panel panel)
int row = 0; int row = 0;
for (Controller controller : panel.getControls()) for (Controller controller : panel.getControls())
{ {
if (controller.getName().startsWith("minitoggle_")) 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)); 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() void setup()
{ {
size(windowWidth, windowHeight);
println("Running polargraph controller"); println("Running polargraph controller");
frame.setResizable(true); frame.setResizable(true);
initLogging(); initLogging();
@ -546,10 +547,6 @@ void setup()
} }
loadFromPropertiesFile(); loadFromPropertiesFile();
// size(400, 400, JAVA2D );
// surface.setResizable(true);
// surface.setSize(windowWidth, windowHeight);
size(windowWidth, windowHeight, JAVA2D);
this.cp5 = new ControlP5(this); this.cp5 = new ControlP5(this);
initTabs(); initTabs();
@ -635,57 +632,50 @@ void preLoadCommandQueue()
void windowResized() void windowResized()
{ {
println("Window resized.");
windowWidth = frame.getWidth(); windowWidth = frame.getWidth();
windowHeight = frame.getHeight(); windowHeight = frame.getHeight();
for (String key : getPanels().keySet()) for (String key : getPanels().keySet())
{ {
println("Panel: " + key);
Panel p = getPanels().get(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() void draw()
{ {
if (getCurrentTab() == TAB_NAME_INPUT) if (getCurrentTab() == TAB_NAME_INPUT) {
{
drawImagePage(); drawImagePage();
} }
else if (getCurrentTab() == TAB_NAME_QUEUE) else if (getCurrentTab() == TAB_NAME_QUEUE) {
{
drawCommandQueuePage(); drawCommandQueuePage();
} }
else if (getCurrentTab() == TAB_NAME_DETAILS) else if (getCurrentTab() == TAB_NAME_DETAILS) {
{
drawDetailsPage(); drawDetailsPage();
} }
else if (getCurrentTab() == TAB_NAME_ROVING) else if (getCurrentTab() == TAB_NAME_ROVING) {
{
drawRovingPage(); drawRovingPage();
} }
else if (getCurrentTab() == TAB_NAME_TRACE) else if (getCurrentTab() == TAB_NAME_TRACE) {
{
drawTracePage(); drawTracePage();
} }
else else {
{
drawDetailsPage(); drawDetailsPage();
} }
if (isShowingSummaryOverlay()) {
if (isShowingSummaryOverlay())
{
drawSummaryOverlay(); drawSummaryOverlay();
} }
if (isShowingDialogBox())
{ if (isShowingDialogBox()) {
drawDialogBox(); drawDialogBox();
} }
if (drawbotReady) if (drawbotReady) {
{
dispatchCommandQueue(); dispatchCommandQueue();
} }
} }
String getCurrentTab() String getCurrentTab()
@ -1640,10 +1630,6 @@ void keyPressed()
getDisplayMachine().getOffset().x = getDisplayMachine().getOffset().x - 10; getDisplayMachine().getOffset().x = getDisplayMachine().getOffset().x - 10;
else if (checkKey(KeyEvent.VK_ESCAPE)) else if (checkKey(KeyEvent.VK_ESCAPE))
key = 0; key = 0;
// if (checkKey(CONTROL) && checkKey(KeyEvent.VK_G))
// println("CTRL+G");
else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_G)) else if (checkKey(CONTROL) && checkKey(KeyEvent.VK_G))
{ {
Toggle t = (Toggle) getAllControls().get(MODE_SHOW_GUIDES); Toggle t = (Toggle) getAllControls().get(MODE_SHOW_GUIDES);
@ -1677,60 +1663,6 @@ void keyPressed()
{ {
displayingInfoTextOnInputPage = (displayingInfoTextOnInputPage) ? false : true; 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 == '#' ) else if (key == '#' )
{ {
addToRealtimeCommandQueue(CMD_PENUP+"END"); addToRealtimeCommandQueue(CMD_PENUP+"END");
@ -1748,15 +1680,6 @@ void keyPressed()
{ {
this.maxSegmentLength++; this.maxSegmentLength++;
} }
// else if (key == ',')
// {
// if (this.minimumVectorLineLength > 0)
// this.minimumVectorLineLength--;
// }
// else if (key == '.')
// {
// this.minimumVectorLineLength++;
// }
} }
void mouseDragged() void mouseDragged()
{ {
@ -1782,7 +1705,7 @@ void mouseClicked()
{ {
if (mouseOverPanel()) if (mouseOverPanel())
{ // changing mode { // changing mode
// panelClicked();
} }
else else
{ {