meltygui-imgui 2.0.0.post3__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. meltygui_imgui/__init__.py +879 -0
  2. meltygui_imgui/_compat.py +16 -0
  3. meltygui_imgui/ansifeed.pxd +20 -0
  4. meltygui_imgui/cimgui.pxd +2242 -0
  5. meltygui_imgui/common.pyx +75 -0
  6. meltygui_imgui/core.cp313-win_amd64.pyd +0 -0
  7. meltygui_imgui/core.cpp +189914 -0
  8. meltygui_imgui/core.h +51 -0
  9. meltygui_imgui/core.pxd +12 -0
  10. meltygui_imgui/core.pyx +12812 -0
  11. meltygui_imgui/enums.pxd +561 -0
  12. meltygui_imgui/enums_internal.pxd +200 -0
  13. meltygui_imgui/extra.py +36 -0
  14. meltygui_imgui/integrations/__init__.py +13 -0
  15. meltygui_imgui/integrations/base.py +33 -0
  16. meltygui_imgui/integrations/cocos2d.py +27 -0
  17. meltygui_imgui/integrations/glfw.py +133 -0
  18. meltygui_imgui/integrations/glumpy.py +369 -0
  19. meltygui_imgui/integrations/opengl.py +422 -0
  20. meltygui_imgui/integrations/pygame.py +152 -0
  21. meltygui_imgui/integrations/pyglet.py +245 -0
  22. meltygui_imgui/integrations/sdl2.py +136 -0
  23. meltygui_imgui/internal.cp313-win_amd64.pyd +0 -0
  24. meltygui_imgui/internal.cpp +13336 -0
  25. meltygui_imgui/internal.h +51 -0
  26. meltygui_imgui/internal.pxd +686 -0
  27. meltygui_imgui/internal.pyx +207 -0
  28. meltygui_imgui-2.0.0.post3.dist-info/DELVEWHEEL +2 -0
  29. meltygui_imgui-2.0.0.post3.dist-info/METADATA +146 -0
  30. meltygui_imgui-2.0.0.post3.dist-info/RECORD +38 -0
  31. meltygui_imgui-2.0.0.post3.dist-info/WHEEL +5 -0
  32. meltygui_imgui-2.0.0.post3.dist-info/licenses/LICENSE +28 -0
  33. meltygui_imgui-2.0.0.post3.dist-info/licenses/LICENSES/imgui-MIT.txt +21 -0
  34. meltygui_imgui-2.0.0.post3.dist-info/licenses/LICENSES/imstb_rectpack.h.license.txt +37 -0
  35. meltygui_imgui-2.0.0.post3.dist-info/licenses/LICENSES/imstb_textedit.h.license.txt +37 -0
  36. meltygui_imgui-2.0.0.post3.dist-info/licenses/LICENSES/imstb_truetype.h.license.txt +37 -0
  37. meltygui_imgui-2.0.0.post3.dist-info/top_level.txt +1 -0
  38. meltygui_imgui.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
