-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlay.py
More file actions
62 lines (50 loc) · 2.45 KB
/
Copy pathoverlay.py
File metadata and controls
62 lines (50 loc) · 2.45 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
import pygame
import win32api
import win32con
import win32gui
class Overlay:
def __init__(self, attachWindowName):
# Initialize overlay
self.attachedWindowName = attachWindowName
self.isOverlayRunning = True
pygame.init()
pygame.font.init()
self.__font = 'chinese_font.ttf'
self.OverlayScreen = pygame.display.set_mode((self.__getGameWindow(self.attachedWindowName)[2],
self.__getGameWindow(self.attachedWindowName)[3]),
pygame.NOFRAME)
self.__fuchsia = (255, 0, 128) # Transparency color
# Set window transparency color
hwnd = pygame.display.get_wm_info()["window"]
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED)
win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(*self.__fuchsia), 0, win32con.LWA_COLORKEY)
def UpdateOverlayPart1(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.isOverlayRunning = False
# Track Game
self.__trackGameWindow(self.attachedWindowName) # Make sure overlay follows the game
self.OverlayScreen.fill(self.__fuchsia)
def DrawText(self, text, textSize, positionXY, rgb, bold = True):
# PYGAME TEXT UPDATES:
overlayFont = pygame.font.Font(self.__font, textSize)
overlayFont.bold = bold
gameText = overlayFont.render(text, False, rgb)
self.OverlayScreen.blit(gameText, positionXY)
def DrawRectangle(self, bbox, thickness, rgb):
pygame.draw.rect(self.OverlayScreen, rgb, pygame.Rect(bbox[0], bbox[1], bbox[2], bbox[3]), thickness)
def UpdateOverlayPart2(self):
pygame.display.update()
def __getGameWindow(self, windowname):
hwnd = win32gui.FindWindow(None, windowname)
windowrect = win32gui.GetWindowRect(hwnd)
x = windowrect[0] - 5 # -5 so it lines up perfectly
y = windowrect[1]
width = windowrect[2] - x
height = windowrect[3] - y
return x, y, width, height
def __trackGameWindow(self, windowname):
win32gui.SetWindowPos(pygame.display.get_wm_info()['window'], -1,
self.__getGameWindow(windowname)[0],
self.__getGameWindow(windowname)[1], 0, 0, 0x0001)