Similar with mouse over
using the text()
command with 5 parameters cuts longer text off
on mouse over, the complete text is shown
// class with tools
Tools tools = new Tools();
// the table
Table tResources;
void setup() {
size(1600, 660);
background(tools.WHITE);
// setting up table (column names / headlines)
tResources = tools.newTable("Item", "brick", "wood", "sheep", "wheat", "ore", "points");
// adding data (must match headlines)
tResources = tools.tableAddData ( tResources, "Street", "1x", "1x", "", "", "", "0" );
tResources = tools.tableAddData ( tResources, "Settlement", "1x", "1x", "1x", "1x", "", "1" );
tResources = tools.tableAddData ( tResources, "City", "", "", "", "2x", "3x", "2");
tResources = tools.tableAddData ( tResources, "Dev Card mn,m,m,mn, eewewrrew ooppopopoi pooopopoo ölööölöllökölk ,m.m..,.,m,m..,m", "", "", "1x", "1x", "1x", "?" );
// ------------------------------
}
void draw() {
background(0);
tools.showTable(tResources,
22, 22);
fill(tools.WHITE);
text("use mouse over to show full text",
22, height/2-110);
}
//===============================================================================
// Tools collection
class Tools {
// class not like a car class Car for an object but a collection of tools.
final color RED = color(255, 0, 0);
final color GREEN = color(0, 255, 0);
final color BLUE = color(0, 0, 255);
final color WHITE = color(255);
final color BLACK = color(0);
final color GRAY = color(255/2);
boolean cursorSignShowFlag=false;
// ----------------------------------------------------------------
void showTable(Table tableBtn,
int x, int y) {
int factorX=78; // column width
// rect
stroke(WHITE);
noFill();
rect( x, y,
tableBtn.getColumnCount()*78-6, (tableBtn.getRowCount()+1) * 22 + 10 );
// headline
showTableHeadline(tableBtn, x+6, y+19, factorX);
// horizontal line
stroke(WHITE);
line( x+2, y+5+19,
6+x+(tableBtn.getColumnCount())*factorX-13, y+5+19);
// grid
// loop over rows (y)
for (int i=0; i<tableBtn.getRowCount(); i++) {
// current data row
TableRow row = tableBtn.getRow(i);
// loop over columns in that row (i2 is for x)
for (int i2=0; i2<tableBtn.getColumnCount(); i2++) {
fill(WHITE);
text(row.getString(i2),
i2*factorX+x+6, 25+ i * 22 +y+8,
factorX-8, 15);
if (mouseInside(i2*factorX+x+6, 25+ i * 22 +y+8,
factorX-8, 15)) {
text (row.getString(i2),
20, height-22);
}//if
// vertical line
line( i2*factorX+x, +y,
i2*factorX+x, tableBtn.getRowCount() * 22 + y + 31);
}//for
}//for
}// method
boolean mouseInside( float x_, float y_,
float w_, float h_) {
return mouseX>x_ &&
mouseX<x_+w_ &&
mouseY>y_ &&
mouseY<y_+h_;
}
void showTableHeadline(Table tableBtn,
int x, int y,
int factorX) {
// headline for table
TableRow row0 = tableBtn.getRow(0);
for (int i=0; i<tableBtn.getColumnCount(); i++) {
// headline
fill(GREEN);
text(row0.getColumnTitle(i),
i*factorX+x, y-2);
}
}//method
// ---
// make table
Table newTable (String... listColumnNames) {
Table newT = new Table();
// make columns
for (String s1 : listColumnNames) {
newT.addColumn(s1);
}
return newT;
}//method
Table tableAddData( Table table1, String... data1 ) {
// add rows with data
TableRow newRow = table1.addRow();
// add rows with data
int i=0;
for (String s1 : data1) {
newRow.setString(newRow.getColumnTitle(i), s1);
i++;
}
return table1;
}//method
// ---
void printlnTable(Table tableBtn) {
// rect
stroke(WHITE);
noFill();
println("------------------------------------");
// headline
printlnTableHeadline(tableBtn);
// grid
// loop over rows (y)
for (int i=0; i<tableBtn.getRowCount(); i++) {
// current data row
TableRow row = tableBtn.getRow(i);
// loop over columns in that row (i2 is for x)
String s1="";
for (int i2=0; i2<tableBtn.getColumnCount(); i2++) {
s1+=" "+row.getString(i2);
//
}//for
println(s1);
}//for
println("===========================================");
//
} // method
void printlnTableHeadline(Table tableBtn ) {
// headline for table
TableRow row0 = tableBtn.getRow(0);
for (int i=0; i<tableBtn.getColumnCount(); i++) {
// headline
print(" "+row0.getColumnTitle(i));
}
println("");
}//method
// ------------------------------------------------------------------
String cursorSign() {
// blinking cursor sign | for Input Box
if (frameCount % 13 == 0)
cursorSignShowFlag= ! cursorSignShowFlag;
if (cursorSignShowFlag)
return"|";
else return"";
}//method
//
}//class
//