@@ -0,0 +1,245 @@
1
+ # -*- coding: utf-8 -*-
2
+ from __future__ import absolute_import
3
+ import warnings
4
+ from distutils.version import LooseVersion
5
+
6
+ from pyglet.window import key, mouse, Window
7
+ import pyglet
8
+ import pyglet.clock
9
+
10
+ import meltygui_imgui
11
+
12
+ from . import compute_fb_scale
13
+ from .opengl import FixedPipelineRenderer, ProgrammablePipelineRenderer
14
+
15
+
16
+ class PygletMixin(object):
17
+ REVERSE_KEY_MAP = {
18
+ key.TAB: meltygui_imgui.KEY_TAB,
19
+ key.LEFT: meltygui_imgui.KEY_LEFT_ARROW,
20
+ key.RIGHT: meltygui_imgui.KEY_RIGHT_ARROW,
21
+ key.UP: meltygui_imgui.KEY_UP_ARROW,
22
+ key.DOWN: meltygui_imgui.KEY_DOWN_ARROW,
23
+ key.PAGEUP: meltygui_imgui.KEY_PAGE_UP,
24
+ key.PAGEDOWN: meltygui_imgui.KEY_PAGE_DOWN,
25
+ key.HOME: meltygui_imgui.KEY_HOME,
26
+ key.END: meltygui_imgui.KEY_END,
27
+ key.INSERT: meltygui_imgui.KEY_INSERT,
28
+ key.DELETE: meltygui_imgui.KEY_DELETE,
29
+ key.BACKSPACE: meltygui_imgui.KEY_BACKSPACE,
30
+ key.SPACE: meltygui_imgui.KEY_SPACE,
31
+ key.RETURN: meltygui_imgui.KEY_ENTER,
32
+ key.ESCAPE: meltygui_imgui.KEY_ESCAPE,
33
+ key.NUM_ENTER: meltygui_imgui.KEY_PAD_ENTER,
34
+ key.A: meltygui_imgui.KEY_A,
35
+ key.C: meltygui_imgui.KEY_C,
36
+ key.V: meltygui_imgui.KEY_V,
37
+ key.X: meltygui_imgui.KEY_X,
38
+ key.Y: meltygui_imgui.KEY_Y,
39
+ key.Z: meltygui_imgui.KEY_Z,
40
+ }
41
+ _gui_time = None
42
+
43
+ MOUSE_CURSORS = {
44
+ meltygui_imgui.MOUSE_CURSOR_ARROW: Window.CURSOR_DEFAULT,
45
+ meltygui_imgui.MOUSE_CURSOR_TEXT_INPUT: Window.CURSOR_TEXT,
46
+ meltygui_imgui.MOUSE_CURSOR_RESIZE_ALL: Window.CURSOR_SIZE,
47
+ meltygui_imgui.MOUSE_CURSOR_RESIZE_NS: Window.CURSOR_SIZE_UP_DOWN,
48
+ meltygui_imgui.MOUSE_CURSOR_RESIZE_EW: Window.CURSOR_SIZE_LEFT_RIGHT,
49
+ meltygui_imgui.MOUSE_CURSOR_RESIZE_NESW: Window.CURSOR_SIZE_DOWN_LEFT,
50
+ meltygui_imgui.MOUSE_CURSOR_RESIZE_NWSE: Window.CURSOR_SIZE_DOWN_RIGHT,
51
+ meltygui_imgui.MOUSE_CURSOR_HAND: Window.CURSOR_HAND
52
+ }
53
+
54
+ def __init__(self):
55
+ super(PygletMixin, self).__init__()
56
+ self._cursor = -2
57
+ self._window = None
58
+ # Let Dear meltygui_imgui know we have mouse cursor support
59
+ self.io.backend_flags |= meltygui_imgui.BACKEND_HAS_MOUSE_CURSORS
60
+
61
+ def _set_pixel_ratio(self, window):
62
+ window_size = window.get_size()
63
+ self.io.display_size = window_size
64
+ # It is conceivable that the pyglet version will not be solely
65
+ # determinant of whether we use the fixed or programmable, so do some
66
+ # minor introspection here to check.
67
+ if hasattr(window, 'get_viewport_size'):
68
+ viewport_size = window.get_viewport_size()
69
+ self.io.display_fb_scale = compute_fb_scale(window_size, viewport_size)
70
+ elif hasattr(window, 'get_pixel_ratio'):
71
+ self.io.display_fb_scale = (window.get_pixel_ratio(),
72
+ window.get_pixel_ratio())
73
+ else:
74
+ # Default to 1.0 in this unlikely circumstance
75
+ self.io.display_fb_scale = (1.0, 1.0)
76
+
77
+
78
+ def _attach_callbacks(self, window):
79
+ self._window = window
80
+ window.push_handlers(
81
+ self.on_mouse_motion,
82
+ self.on_key_press,
83
+ self.on_key_release,
84
+ self.on_text,
85
+ self.on_mouse_drag,
86
+ self.on_mouse_press,
87
+ self.on_mouse_release,
88
+ self.on_mouse_scroll,
89
+ self.on_resize,
90
+ )
91
+
92
+
93
+ def _map_keys(self):
94
+ key_map = self.io.key_map
95
+
96
+ # note: we cannot use default mechanism of mapping keys
97
+ # because pyglet uses weird key translation scheme
98
+ for value in self.REVERSE_KEY_MAP.values():
99
+ key_map[value] = value
100
+
101
+ def _on_mods_change(self, mods, key_pressed = 0):
102
+ self.io.key_ctrl = mods & key.MOD_CTRL or \
103
+ key_pressed in (key.LCTRL, key.RCTRL)
104
+ self.io.key_super = mods & key.MOD_COMMAND or \
105
+ key_pressed in (key.LCOMMAND, key.RCOMMAND)
106
+ self.io.key_alt = mods & key.MOD_ALT or \
107
+ key_pressed in (key.LALT, key.RALT)
108
+ self.io.key_shift = mods & key.MOD_SHIFT or \
109
+ key_pressed in (key.LSHIFT, key.RSHIFT)
110
+
111
+ def _handle_mouse_cursor(self):
112
+ if self.io.config_flags & meltygui_imgui.CONFIG_NO_MOUSE_CURSOR_CHANGE:
113
+ return
114
+
115
+ mouse_cursor = meltygui_imgui.get_mouse_cursor()
116
+ window = self._window
117
+ if self._cursor != mouse_cursor:
118
+ self._cursor = mouse_cursor
119
+ if mouse_cursor == meltygui_imgui.MOUSE_CURSOR_NONE:
120
+ window.set_mouse_visible(False)
121
+ else:
122
+ cursor = self.MOUSE_CURSORS.get(mouse_cursor)
123
+ window.set_mouse_cursor(window.get_system_mouse_cursor(cursor))
124
+
125
+ def on_mouse_motion(self, x, y, dx, dy):
126
+ self.io.mouse_pos = x, self.io.display_size.y - y
127
+
128
+ def on_key_press(self, key_pressed, mods):
129
+ if key_pressed in self.REVERSE_KEY_MAP:
130
+ self.io.keys_down[self.REVERSE_KEY_MAP[key_pressed]] = True
131
+ self._on_mods_change(mods, key_pressed)
132
+
133
+ def on_key_release(self, key_released, mods):
134
+ if key_released in self.REVERSE_KEY_MAP:
135
+ self.io.keys_down[self.REVERSE_KEY_MAP[key_released]] = False
136
+ self._on_mods_change(mods)
137
+
138
+ def on_text(self, text):
139
+ io = meltygui_imgui.get_io()
140
+
141
+ for char in text:
142
+ io.add_input_character(ord(char))
143
+
144
+ def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
145
+ self.io.mouse_pos = x, self.io.display_size.y - y
146
+
147
+ if button == mouse.LEFT:
148
+ self.io.mouse_down[0] = 1
149
+
150
+ if button == mouse.MIDDLE:
151
+ self.io.mouse_down[1] = 1
152
+
153
+ if button == mouse.RIGHT:
154
+ self.io.mouse_down[2] = 1
155
+
156
+ def on_mouse_press(self, x, y, button, modifiers):
157
+ self.io.mouse_pos = x, self.io.display_size.y - y
158
+
159
+ if button == mouse.LEFT:
160
+ self.io.mouse_down[0] = 1
161
+
162
+ if button == mouse.MIDDLE:
163
+ self.io.mouse_down[1] = 1
164
+
165
+ if button == mouse.RIGHT:
166
+ self.io.mouse_down[2] = 1
167
+
168
+ def on_mouse_release(self, x, y, button, modifiers):
169
+ self.io.mouse_pos = x, self.io.display_size.y - y
170
+
171
+ if button == mouse.LEFT:
172
+ self.io.mouse_down[0] = 0
173
+
174
+ if button == mouse.MIDDLE:
175
+ self.io.mouse_down[1] = 0
176
+
177
+ if button == mouse.RIGHT:
178
+ self.io.mouse_down[2] = 0
179
+
180
+ def on_mouse_scroll(self, x, y, mods, scroll):
181
+ self.io.mouse_wheel = scroll
182
+
183
+ def on_resize(self, width, height):
184
+ self.io.display_size = width, height
185
+
186
+ def process_inputs(self):
187
+ io = meltygui_imgui.get_io()
188
+
189
+ current_time = pyglet.clock.tick()
190
+
191
+ if self._gui_time:
192
+ io.delta_time = current_time - self._gui_time
193
+ else:
194
+ io.delta_time = 1. / 60.
195
+ if(io.delta_time <= 0.0): io.delta_time = 1./ 1000.
196
+ self._gui_time = current_time
197
+
198
+
199
+ class PygletFixedPipelineRenderer(PygletMixin, FixedPipelineRenderer):
200
+ def __init__(self, window, attach_callbacks=True):
201
+ super(PygletFixedPipelineRenderer, self).__init__()
202
+ self._set_pixel_ratio(window)
203
+ self._map_keys()
204
+ if attach_callbacks: self._attach_callbacks(window)
205
+
206
+ def render(self, draw_data):
207
+ super(PygletFixedPipelineRenderer, self).render(draw_data)
208
+ self._handle_mouse_cursor()
209
+
210
+
211
+ class PygletProgrammablePipelineRenderer(PygletMixin, ProgrammablePipelineRenderer):
212
+ def __init__(self, window, attach_callbacks = True):
213
+ super(PygletProgrammablePipelineRenderer, self).__init__()
214
+ self._set_pixel_ratio(window)
215
+ self._map_keys()
216
+ if attach_callbacks: self._attach_callbacks(window)
217
+
218
+ def render(self, draw_data):
219
+ super(PygletProgrammablePipelineRenderer, self).render(draw_data)
220
+ self._handle_mouse_cursor()
221
+
222
+
223
+ class PygletRenderer(PygletFixedPipelineRenderer):
224
+ def __init__(self, window, attach_callbacks=True):
225
+ warnings.warn("PygletRenderer is deprecated; please use either "
226
+ "PygletFixedPipelineRenderer (for OpenGL 2.1, pyglet < 2.0) or "
227
+ "PygletProgrammablePipelineRenderer (for later versions) or "
228
+ "create_renderer(window) to auto-detect.",
229
+ DeprecationWarning)
230
+ super(PygletRenderer, self).__init__(window, attach_callbacks)
231
+
232
+
233
+ def create_renderer(window, attach_callbacks=True):
234
+ """
235
+ This is a helper function that wraps the appropriate version of the Pyglet
236
+ renderer class, based on the version of pyglet being used.
237
+ """
238
+ # Determine the context version
239
+ # Pyglet < 2.0 has issues with ProgrammablePipeline even when the context
240
+ # is OpenGL 3, so we need to check the pyglet version rather than looking
241
+ # at window.config.major_version to see if we want to use programmable.
242
+ if LooseVersion(pyglet.version) < LooseVersion('2.0'):
243
+ return PygletFixedPipelineRenderer(window, attach_callbacks)
244
+ else:
245
+ return PygletProgrammablePipelineRenderer(window, attach_callbacks)
@@ -0,0 +1,136 @@
1
+ # -*- coding: utf-8 -*-
2
+ from __future__ import absolute_import
3
+
4
+ from sdl2 import *
5
+
6
+ import meltygui_imgui
7
+ import ctypes
8
+
9
+ from .opengl import ProgrammablePipelineRenderer
10
+
11
+
12
+ class SDL2Renderer(ProgrammablePipelineRenderer):
13
+ """Basic SDL2 integration implementation."""
14
+ MOUSE_WHEEL_OFFSET_SCALE = 0.5
15
+
16
+ def __init__(self, window):
17
+ super(SDL2Renderer, self).__init__()
18
+ self.window = window
19
+
20
+ self._mouse_pressed = [False, False, False]
21
+ self._mouse_wheel = 0.0
22
+ self._gui_time = None
23
+
24
+ width_ptr = ctypes.pointer(ctypes.c_int(0))
25
+ height_ptr = ctypes.pointer(ctypes.c_int(0))
26
+ SDL_GetWindowSize(self.window, width_ptr, height_ptr)
27
+
28
+ self.io.display_size = width_ptr[0], height_ptr[0]
29
+ self.io.get_clipboard_text_fn = self._get_clipboard_text
30
+ self.io.set_clipboard_text_fn = self._set_clipboard_text
31
+
32
+ self._map_keys()
33
+
34
+ def _get_clipboard_text(self):
35
+ return SDL_GetClipboardText()
36
+
37
+ def _set_clipboard_text(self, text):
38
+ SDL_SetClipboardText(ctypes.c_char_p(text.encode()))
39
+
40
+ def _map_keys(self):
41
+ key_map = self.io.key_map
42
+
43
+ key_map[meltygui_imgui.KEY_TAB] = SDL_SCANCODE_TAB
44
+ key_map[meltygui_imgui.KEY_LEFT_ARROW] = SDL_SCANCODE_LEFT
45
+ key_map[meltygui_imgui.KEY_RIGHT_ARROW] = SDL_SCANCODE_RIGHT
46
+ key_map[meltygui_imgui.KEY_UP_ARROW] = SDL_SCANCODE_UP
47
+ key_map[meltygui_imgui.KEY_DOWN_ARROW] = SDL_SCANCODE_DOWN
48
+ key_map[meltygui_imgui.KEY_PAGE_UP] = SDL_SCANCODE_PAGEUP
49
+ key_map[meltygui_imgui.KEY_PAGE_DOWN] = SDL_SCANCODE_PAGEDOWN
50
+ key_map[meltygui_imgui.KEY_HOME] = SDL_SCANCODE_HOME
51
+ key_map[meltygui_imgui.KEY_END] = SDL_SCANCODE_END
52
+ key_map[meltygui_imgui.KEY_INSERT] = SDL_SCANCODE_INSERT
53
+ key_map[meltygui_imgui.KEY_DELETE] = SDL_SCANCODE_DELETE
54
+ key_map[meltygui_imgui.KEY_BACKSPACE] = SDL_SCANCODE_BACKSPACE
55
+ key_map[meltygui_imgui.KEY_SPACE] = SDL_SCANCODE_SPACE
56
+ key_map[meltygui_imgui.KEY_ENTER] = SDL_SCANCODE_RETURN
57
+ key_map[meltygui_imgui.KEY_ESCAPE] = SDL_SCANCODE_ESCAPE
58
+ key_map[meltygui_imgui.KEY_PAD_ENTER] = SDL_SCANCODE_KP_ENTER
59
+ key_map[meltygui_imgui.KEY_A] = SDL_SCANCODE_A
60
+ key_map[meltygui_imgui.KEY_C] = SDL_SCANCODE_C
61
+ key_map[meltygui_imgui.KEY_V] = SDL_SCANCODE_V
62
+ key_map[meltygui_imgui.KEY_X] = SDL_SCANCODE_X
63
+ key_map[meltygui_imgui.KEY_Y] = SDL_SCANCODE_Y
64
+ key_map[meltygui_imgui.KEY_Z] = SDL_SCANCODE_Z
65
+
66
+ def process_event(self, event):
67
+ io = self.io
68
+
69
+ if event.type == SDL_MOUSEWHEEL:
70
+ self._mouse_wheel = event.wheel.y * self.MOUSE_WHEEL_OFFSET_SCALE
71
+ return True
72
+
73
+ if event.type == SDL_MOUSEBUTTONDOWN:
74
+ if event.button.button == SDL_BUTTON_LEFT:
75
+ self._mouse_pressed[0] = True
76
+ if event.button.button == SDL_BUTTON_RIGHT:
77
+ self._mouse_pressed[1] = True
78
+ if event.button.button == SDL_BUTTON_MIDDLE:
79
+ self._mouse_pressed[2] = True
80
+ return True
81
+
82
+ if event.type == SDL_KEYUP or event.type == SDL_KEYDOWN:
83
+ key = event.key.keysym.scancode
84
+
85
+ if key < SDL_NUM_SCANCODES:
86
+ io.keys_down[key] = event.type == SDL_KEYDOWN
87
+
88
+ io.key_shift = ((SDL_GetModState() & KMOD_SHIFT) != 0)
89
+ io.key_ctrl = ((SDL_GetModState() & KMOD_CTRL) != 0)
90
+ io.key_alt = ((SDL_GetModState() & KMOD_ALT) != 0)
91
+ io.key_super = ((SDL_GetModState() & KMOD_GUI) != 0)
92
+
93
+ return True
94
+
95
+ if event.type == SDL_TEXTINPUT:
96
+ for char in event.text.text.decode('utf-8'):
97
+ io.add_input_character(ord(char))
98
+ return True
99
+
100
+ def process_inputs(self):
101
+ io = meltygui_imgui.get_io()
102
+
103
+ s_w = ctypes.pointer(ctypes.c_int(0))
104
+ s_h = ctypes.pointer(ctypes.c_int(0))
105
+ SDL_GetWindowSize(self.window, s_w, s_h)
106
+ w = s_w.contents.value
107
+ h = s_h.contents.value
108
+
109
+ io.display_size = w, h
110
+ io.display_fb_scale = 1, 1
111
+
112
+ current_time = SDL_GetTicks() / 1000.0
113
+
114
+ if self._gui_time:
115
+ io.delta_time = current_time - self._gui_time
116
+ else:
117
+ io.delta_time = 1. / 60.
118
+ if(io.delta_time <= 0.0): io.delta_time = 1./ 1000.
119
+ self._gui_time = current_time
120
+
121
+ mx = ctypes.pointer(ctypes.c_int(0))
122
+ my = ctypes.pointer(ctypes.c_int(0))
123
+ mouse_mask = SDL_GetMouseState(mx, my)
124
+
125
+ if SDL_GetWindowFlags(self.window) & SDL_WINDOW_MOUSE_FOCUS:
126
+ io.mouse_pos = mx.contents.value, my.contents.value
127
+ else:
128
+ io.mouse_pos = -1, -1
129
+
130
+ io.mouse_down[0] = self._mouse_pressed[0] or (mouse_mask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0
131
+ io.mouse_down[1] = self._mouse_pressed[1] or (mouse_mask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0
132
+ io.mouse_down[2] = self._mouse_pressed[2] or (mouse_mask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0
133
+ self._mouse_pressed = [False, False, False]
134
+
135
+ io.mouse_wheel = self._mouse_wheel
136
+ self._mouse_wheel = 0