Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu panels #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion button.pde → child_button.pde
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ public class Button extends ChildPanel

public void clickThis()
{
println("clicked ", name);
println("clicked on ", name);
}

public void hoverThis()
{
println("hovering on ", name);
}

public void updateThis()
Expand Down
39 changes: 39 additions & 0 deletions child_menuitem.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
public class MenuItem extends ChildPanel
{
Element element;

MenuItem ( int xx, int yy, int ww , int hh , Element e)
{
x = xx; y = yy; wid = ww; hei = hh; element = e;
drawPG = createGraphics( wid, hei );
}

public void clickThis()
{
selectElement( element );
}

public void hoverThis()
{
hoverElement(element);
}

public void updateThis()
{
y = (element.index * hei) - scrollDist;
drawPG.fill( 210 );
if (element.selected)
{
drawPG.fill( 255 );
}
else if(element.hovered)
{
drawPG.fill(215);
}
drawPG.rect( 0 , 0 , wid , hei );

drawPG.noStroke();
drawPG.fill( 0 );
drawPG.text( element.name, 25, 25 );
}
}
7 changes: 6 additions & 1 deletion element.pde
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ public class Element
{
String name;
int type;
int index;

int x;
float realX;
int y;
Expand All @@ -10,19 +12,22 @@ public class Element
float realWid;
int hei;
float realHei;

float hSquish = 1.0;
String fontString = ""; //this is a String for the font file to load.
PFont font;
int fontSize = 0;
String colorString = "FFFFFF";
color col = unhex("FFFFFFFF");

boolean selected = false;
boolean hovered = false;

Element (String nn, int tt, int xx, int yy, int ww, int hh)
Element (String nn, int tt, int idx, int xx, int yy, int ww, int hh)
{
name = nn;
type = tt;
index = idx;
x = xx;
realX = x;
y = yy;
Expand Down
40 changes: 36 additions & 4 deletions global_functions.pde
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,57 @@ void constrainOffsets()

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

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

void selectElement(Element e)
{
if( selectedElement != NONE)
{
elements.get(selectedElement).selected = false;
}
e.selected = true;
selectedElement = e.index;
}

void hoverElement(Element e)
{
if( e == null )
{
if( hoveredElement != NONE)
{
elements.get(hoveredElement).hovered = false;
}
hoveredElement = NONE;
}
else
{
if( hoveredElement != NONE)
{
elements.get(hoveredElement).hovered = false;
}
e.hovered = true;
hoveredElement = e.index;
}
}

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

Expand Down
5 changes: 5 additions & 0 deletions global_variables.pde
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ int move_step = 1;

Object lastItemClicked;
float zoom = 0.6;

int scrollDist = 0;

int selectedElement = NONE;
int hoveredElement = NONE;
5 changes: 4 additions & 1 deletion panel.pde
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public abstract class Panel
public abstract void clickThis();
public abstract boolean click( int mx , int my );

public abstract void hoverThis();
public abstract boolean hover( int mx , int my);

public abstract void updateThis();
public abstract void updateDraw();
public abstract void drawToBuffer( PGraphics parentPG);
Expand All @@ -27,7 +30,7 @@ public abstract class Panel
/**
* 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));
boolean isHere = (mx > x && mx < (x + wid) && my > y && my < (y + hei));
return isHere;
}
}
Expand Down
14 changes: 14 additions & 0 deletions panel_child.pde
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ public abstract class ChildPanel extends Panel
return clickedInHere;
}

public boolean hover( 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 hoveredInHere = isInPanel( mx , my );
if ( hoveredInHere )
{
hoverThis();
}
return hoveredInHere;
}

public void updateDraw()
{
updateThis();
Expand Down
23 changes: 22 additions & 1 deletion panel_parent.pde
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,31 @@ public abstract class ParentPanel extends Panel
clickThis();
}
}

return clickedInHere;
}

public boolean hover( int mx , int my)
{
/*
* Passes relative mouse position to all children until it finds the one hovered
*/
boolean hoveredInHere = isInPanel( mx , my );

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

public void updateDraw()
{
updateThis();
Expand Down
11 changes: 7 additions & 4 deletions parent_canvas.pde
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class TemplateCanvas extends ParentPanel
PImage cardPic;
PFont drawFont;

ArrayList<Element> elements;
Table contents;

int canvasWid;
Expand All @@ -24,10 +23,9 @@ public class TemplateCanvas extends ParentPanel
int lastMX;
int lastMY;

TemplateCanvas (String nm, ArrayList<Element> e, Table conts, int xx, int yy, int canW, int canH)
TemplateCanvas (String nm, Table conts, int xx, int yy, int canW, int canH)
{
name = nm; x = xx; y = yy; wid = int(canW * zoom); hei = int(canH * zoom);
elements = e;
canvasWid = canW;
canvasHei = canH;
contents = conts;
Expand Down Expand Up @@ -255,6 +253,11 @@ public class TemplateCanvas extends ParentPanel
lastMY = my;
}

void hoverThis()
{
println("Hovering on ", name);
}

void clickThis()
{
if( isDragging )
Expand All @@ -265,7 +268,7 @@ public class TemplateCanvas extends ParentPanel
}
else
{
println("Clicked ", name);
// println("Clicked ", name);
}
}

Expand Down
7 changes: 7 additions & 0 deletions parent_interface.pde
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ public class Interface extends ParentPanel

void updateThis()
{
wid = width;
hei = height;
drawPG.background(100);
}

void clickThis()
{
println("Clicked ", name);
}

void hoverThis()
{
println("Hovering on ", name);
}
}
Loading