Skip to content

Commit 43c5880

Browse files
committed
initial commit of ux
1 parent bf5c703 commit 43c5880

File tree

11 files changed

+1204
-2
lines changed

11 files changed

+1204
-2
lines changed

button.pde

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class Button
2+
{
3+
int x;
4+
int y;
5+
int wid;
6+
int hei;
7+
PGraphics drawPG;
8+
9+
Button ( int xx , int yy , int ww , int hh, PGraphics pGraph )
10+
{
11+
x = xx;
12+
y = yy;
13+
wid = ww;
14+
hei = hh;
15+
drawPG = pGraph;
16+
}
17+
18+
void drawButton()
19+
{
20+
updatePosition();
21+
drawPG.fill(150);
22+
drawPG.rect( x , y , wid , hei );
23+
}
24+
25+
void updatePosition()
26+
{
27+
28+
}
29+
}

constants.pde

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
int NONE = -1; // for deselected items,
2+
int IMG = 1; // element types
3+
int TXT = 2;
4+
5+
int BORDER_TOP = 1;
6+
int BORDER_LEFT = 2;
7+
int BORDER_BOTTOM = 3;
8+
int BORDER_RIGHT = 4;
9+
10+
int border_select_width = 5;
11+
int move_step = 1;

content_handler.pde

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class ContentHandler
2+
{
3+
Table table;
4+
5+
ContentHandler ( )
6+
{
7+
getContent();
8+
}
9+
10+
void getContent()
11+
{
12+
getContentTable("content.csv");
13+
}
14+
15+
void getContentTable( String filename )
16+
{
17+
table = loadTable(filename, "header");
18+
}
19+
20+
}

data/content.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
saveFile,ImgBackground,ImgPicture,TextName,TextMain,ImgIcon,TextItaliccard_Tinker.tif,temp_red.png,tinker.png,Tinker,Tinker's card text goes here. Tinker's card text goes here. Tinker's card text goes here.,icon1.png,Some italicized text about the Tinker herecard_Tailor.tif,temp_blue.png,tailor.png,Tailor,Tailor's card text goes here. Tailor's card text goes here. Tailor's card text goes here. Tailor's card text goes here.,icon1.png,"""Gobbla bjaljf awle gwe a fsdflwoe fjwoe"""card_Soldier.tif,temp_red.png,soldier.png,Soldier,Soldier's card text goes here. Soldier's card text goes here. Soldier's card text goes here.,icon2.png,Some italicized text about the soldier could go herecard_Spy.tif,temp_blue.png,spy.png,Spy,Spy's card text goes here. Spy's card text goes here. Spy's card text goes here.,icon2.png,"Italicized stuff about the Spy. ""Quote quote quote."""
1+
saveFile,Background,Picture,Name,Main,Icon,Italiccard_Tinker.tif,temp_red.png,tinker.png,Tinker,Tinker's card text goes here. Tinker's card text goes here. Tinker's card text goes here.,icon1.png,Some italicized text about the Tinker herecard_Tailor.tif,temp_blue.png,tailor.png,Tailor,Tailor's card text goes here. Tailor's card text goes here. Tailor's card text goes here. Tailor's card text goes here.,icon1.png,"""Gobbla bjaljf awle gwe a fsdflwoe fjwoe"""card_Soldier.tif,temp_red.png,soldier.png,Soldier,Soldier's card text goes here. Soldier's card text goes here. Soldier's card text goes here.,icon2.png,Some italicized text about the soldier could go herecard_Spy.tif,temp_blue.png,spy.png,Spy,Spy's card text goes here. Spy's card text goes here. Spy's card text goes here.,icon2.png,"Italicized stuff about the Spy. ""Quote quote quote."""

data/template.csv

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
element,x,y,w,h,font,size,hSquish,colorHexImgBackground,0,0,675,1050,,,1,ImgPicture,54,163,566,507,,,1,TextName,170,75,400,200,Sansation-Bold-48.vlw,60,0.6,TextMain,60,710,550,215,Sansation-Regular-48.vlw,45,0.6,ImgIcon,50,50,100,100,,,1,TextItalic,100,925,500,100,Sansation-Italic-48.vlw,35,0.6,FFE268
1+
element,type,x,y,w,h,font,fontsize,hSquish,colorHex
2+
Background,image,0,0,675,1050,,0,1.0,FFFFFF
3+
Picture,image,55,163,560,505,,0,1.0,FFFFFF
4+
Name,text,174,79,434,56,Sansation-Bold-48.vlw,60,0.6,
5+
Main,text,56,705,554,183,Sansation-Regular-48.vlw,45,0.6,
6+
Icon,image,50,50,100,100,,0,1.0,FFFFFF
7+
Italic,text,58,942,550,42,Sansation-Italic-48.vlw,35,0.6,3344FF

