added setting percent display
This commit is contained in:
parent
4902d72ebc
commit
a750ddcd6b
@ -9,7 +9,6 @@ PI = 3.14159265
|
|||||||
VALID_SURFACES = [
|
VALID_SURFACES = [
|
||||||
'dial'
|
'dial'
|
||||||
]
|
]
|
||||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
|
|
||||||
|
|
||||||
def main(windowed_mode=False):
|
def main(windowed_mode=False):
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
import os
|
||||||
|
|
||||||
DIAL_SCALING = 0.9
|
DIAL_SCALING = 0.9
|
||||||
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
class Dial(pygame.Surface):
|
class Dial(pygame.Surface):
|
||||||
def __init__(self, dial_size):
|
def __init__(self, dial_size):
|
||||||
@ -33,13 +33,13 @@ class Dial(pygame.Surface):
|
|||||||
def move_dial(self, movement_amount):
|
def move_dial(self, movement_amount):
|
||||||
self.setting = max(0, min(self.setting + movement_amount, 1))
|
self.setting = max(0, min(self.setting + movement_amount, 1))
|
||||||
|
|
||||||
|
|
||||||
class MouseHandler:
|
class MouseHandler:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.prev_mouse_pos = pygame.mouse.get_pos()
|
self.prev_mouse_pos = pygame.mouse.get_pos()
|
||||||
self.mouse_pos = pygame.mouse.get_pos()
|
self.mouse_pos = pygame.mouse.get_pos()
|
||||||
self.active = False
|
self.active = False
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.prev_mouse_pos = self.mouse_pos
|
self.prev_mouse_pos = self.mouse_pos
|
||||||
self.mouse_pos = pygame.mouse.get_pos()
|
self.mouse_pos = pygame.mouse.get_pos()
|
||||||
@ -52,6 +52,7 @@ class MouseHandler:
|
|||||||
speed_coeff = math.cos((mouse_angle - (0.5 * math.pi)) - diff_angle)
|
speed_coeff = math.cos((mouse_angle - (0.5 * math.pi)) - diff_angle)
|
||||||
return movement_speed * speed_coeff
|
return movement_speed * speed_coeff
|
||||||
|
|
||||||
|
|
||||||
class Surface(pygame.Surface):
|
class Surface(pygame.Surface):
|
||||||
def __init__(self, window_size):
|
def __init__(self, window_size):
|
||||||
super().__init__(window_size, pygame.SRCALPHA)
|
super().__init__(window_size, pygame.SRCALPHA)
|
||||||
@ -64,10 +65,10 @@ class Surface(pygame.Surface):
|
|||||||
self.dial.rect.center = (window_size[0] / 2, window_size[1] / 2)
|
self.dial.rect.center = (window_size[0] / 2, window_size[1] / 2)
|
||||||
|
|
||||||
self.mouse_handler = MouseHandler()
|
self.mouse_handler = MouseHandler()
|
||||||
|
self.font = pygame.font.Font(SCRIPT_DIR + '/resources/tuffy.ttf', 128)
|
||||||
|
|
||||||
pygame.mouse.set_visible(False)
|
pygame.mouse.set_visible(False)
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.fill((32, 32, 32))
|
self.fill((32, 32, 32))
|
||||||
self.mouse_handler.update()
|
self.mouse_handler.update()
|
||||||
@ -83,7 +84,6 @@ class Surface(pygame.Surface):
|
|||||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
self.mouse_handler.active = True
|
self.mouse_handler.active = True
|
||||||
self.mouse_handler.prev_mouse_pos = self.mouse_handler.mouse_pos
|
self.mouse_handler.prev_mouse_pos = self.mouse_handler.mouse_pos
|
||||||
print('yug')
|
|
||||||
if event.type == pygame.MOUSEBUTTONUP:
|
if event.type == pygame.MOUSEBUTTONUP:
|
||||||
self.mouse_handler.active = False
|
self.mouse_handler.active = False
|
||||||
|
|
||||||
@ -91,4 +91,10 @@ class Surface(pygame.Surface):
|
|||||||
self.dial.move_dial(self.mouse_handler.get_circular_speed(self.dial.center) / -3000.0)
|
self.dial.move_dial(self.mouse_handler.get_circular_speed(self.dial.center) / -3000.0)
|
||||||
|
|
||||||
self.blit(self.dial, self.dial.rect)
|
self.blit(self.dial, self.dial.rect)
|
||||||
|
|
||||||
|
text = self.font.render('{0}%'.format(round(self.dial.setting * 100)), True, (255, 255, 255))
|
||||||
|
text_rect = text.get_rect()
|
||||||
|
text_rect.center = self.dial.rect.center
|
||||||
|
self.blit(text, text_rect)
|
||||||
|
|
||||||
self.dial.update()
|
self.dial.update()
|
||||||
|
Loading…
Reference in New Issue
Block a user