1 from panda3d
.core
import WindowProperties
, Texture
2 from direct
.gui
.OnscreenImage
import OnscreenImage
3 from ya2
.utils
.logics
import LogicsTools
8 def __init__(self
, image_path
, scale
, color
, hotspot_position
, functional_test
):
9 self
.__functional
_test
= functional_test
10 if not image_path
: return
11 self
.__hide
_system
_cursor
()
12 self
.__set
_image
(image_path
, scale
, color
)
13 self
.__set
_hotspot
(hotspot_position
, scale
)
14 self
._tsk
= taskMgr
.add(self
.__on
_frame
, 'on_frame_cursor')
16 def __hide_system_cursor(self
):
17 p
= WindowProperties()
18 p
.set_cursor_hidden(True)
19 if LogicsTools
.windowed
: base
.win
.request_properties(p
)
21 def __set_image(self
, image_path
, scale
, color
):
22 self
.__image
= OnscreenImage(image_path
, scale
=scale
)
23 self
.__image
.set_color(color
)
24 self
.__image
.set_bin('gui-popup', 50)
25 alpha_formats
= [Texture
.FRgba
]
26 if self
.__image
.get_texture().get_format() in alpha_formats
:
27 self
.__image
.set_transparency(True)
29 def __set_hotspot(self
, hotspot_position
, scale
):
30 self
.__hotspot
_dx
= scale
[0] * (1 - 2 * hotspot_position
[0])
31 self
.__hotspot
_dy
= scale
[2] * (1 - 2 * hotspot_position
[1])
33 def __on_frame(self
, task
):
34 m
= base
.mouseWatcherNode
35 if not m
or not m
.hasMouse(): return task
.again
36 mouse
= m
.get_mouse_x(), m
.get_mouse_y()
37 h_x
= mouse
[0] * base
.get_aspect_ratio() + self
.__hotspot
_dx
38 self
.__image
.set_pos((h_x
, 1, mouse
[1] - self
.__hotspot
_dy
))
41 def set_image(self
, image
):
42 self
.__image
.set_texture(loader
.load_texture(image
), 1)
44 def set_color(self
, color
):
45 self
.__image
.set_color(color
)
48 if not self
.__functional
_test
: return self
.__image
.show()
51 return self
.__image
.hide()
54 taskMgr
.remove(self
._tsk
)
55 self
.__image
.destroy()