Skip to content

Commit

Permalink
Merge pull request #2 from Zebbeni/clicking
Browse files Browse the repository at this point in the history
Clicking
  • Loading branch information
Zebbeni committed Sep 15, 2014
2 parents d983dc0 + 015515f commit 0ab23ca
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 278 deletions.
25 changes: 10 additions & 15 deletions button.pde
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
public class Button extends Panel
public class Button extends ChildPanel
{
PGraphics drawPG;

Button ( int xx , int yy , int ww , int hh, PGraphics pGraph )
Button ( String nm , int xx , int yy , int ww , int hh )
{
name = nm;
x = xx;
y = yy;
wid = ww;
hei = hh;
drawPG = pGraph;
}

void drawButton()
{
updatePosition();
drawPG.fill(150);
drawPG.rect( x , y , wid , hei );
drawPG = createGraphics( wid, hei );
}

void updatePosition()
public void clickThis()
{

println("clicked ", name);
}

void updateDraw()
public void updateThis()
{
drawPG.strokeWeight(2);
drawPG.fill(150);
drawPG.rect( 0 , 0 , wid , hei );
}
}
2 changes: 0 additions & 2 deletions content_handler.pde
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ public class ContentHandler
{
table = loadTable(filename, "header");
}


}
59 changes: 59 additions & 0 deletions global_functions.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
void zoom(float zm)
{
zoom *= zm;
canvas.x += int(25 * ( zm - 1 ));
canvas.y += int(25 * ( zm - 1 ));
canvas.wid = int(canvas.canvasWid * zoom);
canvas.hei = int(canvas.canvasHei * zoom);
constrainOffsets();
}

void constrainOffsets()
{
canvas.x = constrain(canvas.x , int(-0.8 * canvas.wid), width - 50);
canvas.y = constrain(canvas.y , int(-0.8 * canvas.hei), height - 50);
}

void addElement()
{
Element e = new Element("New Element", IMG, 2, 2, 200, 250);
listbox.addItem(e);
content.table.addColumn(e.name);
}

void removeElement()
{
int selectedId = listbox.selectedItem;
if (selectedId != NONE)
{
Element e = listbox.items.get(selectedId);
content.table.removeColumn(e.name);
listbox.removeItem(e);
}
}

public void handleArrowPress( )
{
int selectedId = listbox.selectedItem;
canvas.handleArrowPress( selectedId );
}

public void toggleDrawHighlights()
{
canvas.toggleHighlight();
}

void toggleDrawContent()
{
canvas.toggleContent();
}

void saveTemplate()
{
template.saveTemplate();
}

public void itemClicked ( int i, Object item )
{
lastItemClicked = item;
}
3 changes: 3 additions & 0 deletions constants.pde → global_variables.pde
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ int BORDER_RIGHT = 4;

int border_select_width = 5;
int move_step = 1;

Object lastItemClicked;
float zoom = 0.6;
27 changes: 27 additions & 0 deletions panel.pde
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ public abstract class Panel
int y;
int wid;
int hei;
PGraphics drawPG;
String name = "No Name";

public abstract void clickThis();
public abstract boolean click( int mx , int my );

public abstract void updateThis();
public abstract void updateDraw();
public abstract void drawToBuffer( PGraphics parentPG);

public void updateDrawPG()
{
drawPG = createGraphics( wid, hei );
drawPG.beginDraw();
updateDraw();
drawPG.endDraw();
}

public boolean isInPanel( int mx , int my )
{
/**
* Returns true if the given mouse X and mouse Y lie in this panel
*/
boolean isHere = (mx > x && mx < (x + wid) && my > y && y < (my + hei));
return isHere;
}
}



