Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

74
LINES

< > BotCompany Repo | #1007338 // class Smiley - AWT smiley

JavaX fragment (include)

sclass Smiley {
  double zoom = 0.5;
  S imageID = #1007256;
  S rectsDef = [[ [Rect(h=415, w=392, x=104, y=168), Rect(h=420, w=393, x=552, y=168), Rect(h=414, w=392, x=1008, y=168), Rect(h=416, w=392, x=1448, y=168), Rect(h=416, w=400, x=112, y=640), Rect(h=416, w=392, x=560, y=640), Rect(h=424, w=400, x=1000, y=632), Rect(h=421, w=393, x=1447, y=632), Rect(h=419, w=400, x=112, y=1112), Rect(h=416, w=392, x=560, y=1112), Rect(h=416, w=392, x=1000, y=1112), Rect(h=424, w=394, x=1446, y=1104), /* the gray one: Rect(h=422, w=393, x=1447, y=1576),*/ Rect(h=420, w=400, x=96, y=1584), Rect(h=420, w=400, x=552, y=1583), Rect(h=416, w=392, x=1000, y=1584)] ]];

  Map<Int, S> names = littreemap(
    1, "happy",
    2, "sad",
    3, "extremely happy",
    4, "happy with tongue",
    5, "whaaat",
    6, "crying",
    7, "shocked",
    8, "worried",
    9, "winking",
    10, "closed eyes",
    11, "uuuhm",
    12, "super-lol",
    13, "oooh",
    14, "angry",
    15, "disappointed"
  );

  ImageSurface is;
  BufferedImage bi;
  Pt size;
  L<Rect> theRects;
  int currentEmotion;
  
  *() {
    bi = loadImage2(imageID);
    theRects = (L<Rect>) unstructure(rectsDef);
    size = ceilScalePt(rectsMaxSize(theRects), zoom);
  }
  
  int emotionToIndex(S s) {
    if "random" ret random(l(theRects))+1;
    for (int i : keys(names))
      if (match(names.get(i), s))
        ret i;
    ret 0;
  }
  
  JFrame show() {
    emotion(currentEmotion != 0 ? currentEmotion : 1);
    ret getFrame(is);
  }
  
  bool showing() { ret getFrame(is) != null; }
  
  void hide {
    disposeFrame(is);
    is = null;
  }
  
  void emotion(S s) {
    emotion(emotionToIndex(s));
  }
  
  void emotion(int _i) {
    final int i = max(1, min(l(theRects), _i));
    swing {
      if (i != currentEmotion) {
        bool first = is == null;
        currentEmotion = i;
        Rect r = theRects.get(i-1);
        is = showZoomedImage_centered(is, clipBufferedImage(bi, r), zoom);
        setFrameTitle(is, names.get(i));
        if (first)
          moveToTopRightCorner(frameInnerSize(size, getFrame(is)));
      }
    }
  }
}

Author comment

Began life as a copy of #1007266

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1007338
Snippet name: class Smiley - AWT smiley
Eternal ID of this version: #1007338/16
Text MD5: 7627af7ab4d34d44ea0eae559e10f710
Author: stefan
Category: javax / a.i. / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-24 18:11:07
Source code size: 2183 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 462 / 1085
Version history: 15 change(s)
Referenced in: [show references]