Integrated Pygame application development support.
Project description
GTC Pygame Runtime Support
集成 Pygame 应用开发支持
Finding an English version? click here
нашли русскую версию? кликните сюда
软件包安装
向绝大多数软件包一样,本软件包也可使用 pip 下载并安装
pip install GTC_Pygame_Runtime_Support
如果 pip 不慎爆炸,您可以从 Github 处直接复制源码
使用示例
按钮
PRS 提供三种按钮类型,全部位于button.py文件内,此处以其中的FeedbackButton为例进行展示
import pygame
import GTC_Pygame_Runtime_Support as gPRS
screen = pygame.display.set_mode((200, 200))
button = gPRS.button.FeedbackButton([40, 40], [20, 20], '114', 15, screen, bg_color=[0, 145, 220],
border_color=[209, 240, 255], text_color=[255, 255, 255],
change_color=((0, 145, 220), (0, 225, 0))) # 生成按钮
running = 1
clock = pygame.time.Clock()
while running: # 主循环
screen.fill((255, 255, 255))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = 0
button.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3)) # 按钮贴图处
if button.on_click:
print("clicked")
pygame.display.flip()
clock.tick(60)
运行如上代码,你将能够创建一个显示文字为 114 的按钮,并且点击这个按钮后,控制台会输出"clicked",并且根据用户的动作,按钮将会有不同的反馈。
页面
PRS 提供的页面类型位于page.py内,此处以PlainPage为例进行展示
import sys
import pygame
import GTC_Pygame_Runtime_Support as gPRS
screen = pygame.display.set_mode((500, 500))
bp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)
if __name__ == '__main__':
clock = pygame.time.Clock()
bp.surface.fill((255, 255, 255))
for i in range(100):
pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])
bp.set_as_background()
mw = [False, False]
while True:
mw = [False, False]
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
mw[1] = True
elif event.button == 5:
mw[0] = True
bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)
pygame.display.flip()
clock.tick(60)
运行上述代码,你将能够创建一个可由鼠标滚轮滚动和鼠标左键拖动的页面,你可以自行更换其背景,只要你在主循环前调用函数bp.set_as_background()
PRS 中的嵌套操作
在 PRS 中,一切展示型组件都可通过托管 (trusteeship) 的方式进行嵌套。
在页面中嵌套按钮
PRS 中所有组件托管按钮的方式均相同,就像下面展示的:
import sys
import pygame
import GTC_Pygame_Runtime_Support as gPRS
screen = pygame.display.set_mode((500, 500))
bp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)
if __name__ == '__main__':
clock = pygame.time.Clock()
bp.surface.fill((255, 255, 255))
for i in range(100):
pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])
bp.set_as_background()
bt = gPRS.button.FeedbackButton([40, 40], [20, 20], '114', 10, bp.surface)
bp.add_button_trusteeship(bt)
mw = [False, False]
while True:
mw = [False, False]
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
mw[1] = True
elif event.button == 5:
mw[0] = True
bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)
if bt.on_click:
print('clicked')
pygame.display.flip()
clock.tick(60)
PRS 通常通过item.add_button_trusteeship(button)的形式添加嵌套按钮,同时按钮声明时的目标 surface 应指向被嵌套对象的 surface,通常是item.surface。
在页面中嵌套页面
原理基本同上。
import sys
import pygame
import GTC_Pygame_Runtime_Support as gPRS
screen = pygame.display.set_mode((500, 500))
bp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)
if __name__ == '__main__':
clock = pygame.time.Clock()
bp.surface.fill((255, 255, 255))
for i in range(100):
pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])
bp.set_as_background()
inner_p = gPRS.page.PlainPage([100, 100], [100, 300], [50, 200], bp.surface, wheel_support=True)
inner_p.surface.fill((255, 255, 255))
for i in range(100):
pygame.draw.line(inner_p.surface, [0, 0, 255], [0, 9 * i], [300, 9 * i])
inner_p.set_as_background()
bp.add_page_trusteeship(inner_p)
mw = [False, False]
while True:
mw = [False, False]
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
mw[1] = True
elif event.button == 5:
mw[0] = True
bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)
pygame.display.flip()
clock.tick(60)
通过以上介绍,您应该能对 PRS 的使用特点有大概的了解。
该页面不仅可以使用滚轮滚动页面,也可以使用鼠标拖动页面,并且在使用add_button_trusteeship()函数后,按钮也可以正常使用。
所有功能组件的 Surface 图层均向开发者开放,这使得开发者在不满意原按钮的美术效果时可以自行修改图层,比如上例中向滚动页面绘制直线,使用者可以直接通过bp.surface获得页面的 Surface,并通过bp.set_as_background()方便地设置其为默认背景。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file GTC_Pygame_Runtime_Support-0.0.16-py3-none-any.whl.
File metadata
- Download URL: GTC_Pygame_Runtime_Support-0.0.16-py3-none-any.whl
- Upload date:
- Size: 36.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59d4d4d11aa104417f30db79d1762d69beaea42d4a23febf21ee86a5c21e0d21
|
|
| MD5 |
190c7496440ab7aeeefcca57f0f9d27d
|
|
| BLAKE2b-256 |
79f34aa3cd67b0d5157a272e39b6a27eecac086601c08573d3d27154e872370e
|