LoginSignup
16
17

More than 5 years have passed since last update.

Processing 3.0で実行中にwindowのsizeの変更やタイトルバーを非表示にする方法

Last updated at Posted at 2015-11-15

processing3.0になってvoid setup(){}内でしかsize()の設定ができなくなったり、windowのタイトルバーを非表示にするframe.setUndecorated(true)がそのまま書くと「fullscreen()を使え」的なerrorが出るから
processing2.0の時に書いたコードが使用できなくなってる... orz

そこでマルチディスプレイにフルスクリーンサイズにしたりサイズをランダムに変更できるようにprocessing3.0仕様に書き換えたのがこれ

size_change.pde
import processing.awt.PSurfaceAWT;

void setup(){
  //windowサイズの初期化
 surface.setResizable(true); 
}

void draw(){
  background(#FFFFFF);

}
void keyPressed() {
  if ( (key == 'a')) {
    //smoothCanvas.getFrame()関連のメソッドを使えるようにする

    PSurfaceAWT awtSurface = (PSurfaceAWT)surface;
    PSurfaceAWT.SmoothCanvas smoothCanvas = (PSurfaceAWT.SmoothCanvas)awtSurface.getNative();

    smoothCanvas.getFrame().setAlwaysOnTop(true);
    smoothCanvas.getFrame().removeNotify();

    //タイトルバー非表示
    smoothCanvas.getFrame().setUndecorated(true);

    //マルチディスプレイ用にsetLocation(x,y);のパラメータのxをマイナスにする
    smoothCanvas.getFrame().setLocation(-1368, 0);
    smoothCanvas.getFrame().addNotify();

    // //window上で"左クリック+a"でフルスクリーンサイズ
    smoothCanvas.getFrame().setSize(1368,720);



}

 if ((keyPressed == true) && (key == 'b')){
    PSurfaceAWT awtSurface = (PSurfaceAWT)surface;
    PSurfaceAWT.SmoothCanvas smoothCanvas = (PSurfaceAWT.SmoothCanvas)awtSurface.getNative();
    smoothCanvas.getFrame().setAlwaysOnTop(true);
    smoothCanvas.getFrame().removeNotify();
    smoothCanvas.getFrame().setUndecorated(true);
    smoothCanvas.getFrame().setLocation(-1368, 0);
    smoothCanvas.getFrame().addNotify();

    //window上で"左クリック+b"でランダムにwindowサイズが変更する
    smoothCanvas.getFrame().setSize(round(random(100, 500)), round(random(100, 500)));


  }
 }

左クリック+Aでフルスクリーン
左クリック+Bでランダムにサイズ変更できます

ちなみにマルチディスプレイを使わないでPC単体の場合は

smoothCanvas.getFrame().setLocation(-1368, 0); 
のところを
smoothCanvas.getFrame().setLocation(0, 0); 
とパラメーターを変えて下さい

16
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17