-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Zebbeni/clicking
Clicking
- Loading branch information
Showing
13 changed files
with
324 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,4 @@ public class ContentHandler | |
{ | ||
table = loadTable(filename, "header"); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ int BORDER_RIGHT = 4; | |
|
||
int border_select_width = 5; | ||
int move_step = 1; | ||
|
||
Object lastItemClicked; | ||
float zoom = 0.6; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.