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 & HelpIntegration › application window size
Page Index Toggle Pages: 1
application window size (Read 1293 times)
application window size
Aug 21st, 2008, 4:51pm
 
Hi,

Currently in the final stage of the little program i'm working on. So far i can export an application with two tabs (comes from ctrlP5) without titlebar and being able to set the application's screen location.

Now i'm stuck with:

How to limit the size of the application to something like 90px width and 16 px height?

Right now,  When exporting i only have a square and the sketch inside this grey square.

How to move the application when mouse is dragged according to mouse location ?

Only manadge a weird behavior right now.

here's my setup:

Quote:
void setup(){
  this.frame.setResizable(true);
  this.frame.setSize(90, 16);
  this.frame.setAlwaysOnTop(true);
  this.frame.setUndecorated(true);
  background(0);
  fill(0);
  smooth();
  copypaste= new CopyPaste();
  PRAunis = loadStrings("PRAunis.txt", "ISO-8859-1");
  PRSherpa = loadStrings("PRSherpa.txt", "ISO-8859-1");
  guiInit();
}



I know it's not so difficult but it's hard to deal with that for me inside of my working environment. And have absolutely no time at home theses days
Re: application window size
Reply #1 - Aug 21st, 2008, 5:33pm
 
You'll have to use the mousePressed() and mouseDragged() functions to do this.  You can use getLocationScreen() to find out where the screen is and then use setLocation() to adjust based on mouse movement.  Something like:

Code:

int offsetX, offsetY;

void mousePressed() {
offsetX = mouseX;
offsetY = mouseY;
}

void mouseDragged() {
Point p = frame.getLocationOnScreen();
frame.setLocation(p.x+mouseX-offsetX,p.y+mouseY-offsetY);
}


should work for you.  Also, if you want to remove the gray box, just put setSize() in draw().  This may be a hack(?), but it works. .  and don't forget to include size(90,16) in setup().

Code:

void draw() {
this.frame.setSize(90, 16);
}

Re: application window size
Reply #2 - Aug 21st, 2008, 6:17pm
 
Thx dan,

The above work.
One problem remain, as i'm initialising the gui with the guiInit() function which is in setup() one. Adding this.frame.setSize(width, height); in draw get rid of the gui.

Actually i can make it work calling guiInit() inside draw But i'm sure it's the most efficient way to do that.

edit: Hum i have to think about the way i used function i'm not sure i did it the best way.

I didn't knew about the getLocation thx for pointing this out. The window still acting weird trough. I have to figure why.

edit 3: it works specifying noLoop in setup().
Re: application window size
Reply #3 - Aug 21st, 2008, 9:23pm
 
I'd recommend that you still use the size() method to set at least an initial size.

For the rest of it, this is a Java issue with regards to how components are laid out. I recommend spending more time with the Sun tutorials that cover that sort of thing. For instance, some AWT calls aren't gonna be happy when they're run from the Processing Animation Thread instead of the EDT. That's why you're getting inconsistent results.
Re: application window size
Reply #4 - Aug 29th, 2008, 3:36pm
 
Hi,

Many thanks for your answers.

Do you refer to http://java.sun.com/docs/books/tutorial/uiswing/components/toplevel.html ?


Re: application window size
Reply #5 - Aug 29th, 2008, 5:06pm
 
I'm facing two major problem atm.

The moving method suggested works very well when i set noLoop in setup(). But with noLoop the interface (controlP5 tab) doesn't higligh when mouse is hover and doesn't flash when mouse is pressed.

The interface behave correctly if i omit noLoop() but the controlP5 library is loaded at each draw() call so that the application is getting slow. And the component move oddly (certainly due to the issue ben pointed me out).


Here's the source code as i'm sure there could be a lot better. Any suggestion for enhancement would be very appreciated.

PreRequisGUI.pde
Quote:
import controlP5.*;
import java.awt.datatransfer.*;

int offsetX, offsetY =0;
boolean CopySherpa, CopyAunis = false;
boolean Movable = false;
String PRAunis[], PRSherpa[];
String PRAunisString, PRSherpaString;
ControlP5 ctrlP5;
CopyPaste copypaste;

/*
static public void main(String args[]) {
PApplet.main(new String[] {
"--location=800,0", "PreRequisGUI"
}
);
}
*/

void setup(){
 size(100, 16);
 copypaste= new CopyPaste();
 PRAunis = loadStrings("PRAunis.txt", "ISO-8859-1");
 PRSherpa = loadStrings("PRSherpa.txt", "ISO-8859-1");
 background(0);
 fill(0);
 smooth();
 guiInit();
 this.frame.setResizable(true);
 this.frame.setAlwaysOnTop(true);
 this.frame.setUndecorated(true);
 //noLoop();
}

void draw(){
 this.frame.setSize(width, height);
 guiInit();
}

void getTabContent(){
 if (CopyAunis){
   PRAunisString = join(PRAunis, "\r\n");
   copypaste.sendString(PRAunisString);
   println(PRAunisString);
   CopyAunis = !CopyAunis;
 }
 if (CopySherpa){
   PRSherpaString = join(PRSherpa, "\r\n");
   copypaste.sendString(PRSherpaString);
   println(PRSherpaString);
   CopySherpa = !CopySherpa;
 }
}

void mousePressed(){
 offsetX = mouseX;
 offsetY = mouseY;
 getTabContent();
}

void mouseDragged(){  
 this.frame.setCursor(Cursor.MOVE_CURSOR);
 Point p = frame.getLocationOnScreen();
 this.frame.setLocation(p.x+mouseX-offsetX,p.y+mouseY-offsetY);
}

void mouseReleased(){
 this.frame.setCursor(Cursor.DEFAULT_CURSOR);
}

void controlEvent (ControlEvent theEvent){
 if (theEvent.isTab()) {
   println("tab : "+theEvent.tab().id()+" / "+theEvent.tab().name()+" /"+theEvent.tab().stringValue());
   switch(theEvent.tab().id()){
   case 0:
     CopyAunis = true;
     break;
   case 1:
     CopySherpa = true;
     break;
   }
 }
}


GUI.pde
Quote:
void guiInit(){
 ctrlP5 = new ControlP5(this);
 ctrlP5.remove("default");
 Tab AunisTab = ctrlP5.addTab("Aunis");
 Tab SherpaTab = ctrlP5.addTab("Sherpa");
 AunisTab.setId(0);
 SherpaTab.setId(1);
 AunisTab.setWidth(50);
 SherpaTab.setWidth(50);
 AunisTab.activateEvent(true);
 SherpaTab.activateEvent(true);
 ctrlP5.update();
}


The other two tabs doesn't really matter with my current problems.

Best regards,
O.
Page Index Toggle Pages: 1