// width more than just one letter on it class CustomKey { PImage[] up; PImage[] down; CapsFont f; PImage upimg; PImage downimg; CustomKey(CapsFont font) { upimg = managedRequestImage("keyup.gif"); downimg = managedRequestImage("keydown.gif"); f = font; inited = false; } boolean inited; void init() { up = new PImage[3]; down = new PImage[3]; int mid = upimg.width/2; up[0] = upimg.get(0,0,mid,upimg.height); up[1] = upimg.get(2,0,6,upimg.height); up[2] = upimg.get(mid,0,upimg.width-mid,upimg.height); down[0] = downimg.get(0,0,mid,downimg.height); down[1] = downimg.get(2,0,6,downimg.height); down[2] = downimg.get(mid,0,downimg.width-mid,downimg.height); inited = true; } void Draw(float xpos, float ypos, String words, boolean isUp, int s) { if (!inited) init(); int len = words.length() - 1; if (isUp) { for (int i = 0; i < len; i++) { image(up[1], xpos+up[0].width*s+i*up[1].width*s, ypos, up[1].width*s, up[1].height*s); } image(up[0], xpos, ypos, up[0].width*s, up[0].height*s); image(up[2], xpos+up[0].width*s+len*up[1].width*s, ypos, up[2].width*s, up[2].height*s); } else { for (int i = 0; i < len; i++) { image(down[1], xpos+down[0].width*s+i*down[1].width*s, ypos, down[1].width*s, down[1].height*s); } image(down[0], xpos, ypos, down[0].width*s, down[0].height*s); image(down[2], xpos+down[0].width*s+len*down[1].width*s, ypos, down[2].width*s, down[2].height*s); } int off = 2; if (!isUp) off = 3; f.Draw(xpos + off*s, ypos + off*s, words, s); } }