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).

1  
!7
2  
3  
cm LiveWebCamOnTop > DynSCP {
4  
  transient WebcamPanel panel;
5  
  int fpsLimit = -1;
6  
  switchable bool autoStart;
7  
  switchable bool showFPS;
8  
  switchable int height = 240;
9  
  switchable int posX;
10  
  switchable int posY;
11  
12  
  void cleanMeUp_panel {
13  
    stopIt();
14  
  }
15  
  
16  
  start {
17  
    dm_onFieldChange(ll("height", "posX", "posY"), r updatePanelSize);
18  
    if (autoStart)
19  
      thread { startIt(); }
20  
  }
21  
  
22  
  enhanceFrame {
23  
    internalFramePopupMenuItem(f, "Save to AI Album",
24  
      rThread { dm_saveToAIAlbum(getImage()) });
25  
    internalFramePopupMenuItem(f, "Set FPS...", r {
26  
      final JTextField tf = jtextfield(str(fpsLimit));
27  
      showFormTitled("Set FPS Limit",
28  
        "FPS Limit (-1 for no limit, 0 for no updates):", tf,
29  
        rThread { setFPSLimit(parseInt(gtt(tf))) });
30  
    });
31  
  }
32  
33  
  JComponent visualize2() {
34  
    ret panel != null
35  
      ? jcenteredbutton("Stop", rThread stopIt)
36  
      : jcenteredbutton("Start", rThread startIt);
37  
  }
38  
  
39  
  void updatePanelSize() swing {
40  
    var window = getWindow(panel);
41  
    if (panel == null || window == null) ret;
42  
    int h = height;
43  
    var pref = getPreferredSize(panel);
44  
    int w = widthForHeight(pref.getWidth(), pref.getHeight(), h);
45  
    int x1 = screenWidth()-w+posX, y1 = posY;
46  
    setWindowBounds(panel, x1, y1, w, h);
47  
    alwaysOnTop(panel);
48  
  }
49  
  
50  
  void startIt enter {
51  
    selectWebCam(vf<Webcam> selectCam);
52  
  }
53  
  
54  
  void startPreferredOrSelect {
55  
    selectWebCam_withPreferred(vf<Webcam> selectCam);
56  
  }
57  
  
58  
  void selectCam(Webcam cam) swing {
59  
    enter;
60  
    if (panel != null) ret;
61  
    WebcamPanel panel = new(cam, false);
62  
    onClick(panel, r { dm_activateOSAndModule(me()) });
63  
    LiveWebCamOnTop.this.panel = panel;
64  
    bindToComponent(panel, null, r { panel.stop() });
65  
    updateFPSLimitInPanel();
66  
    showInTopRightCorner(panel);
67  
    updatePanelSize();
68  
    revisualize2(); // show stop button
69  
  }
70  
  
71  
  void stopIt swing {
72  
    if (panel == null) ret;
73  
    disposeWindow(panel);
74  
    dispose panel;
75  
    revisualize2(); // show start button again
76  
  }
77  
  
78  
  BufferedImage getImage() {
79  
    ret imageFromWebcamPanel(panel);
80  
  }
81  
  
82  
  void setFPSLimit(int limit) {
83  
    setField(fpsLimit := limit);
84  
    updateFPSLimitInPanel();
85  
  }
86  
  
87  
  void updateFPSLimitInPanel swing {
88  
    setModuleName((fpsLimit >= 0 ? fpsLimit + " FPS - " : "") + "Live WebCam");
89  
    if (panel == null) ret;
90  
    panel.stop();
91  
    if (fpsLimit == 0) ret; // TODO - want to keep last image there anyway
92  
    panel.setFPSDisplayed(showFPS && fpsLimit < 0);
93  
    if (fpsLimit > 0) panel.setFPSLimit(fpsLimit);
94  
    panel.setFPSLimited(fpsLimit > 0);
95  
    panel.start();
96  
  }
97  
  
98  
  bool isWebCamLive() {
99  
    ret panel != null && fpsLimit != 0;
100  
  }
101  
}

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: 181 / 901
Version history: 19 change(s)
Referenced in: [show references]