element.pde

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
public class Element
2+
{
3+
String name;
4+
int type;
5+
int x;
6+
float realX;
7+
int y;
8+
float realY;
9+
int wid;
10+
float realWid;
11+
int hei;
12+
float realHei;
13+
float hSquish = 1.0;
14+
String fontString = ""; //this is a String for the font file to load.
15+
PFont font;
16+
int fontSize = 0;
17+
String colorString = "FFFFFF";
18+
color col = unhex("FFFFFFFF");
19+
boolean selected = false;
20+
boolean hovered = false;
21+
22+
Element (String nn, int tt, int xx, int yy, int ww, int hh)
23+
{
24+
name = nn;
25+
type = tt;
26+
x = xx;
27+
realX = x;
28+
y = yy;
29+
realY = y;
30+
wid = ww;
31+
realWid = wid;
32+
hei = hh;
33+
realHei = hei;
34+
}
35+
36+
/**
37+
* Sets extra font variables if this is a text type element
38+
*/
39+
void setFont(String fstr, int fsiz, float hsq, String cstr)
40+
{
41+
fontString = fstr;
42+
fontSize = fsiz;
43+
font = loadFont(fstr);
44+
hSquish = hsq;
45+
colorString = cstr;
46+
col = unhex("FF" + cstr);
47+
}
48+
49+
void move( int dx, int dy )
50+
{
51+
realX += dx;
52+
realY += dy;
53+
}
54+
55+
void updatePosition()
56+
{
57+
x = int(realX);
58+
y = int(realY);
59+
wid = int(realWid);
60+
hei = int(realHei);
61+
}
62+
}

