diff --git a/src-python/config.py b/src-python/config.py index 903f08e7..12d651d9 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -738,19 +738,6 @@ class Config: self._SEND_MESSAGE_BUTTON_TYPE = value self.saveConfig(inspect.currentframe().f_code.co_name, value) - @property - @json_serializable('OVERLAY_SETTINGS') - def OVERLAY_SETTINGS(self): - return self._OVERLAY_SETTINGS - - @OVERLAY_SETTINGS.setter - def OVERLAY_SETTINGS(self, value): - if isinstance(value, dict) and set(value.keys()) == set(self.OVERLAY_SETTINGS.keys()): - for key, value in value.items(): - if isinstance(value, (int, float)): - self._OVERLAY_SETTINGS[key] = float(value) - self.saveConfig(inspect.currentframe().f_code.co_name, self.OVERLAY_SETTINGS) - @property @json_serializable('OVERLAY_SMALL_LOG') def OVERLAY_SMALL_LOG(self): @@ -778,18 +765,46 @@ class Config: case "display_duration" | "fadeout_duration": if isinstance(value, int): self._OVERLAY_SMALL_LOG_SETTINGS[key] = value + case "opacity" | "ui_scaling": + if isinstance(value, (int, float)): + self._OVERLAY_SMALL_LOG_SETTINGS[key] = float(value) self.saveConfig(inspect.currentframe().f_code.co_name, self.OVERLAY_SMALL_LOG_SETTINGS) @property - @json_serializable('OVERLAY_UI_TYPE') - def OVERLAY_UI_TYPE(self): - return self._OVERLAY_UI_TYPE + @json_serializable('OVERLAY_LARGE_LOG') + def OVERLAY_LARGE_LOG(self): + return self._OVERLAY_LARGE_LOG - @OVERLAY_UI_TYPE.setter - def OVERLAY_UI_TYPE(self, value): - if isinstance(value, str): - self._OVERLAY_UI_TYPE = value - # self.saveConfig(inspect.currentframe().f_code.co_name, value) + @OVERLAY_LARGE_LOG.setter + def OVERLAY_LARGE_LOG(self, value): + if isinstance(value, bool): + self._OVERLAY_LARGE_LOG = value + self.saveConfig(inspect.currentframe().f_code.co_name, value) + + @property + @json_serializable('OVERLAY_LARGE_LOG_SETTINGS') + def OVERLAY_LARGE_LOG_SETTINGS(self): + return self._OVERLAY_LARGE_LOG_SETTINGS + + @OVERLAY_LARGE_LOG_SETTINGS.setter + def OVERLAY_LARGE_LOG_SETTINGS(self, value): + if isinstance(value, dict) and set(value.keys()) == set(self.OVERLAY_LARGE_LOG_SETTINGS.keys()): + for key, value in value.items(): + match (key): + case "tracker": + if isinstance(value, str): + # "HMD", "LeftHand", "RightHand" + self._OVERLAY_LARGE_LOG_SETTINGS[key] = value + case "x_pos" | "y_pos" | "z_pos" | "x_rotation" | "y_rotation" | "z_rotation": + if isinstance(value, (int, float)): + self._OVERLAY_LARGE_LOG_SETTINGS[key] = float(value) + case "display_duration" | "fadeout_duration": + if isinstance(value, int): + self._OVERLAY_LARGE_LOG_SETTINGS[key] = value + case "opacity" | "ui_scaling": + if isinstance(value, (int, float)): + self._OVERLAY_LARGE_LOG_SETTINGS[key] = float(value) + self.saveConfig(inspect.currentframe().f_code.co_name, self.OVERLAY_LARGE_LOG_SETTINGS) @property @json_serializable('SEND_MESSAGE_TO_VRC') @@ -1063,10 +1078,6 @@ class Config: self._AUTO_CLEAR_MESSAGE_BOX = True self._SEND_ONLY_TRANSLATED_MESSAGES = False self._SEND_MESSAGE_BUTTON_TYPE = "show" - self._OVERLAY_SETTINGS = { - "opacity": 1.0, - "ui_scaling": 1.0, - } self._OVERLAY_SMALL_LOG = False self._OVERLAY_SMALL_LOG_SETTINGS = { "x_pos": 0.0, @@ -1077,8 +1088,24 @@ class Config: "z_rotation": 0.0, "display_duration": 5, "fadeout_duration": 2, + "opacity": 1.0, + "ui_scaling": 1.0, + "tracker": "HMD", + } + self._OVERLAY_LARGE_LOG = False + self._OVERLAY_LARGE_LOG_SETTINGS = { + "x_pos": 0.0, + "y_pos": 0.0, + "z_pos": 0.0, + "x_rotation": 0.0, + "y_rotation": 0.0, + "z_rotation": 0.0, + "display_duration": 5, + "fadeout_duration": 2, + "opacity": 1.0, + "ui_scaling": 0.5, + "tracker": "LeftHand", } - self._OVERLAY_UI_TYPE = "default" self._SEND_MESSAGE_TO_VRC = True self._SEND_RECEIVED_MESSAGE_TO_VRC = False self._LOGGER_FEATURE = False diff --git a/src-python/model.py b/src-python/model.py index 4adbcbe5..4ba9566d 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -81,20 +81,14 @@ class Model: self.translator = Translator() self.keyword_processor = KeywordProcessor() self.overlay = Overlay( - config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"], - config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"], - config.OVERLAY_SMALL_LOG_SETTINGS["z_pos"], - config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"], - config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"], - config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"], - config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"], - config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"], - config.OVERLAY_SETTINGS["opacity"], - config.OVERLAY_SETTINGS["ui_scaling"], + { + "small": config.OVERLAY_SMALL_LOG_SETTINGS, + "large": config.OVERLAY_LARGE_LOG_SETTINGS, + } ) + self.overlay_small_log_pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS + self.overlay_large_log_pre_settings = config.OVERLAY_LARGE_LOG_SETTINGS self.overlay_image = OverlayImage() - self.pre_overlay_message = None - self.th_overlay = None self.mic_audio_queue = None self.mic_mute_status = None self.kks = kakasi() @@ -683,20 +677,12 @@ class Model: self.speaker_energy_recorder.stop() self.speaker_energy_recorder = None - def createOverlayImageShort(self, message, translation): + def createOverlayImageSmallLog(self, message, translation): your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"] target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"] - ui_type = config.OVERLAY_UI_TYPE - self.pre_overlay_message = { - "message" : message, - "your_language" : your_language, - "translation" : translation, - "target_language" : target_language, - "ui_type" : ui_type, - } - return self.overlay_image.createOverlayImageShort(message, your_language, translation, target_language, ui_type) + return self.overlay_image.createOverlayImageSmallLog(message, your_language, translation, target_language) - def createOverlayImage(self, message): + def createOverlayImageSystemMessage(self, message): ui_language = config.UI_LANGUAGE convert_languages = { "en": "Japanese", @@ -706,42 +692,84 @@ class Model: "zh-Hant":"Chinese Traditional", } language = convert_languages.get(ui_language, "Japanese") - ui_type = config.OVERLAY_UI_TYPE - return self.overlay_image.createOverlayImage(message, language, ui_type) + return self.overlay_image.createOverlayImageSmallLog(message, language) - def clearOverlayImage(self): - self.overlay.clearImage() + def clearOverlayImageSmallLog(self): + self.overlay.clearImage("small") - def updateOverlay(self, img): - self.overlay.updateImage(img) + def updateOverlaySmallLog(self, img): + self.overlay.updateImage(img, "small") + + def updateOverlaySmallLogSettings(self): + for key in self.overlay_small_log_pre_settings.keys(): + if self.overlay_small_log_pre_settings[key] != config.OVERLAY_SMALL_LOG_SETTINGS[key]: + match (key): + case "x_pos" | "y_pos" | "z_pos" | "x_rotation" | "y_rotation" | "z_rotation" | "tracker": + self.overlay.updatePosition( + config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"], + config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"], + config.OVERLAY_SMALL_LOG_SETTINGS["z_pos"], + config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"], + config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"], + config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"], + config.OVERLAY_SMALL_LOG_SETTINGS["tracker"], + "small", + ) + case "display_duration": + self.overlay.updateDisplayDuration(config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"], "small") + case "fadeout_duration": + self.overlay.updateFadeoutDuration(config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"], "small") + case "opacity": + self.overlay.updateOpacity(config.OVERLAY_SMALL_LOG_SETTINGS["opacity"], "small", True) + case "ui_scaling": + self.overlay.updateUiScaling(config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"], "small") + case _: + pass + break + self.overlay_small_log_pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS + + def createOverlayImageLargeLog(self, message_type:str, message:str, translation:str): + your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"] + target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["primary"]["language"] + return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_language) + + def clearOverlayImageLargeLog(self): + self.overlay.clearImage("large") + + def updateOverlayLargeLog(self, img): + self.overlay.updateImage(img, "large") + + def updateOverlayLargeLogSettings(self): + for key in self.overlay_large_log_pre_settings.keys(): + if self.overlay_large_log_pre_settings[key] != config.OVERLAY_LARGE_LOG_SETTINGS[key]: + match (key): + case "x_pos" | "y_pos" | "z_pos" | "x_rotation" | "y_rotation" | "z_rotation" | "tracker": + self.overlay.updatePosition( + config.OVERLAY_LARGE_LOG_SETTINGS["x_pos"], + config.OVERLAY_LARGE_LOG_SETTINGS["y_pos"], + config.OVERLAY_LARGE_LOG_SETTINGS["z_pos"], + config.OVERLAY_LARGE_LOG_SETTINGS["x_rotation"], + config.OVERLAY_LARGE_LOG_SETTINGS["y_rotation"], + config.OVERLAY_LARGE_LOG_SETTINGS["z_rotation"], + config.OVERLAY_LARGE_LOG_SETTINGS["tracker"], + "large", + ) + case "display_duration": + self.overlay.updateDisplayDuration(config.OVERLAY_LARGE_LOG_SETTINGS["display_duration"], "large") + case "fadeout_duration": + self.overlay.updateFadeoutDuration(config.OVERLAY_LARGE_LOG_SETTINGS["fadeout_duration"], "large") + case "opacity": + self.overlay.updateOpacity(config.OVERLAY_LARGE_LOG_SETTINGS["opacity"], "large", True) + case "ui_scaling": + self.overlay.updateUiScaling(config.OVERLAY_LARGE_LOG_SETTINGS["ui_scaling"], "large") + case _: + pass + break + self.overlay_large_log_pre_settings = config.OVERLAY_LARGE_LOG_SETTINGS def startOverlay(self): self.overlay.startOverlay() - def updateOverlayPosition(self): - self.overlay.updatePosition( - config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"], - config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"], - config.OVERLAY_SMALL_LOG_SETTINGS["z_pos"], - config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"], - config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"], - config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"], - ) - - def updateOverlayTimes(self): - display_duration = config.OVERLAY_SMALL_LOG_SETTINGS["display_duration"] - self.overlay.updateDisplayDuration(display_duration) - fadeout_duration = config.OVERLAY_SMALL_LOG_SETTINGS["fadeout_duration"] - self.overlay.updateFadeoutDuration(fadeout_duration) - - def updateOverlayImageOpacity(self): - opacity = config.OVERLAY_SETTINGS["opacity"] - self.overlay.updateOpacity(opacity, with_fade=True) - - def updateOverlayImageUiScaling(self): - ui_scaling = config.OVERLAY_SETTINGS["ui_scaling"] - self.overlay.updateUiScaling(ui_scaling) - def shutdownOverlay(self): self.overlay.shutdownOverlay() diff --git a/src-python/models/overlay/overlay.py b/src-python/models/overlay/overlay.py index 0888a298..5b740728 100644 --- a/src-python/models/overlay/overlay.py +++ b/src-python/models/overlay/overlay.py @@ -10,7 +10,11 @@ try: from . import overlay_utils as utils except ImportError: import overlay_utils as utils -from utils import printLog +try: + from utils import printLog +except ImportError: + def printLog(*args): + print(*args) def mat34Id(array): arr = openvr.HmdMatrix34_t() @@ -63,114 +67,111 @@ def getRightHandBaseMatrix(): return arr class Overlay: - def __init__(self, x_pos, y_pos, z_pos, x_rotation, y_rotation, z_rotation, display_duration, fadeout_duration, opacity, ui_scaling): - self.initialized = False - settings = { - "color": [1, 1, 1], - "opacity": opacity, - "x_pos": x_pos, - "y_pos": y_pos, - "z_pos": z_pos, - "x_rotation": x_rotation, - "y_rotation": y_rotation, - "z_rotation": z_rotation, - "display_duration": display_duration, - "fadeout_duration": fadeout_duration, - "ui_scaling": ui_scaling, - } - self.settings = settings + def __init__(self, settings_dict): self.system = None self.overlay = None self.handle = None - self.lastUpdate = time.monotonic() - self.thread_overlay = None - self.fadeRatio = 1 + self.initialized = False self.loop = True + self.thread_overlay = None + + self.settings = {} + self.lastUpdate = {} + self.fadeRatio = {} + for key, value in settings_dict.items(): + self.settings[key] = value + self.lastUpdate[key] = time.monotonic() + self.fadeRatio[key] = 1 def init(self): try: self.system = openvr.init(openvr.VRApplication_Background) self.overlay = openvr.IVROverlay() self.overlay_system = openvr.IVRSystem() - self.handle = self.overlay.createOverlay("Overlay_Speaker2log", "Overlay_Speaker2log_UI") - self.overlay.showOverlay(self.handle) + self.handle = {} + for i, size in enumerate(self.settings.keys()): + self.handle[size] = self.overlay.createOverlay(f"VRCT{i}", f"VRCT{i}") + self.overlay.showOverlay(self.handle[size]) self.initialized = True - self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0))) - self.updateColor(self.settings["color"]) - self.updateOpacity(self.settings["opacity"]) - self.updateUiScaling(self.settings["ui_scaling"]) - self.updatePosition( - self.settings["x_pos"], - self.settings["y_pos"], - self.settings["z_pos"], - self.settings["x_rotation"], - self.settings["y_rotation"], - self.settings["z_rotation"], - ) + for size in self.settings.keys(): + self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)), size) + self.updateColor([1, 1, 1], size) + self.updateOpacity(self.settings[size]["opacity"], size, True) + self.updateUiScaling(self.settings[size]["ui_scaling"], size) + self.updatePosition( + self.settings[size]["x_pos"], + self.settings[size]["y_pos"], + self.settings[size]["z_pos"], + self.settings[size]["x_rotation"], + self.settings[size]["y_rotation"], + self.settings[size]["z_rotation"], + self.settings[size]["tracker"], + size + ) except Exception as e: printLog("error:Could not initialise OpenVR", e) - def updateImage(self, img): + def updateImage(self, img, size): if self.initialized is True: width, height = img.size img = img.tobytes() img = (ctypes.c_char * len(img)).from_buffer_copy(img) try: - self.overlay.setOverlayRaw(self.handle, img, width, height, 4) + self.overlay.setOverlayRaw(self.handle[size], img, width, height, 4) except Exception as e: printLog("error:Could not update image", e) self.initialized = False self.reStartOverlay() while self.initialized is False: time.sleep(0.1) - self.overlay.setOverlayRaw(self.handle, img, width, height, 4) - self.updateOpacity(self.settings["opacity"]) - self.lastUpdate = time.monotonic() + self.overlay.setOverlayRaw(self.handle[size], img, width, height, 4) + self.updateOpacity(self.settings[size]["opacity"], size, True) + self.lastUpdate[size] = time.monotonic() - def clearImage(self): + def clearImage(self, size): if self.initialized is True: - self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0))) + self.updateImage(Image.new("RGBA", (1, 1), (0, 0, 0, 0)), size) - def updateColor(self, col): + def updateColor(self, col, size): """ col is a 3-tuple representing (r, g, b) """ - self.settings["color"] = col if self.initialized is True: - r, g, b = self.settings["color"] - self.overlay.setOverlayColor(self.handle, r, g, b) + r, g, b = col + self.overlay.setOverlayColor(self.handle[size], r, g, b) - def updateOpacity(self, opacity, with_fade=False): - self.settings["opacity"] = opacity + def updateOpacity(self, opacity, size, with_fade=True): + self.settings[size]["opacity"] = opacity if self.initialized is True: if with_fade is True: - if self.fadeRatio > 0: - self.overlay.setOverlayAlpha(self.handle, self.fadeRatio * self.settings["opacity"]) + if self.fadeRatio[size] > 0: + self.overlay.setOverlayAlpha(self.handle[size], self.fadeRatio[size] * self.settings[size]["opacity"]) else: - self.overlay.setOverlayAlpha(self.handle, self.settings["opacity"]) + self.overlay.setOverlayAlpha(self.handle[size], self.settings[size]["opacity"]) - def updateUiScaling(self, ui_scaling): - self.settings["ui_scaling"] = ui_scaling + def updateUiScaling(self, ui_scaling, size): + self.settings[size]["ui_scaling"] = ui_scaling if self.initialized is True: - self.overlay.setOverlayWidthInMeters(self.handle, self.settings["ui_scaling"]) + self.overlay.setOverlayWidthInMeters(self.handle[size], self.settings[size]["ui_scaling"]) - def updatePosition(self, x_pos, y_pos, z_pos, x_rotation, y_rotation, z_rotation, tracker="HMD"): + def updatePosition(self, x_pos, y_pos, z_pos, x_rotation, y_rotation, z_rotation, tracker, size): """ x_pos, y_pos, z_pos are floats representing the position of overlay x_rotation, y_rotation, z_rotation are floats representing the rotation of overlay tracker is a string representing the tracker to use ("HMD", "LeftHand", "RightHand") """ - self.settings["x_pos"] = x_pos - self.settings["y_pos"] = y_pos - self.settings["z_pos"] = z_pos - self.settings["x_rotation"] = x_rotation - self.settings["y_rotation"] = y_rotation - self.settings["z_rotation"] = z_rotation + self.settings[size]["x_pos"] = x_pos + self.settings[size]["y_pos"] = y_pos + self.settings[size]["z_pos"] = z_pos + self.settings[size]["x_rotation"] = x_rotation + self.settings[size]["y_rotation"] = y_rotation + self.settings[size]["z_rotation"] = z_rotation + self.settings[size]["tracker"] = tracker match tracker: case "HMD": @@ -186,23 +187,23 @@ class Overlay: base_matrix = getHMDBaseMatrix() trackerIndex = openvr.k_unTrackedDeviceIndex_Hmd - translation = (self.settings["x_pos"], self.settings["y_pos"], - self.settings["z_pos"]) - rotation = (self.settings["x_rotation"], self.settings["y_rotation"], self.settings["z_rotation"]) + translation = (self.settings[size]["x_pos"], self.settings[size]["y_pos"], - self.settings[size]["z_pos"]) + rotation = (self.settings[size]["x_rotation"], self.settings[size]["y_rotation"], self.settings[size]["z_rotation"]) transform = utils.transform_matrix(base_matrix, translation, rotation) - self.transform = mat34Id(transform) + transform = mat34Id(transform) if self.initialized is True: self.overlay.setOverlayTransformTrackedDeviceRelative( - self.handle, + self.handle[size], trackerIndex, - self.transform + transform ) - def updateDisplayDuration(self, display_duration): - self.settings["display_duration"] = display_duration + def updateDisplayDuration(self, display_duration, size): + self.settings[size]["display_duration"] = display_duration - def updateFadeoutDuration(self, fadeout_duration): - self.settings["fadeout_duration"] = fadeout_duration + def updateFadeoutDuration(self, fadeout_duration, size): + self.settings[size]["fadeout_duration"] = fadeout_duration def checkActive(self): try: @@ -216,26 +217,27 @@ class Overlay: printLog("error:Could not check SteamVR running", e) return False - def evaluateOpacityFade(self, lastUpdate, currentTime): - if (currentTime - lastUpdate) > self.settings["display_duration"]: - timeThroughInterval = currentTime - lastUpdate - self.settings["display_duration"] - self.fadeRatio = 1 - timeThroughInterval / self.settings["fadeout_duration"] - if self.fadeRatio < 0: - self.fadeRatio = 0 - self.overlay.setOverlayAlpha(self.handle, self.fadeRatio * self.settings["opacity"]) + def evaluateOpacityFade(self, lastUpdate, currentTime, size): + if (currentTime - lastUpdate) > self.settings[size]["display_duration"]: + timeThroughInterval = currentTime - lastUpdate - self.settings[size]["display_duration"] + self.fadeRatio[size] = 1 - timeThroughInterval / self.settings[size]["fadeout_duration"] + if self.fadeRatio[size] < 0: + self.fadeRatio[size] = 0 + self.overlay.setOverlayAlpha(self.handle[size], self.fadeRatio[size] * self.settings[size]["opacity"]) - def update(self): + def update(self, size): currTime = time.monotonic() - if self.settings["fadeout_duration"] != 0: - self.evaluateOpacityFade(self.lastUpdate, currTime) + if self.settings[size]["fadeout_duration"] != 0: + self.evaluateOpacityFade(self.lastUpdate[size], currTime, size) else: - self.updateOpacity(self.settings["opacity"]) + self.updateOpacity(self.settings[size]["opacity"], size, True) def mainloop(self): self.loop = True while self.checkActive() is True and self.loop is True: startTime = time.monotonic() - self.update() + for size in self.settings.keys(): + self.update(size) sleepTime = (1 / 16) - (time.monotonic() - startTime) if sleepTime > 0: time.sleep(sleepTime) @@ -255,8 +257,10 @@ class Overlay: self.loop = False self.thread_overlay.join() self.thread_overlay = None - if isinstance(self.overlay, openvr.IVROverlay) and isinstance(self.handle, int): - self.overlay.destroyOverlay(self.handle) + if isinstance(self.overlay, openvr.IVROverlay): + for size in self.settings.keys(): + if isinstance(self.handle[size], int): + self.overlay.destroyOverlay(self.handle[size]) self.overlay = None if isinstance(self.system, openvr.IVRSystem): openvr.shutdown() @@ -273,45 +277,67 @@ class Overlay: return _proc_name in (p.name() for p in process_iter()) if __name__ == "__main__": - # from overlay_image import OverlayImage - # overlay_image = OverlayImage() + from overlay_image import OverlayImage - # overlay = Overlay(0, 0, 1, 1, 0, 1, 1) - # overlay.startOverlay() - # time.sleep(1) + small_settings = { + "x_pos": 0.0, + "y_pos": 0.0, + "z_pos": 0.0, + "x_rotation": 0.0, + "y_rotation": 0.0, + "z_rotation": 0.0, + "display_duration": 5, + "fadeout_duration": 2, + "opacity": 1.0, + "ui_scaling": 0.5, + "tracker": "HMD", + } - # # Example usage - # img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese") - # overlay.updateImage(img) - # time.sleep(100000) - - # for i in range(100): - # print(i) - # overlay = Overlay(0, 0, 1, 1, 1, 1, 1) - # overlay.startOverlay() - # time.sleep(1) + large_settings = { + "x_pos": 0.0, + "y_pos": 0.0, + "z_pos": 0.0, + "x_rotation": 0.0, + "y_rotation": 0.0, + "z_rotation": 0.0, + "display_duration": 5, + "fadeout_duration": 0, + "opacity": 1.0, + "ui_scaling": 0.5, + "tracker": "LeftHand", + } - # # Example usage - # img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese", ui_type="sakura") - # overlay.updateImage(img) - # time.sleep(0.5) + settings_dict = { + "small": small_settings, + "large": large_settings + } - # img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese") - # overlay.updateImage(img) - # time.sleep(0.5) + overlay_image = OverlayImage() + overlay = Overlay(settings_dict) + overlay.startOverlay() + time.sleep(1) - # overlay.shutdownOverlay() + # Example usage + img = overlay_image.createOverlayImageLargeLog("send", "こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese") + overlay.updateImage(img, "large") - x_pos = 0 - y_pos = 0 - z_pos = 0 - x_rotation = 0 - y_rotation = 0 - z_rotation = 0 + img = overlay_image.createOverlayImageSmallLog("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese") + overlay.updateImage(img, "small") + time.sleep(10) - base_matrix = getLeftHandBaseMatrix() - translation = (x_pos * z_pos, y_pos * z_pos, z_pos) - rotation = (x_rotation, y_rotation, z_rotation) - transform = utils.transform_matrix(base_matrix, translation, rotation) - transform = mat34Id(transform) - print(transform) \ No newline at end of file + img = overlay_image.createOverlayImageSmallLog("こんにちは、世界!さようなら2", "Japanese", "Hello,World!Goodbye", "Japanese") + overlay.updateImage(img, "small") + time.sleep(10) + + for i in range(100): + print(i) + # Example usage + img = overlay_image.createOverlayImageSmallLog(f"こんにちは、世界!さようなら_{i}", "Japanese", "Hello,World!Goodbye", "Japanese") + overlay.updateImage(img, "small") + time.sleep(10) + + # img = overlay_image.createOverlayImageSmallLog("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese") + # overlay.updateImage(img, "small") + # time.sleep(0.5) + + overlay.shutdownOverlay() \ No newline at end of file diff --git a/src-python/models/overlay/overlay_image.py b/src-python/models/overlay/overlay_image.py index 23e24c93..c5180650 100644 --- a/src-python/models/overlay/overlay_image.py +++ b/src-python/models/overlay/overlay_image.py @@ -1,16 +1,9 @@ from os import path as os_path -# from datetime import datetime +from datetime import datetime from typing import Tuple from PIL import Image, ImageDraw, ImageFont class OverlayImage: - # TEXT_COLOR_LARGE = (223, 223, 223) - # TEXT_COLOR_SMALL = (190, 190, 190) - # TEXT_COLOR_SEND = (70, 161, 146) - # TEXT_COLOR_RECEIVE = (220, 20, 60) - # TEXT_COLOR_TIME = (120, 120, 120) - # FONT_SIZE_LARGE = HEIGHT - # FONT_SIZE_SMALL = int(FONT_SIZE_LARGE * 2 / 3) LANGUAGES = { "Japanese": "NotoSansJP-Regular", "Korean": "NotoSansKR-Regular", @@ -19,183 +12,56 @@ class OverlayImage: } def __init__(self): - pass + self.message_log = [] @staticmethod - def concatenateImagesVertically(img1: Image, img2: Image) -> Image: - dst = Image.new("RGBA", (img1.width, img1.height + img2.height)) + def concatenateImagesVertically(img1: Image, img2: Image, margin: int = 0) -> Image: + total_height = img1.height + img2.height + margin + dst = Image.new("RGBA", (img1.width, total_height)) dst.paste(img1, (0, 0)) - dst.paste(img2, (0, img1.height)) + dst.paste(img2, (0, img1.height + margin)) return dst @staticmethod def addImageMargin(image: Image, top: int, right: int, bottom: int, left: int, color: Tuple[int, int, int, int]) -> Image: - width, height = image.size - new_width = width + right + left - new_height = height + top + bottom + new_width = image.width + right + left + new_height = image.height + top + bottom result = Image.new(image.mode, (new_width, new_height), color) result.paste(image, (left, top)) return result - # def create_textimage(self, message_type, size, text, language): - # font_size = self.FONT_SIZE_LARGE if size == "large" else self.FONT_SIZE_SMALL - # text_color = self.TEXT_COLOR_LARGE if size == "large" else self.TEXT_COLOR_SMALL - # anchor = "lm" if message_type == "receive" else "rm" - # text_x = 0 if message_type == "receive" else self.WIDTH - # align = "left" if message_type == "receive" else "right" - - # font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular") - # img = Image.new("RGBA", (0, 0), (0, 0, 0, 0)) - # draw = ImageDraw.Draw(img) - # font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "fonts", f"{font_family}.ttf"), font_size) - # # font = ImageFont.truetype(os_path.join("./fonts", f"{font_family}.ttf"), font_size) - # text_width = draw.textlength(text, font) - # character_width = text_width // len(text) - # character_line_num = int(self.WIDTH // character_width) - # if len(text) > character_line_num: - # text = "\n".join([text[i:i+character_line_num] for i in range(0, len(text), character_line_num)]) - - # n_num = len(text.split("\n")) - 1 - # text_height = int(font_size*(n_num+2)) - - # img = Image.new("RGBA", (self.WIDTH, text_height), (0, 0, 0, 0)) - # draw = ImageDraw.Draw(img) - - # text_y = text_height // 2 - - # draw.multiline_text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font, align=align) - # return img - - # def create_textimage_message_type(self, message_type): - # anchor = "lm" if message_type == "receive" else "rm" - # text = "Receive" if message_type == "receive" else "Send" - # text_color = self.TEXT_COLOR_RECEIVE if message_type == "receive" else self.TEXT_COLOR_SEND - # text_color_time = self.TEXT_COLOR_TIME - - # now = datetime.now() - # formatted_time = now.strftime("%H:%M") - # font_size = self.FONT_SIZE_SMALL - # img = Image.new("RGBA", (0, 0), (0, 0, 0, 0)) - # draw = ImageDraw.Draw(img) - # font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "fonts", "NotoSansJP-Regular.ttf"), font_size) - # # font = ImageFont.truetype(os_path.join("./fonts", "NotoSansJP-Regular.ttf"), font_size) - # text_height = font_size*2 - # text_width = draw.textlength(formatted_time, font) - # character_width = text_width // len(formatted_time) - # img = Image.new("RGBA", (self.WIDTH, text_height), (0, 0, 0, 0)) - # draw = ImageDraw.Draw(img) - # text_y = text_height // 2 - # text_time_x = 0 if message_type == "receive" else self.WIDTH - (text_width + character_width) - # text_x = (text_width + character_width) if message_type == "receive" else self.WIDTH - - # draw.text((text_time_x, text_y), formatted_time, text_color_time, anchor=anchor, stroke_width=0, font=font) - # draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font) - # return img - - # def create_textbox(self, message_type, message, your_language, translation, target_language): - # message_type_img = self.create_textimage_message_type(message_type) - # if len(translation) > 0 and target_language is not None: - # img = self.create_textimage(message_type, "small", message, your_language) - # translation_img = self.create_textimage(message_type, "large",translation, target_language) - # img = self.concatenateImagesVertically(img, translation_img) - # else: - # img = self.create_textimage(message_type, "large", message, your_language) - # return self.concatenateImagesVertically(message_type_img, img) - - # def create_overlay_image_long(self, message_type, message, your_language, translation="", target_language=None): - # if len(self.log_data) > 10: - # self.log_data.pop(0) - - # self.log_data.append( - # { - # "message_type":message_type, - # "message":message, - # "your_language":your_language, - # "translation":translation, - # "target_language":target_language, - # } - # ) - - # imgs = [] - # for log in self.log_data: - # message_type = log["message_type"] - # message = log["message"] - # your_language = log["your_language"] - # translation = log["translation"] - # target_language = log["target_language"] - # img = self.create_textbox(message_type, message, your_language, translation, target_language) - # imgs.append(img) - - # img = imgs[0] - # for i in imgs[1:]: - # img = self.concatenateImagesVertically(img, i) - # img = self.addImageMargin(img, 0, 20, 0, 20, (0, 0, 0, 0)) - - # width, height = img.size - # background = Image.new("RGBA", (width, height), (0, 0, 0, 0)) - # draw = ImageDraw.Draw(background) - # draw.rounded_rectangle([(0, 0), (width, height)], radius=15, fill=self.BACKGROUND_COLOR, outline=self.BACKGROUND_OUTLINE_COLOR, width=5) - # img = Image.alpha_composite(background, img) - # return img - - def getUiSize(self): + @staticmethod + def getUiSizeSmallLog() -> dict: return { - "width": int(960*4), - "height": int(23*4), - "font_size": int(23*4), + "width": 3840, + "height": 92, + "font_size": 92, } - def getUiColors(self, ui_type): - match ui_type: - case "default": - background_color = (41, 42, 45) - background_outline_color = (41, 42, 45) - text_color = (223, 223, 223) - case "sakura": - background_color = (225, 40, 30) - background_outline_color = (255, 255, 255) - text_color = (223, 223, 223) - return { - "background_color": background_color, - "background_outline_color": background_outline_color, - "text_color": text_color + @staticmethod + def getUiColorSmallLog() -> dict: + colors = { + "background_color": (41, 42, 45), + "background_outline_color": (41, 42, 45), + "text_color": (223, 223, 223) } + return colors - def createDecorationImage(self, ui_type, image_size): - decoration_image = Image.new("RGBA", image_size, (0, 0, 0, 0)) - match ui_type: - case "default": - pass - case "sakura": - margin = 7 - alpha_ratio = 0.4 - overlay_tl = Image.open(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "img", "overlay_tl_sakura.png")) - overlay_br = Image.open(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "img", "overlay_br_sakura.png")) - if overlay_tl.size[1] > image_size[1]: - overlay_tl = overlay_tl.resize((image_size[1]-margin, image_size[1]-margin)) - if overlay_br.size[1] > image_size[1]: - overlay_br = overlay_br.resize((image_size[1]-margin, image_size[1]-margin)) - - alpha = overlay_tl.getchannel("A") - alpha = alpha.point(lambda x: x * alpha_ratio) - overlay_tl.putalpha(alpha) - alpha = overlay_br.getchannel("A") - alpha = alpha.point(lambda x: x * alpha_ratio) - overlay_br.putalpha(alpha) - decoration_image.paste(overlay_tl, (margin, margin)) - decoration_image.paste(overlay_br, (image_size[0]-overlay_br.size[0]-margin, image_size[1]-overlay_br.size[1]-margin)) - return decoration_image - - def createTextboxShort(self, text, language, text_color, base_width, base_height, font_size): + def createTextboxSmallLog(self, text:str, language:str, text_color:tuple, base_width:int, base_height:int, font_size:int) -> Image: font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular") img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0)) draw = ImageDraw.Draw(img) - font = ImageFont.truetype(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf"), font_size) + font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf") + try: + font = ImageFont.truetype(font_path, font_size) + except Exception: + font = ImageFont.truetype(font_path, font_size) + text_width = draw.textlength(text, font) character_width = text_width // len(text) - character_line_num = int((base_width) // character_width) - 12 + character_line_num = (base_width // character_width) - 12 if len(text) > character_line_num: - text = "\n".join([text[i:i+character_line_num] for i in range(0, len(text), character_line_num)]) + text = "\n".join([text[i:i + character_line_num] for i in range(0, len(text), character_line_num)]) text_height = font_size * (len(text.split("\n")) + 1) + 20 img = Image.new("RGBA", (base_width, text_height), (0, 0, 0, 0)) draw = ImageDraw.Draw(img) @@ -205,49 +71,178 @@ class OverlayImage: draw.text((text_x, text_y), text, text_color, anchor="mm", stroke_width=0, font=font, align="center") return img - def createOverlayImageShort(self, message, your_language, translation="", target_language=None, ui_type="default"): - ui_size = self.getUiSize() - height = ui_size["height"] - width = ui_size["width"] - font_size = ui_size["font_size"] + def createOverlayImageSmallLog(self, message:str, your_language:str, translation:str="", target_language:str=None) -> Image: + ui_size = self.getUiSizeSmallLog() + width, height, font_size = ui_size["width"], ui_size["height"], ui_size["font_size"] - ui_colors = self.getUiColors(ui_type) + ui_colors = self.getUiColorSmallLog() text_color = ui_colors["text_color"] background_color = ui_colors["background_color"] background_outline_color = ui_colors["background_outline_color"] - img = self.createTextboxShort(message, your_language, text_color, width, height, font_size) - if len(translation) > 0 and target_language is not None: - translation_img = self.createTextboxShort(translation, target_language, text_color, width, height, font_size) + img = self.createTextboxSmallLog(message, your_language, text_color, width, height, font_size) + if translation and target_language: + translation_img = self.createTextboxSmallLog(translation, target_language, text_color, width, height, font_size) img = self.concatenateImagesVertically(img, translation_img) background = Image.new("RGBA", img.size, (0, 0, 0, 0)) draw = ImageDraw.Draw(background) - draw.rounded_rectangle([(0, 0), img.size], radius=30, fill=background_color, outline=background_outline_color, width=5) + draw.rounded_rectangle([(0, 0), img.size], radius=50, fill=background_color, outline=background_outline_color, width=5) - decoration_image = self.createDecorationImage(ui_type, img.size) - background = Image.alpha_composite(background, decoration_image) - img = Image.alpha_composite(background, img) + return Image.alpha_composite(background, img) + + @staticmethod + def getUiSizeLargeLog() -> dict: + return { + "width": 960, + "font_size_large": 30, + "font_size_small": 20, + "margin": 25, + "radius": 25, + "padding": 10, + "clause_margin": 20, + } + + @staticmethod + def getUiColorLargeLog() -> dict: + return { + "background_color": (41, 42, 45), + "background_outline_color": (41, 42, 45), + "text_color_large": (223, 223, 223), + "text_color_small": (190, 190, 190), + "text_color_send": (97, 151, 180), + "text_color_receive": (168, 97, 180), + "text_color_time": (120, 120, 120) + } + + def createTextImageLargeLog(self, message_type:str, size:str, text:str, language:str) -> Image: + ui_size = self.getUiSizeLargeLog() + font_size = ui_size["font_size_large"] if size == "large" else ui_size["font_size_small"] + text_color = self.getUiColorLargeLog()[f"text_color_{size}"] + anchor = "lm" if message_type == "receive" else "rm" + text_x = 0 if message_type == "receive" else ui_size["width"] + align = "left" if message_type == "receive" else "right" + font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular") + + img = Image.new("RGBA", (0, 0), (0, 0, 0, 0)) + draw = ImageDraw.Draw(img) + font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf") + try: + font = ImageFont.truetype(font_path, font_size) + except Exception: + font = ImageFont.truetype(font_path, font_size) + + text_width = draw.textlength(text, font) + character_width = text_width // len(text) + character_line_num = int((ui_size["width"] // character_width) - 1) + if len(text) > character_line_num: + text = "\n".join([text[i:i + character_line_num] for i in range(0, len(text), character_line_num)]) + text_height = font_size * len(text.split("\n")) + ui_size["padding"] + img = Image.new("RGBA", (ui_size["width"], text_height), (0, 0, 0, 0)) + draw = ImageDraw.Draw(img) + text_y = text_height // 2 + draw.multiline_text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font, align=align) return img - def createOverlayImage(self, message, your_language, ui_type="default"): - ui_size = self.getUiSize() - height = ui_size["height"] - width = ui_size["width"] - font_size = ui_size["font_size"] + def createTextImageMessageType(self, message_type:str, date_time:str) -> Image: + ui_size = self.getUiSizeLargeLog() + font_size = ui_size["font_size_small"] + ui_padding = ui_size["padding"] - ui_colors = self.getUiColors(ui_type) - text_color = ui_colors["text_color"] - background_color = ui_colors["background_color"] - background_outline_color = ui_colors["background_outline_color"] + ui_color = self.getUiColorLargeLog() + text_color = ui_color[f"text_color_{message_type}"] + text_color_time = ui_color["text_color_time"] - img = self.createTextboxShort(message, your_language, text_color, width, height, font_size) + anchor = "lm" if message_type == "receive" else "rm" + text = "Receive" if message_type == "receive" else "Send" - background = Image.new("RGBA", img.size, (0, 0, 0, 0)) + img = Image.new("RGBA", (0, 0), (0, 0, 0, 0)) + draw = ImageDraw.Draw(img) + font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf") + try: + font = ImageFont.truetype(font_path, font_size) + except Exception: + font = ImageFont.truetype(font_path, font_size) + + text_height = font_size + ui_padding + text_width = draw.textlength(date_time, font) + character_width = text_width // len(date_time) + img = Image.new("RGBA", (ui_size["width"], text_height), (0, 0, 0, 0)) + draw = ImageDraw.Draw(img) + text_y = text_height // 2 + text_time_x = 0 if message_type == "receive" else ui_size["width"] - (text_width + character_width) + text_x = (text_width + character_width) if message_type == "receive" else ui_size["width"] + draw.text((text_time_x, text_y), date_time, text_color_time, anchor=anchor, stroke_width=0, font=font) + draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font) + return img + + def createTextboxLargeLog(self, message_type:str, message:str, your_language:str, translation:str, target_language:str, date_time:str) -> Image: + message_type_img = self.createTextImageMessageType(message_type, date_time) + if translation and target_language: + img = self.createTextImageLargeLog(message_type, "small", message, your_language) + translation_img = self.createTextImageLargeLog(message_type, "large", translation, target_language) + img = self.concatenateImagesVertically(img, translation_img) + else: + img = self.createTextImageLargeLog(message_type, "large", message, your_language) + return self.concatenateImagesVertically(message_type_img, img) + + def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:str="", target_language:str=None) -> Image: + ui_color = self.getUiColorLargeLog() + background_color = ui_color["background_color"] + background_outline_color = ui_color["background_outline_color"] + + ui_size = self.getUiSizeLargeLog() + ui_margin = ui_size["margin"] + ui_radius = ui_size["radius"] + ui_clause_margin = ui_size["clause_margin"] + + self.message_log.append({ + "message_type": message_type, + "message": message, + "your_language": your_language, + "translation": translation, + "target_language": target_language, + "datetime": datetime.now().strftime("%H:%M") + }) + + if len(self.message_log) > 10: + self.message_log = self.message_log[-10:] + + imgs = [ + self.createTextboxLargeLog( + log["message_type"], + log["message"], + log["your_language"], + log["translation"], + log["target_language"], + log["datetime"]) for log in self.message_log + ] + + img = imgs[0] + for i in imgs[1:]: + img = self.concatenateImagesVertically(img, i, ui_clause_margin) + img = self.addImageMargin(img, ui_margin, ui_margin, ui_margin, ui_margin, (0, 0, 0, 0)) + + width, height = img.size + background = Image.new("RGBA", (width, height), (0, 0, 0, 0)) draw = ImageDraw.Draw(background) - draw.rounded_rectangle([(0, 0), img.size], radius=30, fill=background_color, outline=background_outline_color, width=5) + draw.rounded_rectangle([(0, 0), (width, height)], radius=ui_radius, fill=background_color, outline=background_outline_color, width=5) + return Image.alpha_composite(background, img) - decoration_image = self.createDecorationImage(ui_type, img.size) - background = Image.alpha_composite(background, decoration_image) - img = Image.alpha_composite(background, img) - return img \ No newline at end of file +if __name__ == "__main__": + overlay = OverlayImage() + img = overlay.createOverlayImageSmallLog("Hello, World!", "English", "こんにちは、世界!", "Japanese") + img.save("overlay_small.png") + img = overlay.createOverlayImageLargeLog("send", "Hello, World!", "English", "こんにちは、世界!", "Japanese") + img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!", "Japanese", "Hello, World!", "English") + img = overlay.createOverlayImageLargeLog("send", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English", "aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああこんにちは、世界!", "Japanese") + img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "Japanese", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English") + img = overlay.createOverlayImageLargeLog("send", "Hello, World!", "English", "こんにちは、世界!", "Japanese") + img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!", "Japanese", "Hello, World!", "English") + img = overlay.createOverlayImageLargeLog("send", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English", "aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああこんにちは、世界!", "Japanese") + img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "Japanese", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English") + img = overlay.createOverlayImageLargeLog("send", "Hello, World!", "English", "こんにちは、世界!", "Japanese") + img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!", "Japanese", "Hello, World!", "English") + img = overlay.createOverlayImageLargeLog("send", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English", "aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああこんにちは、世界!", "Japanese") + img = overlay.createOverlayImageLargeLog("receive", "こんにちは、世界!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "Japanese", "Hello, World!aaaaaaaaaaaaaaaaaあああああああああああああああaaaaaaaaaaaaaaaaaあああああああああああああああ", "English") + img.save("overlay_large.png") \ No newline at end of file diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 39a17dc1..6616de8e 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -250,11 +250,9 @@ class Controller: translation = " (" + "/".join(translation) + ")" model.logger.info(f"[SENT] {message}{translation}") - # if config.OVERLAY_SMALL_LOG is True: - # overlay_image = model.createOverlayImageShort(message, translation) - # model.updateOverlay(overlay_image) - # overlay_image = model.createOverlayImageLong("send", message, translation) - # model.updateOverlay(overlay_image) + if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True: + overlay_image = model.createOverlayImageLargeLog("send", message, translation) + model.updateOverlayLargeLog(overlay_image) def speakerMessage(self, message) -> None: if isinstance(message, bool) and message is False: @@ -291,12 +289,13 @@ class Controller: transliteration = model.convertMessageToTransliteration(message) if config.ENABLE_TRANSCRIPTION_RECEIVE is True: - if config.OVERLAY_SMALL_LOG is True: - if model.overlay.initialized is True: - overlay_image = model.createOverlayImageShort(message, translation) - model.updateOverlay(overlay_image) - # overlay_image = model.createOverlayImageLong("receive", message, translation) - # model.updateOverlay(overlay_image) + if config.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True: + overlay_image = model.createOverlayImageSmallLog(message, translation) + model.updateOverlaySmallLog(overlay_image) + + if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True: + overlay_image = model.createOverlayImageLargeLog("receive", message, translation) + model.updateOverlayLargeLog(overlay_image) if config.SEND_RECEIVED_MESSAGE_TO_VRC is True: osc_message = self.messageFormatter("RECEIVED", translation, [message]) @@ -361,11 +360,9 @@ class Controller: osc_message = self.messageFormatter("SEND", translation, [message]) model.oscSendMessage(osc_message) - # if config.OVERLAY_SMALL_LOG is True: - # overlay_image = model.createOverlayImageShort(message, translation) - # model.updateOverlay(overlay_image) - # overlay_image = model.createOverlayImageLong("send", message, translation) - # model.updateOverlay(overlay_image) + if config.OVERLAY_LARGE_LOG is True: + overlay_image = model.createOverlayImageLargeLog("send", message, translation) + model.updateOverlayLargeLog(overlay_image) # update textbox message log (Sent) if config.LOGGER_FEATURE is True: @@ -1164,15 +1161,24 @@ class Controller: return {"status":200, "result":config.SEND_MESSAGE_BUTTON_TYPE} @staticmethod - def getOverlaySettings(*args, **kwargs) -> dict: - return {"status":200, "result":config.OVERLAY_SETTINGS} + def getOverlaySmallLog(*args, **kwargs) -> dict: + return {"status":200, "result":config.OVERLAY_SMALL_LOG} @staticmethod - def setOverlaySettings(data, *args, **kwargs) -> dict: - config.OVERLAY_SETTINGS = data - model.updateOverlayImageOpacity() - model.updateOverlayImageUiScaling() - return {"status":200, "result":config.OVERLAY_SETTINGS} + def setEnableOverlaySmallLog(*args, **kwargs) -> dict: + config.OVERLAY_SMALL_LOG = True + if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: + model.startOverlay() + return {"status":200, "result":config.OVERLAY_SMALL_LOG} + + @staticmethod + def setDisableOverlaySmallLog(*args, **kwargs) -> dict: + config.OVERLAY_SMALL_LOG = False + if config.OVERLAY_SMALL_LOG is False: + model.clearOverlayImageSmallLog() + if config.OVERLAY_LARGE_LOG is False: + model.shutdownOverlay() + return {"status":200, "result":config.OVERLAY_SMALL_LOG} @staticmethod def getOverlaySmallLogSettings(*args, **kwargs) -> dict: @@ -1181,28 +1187,38 @@ class Controller: @staticmethod def setOverlaySmallLogSettings(data, *args, **kwargs) -> dict: config.OVERLAY_SMALL_LOG_SETTINGS = data - model.updateOverlayPosition() + model.updateOverlaySmallLogSettings() return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS} @staticmethod - def getOverlaySmallLog(*args, **kwargs) -> dict: - return {"status":200, "result":config.OVERLAY_SMALL_LOG} + def getOverlayLargeLog(*args, **kwargs) -> dict: + return {"status":200, "result":config.OVERLAY_LARGE_LOG} @staticmethod - def setEnableOverlaySmallLog(*args, **kwargs) -> dict: - config.OVERLAY_SMALL_LOG = True - if config.OVERLAY_SMALL_LOG is True and config.ENABLE_TRANSCRIPTION_RECEIVE is True: - if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: - model.startOverlay() - return {"status":200, "result":config.OVERLAY_SMALL_LOG} + def setEnableOverlayLargeLog(*args, **kwargs) -> dict: + config.OVERLAY_LARGE_LOG = True + if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: + model.startOverlay() + return {"status":200, "result":config.OVERLAY_LARGE_LOG} @staticmethod - def setDisableOverlaySmallLog(*args, **kwargs) -> dict: - config.OVERLAY_SMALL_LOG = False - if config.OVERLAY_SMALL_LOG is False: - model.clearOverlayImage() - model.shutdownOverlay() - return {"status":200, "result":config.OVERLAY_SMALL_LOG} + def setDisableOverlayLargeLog(*args, **kwargs) -> dict: + config.OVERLAY_LARGE_LOG = False + if config.OVERLAY_LARGE_LOG is False: + model.clearOverlayImageLargeLog() + if config.OVERLAY_SMALL_LOG is False: + model.shutdownOverlay() + return {"status":200, "result":config.OVERLAY_LARGE_LOG} + + @staticmethod + def getOverlayLargeLogSettings(*args, **kwargs) -> dict: + return {"status":200, "result":config.OVERLAY_LARGE_LOG_SETTINGS} + + @staticmethod + def setOverlayLargeLogSettings(data, *args, **kwargs) -> dict: + config.OVERLAY_LARGE_LOG_SETTINGS = data + model.updateOverlayLargeLogSettings() + return {"status":200, "result":config.OVERLAY_LARGE_LOG_SETTINGS} @staticmethod def getSendMessageToVrc(*args, **kwargs) -> dict: @@ -1340,6 +1356,10 @@ class Controller: def setEnableTranscriptionSend(self, *args, **kwargs) -> dict: self.startThreadingTranscriptionSendMessage() config.ENABLE_TRANSCRIPTION_SEND = True + if (config.OVERLAY_LARGE_LOG is True and + model.overlay.initialized is False and + model.overlay.checkSteamvrRunning() is True): + model.startOverlay() return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND} def setDisableTranscriptionSend(self, *args, **kwargs) -> dict: @@ -1349,8 +1369,13 @@ class Controller: def setEnableTranscriptionReceive(self, *args, **kwargs) -> dict: self.startThreadingTranscriptionReceiveMessage() - if config.OVERLAY_SMALL_LOG is True: - if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: + if (config.OVERLAY_SMALL_LOG is True and + model.overlay.initialized is False and + model.overlay.checkSteamvrRunning() is True): + model.startOverlay() + if (config.OVERLAY_LARGE_LOG is True and + model.overlay.initialized is False and + model.overlay.checkSteamvrRunning() is True): model.startOverlay() config.ENABLE_TRANSCRIPTION_RECEIVE = True return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE} @@ -1380,8 +1405,8 @@ class Controller: def sendTextOverlaySmallLog(data, *args, **kwargs) -> dict: if config.OVERLAY_SMALL_LOG is True: if model.overlay.initialized is True: - overlay_image = model.createOverlayImage(data) - model.updateOverlay(overlay_image) + overlay_image = model.createOverlayImageSystemMessage(data) + model.updateOverlaySmallLog(overlay_image) return {"status":200, "result":data} def swapYourLanguageAndTargetLanguage(self, *args, **kwargs) -> dict: diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 17ca42a6..994ad941 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -247,15 +247,19 @@ mapping = { "/run/download_whisper_weight": {"status": True, "variable":controller.downloadWhisperWeight}, # VR - "/get/data/overlay_settings": {"status": True, "variable":controller.getOverlaySettings}, - "/set/data/overlay_settings": {"status": True, "variable":controller.setOverlaySettings}, + "/get/data/overlay_small_log": {"status": True, "variable":controller.getOverlaySmallLog}, + "/set/enable/overlay_small_log": {"status": True, "variable":controller.setEnableOverlaySmallLog}, + "/set/disable/overlay_small_log": {"status": True, "variable":controller.setDisableOverlaySmallLog}, "/get/data/overlay_small_log_settings": {"status": True, "variable":controller.getOverlaySmallLogSettings}, "/set/data/overlay_small_log_settings": {"status": True, "variable":controller.setOverlaySmallLogSettings}, - "/get/data/overlay_small_log": {"status": True, "variable":controller.getOverlaySmallLog}, - "/set/enable/overlay_small_log": {"status": True, "variable":controller.setEnableOverlaySmallLog}, - "/set/disable/overlay_small_log": {"status": True, "variable":controller.setDisableOverlaySmallLog}, + "/get/data/overlay_large_log": {"status": True, "variable":controller.getOverlayLargeLog}, + "/set/enable/overlay_large_log": {"status": True, "variable":controller.setEnableOverlayLargeLog}, + "/set/disable/overlay_large_log": {"status": True, "variable":controller.setDisableOverlayLargeLog}, + + "/get/data/overlay_large_log_settings": {"status": True, "variable":controller.getOverlayLargeLogSettings}, + "/set/data/overlay_large_log_settings": {"status": True, "variable":controller.setOverlayLargeLogSettings}, # Others "/get/data/auto_clear_message_box": {"status": True, "variable":controller.getAutoClearMessageBox},