-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
100 lines (76 loc) · 2.81 KB
/
main.py
File metadata and controls
100 lines (76 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 基于pygame的图形化CAD编辑器
# made by Gaoxuan
import pygame, sys, os
from pygame.locals import *
os.chdir(os.path.dirname(__file__))
mainwindow = pygame.display.set_mode((1600, 900), pygame.RESIZABLE, 32)
pygame.display.set_caption('PyCAD')
icon = pygame.image.load('./resources/pic/icon.png')
pygame.display.set_icon(icon)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
YELLOW = (225, 225, 0)
pygame.init()
fpsClock = pygame.time.Clock()
bar_h = 36
bar_font_file = pygame.font.match_font('SimHei')
bar_font = pygame.font.Font(bar_font_file, 20)
menu_bar_tabs = ['文件', '编辑']
tab_interval = 10
def display_menu_bar_tabs():
tab_x = tab_interval
for tab_text in menu_bar_tabs:
tab_text_surface = bar_font.render(tab_text, True, BLACK, GREEN)
tab_rect = tab_text_surface.get_rect()
tab_rect.topleft = (tab_x, 8)
tab_x = tab_x + tab_rect.width + tab_interval
mainwindow.blit(tab_text_surface, tab_rect)
def display_menu_bar():
menu_bar_rect = (0, 0, mainwindow_w, bar_h)
pygame.draw.rect(mainwindow, BLUE, menu_bar_rect)
display_menu_bar_tabs()
bar_interval = 3
tool_bar_tabs = []
tool_tab_img = [pygame.image.load('./resources/tools/%s' % tab_img_name) for tab_img_name in tool_bar_tabs]
def display_tool_bar_tabs():
tab_x = tab_interval
for tab_img in tool_tab_img:
mainwindow.blit(tab_img, (tab_x, bar_h+bar_interval+2))
tab_x = tab_x+tab_img.get_width()+tab_interval
def display_tool_bar():
tool_bar_rect = (0, bar_h+bar_interval, mainwindow_w, bar_h)
pygame.draw.rect(mainwindow, BLUE, tool_bar_rect)
display_tool_bar_tabs()
def display_xy_status():
xy_status = 'x:%d y:%d' % (mouse_x, mouse_y)
tab_text_surface = bar_font.render(xy_status, True, BLACK, YELLOW)
tab_rect = tab_text_surface.get_rect()
tab_rect.topleft = (10, mainwindow_h - 28)
mainwindow.blit(tab_text_surface, tab_rect)
def display_status_bar():
status_bar_rect = (0, mainwindow_h - bar_h, mainwindow_w, bar_h)
pygame.draw.rect(mainwindow, RED, status_bar_rect)
display_xy_status()
def display_main_window():
mainwindow.fill(WHITE)
display_menu_bar()
display_status_bar()
display_tool_bar()
def init():
cursor = pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_CROSSHAIR)
pygame.mouse.set_cursor(cursor)
init()
while True:
mainwindow_w, mainwindow_h = pygame.display.get_surface().get_size()
mouse_x, mouse_y = pygame.mouse.get_pos()
display_main_window()
for event in pygame.event.get():
if event.type == QUIT:
print("exit with 0")
pygame.quit()
sys.exit()
pygame.display.update()
fpsClock.tick(60)