list_box.pde

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
public void itemClicked ( int i, Object item )
2+
{
3+
lastItemClicked = item;
4+
}
5+
6+
public class Listbox
7+
{
8+
PGraphics listPG;
9+
int x, y, listHeight;
10+
11+
ArrayList<Element> items;
12+
int selectedItem = NONE;
13+
int hoverItem = NONE;
14+
15+
int itemHeight;
16+
int itemWidth;
17+
18+
int scrolltabWidth = 15;
19+
int scrolltabHeight;
20+
int scrolltabX;
21+
int scrolltabY;
22+
int scrollDist = 0;
23+
24+
int maxScrollDist = 0;
25+
26+
int pgHeight;
27+
int pgWidth;
28+
int listStartAt = 0;
29+
30+
Listbox ( int xx, int yy, int ww, int hh, int ih, ArrayList<Element> e )
31+
{
32+
x = xx; y = yy;
33+
pgWidth = ww;
34+
pgHeight = hh;
35+
listPG = createGraphics(pgWidth, pgHeight);
36+
37+
itemHeight = ih; itemWidth = pgWidth - scrolltabWidth;
38+
39+
items = e;
40+
calculateListHeight();
41+
updateScrollTab();
42+
43+
// register it
44+
Interactive.add( this );
45+
}
46+
47+
public void addItem ( Element item )
48+
{
49+
if ( items == null ) items = new ArrayList();
50+
items.add( item );
51+
}
52+
53+
public void removeItem ( Element item )
54+
{
55+
items.remove(item);
56+
selectedItem = NONE;
57+
hoverItem = NONE;
58+
}
59+
60+
// called from manager
61+
void mouseScrolled ( float step )
62+
{
63+
scrollDist += (step*5);
64+
scrollDist = constrain( scrollDist, 0, maxScrollDist <= 0 ? 0 : maxScrollDist );
65+
}
66+
67+
void drawList ()
68+
{
69+
updatePosition();
70+
listPG.beginDraw();
71+
listPG.background(200);
72+
listPG.noStroke();
73+
listPG.fill( 100 );
74+
listPG.rect( 0 , 0 - scrollDist, pgWidth , listHeight );
75+
if ( items != null )
76+
{
77+
for ( int i = 0; i < items.size(); i++ )
78+
{
79+
listPG.stroke( 80 );
80+
listPG.fill( 200 );
81+
if (items.get(i).selected)
82+
{
83+
listPG.fill( 255 );
84+
}
85+
else if(items.get(i).hovered)
86+
{
87+
listPG.fill(215);
88+
}
89+
listPG.rect( 0, (i*itemHeight) - scrollDist, pgWidth, itemHeight );
90+
91+
listPG.noStroke();
92+
listPG.fill( 0 );
93+
listPG.text( items.get(i+listStartAt).name, 25, (i+1)*(itemHeight) - 20 - scrollDist );
94+
}
95+
}
96+
97+
//draw scrollbar
98+
listPG.stroke(80);
99+
listPG.fill(100);
100+
listPG.rect(itemWidth, 0, pgWidth, pgHeight);
101+
listPG.fill(200);
102+
listPG.rect(scrolltabX, scrolltabY, scrolltabWidth, scrolltabHeight);
103+
104+
listPG.endDraw();
105+
}
106+
107+
/**
108+
* update x position and list height in case window is resized
109+
*/
110+
void updatePosition(){
111+
x = width - pgWidth;
112+
pgHeight = height - y - 100;
113+
updateMaxScrollDist();
114+
updateScrollTab();
115+
listPG = createGraphics(pgWidth, pgHeight);
116+
}
117+
118+
void updateMaxScrollDist()
119+
{
120+
calculateListHeight();
121+
maxScrollDist = listHeight - pgHeight;
122+
}
123+
124+
void calculateListHeight(){
125+
listHeight = itemHeight * items.size();
126+
}
127+
128+
void updateScrollTab()
129+
{
130+
scrolltabHeight = int(float(pgHeight * pgHeight) / float(listHeight));
131+
scrolltabHeight = constrain(scrolltabHeight, 0, pgHeight);
132+
scrolltabX = itemWidth;
133+
scrolltabY = int(float(pgHeight * scrollDist) / float(listHeight)); //tabY is relative to listPG
134+
}
135+
136+
boolean handleMoved ( int mx, int my)
137+
{
138+
if(inArea(mx,my))
139+
{
140+
if(inItem(mx,my))
141+
{
142+
hoverItem(my);
143+
}
144+
return true;
145+
}
146+
else
147+
{
148+
unHover();
149+
return false;
150+
}
151+
}
152+
153+
boolean handleClicked ( int mx, int my)
154+
{
155+
if(inArea(mx,my))
156+
{
157+
if(inItem(mx,my))
158+
{
159+
selectItem(my);
160+
}
161+
else if(inScrollbar(mx,my))
162+
{
163+
clickScrollBar(my);
164+
}
165+
return true;
166+
}
167+
else
168+
{
169+
return false;
170+
}
171+
}
172+
173+
void hoverItem( int my )
174+
{
175+
int listClick = my + scrollDist - y;
176+
int index = ceil(listClick / itemHeight);
177+
if ( index >= items.size())
178+
{
179+
if( hoverItem != NONE )
180+
{
181+
items.get(hoverItem).hovered = false;
182+
hoverItem = NONE;
183+
}
184+
}
185+
else
186+
{
187+
if(hoverItem != NONE)
188+
{
189+
items.get(hoverItem).hovered = false;
190+
}
191+
hoverItem = index;
192+
items.get(hoverItem).hovered = true;
193+
}
194+
}
195+
196+
void unHover()
197+
{
198+
if( hoverItem != NONE)
199+
{
200+
items.get(hoverItem).hovered = false;
201+
hoverItem = NONE;
202+
}
203+
}
204+
205+
void selectItem( int my )
206+
{
207+
int listClick = my + scrollDist - y;
208+
int index = int(listClick / itemHeight);
209+
if(index >= items.size())
210+
{
211+
if( selectedItem != NONE)
212+
{
213+
items.get(selectedItem).selected = false;
214+
}
215+
selectedItem = NONE;
216+
}
217+
else
218+
{
219+
if( selectedItem != NONE)
220+
{
221+
items.get(selectedItem).selected = false;
222+
}
223+
selectedItem = index;
224+
items.get(selectedItem).selected = true;
225+
}
226+
}
227+
228+
void clickScrollBar( int my )
229+
{
230+
println("clicked the scrollbar");
231+
}
232+
233+
boolean inArea( int mx, int my)
234+
{
235+
boolean isInArea = (mx > x && mx < x + pgWidth && my > y && my < y + pgHeight);
236+
return isInArea;
237+
}
238+
239+
boolean inItem( int mx, int my)
240+
{
241+
boolean isInItem = (mx < x + itemWidth);
242+
return isInItem;
243+
}
244+
245+
boolean inScrollbar( int mx, int my)
246+
{
247+
boolean isInArea = (mx >= x + itemWidth);
248+
return isInArea;
249+
}
250+
}
251+

0 commit comments

Comments
 (0)