├── README.md ├── examples └── example.py └── src ├── icon.png └── oGUI.py /README.md: -------------------------------------------------------------------------------- 1 | # overlayGUI 2 | A simple but powerful GUI python package for overlays. 3 | 4 | This package will create a transparent, clickable window that you can draw things such as menus on. You can still interact with the window behind the overlay window. 5 | (Windows only) 6 | 7 | **Documentation** 8 | ----------------- 9 | **Introduction** 10 | 11 | To *initialize* oGUI, you need to call 12 | ```py 13 | oGUI.init() 14 | ``` 15 | Once you have called this, you can create an **infinite loop** and call two functions, **startLoop()** and **endLoop()**. 16 | ```py 17 | while True: 18 | oGUI.startLoop() 19 | 20 | oGUI.endLoop() 21 | ``` 22 | 23 | *Inbetween* the `start` and `end` loop, you can call the drawing functions. 24 | 25 | *Here is an example:* 26 | ```py 27 | checkbox = oGUI.Checkbox(oGUI.gray, oGUI.orange, 125, 150, 20, 20) 28 | 29 | while True: 30 | oGUI.startLoop() 31 | 32 | checkbox.draw() 33 | 34 | oGUI.endLoop() 35 | ``` 36 | Here we are creating a variable called `checkbox` which is equal to the `oGUI.Checkbox()` function. 37 | 38 | **Colors** 39 | --------------------- 40 | 41 | *oGUI* comes with a few **color variables** you can access by using `oGUI.colorname` 42 | These are the available colors: 43 | 44 | `oGUI.white` 45 | `oGUI.red` 46 | `oGUI.green` 47 | `oGUI.blue` 48 | `oGUI.cyan` 49 | `oGUI.orange` 50 | `oGUI.black` 51 | `oGUI.gray` 52 | `oGUI.purple` 53 | `oGUI.yellow` 54 | `oGUI.lightgray` 55 | `oGUI.darkgray` 56 | 57 | **Functions** 58 | --------------------- 59 | Creating *checkboxes* 60 | 61 | To create a **checkbox**, we can create a variable and then call the `oGUI.Checkbox()` function. Usage: 62 | ```py 63 | checkbox1 = oGUI.Checkbox(outsideColor, insideColor, x position, y position, width, height, enabledByDefault) 64 | ``` 65 | enabledByDefault is optional, and if you leave it blank (dont specify it), it will be false. 66 | 67 | We will continue to use *checkbox1* as the *checkbox variable* for the rest of the documentation, and the *rest of these functions* should be called in an **infinite loop.** 68 | 69 | To *render* the actual checkbox, we must call its `.draw()` function. Usage: 70 | ```py 71 | checkbox1.draw() 72 | ``` 73 | We need to put this function inbetween of our `startLoop()` and `endLoop()`. 74 | 75 | We can also change the *color* of the box if it is hovered over, using the `.is_hovered()` function. Usage: 76 | ```py 77 | checkbox1.is_hovered(color) 78 | ``` 79 | The **color** parameter accepts an *RGB value*, for example: `(255, 0, 0)` or it will accept *oGUI colors*. For example, `oGUI.orange`. All the oGUI colors are listed in the **Colors** section, below the Introduction section. 80 | 81 | We can use `.printMousePos()` to print the mouse's position in the GUI window to the console. Usage: 82 | ```py 83 | checkbox1.printMousePos() 84 | ``` 85 | 86 | We can also *detect* when the checkbox **is enabled** by doing `.is_enabled()`, this will *return a boolean value* (True/False). Usage: 87 | ```py 88 | checkbox1.is_enabled() 89 | ``` 90 | 91 | Creating *buttons* 92 | 93 | Creating a button is the same as creating a checkbox with all the same functions, but for the button we call `oGUI.Button()`. 94 | 95 | Creating *text* 96 | 97 | To create **text**, we can create a variable and then call the `oGUI.Text()` function. Usage: 98 | ```py 99 | myText = oGUI.Text(color, x, y, fontSize, "TextToDisplay") 100 | ``` 101 | 102 | To *render* the text, we must call its `.draw()` function. Usage: 103 | ```py 104 | myText.draw() 105 | ``` 106 | 107 | We can also display a dropshadow for the text by calling the `.dropShadow()` function. Usage: 108 | ```py 109 | myText.dropShadow(color, pixelOffset) 110 | ``` 111 | 112 | Additionally, we can change the font of the text by calling `.font()` Usage: 113 | ```py 114 | myText.font('Roboto') 115 | ``` 116 | -------------------------------------------------------------------------------- /examples/example.py: -------------------------------------------------------------------------------- 1 | import oGUI 2 | 3 | oGUI.init() 4 | 5 | checkbox = oGUI.Checkbox(oGUI.gray, oGUI.orange, 125, 150, 20, 20) 6 | rect = oGUI.Rect(oGUI.darkgray, 100, 100, 300, 500) 7 | box = oGUI.Box(oGUI.lightgray, 100, 100, 300, 500, 5) 8 | button = oGUI.Button(oGUI.gray, oGUI.orange, 120, 200, 30, 30) 9 | button2 = oGUI.Button(oGUI.darkgray, oGUI.lightgray, 368, 103, 30, 35) 10 | 11 | myText = oGUI.Text(oGUI.orange, 195, 110, 30, "oGUI Demo") 12 | myText2 = oGUI.Text(oGUI.orange, 155, 152, 25, "Checkbox") 13 | myText3 = oGUI.Text(oGUI.orange, 155, 208, 25, "Button") 14 | myText4 = oGUI.Text(oGUI.black, 375, 105, 30, "X") 15 | 16 | while True: 17 | 18 | oGUI.startLoop() #Start of Draw Loop 19 | 20 | rect.draw() #Drawing Rectangle, Box, Checkbox, and Button 21 | box.draw() 22 | checkbox.draw() 23 | button.draw() 24 | button2.draw() 25 | 26 | myText.draw() #Drawing Text 27 | myText2.draw() 28 | myText3.draw() 29 | myText4.draw() 30 | 31 | oGUI.endLoop() #End of Draw Loop 32 | 33 | checkbox.is_hovered(oGUI.lightgray) #Changes color when checkbox and button(s) is hovered over 34 | button.is_hovered(oGUI.lightgray) 35 | button2.is_hovered(oGUI.gray) 36 | 37 | myText.font('Roboto') #Setting Text Object's font 38 | myText2.font('Roboto') 39 | myText3.font('Roboto') 40 | 41 | myText.dropShadow(oGUI.black, 2) #Setting Text Object's DropShadow 42 | myText2.dropShadow(oGUI.black, 2) 43 | myText3.dropShadow(oGUI.black, 2) 44 | 45 | if button.is_enabled(): #Do something if the button is enabled/pressed 46 | print('Button was pressed') 47 | 48 | if button2.is_enabled(): #Exit Button 49 | exit(0) 50 | 51 | if checkbox.is_enabled(): #Do something if the checkbox is enabled 52 | print('Checkbox is Enabled!') 53 | -------------------------------------------------------------------------------- /src/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanedits/overlayGUI/ffa82318e4a7e1082c062683282d4569831de9b1/src/icon.png -------------------------------------------------------------------------------- /src/oGUI.py: -------------------------------------------------------------------------------- 1 | import pygame, win32api, win32gui, win32con, time 2 | 3 | version = 0.4 4 | 5 | width = win32api.GetSystemMetrics(0) 6 | height = win32api.GetSystemMetrics(1) 7 | screen = pygame.display.set_mode((width, height), pygame.NOFRAME) 8 | fuchsia = (255, 0, 128) 9 | hwnd = pygame.display.get_wm_info()["window"] 10 | 11 | programIcon = pygame.image.load('icon.png') 12 | 13 | pygame.display.set_icon(programIcon) 14 | 15 | white = (255, 255, 255) 16 | red = (255, 0, 0) 17 | green = (0, 255, 0) 18 | blue = (0, 0, 255) 19 | cyan = (52, 204, 235) 20 | orange = (242, 137, 31) 21 | black = (0, 0, 0) 22 | yellow = (255, 255, 0) 23 | gray = (61, 61, 61) 24 | lightgray = (110, 110, 110) 25 | darkgray = (41, 41, 41) 26 | purple = (133, 55, 250) 27 | 28 | def init(): 29 | pygame.init() 30 | pygame.display.set_caption('oGUI window') 31 | print('') 32 | print(f'OverlayGUI {version}') 33 | print('oGUI package by EthanEDITS') 34 | print('') 35 | 36 | win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, 37 | win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED) 38 | win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(*fuchsia), 0, win32con.LWA_COLORKEY) 39 | win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOSIZE) 40 | 41 | def startLoop(): 42 | for event in pygame.event.get(): 43 | if event.type == pygame.QUIT: 44 | exit(0) 45 | screen.fill(fuchsia) 46 | 47 | def endLoop(): 48 | pygame.display.update() 49 | 50 | class Checkbox: 51 | 52 | def __init__(self, outsideColor, insideColor, x, y, width, height, enabledByDefault = False): 53 | self.outsideColor = outsideColor 54 | self.insideColor = insideColor 55 | self.x = x 56 | self.y = y 57 | self.width = width 58 | self.height = height 59 | self.checkBox_enabled = enabledByDefault 60 | self.is_hoverable = False 61 | self.hover_color = gray 62 | self.boolMousePos = False 63 | 64 | def is_hovered(self, hoveredColor): 65 | self.is_hoverable = True 66 | self.hover_color = hoveredColor 67 | 68 | def printMousePos(self): 69 | self.boolMousePos = True 70 | 71 | def is_enabled(self): 72 | return self.checkBox_enabled 73 | 74 | def draw(self): 75 | pygame.draw.rect(screen, self.outsideColor, pygame.Rect(self.x - self.width/8, self.y - self.height/8, self.width + self.width/4, self.height + self.height/4)) 76 | 77 | mouse = pygame.mouse 78 | 79 | if self.x + self.width > mouse.get_pos()[0] > self.x and self.y + self.height > mouse.get_pos()[1] > self.y: 80 | #When Hovered Over 81 | if self.is_hoverable: 82 | pygame.draw.rect(screen, self.hover_color, pygame.Rect(self.x - self.width/8, self.y - self.height/8, self.width + self.width/4, self.height + self.height/4)) 83 | 84 | #When clicked 85 | if mouse.get_pressed()[0]: 86 | self.checkBox_enabled = not self.checkBox_enabled 87 | time.sleep(0.15) 88 | 89 | if self.checkBox_enabled: 90 | pygame.draw.rect(screen, self.insideColor, pygame.Rect(self.x, self.y, self.width, self.height)) 91 | 92 | if self.boolMousePos: 93 | print(mouse.get_pos()) 94 | 95 | class Rect: 96 | 97 | def __init__(self, color, x, y, width, height): 98 | self.color = color 99 | self.x = x 100 | self.y = y 101 | self.width = width 102 | self.height = height 103 | 104 | def draw(self): 105 | pygame.draw.rect(screen, self.color, pygame.Rect(self.x, self.y, self.width, self.height)) 106 | 107 | class Box: 108 | 109 | def __init__(self, color, x, y, width, height, thickness): 110 | self.color = color 111 | self.x = x 112 | self.y = y 113 | self.width = width 114 | self.height = height 115 | self.thickness = thickness 116 | 117 | def draw(self): 118 | pygame.draw.line(screen, self.color, (self.x + self.width, self.y), (self.x, self.y), self.thickness) #Top 119 | pygame.draw.line(screen, self.color, (self.x, self.y + self.height), (self.x, self.y), self.thickness) #Left 120 | pygame.draw.line(screen, self.color, (self.x + self.width, self.y), (self.x + self.width, self.y + self.height), self.thickness) #Right 121 | pygame.draw.line(screen, self.color, (self.x, self.y + self.height), (self.x + self.width, self.y + self.height), self.thickness) #Bottom 122 | 123 | class Text: 124 | 125 | def __init__(self, color, x, y, FontSize, textStr): 126 | pygame.font.init() 127 | self.color = color 128 | self.x = x 129 | self.y = y 130 | self.FontSize = FontSize 131 | self.textStr = textStr 132 | self.FontString = 'Arial' 133 | #DropShadow 134 | self.dropShadowEnabled = False 135 | self.dropShadowColor = black 136 | self.dropShadowOffset = 2 137 | 138 | def font(self, fontStr): 139 | self.FontString = fontStr 140 | 141 | def dropShadow(self, color, offset): 142 | self.dropShadowEnabled = True 143 | self.dropShadowColor = color 144 | self.dropShadowOffset = offset 145 | 146 | def draw(self): 147 | myfont = pygame.font.SysFont(self.FontString, self.FontSize) 148 | textSurface = myfont.render(self.textStr, True, self.color) #Main Text 149 | 150 | if self.dropShadowEnabled: 151 | textSurface2 = myfont.render(self.textStr, True, black) #DropShadow 152 | screen.blit(textSurface2, (self.x + self.dropShadowOffset, self.y)) #DropShadow 153 | 154 | screen.blit(textSurface, (self.x, self.y)) #Main Text 155 | 156 | class Button: 157 | def __init__(self, color, clickedColor, x,y,width,height, text=''): 158 | self.color = color 159 | self.clickedColor = clickedColor 160 | self.x = x 161 | self.y = y 162 | self.width = width 163 | self.height = height 164 | self.text = text 165 | self.is_hoverable = False 166 | self.hover_color = gray 167 | self.button_enabled = False 168 | 169 | def is_enabled(self): 170 | return self.button_enabled 171 | 172 | def is_hovered(self, hoveredColor): 173 | self.is_hoverable = True 174 | self.hover_color = hoveredColor 175 | 176 | def draw(self): 177 | pygame.draw.rect(screen, self.color, pygame.Rect(self.x, self.y, self.width, self.height)) 178 | 179 | mouse = pygame.mouse 180 | 181 | if self.x + self.width > mouse.get_pos()[0] > self.x and self.y + self.height > mouse.get_pos()[1] > self.y: 182 | if self.is_hoverable: 183 | pygame.draw.rect(screen, self.hover_color, pygame.Rect(self.x, self.y, self.width, self.height)) 184 | 185 | if mouse.get_pressed()[0]: 186 | self.button_enabled = True 187 | pygame.draw.rect(screen, self.clickedColor, pygame.Rect(self.x, self.y, self.width, self.height)) 188 | else: 189 | self.button_enabled = False 190 | --------------------------------------------------------------------------------