1
1
import obspython as obs
2
- from mouse import get_position # python -m pip install mouse
2
+ from pynput . mouse import Controller # python -m pip install pynput
3
3
4
- __version__ = "0.3.0-alpha"
5
- REFRESH_RATE = 15
6
- FLAG = True
4
+ c = Controller ()
5
+ get_position = lambda : c .position
6
+
7
+ __version__ = "1.0.0"
7
8
8
9
9
10
def apply_scale (x , y , width , height ):
@@ -13,16 +14,12 @@ def apply_scale(x, y, width, height):
13
14
14
15
15
16
class CursorAsSource :
16
- def __init__ (self , source_name = None ):
17
- self .source_name = source_name
18
- self .lock = True
19
- self .update_xy = False
20
- self .update_gs = False # green screen
21
- self .update_cr = False
17
+ source_name = None
18
+ lock = True
19
+ flag = True
20
+ refresh_rate = 15
22
21
23
22
def update_cursor (self ):
24
- """ in script settings check update cursor"""
25
-
26
23
source = obs .obs_get_source_by_name (self .source_name )
27
24
settings = obs .obs_data_create ()
28
25
if source is not None :
@@ -48,58 +45,14 @@ def update_cursor(self):
48
45
obs .obs_scene_release (scene )
49
46
obs .obs_source_release (source )
50
47
51
- def update_green (self ):
52
- """
53
- create new scene with name:__spotlight__
54
- add color source , add opacity(color correction) to that source
55
- add green circle
56
- add that scene as source to ur current scene
57
- apply chromakey filter to that source
58
- in script settings check update green
59
- """
60
- source = obs .obs_get_source_by_name (self .source_name )
61
- settings = obs .obs_data_create ()
62
- if source is not None :
63
- scene_width = obs .obs_source_get_width (source )
64
- scene_height = obs .obs_source_get_height (source )
65
- # get all scenes
66
- scenes = obs .obs_frontend_get_scenes ()
67
- for sc in scenes :
68
- # select the one with chromakey cursor(green)
69
- name = obs .obs_source_get_name (sc )
70
- if name == "__spotlight__" :
71
- # assign it
72
- _item = sc
73
- else :
74
- obs .obs_source_release (sc )
75
-
76
- scene = obs .obs_scene_from_source (_item )
77
- scene_item = obs .obs_scene_find_source (scene , self .source_name )
78
- if scene_item :
79
- scale = obs .vec2 ()
80
- obs .obs_sceneitem_get_scale (scene_item , scale )
81
- scene_width , scene_height = apply_scale (
82
- scale .x , scale .y , scene_width , scene_height
83
- )
84
- next_pos = obs .vec2 ()
85
- next_pos .x , next_pos .y = get_position ()
86
- next_pos .x -= scene_width / 2
87
- next_pos .y -= scene_height / 2
88
- # set position to center of source where cursor is
89
- obs .obs_sceneitem_set_pos (scene_item , next_pos )
90
-
91
- obs .obs_data_release (settings )
92
- obs .obs_scene_release (scene )
93
- obs .obs_source_release (source )
94
-
95
48
def update_crop (self ):
96
49
"""
97
50
Create 2 display captures.
98
51
Create crop filter with this name: cropXY.
99
52
Check relative.
100
53
Set Width and Height to relatively small numbers e.g : 64x64 .
101
54
Image mask blend + color correction might be an option too.
102
- Run script,select this source as cursor source , check Update crop and updated cursor , click start.
55
+ Run script,select this source as cursor source , check Update crop, click start.
103
56
"""
104
57
source = obs .obs_get_source_by_name (self .source_name )
105
58
crop = obs .obs_source_get_filter_by_name (source , "cropXY" )
@@ -125,54 +78,42 @@ def ticker(self):
125
78
if self .update_xy :
126
79
self .update_crop ()
127
80
self .update_cursor ()
128
- if self .update_gs :
129
- self .update_green ()
130
- if self .update_cr :
81
+ else :
131
82
self .update_cursor ()
132
83
133
84
if not self .lock :
134
85
obs .remove_current_callback ()
135
86
136
87
137
- py_cursor = CursorAsSource () # class created ,obs part starts
88
+ py_cursor = CursorAsSource ()
138
89
139
90
140
91
def stop_pressed (props , prop ):
141
- global FLAG
142
- FLAG = True
92
+ py_cursor .flag = True
143
93
py_cursor .lock = False
144
94
145
95
146
96
def start_pressed (props , prop ):
147
- global FLAG # to keep only one timer callback
148
- if py_cursor .source_name != "" and FLAG :
149
- obs .timer_add (py_cursor .ticker , REFRESH_RATE )
97
+ if py_cursor .source_name != "" and py_cursor .flag :
98
+ obs .timer_add (py_cursor .ticker , py_cursor .refresh_rate )
150
99
py_cursor .lock = True
151
- FLAG = False
152
-
153
-
154
- def script_description ():
155
- return "USE SOURCE AS CURSOR"
100
+ py_cursor .flag = False # to keep only one timer callback
156
101
157
102
158
103
def script_defaults (settings ):
159
- global REFRESH_RATE
160
- obs .obs_data_set_default_int (settings , "refresh_rate" , REFRESH_RATE )
104
+ obs .obs_data_set_default_int (settings , "_refresh_rate" , py_cursor .refresh_rate )
161
105
162
106
163
107
def script_update (settings ):
164
- global REFRESH_RATE
165
108
py_cursor .update_xy = obs .obs_data_get_bool (settings , "bool_yn" )
166
- py_cursor .update_xy = obs .obs_data_get_bool (settings , "bool_yn_cursor" )
167
- py_cursor .update_gs = obs .obs_data_get_bool (settings , "bool_yn_green" )
168
109
py_cursor .source_name = obs .obs_data_get_string (settings , "source" )
169
- REFRESH_RATE = obs .obs_data_get_int (settings , "refresh_rate " )
110
+ py_cursor . refresh_rate = obs .obs_data_get_int (settings , "_refresh_rate " )
170
111
171
112
172
- def script_properties (): # ui
113
+ def script_properties ():
173
114
props = obs .obs_properties_create ()
174
115
number = obs .obs_properties_add_int (
175
- props , "refresh_rate " , "Refresh rate (ms)" , 15 , 300 , 5
116
+ props , "_refresh_rate " , "Refresh rate (ms)" , 15 , 300 , 5
176
117
)
177
118
p = obs .obs_properties_add_list (
178
119
props ,
@@ -191,6 +132,4 @@ def script_properties(): # ui
191
132
obs .obs_properties_add_button (props , "button" , "Stop" , stop_pressed )
192
133
obs .obs_properties_add_button (props , "button2" , "Start" , start_pressed )
193
134
obs .obs_properties_add_bool (props , "bool_yn" , "Update crop" )
194
- obs .obs_properties_add_bool (props , "bool_yn_green" , "Update green circle" )
195
- obs .obs_properties_add_bool (props , "bool_yn_cursor" , "Update cursro " )
196
135
return props
0 commit comments