From 2b0b99683b33a0f08e85ec1335ed3aa4d61ede09 Mon Sep 17 00:00:00 2001 From: Zebbeni Date: Sat, 13 Sep 2014 12:15:46 -0600 Subject: [PATCH] added panel abstract class --- CardCreator.pde | 344 ++++++++++----------- button.pde | 10 +- content_handler.pde | 1 + data/template.csv | 2 +- list_box.pde | 10 +- panel.pde | 9 + template_drawer.pde => template_canvas.pde | 118 +++---- toolbar.pde | 10 +- user_interface.pde | 44 ++- 9 files changed, 287 insertions(+), 261 deletions(-) create mode 100644 panel.pde rename template_drawer.pde => template_canvas.pde (77%) diff --git a/CardCreator.pde b/CardCreator.pde index 7dee175..29d50e0 100644 --- a/CardCreator.pde +++ b/CardCreator.pde @@ -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 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(); - 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 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(); +// 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"); +//} diff --git a/button.pde b/button.pde index 8cc0fb2..4876164 100644 --- a/button.pde +++ b/button.pde @@ -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 ) @@ -26,4 +22,8 @@ public class Button { } + + void updateDraw() + { + } } diff --git a/content_handler.pde b/content_handler.pde index 3867bbe..af1410e 100644 --- a/content_handler.pde +++ b/content_handler.pde @@ -17,4 +17,5 @@ public class ContentHandler table = loadTable(filename, "header"); } + } diff --git a/data/template.csv b/data/template.csv index cf049cf..9267b77 100644 --- a/data/template.csv +++ b/data/template.csv @@ -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 diff --git a/list_box.pde b/list_box.pde index 63eb8d9..aac3831 100644 --- a/list_box.pde +++ b/list_box.pde @@ -3,10 +3,10 @@ public void itemClicked ( int i, Object item ) lastItemClicked = item; } -public class Listbox +public class Listbox extends Panel { PGraphics listPG; - int x, y, listHeight; + int listHeight; ArrayList items; int selectedItem = NONE; @@ -29,7 +29,7 @@ public class Listbox Listbox ( int xx, int yy, int ww, int hh, int ih, ArrayList e ) { - x = xx; y = yy; + x = xx; y = yy; wid = ww; hei = hh; pgWidth = ww; pgHeight = hh; listPG = createGraphics(pgWidth, pgHeight); @@ -64,6 +64,10 @@ public class Listbox scrollDist = constrain( scrollDist, 0, maxScrollDist <= 0 ? 0 : maxScrollDist ); } + void updateDraw() + { + } + void drawList () { updatePosition(); diff --git a/panel.pde b/panel.pde new file mode 100644 index 0000000..fee830a --- /dev/null +++ b/panel.pde @@ -0,0 +1,9 @@ +public abstract class Panel +{ + int x; + int y; + int wid; + int hei; + + public abstract void updateDraw(); +} diff --git a/template_drawer.pde b/template_canvas.pde similarity index 77% rename from template_drawer.pde rename to template_canvas.pde index 88098cb..ec86371 100644 --- a/template_drawer.pde +++ b/template_canvas.pde @@ -1,4 +1,4 @@ -public class TemplateDrawer +public class TemplateCanvas extends Panel { PGraphics drawPG; PGraphics fontPlacer; @@ -8,13 +8,9 @@ public class TemplateDrawer ArrayList elements; Table contents; - int canvasWidth; - int canvasHeight; - int x = 0; - int y = 0; - int offsetX = 300; - int offsetY = 100; - float zoom = 0.5; +// int offsetX = 300; +// int offsetY = 100; +// float zoom = 0.5; int pgWidth; int pgHeight; @@ -32,27 +28,33 @@ public class TemplateDrawer int lastMX; int lastMY; - TemplateDrawer (ArrayList e, Table conts, int canW, int canH) + TemplateCanvas (ArrayList e, Table conts, int xx, int yy, int canW, int canH) { + x = xx; + y = yy; elements = e; - canvasWidth = canW; - canvasHeight = canH; + wid = canW; + hei = canH; contents = conts; } void drawAll() { - drawPG = createGraphics(width,height); + drawPG = createGraphics(wid,hei); drawPG.beginDraw(); drawCanvas(); drawElements(); drawPG.endDraw(); } + void updateDraw() + { + } + void drawCanvas() { drawPG.fill(150); - drawPG.rect(offsetX, offsetY, canvasWidth*zoom, canvasHeight*zoom); + drawPG.rect(0, 0, wid, hei); } void drawElements() @@ -61,10 +63,10 @@ public class TemplateDrawer { e.updatePosition(); - int cx = int(e.x * zoom) + offsetX; - int cy = int(e.y * zoom) + offsetY; - int cwid = int(e.wid * zoom); - int chei = int(e.hei * zoom); + int cx = int(e.x); + int cy = int(e.y); + int cwid = int(e.wid); + int chei = int(e.hei); drawPG.noStroke(); if (doContent && contentExample != NONE) @@ -84,7 +86,7 @@ public class TemplateDrawer int alpha = 50; if ( e.hovered ) { - drawPG.fill(255,255,255,int(75 * fade)); + drawPG.fill(255,255,255,100); } else if ( e.type == IMG ) { @@ -94,7 +96,7 @@ public class TemplateDrawer { drawPG.fill(100,100,255,alpha); } - drawPG.rect((e.x * zoom) + offsetX, (e.y * zoom) + offsetY, e.wid * zoom, e.hei*zoom); + drawPG.rect(e.x, e.y, e.wid, e.hei); } void drawContent( Element e , int cx , int cy , int cwid , int chei ) @@ -115,7 +117,7 @@ public class TemplateDrawer fontPlacer = createGraphics(int(cwid/hSquish),chei); fontPlacer.beginDraw(); fontPlacer.textFont(e.font); - fontPlacer.textSize(e.fontSize*zoom); + fontPlacer.textSize(e.fontSize); fontPlacer.textAlign(LEFT,TOP); fontPlacer.fill(e.col); try { @@ -134,7 +136,7 @@ public class TemplateDrawer { drawPG.stroke(200); drawPG.strokeWeight(2); - drawPG.fill(255,255,255,fade*100); + drawPG.fill(255,255,255,50); if( isDragging ) { drawPG.stroke(200,200,200,255); @@ -200,8 +202,8 @@ public class TemplateDrawer { if(resizing[1] == BORDER_TOP) { - e.realY += (my - lastMY) / zoom; - e.realHei -= (my - lastMY) / zoom; + e.realY += (my - lastMY); + e.realHei -= (my - lastMY); if(keyPressed && keyCode == SHIFT) { e.realWid = e.realHei * widHeiRatio; @@ -210,7 +212,7 @@ public class TemplateDrawer } else if(resizing[1] == BORDER_BOTTOM) { - e.realHei += (my - lastMY) / zoom; + e.realHei += (my - lastMY); if(keyPressed && keyCode == SHIFT) { e.realWid = e.realHei * widHeiRatio; @@ -219,7 +221,7 @@ public class TemplateDrawer if(resizing[0] == BORDER_RIGHT) { - e.realWid += (mx - lastMX) / zoom; + e.realWid += (mx - lastMX); if(keyPressed && keyCode == SHIFT) { e.realHei = e.realWid / widHeiRatio; @@ -227,8 +229,8 @@ public class TemplateDrawer } else if(resizing[0] == BORDER_LEFT) { - e.realX += (mx - lastMX) / zoom; - e.realWid -= (mx - lastMX) / zoom; + e.realX += (mx - lastMX); + e.realWid -= (mx - lastMX); if(keyPressed && keyCode == SHIFT) { e.realHei = e.realWid / widHeiRatio; @@ -243,16 +245,16 @@ public class TemplateDrawer void dragCanvas(int mx, int my) { - offsetX += (mx - lastMX); - offsetY += (my - lastMY); + x += (mx - lastMX); + y += (my - lastMY); resetLastMouse(mx,my); constrainOffsets(); } void dragElement(Element e, int mx, int my) { - e.realX += (mx - lastMX) / zoom; - e.realY += (my - lastMY) / zoom; + e.realX += (mx - lastMX); + e.realY += (my - lastMY); resetLastMouse(mx,my); } @@ -279,20 +281,20 @@ public class TemplateDrawer Element e = elements.get(selectId); if(keyCode == UP) { - e.move(0, -1 * ceil( move_step / zoom) ); + e.move(0, -1 * ceil( move_step ) ); println("moving up"); } else if(keyCode == DOWN) { - e.move(0, ceil(move_step / zoom)); + e.move(0, ceil(move_step )); } else if(keyCode == LEFT) { - e.move( -1 * ceil(move_step / zoom ) , 0); + e.move( -1 * ceil(move_step ) , 0); } else { - e.move( ceil(move_step / zoom ) , 0); + e.move( ceil(move_step ) , 0); } } else if(doContent) @@ -308,35 +310,35 @@ public class TemplateDrawer } } - void zoomIn() - { - zoom *= 1.2; - offsetX -= int(50 * drawer.zoom); - offsetY -= int(50 * drawer.zoom); - constrainOffsets(); - } - - void zoomOut() - { - drawer.zoom /= 1.2; - drawer.offsetX += int(50 * drawer.zoom); - drawer.offsetY += int(50 * drawer.zoom); - constrainOffsets(); - } - - void constrainOffsets() - { - offsetX = constrain(offsetX , int(canvasWidth * zoom * -1) + 200, width - 200); - offsetY = constrain(offsetY , int(canvasHeight * zoom * -1) + 200, height - 200); - } +// void zoomIn() +// { +// zoom *= 1.2; +// offsetX -= int(50 * canvas.zoom); +// offsetY -= int(50 * canvas.zoom); +// constrainOffsets(); +// } +// +// void zoomOut() +// { +// canvas.zoom /= 1.2; +// canvas.offsetX += int(50 * canvas.zoom); +// canvas.offsetY += int(50 * canvas.zoom); +// constrainOffsets(); +// } +// +// void constrainOffsets() +// { +// offsetX = constrain(offsetX , int(wid * zoom * -1) + 200, width - 200); +// offsetY = constrain(offsetY , int(hei * zoom * -1) + 200, height - 200); +// } void setResizing( Element e, int mx, int my) { resizing[0] = NONE; resizing[1] = NONE; - int dispX = int(e.x * zoom) + offsetX; - int dispY = int(e.y * zoom) + offsetY; + int dispX = int(e.x * zoom); + int dispY = int(e.y * zoom); int dispW = int(e.wid * zoom); int dispH = int(e.hei * zoom); diff --git a/toolbar.pde b/toolbar.pde index 6887b3a..f3ac240 100644 --- a/toolbar.pde +++ b/toolbar.pde @@ -1,9 +1,5 @@ -public class Toolbar +public class Toolbar extends Panel { - int x; - int y; - int wid; - int hei; PGraphics drawPG; ArrayList