Skip to content

Commit c9b5d22

Browse files
the second step
1 parent dc606aa commit c9b5d22

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

main.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,70 @@
11
# 基于pygame的图形化CAD编辑器
22
# made by Gaoxuan
33

4-
import pygame, sys
4+
import pygame, sys, time
55
from pygame.locals import *
66

7-
pygame.init()
8-
fpsClock = pygame.time.Clock()
9-
10-
mainwindow = pygame.display.set_mode((400, 300), 0, 32)
7+
mainwindow = pygame.display.set_mode((1600, 900), pygame.RESIZABLE, 32)
118
pygame.display.set_caption('PyCAD')
129
# icon = pygame.image.load('./img/icon.png')
1310
# pygame.display.set_icon(icon)
1411

1512
WHITE = (255, 255, 255)
13+
BLACK = (0, 0, 0)
14+
BLUE = (0, 0, 255)
15+
GREEN = (0, 255, 0)
16+
RED = (255, 0, 0)
17+
YELLOW = (225, 225, 0)
18+
19+
pygame.init()
20+
fpsClock = pygame.time.Clock()
21+
22+
bar_font_file = pygame.font.match_font('SimHei')
23+
bar_font = pygame.font.Font(bar_font_file, 20)
24+
25+
menu_bar_tabs = ['文件', '编辑']
26+
tab_interval = 10
27+
28+
29+
def display_menu_bar_tabs():
30+
tabx = tab_interval
31+
for tab_text in menu_bar_tabs:
32+
tab_text_surface = bar_font.render(tab_text, True, BLACK, GREEN)
33+
tab_rect = tab_text_surface.get_rect()
34+
tab_rect.topleft = (tabx, 8)
35+
tabx = tabx + tab_rect.width + tab_interval
36+
mainwindow.blit(tab_text_surface, tab_rect)
37+
38+
39+
def display_menu_bar():
40+
menu_bar_rect = (0, 0, mainwindow_w, 36)
41+
pygame.draw.rect(mainwindow, BLUE, menu_bar_rect)
42+
display_menu_bar_tabs()
43+
44+
45+
def display_xy_status():
46+
xy_status = 'x:%d y:%d' % (mouse_x, mouse_y)
47+
tab_text_surface = bar_font.render(xy_status, True, BLACK, YELLOW)
48+
tab_rect = tab_text_surface.get_rect()
49+
tab_rect.topleft = (10, mainwindow_h - 28)
50+
mainwindow.blit(tab_text_surface, tab_rect)
51+
52+
53+
def display_status_bar():
54+
status_bar_rect = (0, mainwindow_h - 36, mainwindow_w, 36)
55+
pygame.draw.rect(mainwindow, RED, status_bar_rect)
56+
display_xy_status()
1657

1758

1859
def display_main_window():
1960
mainwindow.fill(WHITE)
61+
display_menu_bar()
62+
display_status_bar()
2063

2164

2265
while True:
66+
mainwindow_w, mainwindow_h = pygame.display.get_surface().get_size()
67+
mouse_x, mouse_y = pygame.mouse.get_pos()
2368
display_main_window()
2469
for event in pygame.event.get():
2570
if event.type == QUIT:

0 commit comments

Comments
 (0)