Skip to content

Commit 9650127

Browse files
authored
Merge pull request #4 from 34700/master
uhhh idk what to put here
2 parents e02d2bd + d0d25bc commit 9650127

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1+
Fork by 3_4_700, original by upgradeQ
2+
The main purpose of this fork is to be able to make a precise custom cursor, like a handdrawn arm holding a pen for artists
3+
14
# OBS Studio Cursor skin
25
Selected source will follow mouse pointer.
36
Using [`obs_sceneitem_set_pos`](https://obsproject.com/docs/reference-scenes.html#c.obs_sceneitem_set_pos)
47
# Installation
5-
- Make sure your OBS Studio supports [scripting](https://obsproject.com/docs/scripting.html)
68
- Install pynput package from [pypi](https://pypi.org/project/pynput/)
9+
- Make sure your OBS Studio supports [scripting](https://obsproject.com/docs/scripting.html)
710
`python -m pip install pynput`
811
# Limitations
9-
- Multilpe monitors setup will not work .
12+
- Multiple monitors setup will not work .
1013
- If used in fullscreen apps, offset will appear.
14+
- Current code only works for 1920x1080 res
1115
# Usage
12-
- Create _source_ with desired cursor(e.g Image source or Media source).
16+
- Create a _source_ with desired cursor(e.g Image source or Media source).
1317
- In scripts select _that_ source name.
18+
- Make a group, add Display Capture, Window Capture
19+
20+
![img](https://i.imgur.com/CHuLwmp.png)
21+
22+
- To crop, crop the _group_, the size should still have the same ratio as your monitor even if you scale it
23+
- To set offset/calibrate, use the Display Capture to see mouse and adjust it at Scripts (or use Tab/Shift+tab to navigate if in Window Capture to not move mouse). You have to do this every time you change the Group scale/move the Group
24+
25+
![img](https://user-images.githubusercontent.com/66927691/121442471-56133280-c9be-11eb-9bb4-ad12b2e4ebfb.jpg)
26+
27+
![img](https://user-images.githubusercontent.com/66927691/121442809-f23d3980-c9be-11eb-954f-c0e635e95d88.jpg)
28+
29+
1430
- Test it: press Start, press Stop, tweak refresh rate.
1531
# Crop auto update
1632
Zoom or higlight.

mouse_skin_obs.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
c = Controller()
55
get_position = lambda: c.position
66

7+
78
__version__ = "1.0.0"
89

910

@@ -12,6 +13,9 @@ def apply_scale(x, y, width, height):
1213
height = round(height * y)
1314
return width, height
1415

16+
def lerp(minVal, maxVal, k):
17+
val = minVal + ((maxVal - minVal)*k)
18+
return val
1519

1620
class CursorAsSource:
1721
source_name = None
@@ -28,17 +32,31 @@ def update_cursor(self):
2832
scene_height = obs.obs_source_get_height(source)
2933
scene = obs.obs_scene_from_source(scene_source)
3034
scene_item = obs.obs_scene_find_source(scene, self.source_name)
35+
target_item = obs.obs_scene_find_source(scene, self.target_name)
3136
if scene_item:
3237
scale = obs.vec2()
3338
obs.obs_sceneitem_get_scale(scene_item, scale)
3439
scene_width, scene_height = apply_scale(
3540
scale.x, scale.y, scene_width, scene_height
3641
)
42+
3743
next_pos = obs.vec2()
3844
next_pos.x, next_pos.y = get_position()
39-
next_pos.x -= scene_width / 2
40-
next_pos.y -= scene_height / 2
41-
# set position to center of source where cursor is
45+
next_pos.x -= self.offset_x
46+
next_pos.y -= self.offset_y
47+
## base: 1920*1080, i should add something to make this automatically change based on the Desktop Capture used
48+
## maybe make it able to use multiple monitors as well?
49+
ratio_x = next_pos.x/1920
50+
ratio_y = next_pos.y/1080
51+
52+
target_scale = obs.vec2()
53+
target = obs.obs_get_source_by_name(self.target_name)
54+
obs.obs_sceneitem_get_scale(target_item, target_scale)
55+
target_x = obs.obs_source_get_width(target) * target_scale.x
56+
target_y = obs.obs_source_get_height(target) * target_scale.y
57+
58+
next_pos.x = lerp(0, target_x, ratio_x)
59+
next_pos.y = lerp(0, target_y, ratio_y)
4260
obs.obs_sceneitem_set_pos(scene_item, next_pos)
4361

4462
obs.obs_data_release(settings)
@@ -107,27 +125,52 @@ def script_defaults(settings):
107125
def script_update(settings):
108126
py_cursor.update_xy = obs.obs_data_get_bool(settings, "bool_yn")
109127
py_cursor.source_name = obs.obs_data_get_string(settings, "source")
128+
py_cursor.target_name = obs.obs_data_get_string(settings, "target")
110129
py_cursor.refresh_rate = obs.obs_data_get_int(settings, "_refresh_rate")
130+
py_cursor.offset_x = obs.obs_data_get_int(settings, "_offset_x")
131+
py_cursor.offset_y = obs.obs_data_get_int(settings, "_offset_y")
111132

112133

113134
def script_properties():
114135
props = obs.obs_properties_create()
115136
number = obs.obs_properties_add_int(
116137
props, "_refresh_rate", "Refresh rate (ms)", 15, 300, 5
117138
)
118-
p = obs.obs_properties_add_list(
139+
## i am only winging this so please forgive me
140+
offsetx = obs.obs_properties_add_int(
141+
props, "_offset_x", "Offset X", -5000, 5000, 1
142+
)
143+
offsety = obs.obs_properties_add_int(
144+
props, "_offset_y", "Offset Y", -5000, 5000, 1
145+
)
146+
147+
p1 = obs.obs_properties_add_list(
119148
props,
120149
"source",
121150
"Select cursor source",
122151
obs.OBS_COMBO_TYPE_EDITABLE,
123152
obs.OBS_COMBO_FORMAT_STRING,
124153
)
154+
p2 = obs.obs_properties_add_list(
155+
props,
156+
"target",
157+
"Select target window",
158+
obs.OBS_COMBO_TYPE_EDITABLE,
159+
obs.OBS_COMBO_FORMAT_STRING,
160+
)
125161
sources = obs.obs_enum_sources()
126162
if sources is not None:
163+
## property 1 for image source
127164
for source in sources:
128165
source_id = obs.obs_source_get_unversioned_id(source)
129166
name = obs.obs_source_get_name(source)
130-
obs.obs_property_list_add_string(p, name, name)
167+
obs.obs_property_list_add_string(p1, name, name)
168+
## property 2 for target window
169+
for target in sources:
170+
source_id = obs.obs_source_get_unversioned_id(target)
171+
name = obs.obs_source_get_name(target)
172+
obs.obs_property_list_add_string(p2, name, name)
173+
131174
obs.source_list_release(sources)
132175
obs.obs_properties_add_button(props, "button", "Stop", stop_pressed)
133176
obs.obs_properties_add_button(props, "button2", "Start", start_pressed)

0 commit comments

Comments
 (0)