G4P library - Is there a way to make big letters on numbers?


#1

I am building a touch tablet interface for a robotic arm. It seems that the G4P library is the only one to respond to touch as a mouse click. That is nice, thank you author.

However the buttons have very small writing , even when bold.
Is there a way to make bigger fonts? I would rather not load pics for each button.
Tried that and it was a pain, no documentations or examples of how to do it?

Thanks

15%20PM


#2

Glad you like G4P :grinning:

The sketch below shows how you can change the font, font style and size for a GButton. Just be careful that you make the button big enough in the constructor to display the text.

import g4p_controls.*;
import java.awt.Font;

GButton btn;

void setup() {
  size(300, 200);
  btn = new GButton(this, 80, 40, 120, 40);
  btn.setText("STOP");
  btn.setFont(new Font("Arial", Font.BOLD, 30));
}

void draw() {
  background(200, 200, 255);
}

#3

Peter
Thanks for the reply, here is what I did in the public void createGUI() function

HOME = new GButton(this, 1520, 816, 250, 100);
HOME.setFont(new Font(“Arial”, Font.BOLD, 70));
HOME.setText(“HOME”);
HOME.setTextBold();

I ran it and the fonts are big and nice.
However the moment I move or resize the HOME button, all the text formating gets erased.
I am planning to have about 15 buttons that I will arrange for a while on the screen.
It will be very difficult to re-enter the text line every time.

Any ideas?


#4

What methods are you using to move resize the button?


#5

I open the GP4 Gui builder from tools.
Then I drag and drop the buttons. Etc
Should I try something else?


#6

Also is there a way to have a delay in the action of the button?
I tried
public void button2_click2(GButton source, GEvent event) { //CODE:Send:350849:
streamer.send(BeforeSending.toString()); ///Sent step button
BeforeSending = “”;
fill(o);
textFont(font, 130);

text( “SENT”, 1250, 150);
delay (1000);

} //CODE:Send:350849:

Hoping to have the word SENT linger about a sec on the screen as a confirmation…
It flashes for a mS only


#7

I didn’t realize you were using GUI Builder. Note that the comments in the gui tab, you must not alter the contents of the createGUI() method any additional code needed to modify the controls should be in the custonGUI() method. The following sketch was created with GUI Builder and shows how to do it.

Main Tab

// Need G4P library
import g4p_controls.*;
import java.awt.Font;

public void setup() {
  size(300, 200, JAVA2D);
  createGUI();
  customGUI();
  // Place your setup code here
}

public void draw() {
  background(230);
}

// Use this method to add additional statements
// to customise the GUI controls
public void customGUI() {
  btn.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 40));
}

gui Tab

/* =========================================================
 * ====                   WARNING                        ===
 * =========================================================
 * The code in this tab has been generated from the GUI form
 * designer and care should be taken when editing this file.
 * Only add/edit code inside the event handlers i.e. only
 * use lines between the matching comment tags. e.g.

 void myBtnEvents(GButton button) { //_CODE_:button1:12356:
     // It is safe to enter your event code here  
 } //_CODE_:button1:12356:
 
 * Do not rename this tab!
 * =========================================================
 */

public void btn_click(GButton source, GEvent event) { //_CODE_:btn:877482:
  println("btn - GButton >> GEvent." + event + " @ " + millis());
} //_CODE_:btn:877482:

// Create all the GUI controls. 
// autogenerated do not edit
public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setCursor(ARROW);
  surface.setTitle("Sketch Window");
  btn = new GButton(this, 10, 10, 250, 60);
  btn.setText("Click Me!");
  btn.addEventHandler(this, "btn_click");
}

// Variable declarations 
// autogenerated do not edit
GButton btn; 

#8

OK you are not trying to delay the action of the button you are trying to get the text to stay on the screen for a short time. These are 2 very different things!

Having said that G4P can help because it has a means for grouping controls and then fading them in an out. This sketch is a modified version of the one above when the button is clicked a message will appear for 2 seconds and fade out over the next half second. It uses the GGroup class which can hold 1 or more controls that can be faded in and out as a group.

Main Tab

// Need G4P library
import g4p_controls.*;
import java.awt.Font;

GGroup grp;

public void setup() {
  size(300, 200, JAVA2D);
  createGUI();
  customGUI();
  // Place your setup code here
}

public void draw() {
  background(230);
}

// Use this method to add additional statements
// to customise the GUI controls
public void customGUI() {
  // Set button font
  btn.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 40));
  // Create group
  grp = new GGroup(this);
  // Set label font
  lbl.setFont(new Font("Times New Roman", Font.PLAIN, 30));
  // Add label to group
  grp.addControl(lbl);
  // Hide the group - fade to invisible (alpha = 0)
  grp.fadeOut(0, 0);
}

guiTab

/* =========================================================
 * ====                   WARNING                        ===
 * =========================================================
 * The code in this tab has been generated from the GUI form
 * designer and care should be taken when editing this file.
 * Only add/edit code inside the event handlers i.e. only
 * use lines between the matching comment tags. e.g.
 
 void myBtnEvents(GButton button) { //_CODE_:button1:12356:
 // It is safe to enter your event code here  
 } //_CODE_:button1:12356:
 
 * Do not rename this tab!
 * =========================================================
 */

public void btn_click(GButton source, GEvent event) { //_CODE_:btn:877482:
  println("Show message");
  grp.fadeIn(0, 10); // Fade in fast
  grp.fadeOut(2000, 500); // After 2 seconds fade out over a 0.5second period
} //_CODE_:btn:877482:



// Create all the GUI controls. 
// autogenerated do not edit
public void createGUI() {
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setCursor(ARROW);
  surface.setTitle("Sketch Window");
  btn = new GButton(this, 10, 10, 250, 60);
  btn.setText("Click Me!");
  btn.addEventHandler(this, "btn_click");
  lbl = new GLabel(this, 10, 90, 250, 60);
  lbl.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  lbl.setText("STARTING");
  lbl.setOpaque(false);
}

// Variable declarations 
// autogenerated do not edit
GButton btn; 
GLabel lbl; 

#9

I am happy to just use

public void customGUI() {
  btn.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 40));
}

I made many entries, one for each button, and they work fine. I rather keep it simple.
However: I wish I could change the font.
I tried even no font
HOME.setFont(new Font(“AgencyFB-Bold-200”, Font.BOLD, 70));
Send.setFont(new Font("", Font.BOLD, 70));

But your standard font still shows. Size is right.

Thanks

Did not work on the delay yet… Thanks for that advice


#10
new Font("Arial", Font.BOLD | Font.ITALIC, 40)

The first parameter is the font name. This only works correctly if the font is installed on your computer. If the sketch can’t find the font it will use the system default and then apply the style (second parameter) and font size (third parameter).

This is why I selected Arial because it is installed on virtually all computers. You can also try “Times New Roman” and “Courier” or “Courier New” as these should be installed on your computer.

I created this using a font called “Blood Of Dracula” bet you don’t have that on your computer. :grinning:
39