freepygame 0.1.0__tar.gz

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.
@@ -0,0 +1,337 @@
1
+ Metadata-Version: 2.4
2
+ Name: freepygame
3
+ Version: 0.1.0
4
+ Summary: A Pygame UI controls library providing buttons, text, circles and other widgets
5
+ Home-page: https://github.com/freebird/freepygame
6
+ Author: freebird
7
+ Author-email: freebird <freebird@example.com>
8
+ License-Expression: Apache-2.0
9
+ Project-URL: Homepage, https://github.com/freebird/freepygame
10
+ Project-URL: Bug-Tracker, https://github.com/freebird/freepygame/issues
11
+ Project-URL: Source, https://github.com/freebird/freepygame
12
+ Project-URL: Documentation, https://github.com/freebird/freepygame#readme
13
+ Keywords: pygame,ui,controls,widgets,buttons,text,circles
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Topic :: Software Development :: Libraries :: pygame
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Operating System :: OS Independent
25
+ Requires-Python: >=3.7
26
+ Description-Content-Type: text/markdown
27
+ License-File: license.txt
28
+ Requires-Dist: pygame>=2.0.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
32
+ Requires-Dist: black>=23.0.0; extra == "dev"
33
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
34
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
35
+ Dynamic: author
36
+ Dynamic: home-page
37
+ Dynamic: license-file
38
+ Dynamic: requires-python
39
+
40
+ # freepygame
41
+
42
+ 一个为 Pygame 游戏开发提供 UI 控件和工具的 Python 库。
43
+
44
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
45
+ [![Python](https://img.shields.io/badge/Python-3.7%2B-blue)](https://www.python.org/)
46
+ [![Pygame](https://img.shields.io/badge/Pygame-2.0%2B-orange)](https://www.pygame.org/)
47
+
48
+ ## 特性
49
+
50
+ - 🎨 **丰富的 UI 组件**: 按钮、文本、圆形、图标等
51
+ - 🖌️ **抗锯齿支持**: 高质量图形渲染
52
+ - 🔧 **易于使用**: 简单的 API 和直观的接口
53
+ - 🎯 **灵活配置**: 支持颜色、大小、位置等属性动态调整
54
+ - ✨ **特效支持**: 粒子系统、图像处理等高级功能
55
+ - 📱 **缩放支持**: 支持高DPI显示和界面缩放
56
+
57
+ ## 安装
58
+
59
+ ```bash
60
+ pip install freepygame
61
+ ```
62
+
63
+ 或者从源代码安装:
64
+
65
+ ```bash
66
+ git clone https://github.com/freebird/freebPygame.git
67
+ cd freebPygame
68
+ pip install -e .
69
+ ```
70
+
71
+ ## 快速开始
72
+
73
+ ```python
74
+ import pygame
75
+ from freepygame import FreeButton, FreeText, position_button_class
76
+
77
+ # 初始化 Pygame
78
+ pygame.init()
79
+ screen = pygame.display.set_mode((800, 600))
80
+ clock = pygame.time.Clock()
81
+
82
+ # 创建按钮
83
+ button = FreeButton(
84
+ screen=screen,
85
+ coordinates=[100, 100],
86
+ button_size=[200, 50],
87
+ msg="点击我",
88
+ button_color=(70, 130, 180),
89
+ text_color=(255, 255, 255)
90
+ )
91
+
92
+ # 创建文本
93
+ text = FreeText(
94
+ screen=screen,
95
+ coordinates=[100, 170],
96
+ msg="欢迎使用 freepygame!",
97
+ color=(0, 0, 0)
98
+ )
99
+
100
+ running = True
101
+ while running:
102
+ for event in pygame.event.get():
103
+ if event.type == pygame.QUIT:
104
+ running = False
105
+ elif event.type == pygame.MOUSEBUTTONDOWN:
106
+ if position_button_class(button, pygame.mouse.get_pos()):
107
+ text.set_msg("按钮被点击了!")
108
+
109
+ # 绘制
110
+ screen.fill((240, 240, 245))
111
+ button.draw()
112
+ text.draw()
113
+
114
+ pygame.display.flip()
115
+ clock.tick(60)
116
+
117
+ pygame.quit()
118
+ ```
119
+
120
+ ## 主要组件
121
+
122
+ ### 按钮组件
123
+
124
+ #### FreeButton - 矩形按钮
125
+ ```python
126
+ button = FreeButton(
127
+ screen=screen,
128
+ coordinates=[x, y], # 左上角坐标
129
+ button_size=[width, height], # 按钮尺寸
130
+ msg="按钮文本", # 显示文本
131
+ button_color=(r, g, b), # 按钮背景色
132
+ text_color=(r, g, b), # 文本颜色
133
+ draw_border=True, # 是否显示边框
134
+ border_width=2, # 边框宽度
135
+ dsm=1 # 缩放系数
136
+ )
137
+ ```
138
+
139
+ #### CircleButton - 圆形按钮
140
+ ```python
141
+ circle_btn = CircleButton(
142
+ screen=screen,
143
+ coordinates=[x, y], # 圆心坐标
144
+ radius=50, # 半径
145
+ msg="圆形按钮", # 显示文本
146
+ button_color=(r, g, b), # 按钮颜色
147
+ msg_color=(r, g, b) # 文本颜色
148
+ )
149
+ ```
150
+
151
+ ### 文本组件
152
+
153
+ #### FreeText - 基础文本
154
+ ```python
155
+ text = FreeText(
156
+ screen=screen,
157
+ coordinates=[x, y], # 文本位置
158
+ msg="文本内容", # 显示文本
159
+ font=None, # 字体文件路径或 Pygame 字体对象
160
+ size=24, # 字体大小
161
+ color=(r, g, b) # 文本颜色
162
+ )
163
+ ```
164
+
165
+ #### SuperText - 超级文本(支持缩放)
166
+ ```python
167
+ super_text = SuperText(
168
+ screen=screen,
169
+ coordinates=[x, y],
170
+ msg="支持缩放的文本",
171
+ size=24,
172
+ color=(r, g, b),
173
+ dsm=1.5 # 1.5倍缩放
174
+ )
175
+ ```
176
+
177
+ ### 图形组件
178
+
179
+ #### FreeCircle - 圆形/弧形
180
+ ```python
181
+ circle = FreeCircle(
182
+ screen=screen,
183
+ coordinates=[x, y], # 圆心坐标
184
+ radius=50, # 半径
185
+ width=2, # 线宽(0为实心)
186
+ angle=(0, 360), # 角度范围(用于绘制弧)
187
+ aa=True, # 是否抗锯齿
188
+ color=(r, g, b) # 颜色
189
+ )
190
+ ```
191
+
192
+ #### FreeAllCircle - 静态绘图方法
193
+ ```python
194
+ # 绘制抗锯齿圆
195
+ FreeAllCircle.draw_aacircle(screen, (x, y), radius, color)
196
+
197
+ # 绘制贝塞尔曲线
198
+ points = [(100, 100), (200, 50), (300, 150), (400, 100)]
199
+ FreeAllCircle.draw_bezier(screen, points, steps=100, color=(128, 128, 128))
200
+ ```
201
+
202
+ ### 其他组件
203
+
204
+ #### FreeIcon - 图标
205
+ ```python
206
+ icon = FreeIcon(
207
+ screen=screen,
208
+ coordinates=[x, y], # 图标位置
209
+ image_1=normal_image, # 正常状态图像
210
+ image_2=hover_image # 悬停状态图像
211
+ )
212
+
213
+ # 切换图标状态
214
+ icon.set_index(0) # 显示 image_1
215
+ icon.set_index(1) # 显示 image_2
216
+ ```
217
+
218
+ #### ParticleEngine - 粒子系统
219
+ ```python
220
+ engine = ParticleEngine()
221
+
222
+ # 生成粒子
223
+ engine.generate_particles(50, (x, y))
224
+
225
+ # 更新粒子
226
+ engine.update_particles()
227
+
228
+ # 绘制粒子
229
+ engine.draw_particles(screen)
230
+ ```
231
+
232
+ ### 图像处理
233
+
234
+ ```python
235
+ from freepygame import image_blur_processing, array_mean_rgba
236
+
237
+ # 图像模糊处理
238
+ blurred_image = image_blur_processing(image, level=2)
239
+
240
+ # 计算图像区域的平均颜色
241
+ avg_color = array_mean_rgba(pixel_data)
242
+ ```
243
+
244
+ ## 实用函数
245
+
246
+ ### 点击检测
247
+ ```python
248
+ # 检测点是否在按钮内
249
+ if position_button(rect, pos):
250
+ print("点在矩形内")
251
+
252
+ # 检测点是否在按钮对象内
253
+ if position_button_class(button, pos):
254
+ print("点在按钮内")
255
+ ```
256
+
257
+ ## 高级特性
258
+
259
+ ### 操作符重载
260
+
261
+ #### SuperText 的操作符
262
+ ```python
263
+ text = SuperText(screen, [100, 100], "Hello")
264
+
265
+ # << 操作符快捷设置属性
266
+ text << (36,) # 设置字体大小
267
+ text << (200, 150) # 设置位置
268
+ text << (255, 0, 0) # 设置颜色
269
+
270
+ # + 操作符拼接文本
271
+ text + " World!" # 文本变为 "Hello World!"
272
+ ```
273
+
274
+ #### SuperCircle 的操作符
275
+ ```python
276
+ circle = SuperCircle(screen, [400, 300], 50)
277
+
278
+ circle << (75,) # 设置半径
279
+ circle << ((80, 60),) # 设置长短半轴
280
+ circle << ((255, 0, 0),) # 设置颜色
281
+ ```
282
+
283
+ ## 示例
284
+
285
+ 查看 `examples/` 目录获取完整示例:
286
+
287
+ - `basic_demo.py` - 基础演示程序
288
+ - `particle_demo.py` - 粒子系统演示
289
+ - `ui_demo.py` - 完整UI界面演示
290
+
291
+ 运行示例:
292
+ ```bash
293
+ cd examples
294
+ python basic_demo.py
295
+ ```
296
+
297
+ ## 项目结构
298
+ ```
299
+ freepygame/
300
+ ├── freepygame/ # 主包目录
301
+ │ ├── __init__.py # 包初始化
302
+ │ ├── freebutton.py # 按钮组件
303
+ │ ├── freecircle.py # 圆形组件
304
+ │ ├── freetext.py # 文本组件
305
+ │ ├── freeicon.py # 图标组件
306
+ │ ├── freeparticle.py # 粒子系统
307
+ │ ├── freetransformation.py # 图像处理
308
+ │ └── freepygamelib.py # 单文件版本
309
+ ├── tests/ # 测试目录
310
+ │ ├── conftest.py # 测试配置
311
+ │ ├── test_components/ # 组件测试
312
+ │ └── test_integration/ # 集成测试
313
+ ├── examples/ # 示例目录
314
+ ├── setup.py # 安装配置
315
+ ├── README.md # 本文档
316
+ └── LICENSE.txt # 许可证文件
317
+ ```
318
+
319
+ ## 许可证
320
+
321
+ 本项目采用 Apache License 2.0 许可证。详见 [LICENSE.txt](LICENSE.txt)。
322
+
323
+ ## 贡献
324
+
325
+ 欢迎提交 Issue 和 Pull Request!
326
+
327
+ ## 作者
328
+
329
+ freebird
330
+
331
+ ## 致谢
332
+
333
+ - [Pygame](https://www.pygame.org/) - 游戏开发库
334
+
335
+ ---
336
+
337
+ **注意**: 本库仍在积极开发中,API 可能会有变动。
@@ -0,0 +1,298 @@
1
+ # freepygame
2
+
3
+ 一个为 Pygame 游戏开发提供 UI 控件和工具的 Python 库。
4
+
5
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
+ [![Python](https://img.shields.io/badge/Python-3.7%2B-blue)](https://www.python.org/)
7
+ [![Pygame](https://img.shields.io/badge/Pygame-2.0%2B-orange)](https://www.pygame.org/)
8
+
9
+ ## 特性
10
+
11
+ - 🎨 **丰富的 UI 组件**: 按钮、文本、圆形、图标等
12
+ - 🖌️ **抗锯齿支持**: 高质量图形渲染
13
+ - 🔧 **易于使用**: 简单的 API 和直观的接口
14
+ - 🎯 **灵活配置**: 支持颜色、大小、位置等属性动态调整
15
+ - ✨ **特效支持**: 粒子系统、图像处理等高级功能
16
+ - 📱 **缩放支持**: 支持高DPI显示和界面缩放
17
+
18
+ ## 安装
19
+
20
+ ```bash
21
+ pip install freepygame
22
+ ```
23
+
24
+ 或者从源代码安装:
25
+
26
+ ```bash
27
+ git clone https://github.com/freebird/freebPygame.git
28
+ cd freebPygame
29
+ pip install -e .
30
+ ```
31
+
32
+ ## 快速开始
33
+
34
+ ```python
35
+ import pygame
36
+ from freepygame import FreeButton, FreeText, position_button_class
37
+
38
+ # 初始化 Pygame
39
+ pygame.init()
40
+ screen = pygame.display.set_mode((800, 600))
41
+ clock = pygame.time.Clock()
42
+
43
+ # 创建按钮
44
+ button = FreeButton(
45
+ screen=screen,
46
+ coordinates=[100, 100],
47
+ button_size=[200, 50],
48
+ msg="点击我",
49
+ button_color=(70, 130, 180),
50
+ text_color=(255, 255, 255)
51
+ )
52
+
53
+ # 创建文本
54
+ text = FreeText(
55
+ screen=screen,
56
+ coordinates=[100, 170],
57
+ msg="欢迎使用 freepygame!",
58
+ color=(0, 0, 0)
59
+ )
60
+
61
+ running = True
62
+ while running:
63
+ for event in pygame.event.get():
64
+ if event.type == pygame.QUIT:
65
+ running = False
66
+ elif event.type == pygame.MOUSEBUTTONDOWN:
67
+ if position_button_class(button, pygame.mouse.get_pos()):
68
+ text.set_msg("按钮被点击了!")
69
+
70
+ # 绘制
71
+ screen.fill((240, 240, 245))
72
+ button.draw()
73
+ text.draw()
74
+
75
+ pygame.display.flip()
76
+ clock.tick(60)
77
+
78
+ pygame.quit()
79
+ ```
80
+
81
+ ## 主要组件
82
+
83
+ ### 按钮组件
84
+
85
+ #### FreeButton - 矩形按钮
86
+ ```python
87
+ button = FreeButton(
88
+ screen=screen,
89
+ coordinates=[x, y], # 左上角坐标
90
+ button_size=[width, height], # 按钮尺寸
91
+ msg="按钮文本", # 显示文本
92
+ button_color=(r, g, b), # 按钮背景色
93
+ text_color=(r, g, b), # 文本颜色
94
+ draw_border=True, # 是否显示边框
95
+ border_width=2, # 边框宽度
96
+ dsm=1 # 缩放系数
97
+ )
98
+ ```
99
+
100
+ #### CircleButton - 圆形按钮
101
+ ```python
102
+ circle_btn = CircleButton(
103
+ screen=screen,
104
+ coordinates=[x, y], # 圆心坐标
105
+ radius=50, # 半径
106
+ msg="圆形按钮", # 显示文本
107
+ button_color=(r, g, b), # 按钮颜色
108
+ msg_color=(r, g, b) # 文本颜色
109
+ )
110
+ ```
111
+
112
+ ### 文本组件
113
+
114
+ #### FreeText - 基础文本
115
+ ```python
116
+ text = FreeText(
117
+ screen=screen,
118
+ coordinates=[x, y], # 文本位置
119
+ msg="文本内容", # 显示文本
120
+ font=None, # 字体文件路径或 Pygame 字体对象
121
+ size=24, # 字体大小
122
+ color=(r, g, b) # 文本颜色
123
+ )
124
+ ```
125
+
126
+ #### SuperText - 超级文本(支持缩放)
127
+ ```python
128
+ super_text = SuperText(
129
+ screen=screen,
130
+ coordinates=[x, y],
131
+ msg="支持缩放的文本",
132
+ size=24,
133
+ color=(r, g, b),
134
+ dsm=1.5 # 1.5倍缩放
135
+ )
136
+ ```
137
+
138
+ ### 图形组件
139
+
140
+ #### FreeCircle - 圆形/弧形
141
+ ```python
142
+ circle = FreeCircle(
143
+ screen=screen,
144
+ coordinates=[x, y], # 圆心坐标
145
+ radius=50, # 半径
146
+ width=2, # 线宽(0为实心)
147
+ angle=(0, 360), # 角度范围(用于绘制弧)
148
+ aa=True, # 是否抗锯齿
149
+ color=(r, g, b) # 颜色
150
+ )
151
+ ```
152
+
153
+ #### FreeAllCircle - 静态绘图方法
154
+ ```python
155
+ # 绘制抗锯齿圆
156
+ FreeAllCircle.draw_aacircle(screen, (x, y), radius, color)
157
+
158
+ # 绘制贝塞尔曲线
159
+ points = [(100, 100), (200, 50), (300, 150), (400, 100)]
160
+ FreeAllCircle.draw_bezier(screen, points, steps=100, color=(128, 128, 128))
161
+ ```
162
+
163
+ ### 其他组件
164
+
165
+ #### FreeIcon - 图标
166
+ ```python
167
+ icon = FreeIcon(
168
+ screen=screen,
169
+ coordinates=[x, y], # 图标位置
170
+ image_1=normal_image, # 正常状态图像
171
+ image_2=hover_image # 悬停状态图像
172
+ )
173
+
174
+ # 切换图标状态
175
+ icon.set_index(0) # 显示 image_1
176
+ icon.set_index(1) # 显示 image_2
177
+ ```
178
+
179
+ #### ParticleEngine - 粒子系统
180
+ ```python
181
+ engine = ParticleEngine()
182
+
183
+ # 生成粒子
184
+ engine.generate_particles(50, (x, y))
185
+
186
+ # 更新粒子
187
+ engine.update_particles()
188
+
189
+ # 绘制粒子
190
+ engine.draw_particles(screen)
191
+ ```
192
+
193
+ ### 图像处理
194
+
195
+ ```python
196
+ from freepygame import image_blur_processing, array_mean_rgba
197
+
198
+ # 图像模糊处理
199
+ blurred_image = image_blur_processing(image, level=2)
200
+
201
+ # 计算图像区域的平均颜色
202
+ avg_color = array_mean_rgba(pixel_data)
203
+ ```
204
+
205
+ ## 实用函数
206
+
207
+ ### 点击检测
208
+ ```python
209
+ # 检测点是否在按钮内
210
+ if position_button(rect, pos):
211
+ print("点在矩形内")
212
+
213
+ # 检测点是否在按钮对象内
214
+ if position_button_class(button, pos):
215
+ print("点在按钮内")
216
+ ```
217
+
218
+ ## 高级特性
219
+
220
+ ### 操作符重载
221
+
222
+ #### SuperText 的操作符
223
+ ```python
224
+ text = SuperText(screen, [100, 100], "Hello")
225
+
226
+ # << 操作符快捷设置属性
227
+ text << (36,) # 设置字体大小
228
+ text << (200, 150) # 设置位置
229
+ text << (255, 0, 0) # 设置颜色
230
+
231
+ # + 操作符拼接文本
232
+ text + " World!" # 文本变为 "Hello World!"
233
+ ```
234
+
235
+ #### SuperCircle 的操作符
236
+ ```python
237
+ circle = SuperCircle(screen, [400, 300], 50)
238
+
239
+ circle << (75,) # 设置半径
240
+ circle << ((80, 60),) # 设置长短半轴
241
+ circle << ((255, 0, 0),) # 设置颜色
242
+ ```
243
+
244
+ ## 示例
245
+
246
+ 查看 `examples/` 目录获取完整示例:
247
+
248
+ - `basic_demo.py` - 基础演示程序
249
+ - `particle_demo.py` - 粒子系统演示
250
+ - `ui_demo.py` - 完整UI界面演示
251
+
252
+ 运行示例:
253
+ ```bash
254
+ cd examples
255
+ python basic_demo.py
256
+ ```
257
+
258
+ ## 项目结构
259
+ ```
260
+ freepygame/
261
+ ├── freepygame/ # 主包目录
262
+ │ ├── __init__.py # 包初始化
263
+ │ ├── freebutton.py # 按钮组件
264
+ │ ├── freecircle.py # 圆形组件
265
+ │ ├── freetext.py # 文本组件
266
+ │ ├── freeicon.py # 图标组件
267
+ │ ├── freeparticle.py # 粒子系统
268
+ │ ├── freetransformation.py # 图像处理
269
+ │ └── freepygamelib.py # 单文件版本
270
+ ├── tests/ # 测试目录
271
+ │ ├── conftest.py # 测试配置
272
+ │ ├── test_components/ # 组件测试
273
+ │ └── test_integration/ # 集成测试
274
+ ├── examples/ # 示例目录
275
+ ├── setup.py # 安装配置
276
+ ├── README.md # 本文档
277
+ └── LICENSE.txt # 许可证文件
278
+ ```
279
+
280
+ ## 许可证
281
+
282
+ 本项目采用 Apache License 2.0 许可证。详见 [LICENSE.txt](LICENSE.txt)。
283
+
284
+ ## 贡献
285
+
286
+ 欢迎提交 Issue 和 Pull Request!
287
+
288
+ ## 作者
289
+
290
+ freebird
291
+
292
+ ## 致谢
293
+
294
+ - [Pygame](https://www.pygame.org/) - 游戏开发库
295
+
296
+ ---
297
+
298
+ **注意**: 本库仍在积极开发中,API 可能会有变动。