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

101
LINES

< > BotCompany Repo | #1033194 // Live WebCam On Top [Dyn Module]

JavaX source code (Dynamic Module) [tags: new-tfs use-pretranspiled] - run with: Stefan's OS

Uses 3730K of libraries. Click here for Pure Java version (15103L/77K).

!7

cm LiveWebCamOnTop > DynSCP {
  transient WebcamPanel panel;
  int fpsLimit = -1;
  switchable bool autoStart;
  switchable bool showFPS;
  switchable int height = 240;
  switchable int posX;
  switchable int posY;

  void cleanMeUp_panel {
    stopIt();
  }
  
  start {
    dm_onFieldChange(ll("height", "posX", "posY"), r updatePanelSize);
    if (autoStart)
      thread { startIt(); }
  }
  
  enhanceFrame {
    internalFramePopupMenuItem(f, "Save to AI Album",
      rThread { dm_saveToAIAlbum(getImage()) });
    internalFramePopupMenuItem(f, "Set FPS...", r {
      final JTextField tf = jtextfield(str(fpsLimit));
      showFormTitled("Set FPS Limit",
        "FPS Limit (-1 for no limit, 0 for no updates):", tf,
        rThread { setFPSLimit(parseInt(gtt(tf))) });
    });
  }

  JComponent visualize2() {
    ret panel != null
      ? jcenteredbutton("Stop", rThread stopIt)
      : jcenteredbutton("Start", rThread startIt);
  }
  
  void updatePanelSize() swing {
    var window = getWindow(panel);
    if (panel == null || window == null) ret;
    int h = height;
    var pref = getPreferredSize(panel);
    int w = widthForHeight(pref.getWidth(), pref.getHeight(), h);
    int x1 = screenWidth()-w+posX, y1 = posY;
    setWindowBounds(panel, x1, y1, w, h);
    alwaysOnTop(panel);
  }
  
  void startIt enter {
    selectWebCam(vf<Webcam> selectCam);
  }
  
  void startPreferredOrSelect {
    selectWebCam_withPreferred(vf<Webcam> selectCam);
  }
  
  void selectCam(Webcam cam) swing {
    enter;
    if (panel != null) ret;
    WebcamPanel panel = new(cam, false);
    onClick(panel, r { dm_activateOSAndModule(me()) });
    LiveWebCamOnTop.this.panel = panel;
    bindToComponent(panel, null, r { panel.stop() });
    updateFPSLimitInPanel();
    showInTopRightCorner(panel);
    updatePanelSize();
    revisualize2(); // show stop button
  }
  
  void stopIt swing {
    if (panel == null) ret;
    disposeWindow(panel);
    dispose panel;
    revisualize2(); // show start button again
  }
  
  BufferedImage getImage() {
    ret imageFromWebcamPanel(panel);
  }
  
  void setFPSLimit(int limit) {
    setField(fpsLimit := limit);
    updateFPSLimitInPanel();
  }
  
  void updateFPSLimitInPanel swing {
    setModuleName((fpsLimit >= 0 ? fpsLimit + " FPS - " : "") + "Live WebCam");
    if (panel == null) ret;
    panel.stop();
    if (fpsLimit == 0) ret; // TODO - want to keep last image there anyway
    panel.setFPSDisplayed(showFPS && fpsLimit < 0);
    if (fpsLimit > 0) panel.setFPSLimit(fpsLimit);
    panel.setFPSLimited(fpsLimit > 0);
    panel.start();
  }
  
  bool isWebCamLive() {
    ret panel != null && fpsLimit != 0;
  }
}

Author comment

Began life as a copy of #1016673

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

-
Snippet ID: #1033194
Snippet name: Live WebCam On Top [Dyn Module]
Eternal ID of this version: #1033194/20
Text MD5: 4d27dc0b5b39afd167b24d8f0a5e9e15
Transpilation MD5: f4d61f503f2fe101c9bfcf47f9c76be4
Author: stefan
Category: javax / desktop / camera
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-11-01 20:36:56
Source code size: 2669 bytes / 101 lines
Pitched / IR pitched: No / No
Views / Downloads: 180 / 900
Version history: 19 change(s)
Referenced in: