forked from andrewalbers/CardCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardCreator.pde
173 lines (172 loc) · 5.03 KB
/
CardCreator.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
///**
// * 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");
//}