Skip to content

Commit

Permalink
Merge pull request #1 from Zebbeni/ux-feature
Browse files Browse the repository at this point in the history
added panel abstract class
  • Loading branch information
Zebbeni committed Sep 13, 2014
2 parents 0117852 + 2b0b996 commit d983dc0
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 261 deletions.
344 changes: 172 additions & 172 deletions CardCreator.pde
Original file line number Diff line number Diff line change
@@ -1,173 +1,173 @@
/**
* CardCreator.pde
*
* This script aids in playing card design by using a customizable card
* template, building each card file with information provided in two
* spreadsheets.
*
* @author Andrew Albers
* @version 1.0
* @since 2014-08-30
*/

PGraphics cardMain;
PGraphics fontPlacer;
PImage cardPic;
PFont font;
Table content;
Table template;
int maxWid = 0;
int maxHei = 0;
ArrayList<String> elements;

/**
* Reads csv files, defines card dimensions to accomodate
* largest x + width and largest y + height of elements
* in template.csv
*
* TODO: Let user choose other card sizes to generate
* TODO: Add bleed area to card sizes for printing.
*/
void setup(){
getCardValues();
cardMain = createGraphics(maxWid,maxHei);
noLoop();
}

/**
* Kicks off card creation safter setup.
*/
void draw(){
createAllCards();
}

/**
* Passes each row in the content.csv file to createCard()
*/
void createAllCards() {
println("Creating All Cards");
for (TableRow conRow : content.rows()) {
createCard(conRow);
}
println("Done. Check the CardCreator directory for updated cards.");
}

/**
* Builds a single card, placing each element in the order it appears in
* template.csv. Saves the finished image with the filename given under
* "Name" in the content.csv file.
*
* @param conRow a row in the user-created content.csv file
*/
void createCard(TableRow conRow) {
cardMain.clear();
println("creating ", conRow.getString("saveFile"));
for(int i = 0; i < elements.size(); i++){
//calls drawImg() if "Img" is in element name
if(elements.get(i).indexOf("Img") != -1){
drawImg(conRow.getString(elements.get(i)), template.getRow(i));
}
//calls drawText() if "Text" is in element name
else if(elements.get(i).indexOf("Text") != -1){
drawText(conRow.getString(elements.get(i)), template.getRow(i));
}
}
saveCard(conRow.getString("saveFile"));
}

/**
* Saves a file to a given filename.
*
* @param filename
*/
void saveCard(String filename){
cardMain.save(filename);
}

/**
* Draws text given a text string, an x and y position,
* a width, height, and font. Optionally it will also squish
* the text given an hSquish (horizontal squish percentage).
* Also added an (optional) colorHex value. Default is white.
*
* @param t text to print
* @param row template.csv attributes for this text element
*/
void drawText(String t, TableRow row) {
int x = int(row.getString("x"));
int y = int(row.getString("y"));
int w = int(row.getString("w"));
int h = int(row.getString("h"));

//get the text color or default to white
String hexStr = "FF" + row.getString("colorHex");
if(hexStr.equals("")){
hexStr = "FFFFFFFF";
}
color col = unhex(hexStr);

//get the horizontal squish value or defualt to 1
float hSquish = float(row.getString("hSquish"));
if(Float.isNaN(hSquish) || hSquish <= 0) {
hSquish = 1; //set hSquish to 1 if undefined or <= 0
}

String text = t;
font = loadFont(row.getString("font"));
fontPlacer = createGraphics(int(w/hSquish),h);
fontPlacer.beginDraw();
fontPlacer.textFont(font);
fontPlacer.textSize(int(row.getString("size")));
fontPlacer.textAlign(LEFT,TOP);
fontPlacer.fill(col);
//provide extra horizontal space for text if 0 < hSquish < 1...
fontPlacer.text(text,0,0,int(w/hSquish),h);
fontPlacer.endDraw();
//... and then compresses to the stated width
cardMain.image(fontPlacer.get(),x,y,w,h);
}

