👍️[Update] Model : overlayのUIの動作に連動するようにCallbackを設定(未検証)

This commit is contained in:
misygauziya
2024-04-24 16:09:24 +09:00
parent 5b38db9557
commit 143107b7f9
4 changed files with 123 additions and 44 deletions

View File

@@ -59,7 +59,7 @@ class UIElement:
def setTransparency(self, a):
self.overlay.setOverlayAlpha(self.handle, a)
def setPosition(self, pos):
def updatePosition(self, pos):
"""
pos is a 2-tuple representing normalized (x, y)
"""
@@ -76,6 +76,13 @@ class UIElement:
self.transform
)
def setPosition(self, pos):
self.settings["Normalized_icon_X_position"] = pos[0]
self.settings["Normalized_icon_Y_position"] = pos[1]
def setDepth(self, depth):
self.settings["Icon_plane_depth"] = depth
class UIManager:
def __init__(self, overlay_key, overlay_name, settings):
self.overlay = openvr.IVROverlay()
@@ -93,8 +100,11 @@ class UIManager:
if self.settings['Fade_interval'] != 0:
self.evaluateTransparencyFade(self.overlayUI, self.lastUpdate, currTime)
def uiUpdate(self, img):
def setImage(self, img):
self.overlayUI.setImage(img)
def uiUpdate(self, img):
self.setImage(img)
self.overlayUI.setTransparency(self.settings['Transparency'])
self.lastUpdate = time.monotonic()
@@ -107,21 +117,33 @@ class UIManager:
ui.setTransparency(fadeRatio * self.settings['Transparency'])
def posUpdate(self, pos):
def posUpdate(self):
self.overlayUI.updatePosition()
def setPosition(self, pos):
self.overlayUI.setPosition(pos)
def setDepth(self, depth):
self.overlayUI.setDepth(depth)
def setFadeTime(self, fade_time):
self.settings["Fade_time"] = fade_time
def setFadeInterval(self, fade_interval):
self.settings["Fade_interval"] = fade_interval
class Overlay:
def __init__(self):
def __init__(self, x, y , depth, fade_time, fade_interval):
self.initFlag = False
settings = {
"Color": [1, 1, 1],
"Transparency": 1,
"Normalized_icon_X_position": 0.0,
"Normalized_icon_Y_position": -0.41,
"Icon_plane_depth": 1,
"Normalized_icon_X_position": x,
"Normalized_icon_Y_position": y,
"Icon_plane_depth": depth,
"Normalized_icon_width": 1,
"Fade_time": 5,
"Fade_interval": 2,
"Fade_time": fade_time,
"Fade_interval": fade_interval,
}
self.settings = settings

View File

@@ -4,10 +4,6 @@ from typing import Tuple
from PIL import Image, ImageDraw, ImageFont
class OverlayImage:
WIDTH = 1920//2
HEIGHT = 46//2
FONT_SIZE_SHORT = HEIGHT
# TEXT_COLOR_LARGE = (223, 223, 223)
# TEXT_COLOR_SMALL = (190, 190, 190)
# TEXT_COLOR_SEND = (70, 161, 146)
@@ -22,8 +18,9 @@ class OverlayImage:
"Chinese Traditional": "NotoSansTC-Regular",
}
def __init__(self):
self.log_data = []
def __init__(self, opacity, ui_scaling):
self.opacity = int(opacity*255)
self.ui_scaling = ui_scaling
@staticmethod
def concatenateImagesVertically(img1: Image, img2: Image) -> Image:
@@ -142,23 +139,29 @@ class OverlayImage:
# img = Image.alpha_composite(background, img)
# return img
def setOpacity(self, opacity):
self.opacity = int(opacity*255)
def setUiScaling(self, ui_scaling):
self.ui_scaling = ui_scaling
def getUiSize(self):
return {
"width": 960,
"height": 23,
"font_size": 23,
"width": int(960*self.ui_scaling),
"height": int(23*self.ui_scaling),
"font_size": int(23*self.ui_scaling),
}
def getUiColors(self, ui_type):
match ui_type:
case "default":
background_color = (41, 42, 45, 240)
background_outline_color = (41, 42, 45, 240)
text_color = (223, 223, 223)
background_color = (41, 42, 45, self.opacity)
background_outline_color = (41, 42, 45, self.opacity)
text_color = (223, 223, 223, self.opacity)
case "sakura":
background_color = (225, 40, 30, 80)
background_outline_color = (255, 255, 255, 200)
text_color = (223, 223, 223)
background_color = (225, 40, 30, self.opacity)
background_outline_color = (255, 255, 255, self.opacity)
text_color = (223, 223, 223, self.opacity)
return {
"background_color": background_color,
"background_outline_color": background_outline_color,