We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Text Help Required
Page Index Toggle Pages: 1
Text Help Required (Read 317 times)
Text Help Required
Mar 21st, 2009, 12:36am
 
Hi,

I am working on a project visualizing football player movement in Europe. I would like text to appear on the bottom right of the output screen when mousing over each dot on my map which represents a city. For example, when mousing over London, some text to appear on the screen saying 'London, UK'.

The names, and X/Y positions of each city are contained in a TSV file. I have set up an array and specified that when the mouse cursor is within a certain amount of pixels from the dot it will find the relavant information from the TSV and print it. At present this information only appears in the text area within processing but I would like to display this properly.

If anyone could help me out or suggest a better way of doing this I would be really grateful.

The entire sketch folder can be found here: https://rcpt.yousendit.com/666493835/0465ff54c0bf7c51c54c297b216bb2e8
Re: Text Help Required
Reply #1 - Mar 21st, 2009, 9:05am
 
You have to look at the Typography section of the Reference. Particularly createFont, textFont and text function.
Re: Text Help Required
Reply #2 - Mar 22nd, 2009, 1:00pm
 
I did look at the text examples, and im ok with getting words to appear on the screen, but im pretty much a beginner to this so am finding it hard to transfer what I have managed to get the program to generate in the text box, onto the screen itself and to select a position in which it will generate it (ideally, bottom right).

I think the function I am looking for is ToolTip?
Re: Text Help Required
Reply #3 - Mar 22nd, 2009, 2:09pm
 
looking at the  text examples should have answered all your questions... anyway, here it is...



PImage mapImage;
Table locationTable;
Table connTable;
int rowCount;
int transCount;
int x1, x2, y1, y2;
int mapWidth = 600;
int mapHeight = 563;
boolean reFresh = false;
PFont myFont;

String[] Locs = new String[mapWidth * mapHeight];


void setup() {
 size(mapWidth, 563);
 rectMode(CORNER);
  myFont = createFont("Arial", 14);
 textFont(myFont);
 mapImage = loadImage("europe_plastic.png");
 //Make a data table from a file that contains
 //the coordinates of each country.
 locationTable = new Table("locations20072009.tsv");
 connTable = new Table("conns20072009.tsv");
 // The row count will be used a lot, so store it globally.
 rowCount = locationTable.getRowCount();
 transCount = connTable.getRowCount();
 
 print("tranfers ="+transCount);
 
 for (int L = 0; L < (mapWidth * mapHeight); L++) {
   Locs[L] ="                ";  // clear out array
 }
 

}



void draw() {
   
   if ( reFresh == false){
     drawMap();
     reFresh = true;
   }
   
   if (Locs[(mouseY * mapWidth)+ mouseX].equals("                ") == false){
     //print("Location ="+ Locs[(mouseY * mapWidth)+ mouseX] + "\n");

      noStroke();
      fill(255);
      rect(0,0,230,30);
      fill(0);
      text("Location: "+ Locs[(mouseY * mapWidth)+ mouseX] + "\n", 10,20);
 }

 }








 
void drawMap() {
   
   background(255);
   image(mapImage, 0, 0);
   
   //line(168, 335, 153, 312);
   
   //Drawing attributes for the ellipses.
   smooth();
   fill(192, 0, 0);
   //noStroke();
   
   // Loop through the rows of the locations file and draw the points.
   for (int row = 0; row < rowCount; row++) {
     int x = locationTable.getInt(row, 1);  // column 1
     int y = locationTable.getInt(row, 2);  // column 2
     
     
     // instead of a single point, make this a square 5 pix high x 5 pix wide
     Locs[(mapWidth*y)+x] = locationTable.getString(row, 0);  // column 0
     
     Locs[(mapWidth*y)+x-1] = locationTable.getString(row, 0);
     Locs[(mapWidth*y)+x+1] = locationTable.getString(row, 0);
     Locs[(mapWidth*(y-1))+x] = locationTable.getString(row, 0);
     //Locs[(mapWidth*(y+1))+x] = locationTable.getString(row, 0);
     
     // add loop writing Locs[(mapWidth*y)+x] = locationTable.getString(row, 0) to each cell in array
     
     ellipse(x, y, 5, 5);
     
   }
   
   
 
 
   // Loop through the rows of the conns file and draw the points.
   
   for (int row = 0; row < transCount; row++) {
     x1 = connTable.getInt(row, 1);  // column 1
     y1 = connTable.getInt(row, 2);  // column 2
     
     x2 = connTable.getInt(row, 3);  // column 1
     y2 = connTable.getInt(row, 4);  // column 2
     
     //line(x1, y1, x2, y2);
     
     noFill();
     stroke(0,0,0,64);
     strokeWeight(2);
     //alpha(20);
     bezier(x1, y1, x1, y1-30, x2, y2-30, x2, y2);
     
     
     
   }
 }
 
 


 
 
 
Re: Text Help Required
Reply #4 - Mar 22nd, 2009, 3:08pm
 
Thanks Cedric, thats been really helpful
Page Index Toggle Pages: 1