29 changes: 29 additions & 0 deletions panel_child.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public abstract class ChildPanel extends Panel
{
public boolean click( int mx , int my )
{
/**
* Returns true if the click occurred in this panel
* calls class-specific click function with mouse X and mouse Y
*/
boolean clickedInHere = isInPanel( mx , my );
if ( clickedInHere )
{
clickThis();
}
return clickedInHere;
}

public void updateDraw()
{
updateThis();
}

public void drawToBuffer( PGraphics parentPG )
{
/*
* draws thisPG to the parentPG
*/
parentPG.image( drawPG , x , y );
}
}
52 changes: 52 additions & 0 deletions panel_parent.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
public abstract class ParentPanel extends Panel
{
ArrayList<Panel> childPanels = new ArrayList<Panel>();

public boolean click( int mx , int my )
{
/*
* Passes relative click info to all children until it finds one clicked
* by the mouse.
*/
boolean clickedInHere = isInPanel( mx , my );

if( clickedInHere )
{
boolean clickedChild = false;
for( int i = 0; i < childPanels.size() && !clickedChild ; i++ )
{
clickedChild = childPanels.get(i).click( mx - x, my - y);
}
if( !clickedChild )
{
clickThis();
}
}

return clickedInHere;
}

public void updateDraw()
{
updateThis();
for( Panel p : childPanels)
{
p.updateDrawPG();
}
}

public void drawToBuffer( PGraphics parentPG )
{
/*
* Begins drawing drawPG and passes this to children to
* draw on, before passing the final image to its own parent
*/
drawPG.beginDraw();
for( Panel p : childPanels )
{
p.drawToBuffer( drawPG );
}
drawPG.endDraw();
parentPG.image( drawPG , x , y );
}
}
73 changes: 23 additions & 50 deletions template_canvas.pde → parent_canvas.pde
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
public class TemplateCanvas extends Panel
public class TemplateCanvas extends ParentPanel
{
PGraphics drawPG;
PGraphics fontPlacer;
PImage cardPic;
PFont drawFont;

ArrayList<Element> elements;
Table contents;

// int offsetX = 300;
// int offsetY = 100;
// float zoom = 0.5;
int pgWidth;
int pgHeight;
int canvasWid;
int canvasHei;

int contentExample = 0;

Expand All @@ -28,30 +24,25 @@ public class TemplateCanvas extends Panel
int lastMX;
int lastMY;

TemplateCanvas (ArrayList<Element> e, Table conts, int xx, int yy, int canW, int canH)
TemplateCanvas (String nm, ArrayList<Element> e, Table conts, int xx, int yy, int canW, int canH)
{
x = xx;
y = yy;
name = nm; x = xx; y = yy; wid = int(canW * zoom); hei = int(canH * zoom);
elements = e;
wid = canW;
hei = canH;
canvasWid = canW;
canvasHei = canH;
contents = conts;
drawPG = createGraphics(wid,hei);
}

void drawAll()
public void updateThis()
{
drawPG = createGraphics(wid,hei);
drawPG.beginDraw();
wid = int(canvasWid * zoom);
hei = int(canvasHei * zoom);
drawCanvas();
drawElements();
drawPG.endDraw();
}

void updateDraw()
{
}

void drawCanvas()
public void drawCanvas()
{
drawPG.fill(150);
drawPG.rect(0, 0, wid, hei);
Expand All @@ -63,10 +54,10 @@ public class TemplateCanvas extends Panel
{
e.updatePosition();

int cx = int(e.x);
int cy = int(e.y);
int cwid = int(e.wid);
int chei = int(e.hei);
int cx = int(e.x * zoom);
int cy = int(e.y * zoom);
int cwid = int(e.wid * zoom);
int chei = int(e.hei * zoom);

drawPG.noStroke();
if (doContent && contentExample != NONE)
Expand Down Expand Up @@ -96,7 +87,7 @@ public class TemplateCanvas extends Panel
{
drawPG.fill(100,100,255,alpha);
}
drawPG.rect(e.x, e.y, e.wid, e.hei);
drawPG.rect( int(e.x * zoom), int(e.y * zoom), int(e.wid * zoom), int(e.hei * zoom));
}

void drawContent( Element e , int cx , int cy , int cwid , int chei )
Expand All @@ -117,7 +108,7 @@ public class TemplateCanvas extends Panel
fontPlacer = createGraphics(int(cwid/hSquish),chei);
fontPlacer.beginDraw();
fontPlacer.textFont(e.font);
fontPlacer.textSize(e.fontSize);
fontPlacer.textSize(constrain(e.fontSize * zoom,0,chei));
fontPlacer.textAlign(LEFT,TOP);
fontPlacer.fill(e.col);
try {
Expand Down Expand Up @@ -264,14 +255,18 @@ public class TemplateCanvas extends Panel
lastMY = my;
}

void handleReleased(int mx, int my)
void clickThis()
{
if( isDragging )
{
isDragging = false;
resizing[0] = NONE;
resizing[1] = NONE;
}
else
{
println("Clicked ", name);
}
}

void handleArrowPress(int selectId)
Expand Down Expand Up @@ -310,28 +305,6 @@ public class TemplateCanvas extends Panel
}
}

// void zoomIn()
// {
// zoom *= 1.2;
// offsetX -= int(50 * canvas.zoom);
// offsetY -= int(50 * canvas.zoom);
// constrainOffsets();
// }
//
// void zoomOut()
// {
// canvas.zoom /= 1.2;
// canvas.offsetX += int(50 * canvas.zoom);
// canvas.offsetY += int(50 * canvas.zoom);
// constrainOffsets();
// }
//
// void constrainOffsets()
// {
// offsetX = constrain(offsetX , int(wid * zoom * -1) + 200, width - 200);
// offsetY = constrain(offsetY , int(hei * zoom * -1) + 200, height - 200);
// }

void setResizing( Element e, int mx, int my)
{
resizing[0] = NONE;
Expand Down
Loading

0 comments on commit 0ab23ca

Please sign in to comment.