|
1 | 1 | # 基于pygame的图形化CAD编辑器 |
2 | 2 | # made by Gaoxuan |
3 | 3 |
|
4 | | -import pygame, sys |
| 4 | +import pygame, sys, time |
5 | 5 | from pygame.locals import * |
6 | 6 |
|
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) |
11 | 8 | pygame.display.set_caption('PyCAD') |
12 | 9 | # icon = pygame.image.load('./img/icon.png') |
13 | 10 | # pygame.display.set_icon(icon) |
14 | 11 |
|
15 | 12 | 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() |
16 | 57 |
|
17 | 58 |
|
18 | 59 | def display_main_window(): |
19 | 60 | mainwindow.fill(WHITE) |
| 61 | + display_menu_bar() |
| 62 | + display_status_bar() |
20 | 63 |
|
21 | 64 |
|
22 | 65 | while True: |
| 66 | + mainwindow_w, mainwindow_h = pygame.display.get_surface().get_size() |
| 67 | + mouse_x, mouse_y = pygame.mouse.get_pos() |
23 | 68 | display_main_window() |
24 | 69 | for event in pygame.event.get(): |
25 | 70 | if event.type == QUIT: |
|
0 commit comments