0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Processing / ControlP5 > C++ BuilderのTMemoに相当するものを実装

Last updated at Posted at 2016-07-19
動作環境
Processing 3.1.1 on Windows 8.1 pro(64bit)
ControlP5 v2.2.6

欲しい機能

C++ BuilderのTMemoのように、複数行のテキスト表示機能が欲しい。
テキストの行数が多くなった時点で、上の行が消えて新規の行が追加されるという機能。

ProcessingやControlP5関連でAPIを探したが、それらしいものを見つけられなかったので実装してみた。

code

split()という関数があったので、それを使った。

import controlP5.*;

String dispLabel = "";
int count = 0;

void setup() {
  size(700,400);
  frameRate(1);
}

String suppressToNLines(String srcstr, int nlines)
{
  String[] wrk = split(srcstr, '\n');
  int loop = min(wrk.length, nlines + 1);
  
  int strt = 0;
  if ( wrk.length == (nlines + 1) ) {
     strt = 1; 
  }
  
  println(loop);
  
  String res = "";
  for(int idx = strt; idx < loop; idx++) {
    if (res.length() > 0) {
      res = res + '\n';
    }
    res = res + wrk[idx];
  }
  return res;
}

void draw() {
  background(255);
  count++;
  
  if (dispLabel.length() > 0) {
    dispLabel = dispLabel + "\r\n";
  }
  dispLabel = dispLabel + str(count);
  dispLabel = dispLabel + "  3.14  2.718  6.022  1023";
  dispLabel = suppressToNLines(dispLabel, /*nlines=*/5);

  if (dispLabel.length() > 0) {
    fill(50);
    text(dispLabel, 10, 10, 700, 80);
  }
}

結果

それなりに動いている気がする。

qiita.png

qiita.png

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?