/**
* Draws an image given a filename, an x and y position,
* a width, and height.
*
* @param filename the image file to draw
* @param row template.csv attributes for this image element
*/
void drawImg(String filename, TableRow row) {
if(filename.length() != 0){
cardPic = loadImage(filename);
int x = int(row.getString("x"));
int y = int(row.getString("y"));
int w = int(row.getString("w"));
int h = int(row.getString("h"));
cardMain.image(cardPic,x,y,w,h);
}
}

/**
* Reads template.csv and content.csv, stores their values in
* two tables: template and content.
*
* TODO: Allow multiple template.csv/content.csv files to be
* read. ie generate landscape and portrait-formatted
* cards at the same time
*/
void getCardValues(){
elements = new ArrayList<String>();
template = loadTable("template.csv", "header");
for (TableRow row : template.rows()) {
//add to the list of elements
elements.add(row.getString("element"));

//
if(int(row.getString("x"))+int(row.getString("w")) > maxWid){
maxWid = int(row.getString("x"))+int(row.getString("w"));
}
if(int(row.getString("y"))+int(row.getString("h")) > maxHei) {
maxHei = int(row.getString("y"))+int(row.getString("h"));
}
}
content = loadTable("content.csv", "header");
}
///**
// * CardCreator.pde
// *
// * This script aids in playing card design by using a customizable card
// * template, building each card file with information provided in two
// * spreadsheets.
// *
// * @author Andrew Albers
// * @version 1.0
// * @since 2014-08-30
// */
//
//PGraphics cardMain;
//PGraphics fontPlacer;
//PImage cardPic;
//PFont font;
//Table content;
//Table template;
//int maxWid = 0;
//int maxHei = 0;
//ArrayList<String> elements;
//
///**
// * Reads csv files, defines card dimensions to accomodate
// * largest x + width and largest y + height of elements
// * in template.csv
// *
// * TODO: Let user choose other card sizes to generate
// * TODO: Add bleed area to card sizes for printing.
// */
//void setup(){
// getCardValues();
// cardMain = createGraphics(maxWid,maxHei);
// noLoop();
//}
//
///**
// * Kicks off card creation safter setup.
// */
//void draw(){
// createAllCards();
//}
//
///**
// * Passes each row in the content.csv file to createCard()
// */
//void createAllCards() {
// println("Creating All Cards");
// for (TableRow conRow : content.rows()) {
// createCard(conRow);
// }
// println("Done. Check the CardCreator directory for updated cards.");
//}
//
///**
// * Builds a single card, placing each element in the order it appears in
// * template.csv. Saves the finished image with the filename given under
// * "Name" in the content.csv file.
// *
// * @param conRow a row in the user-created content.csv file
// */
//void createCard(TableRow conRow) {
// cardMain.clear();
// println("creating ", conRow.getString("saveFile"));
// for(int i = 0; i < elements.size(); i++){
// //calls drawImg() if "Img" is in element name
// if(elements.get(i).indexOf("Img") != -1){
// drawImg(conRow.getString(elements.get(i)), template.getRow(i));
// }
// //calls drawText() if "Text" is in element name
// else if(elements.get(i).indexOf("Text") != -1){
// drawText(conRow.getString(elements.get(i)), template.getRow(i));
// }
// }
// saveCard(conRow.getString("saveFile"));
//}
//
///**
// * Saves a file to a given filename.
// *
// * @param filename
// */
//void saveCard(String filename){
// cardMain.save(filename);
//}
//
///**
// * Draws text given a text string, an x and y position,
// * a width, height, and font. Optionally it will also squish
// * the text given an hSquish (horizontal squish percentage).
// * Also added an (optional) colorHex value. Default is white.
// *
// * @param t text to print
// * @param row template.csv attributes for this text element
// */
//void drawText(String t, TableRow row) {
// int x = int(row.getString("x"));
// int y = int(row.getString("y"));
// int w = int(row.getString("w"));
// int h = int(row.getString("h"));
//
// //get the text color or default to white
// String hexStr = "FF" + row.getString("colorHex");
// if(hexStr.equals("")){
// hexStr = "FFFFFFFF";
// }
// color col = unhex(hexStr);
//
// //get the horizontal squish value or defualt to 1
// float hSquish = float(row.getString("hSquish"));
// if(Float.isNaN(hSquish) || hSquish <= 0) {
// hSquish = 1; //set hSquish to 1 if undefined or <= 0
// }
//
// String text = t;
// font = loadFont(row.getString("font"));
// fontPlacer = createGraphics(int(w/hSquish),h);
// fontPlacer.beginDraw();
// fontPlacer.textFont(font);
// fontPlacer.textSize(int(row.getString("size")));
// fontPlacer.textAlign(LEFT,TOP);
// fontPlacer.fill(col);
// //provide extra horizontal space for text if 0 < hSquish < 1...
// fontPlacer.text(text,0,0,int(w/hSquish),h);
// fontPlacer.endDraw();
// //... and then compresses to the stated width
// cardMain.image(fontPlacer.get(),x,y,w,h);
//}
//
///**
// * Draws an image given a filename, an x and y position,
// * a width, and height.
// *
// * @param filename the image file to draw
// * @param row template.csv attributes for this image element
// */
//void drawImg(String filename, TableRow row) {
// if(filename.length() != 0){
// cardPic = loadImage(filename);
// int x = int(row.getString("x"));
// int y = int(row.getString("y"));
// int w = int(row.getString("w"));
// int h = int(row.getString("h"));
// cardMain.image(cardPic,x,y,w,h);
// }
//}
//
///**
// * Reads template.csv and content.csv, stores their values in
// * two tables: template and content.
// *
// * TODO: Allow multiple template.csv/content.csv files to be
// * read. ie generate landscape and portrait-formatted
// * cards at the same time
// */
//void getCardValues(){
// elements = new ArrayList<String>();
// template = loadTable("template.csv", "header");
// for (TableRow row : template.rows()) {
// //add to the list of elements
// elements.add(row.getString("element"));
//
// //
// if(int(row.getString("x"))+int(row.getString("w")) > maxWid){
// maxWid = int(row.getString("x"))+int(row.getString("w"));
// }
// if(int(row.getString("y"))+int(row.getString("h")) > maxHei) {
// maxHei = int(row.getString("y"))+int(row.getString("h"));
// }
// }
// content = loadTable("content.csv", "header");
//}

10 changes: 5 additions & 5 deletions button.pde
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
public class Button
public class Button extends Panel
{
int x;
int y;
int wid;
int hei;
PGraphics drawPG;

Button ( int xx , int yy , int ww , int hh, PGraphics pGraph )
Expand All @@ -26,4 +22,8 @@ public class Button
{

}

void updateDraw()
{
}
}
1 change: 1 addition & 0 deletions content_handler.pde
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class ContentHandler
table = loadTable(filename, "header");
}


}
2 changes: 1 addition & 1 deletion data/template.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ element,type,x,y,w,h,font,fontsize,hSquish,colorHex
Background,image,0,0,675,1050,,0,1.0,FFFFFF
Picture,image,55,163,560,505,,0,1.0,FFFFFF
Name,text,174,79,434,56,Sansation-Bold-48.vlw,60,0.6,
Main,text,56,705,554,183,Sansation-Regular-48.vlw,45,0.6,
Main,text,60,707,554,183,Sansation-Regular-48.vlw,45,0.6,
Icon,image,50,50,100,100,,0,1.0,FFFFFF
Italic,text,58,942,550,42,Sansation-Italic-48.vlw,35,0.6,3344FF
Loading

0 comments on commit d983dc0

Please sign in to comment.