Skip to content

Commit

Permalink
the second step
Browse files Browse the repository at this point in the history
  • Loading branch information
speedyGaoxuan authored Feb 29, 2024
1 parent dc606aa commit c9b5d22
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,70 @@
# 基于pygame的图形化CAD编辑器
# made by Gaoxuan

import pygame, sys
import pygame, sys, time
from pygame.locals import *

pygame.init()
fpsClock = pygame.time.Clock()

mainwindow = pygame.display.set_mode((400, 300), 0, 32)
mainwindow = pygame.display.set_mode((1600, 900), pygame.RESIZABLE, 32)
pygame.display.set_caption('PyCAD')
# icon = pygame.image.load('./img/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_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():
tabx = 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 = (tabx, 8)
tabx = tabx + tab_rect.width + tab_interval
mainwindow.blit(tab_text_surface, tab_rect)


def display_menu_bar():
menu_bar_rect = (0, 0, mainwindow_w, 36)
pygame.draw.rect(mainwindow, BLUE, menu_bar_rect)
display_menu_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 - 36, mainwindow_w, 36)
pygame.draw.rect(mainwindow, RED, status_bar_rect)
display_xy_status()


def display_main_window():
mainwindow.fill(WHITE)
display_menu_bar()
display_status_bar()


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:
Expand Down

0 comments on commit c9b5d22

Please sign in to comment.