From 67b8c7cfe5218159c1de35031946bf8266826065 Mon Sep 17 00:00:00 2001 From: ennucore Date: Sat, 11 Dec 2021 19:13:09 +0300 Subject: [PATCH] Rendering active chat in interface (header) --- degeon_py/active_chat.py | 34 +++++++++++++++++++++++++++++++--- degeon_py/config.py | 1 + degeon_py/degeon.py | 3 ++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/degeon_py/active_chat.py b/degeon_py/active_chat.py index f00466f..30874f4 100644 --- a/degeon_py/active_chat.py +++ b/degeon_py/active_chat.py @@ -3,7 +3,7 @@ from __future__ import annotations from dataclasses import dataclass import pygame -from config import HEIGHT, WIDTH, CHAT_SELECTOR_WIDTH +from config import HEIGHT, WIDTH, CHAT_SELECTOR_WIDTH, DARKER_BLUE, CHAT_PREVIEW_HEIGHT, BLUE, WHITE, font, DARK_BLUE import degeon_core as dc @@ -14,22 +14,50 @@ class ActiveChat: Attributes: :param chat (dc.Chat): the chat (Rust Chat type) + :param height (int): the height of the active chat widget + :param width (int): its width + :param delta_x (int): distance from the left edge of the application to the left edge of the screen + :param header_height (int): height of the header (the title) """ chat: dc.Chat height: int = HEIGHT - width: int = WIDTH - CHAT_SELECTOR_WIDTH + width: int = WIDTH - CHAT_SELECTOR_WIDTH - 10 + delta_x: int = CHAT_SELECTOR_WIDTH + 10 + header_height: int = int(CHAT_PREVIEW_HEIGHT * 1.5) @classmethod - def new(cls, chat: 'dc.Chat', **kwargs) -> ActiveChat: + def new(cls, chat: dc.Chat, **kwargs) -> ActiveChat: + """ + Create a new `Chat` from a rust Chat object + :param chat: rusty chat + :param kwargs: optional other paraeters + :return: the `Chat` + """ return cls(chat=chat, **kwargs) + def get_header(self) -> pygame.Surface: + """ + Render a pygame surface with the header. + The header is (for now) just a name of the user written on a background + + :return: the header + """ + surface: pygame.Surface = pygame.Surface((self.width, self.header_height)) + surface.fill(DARK_BLUE) + name_surface: pygame.Surface = font.render(self.chat.profile.name, True, WHITE) + surface.blit(name_surface, (20, 20)) + return surface + def render(self) -> pygame.Surface: """ Creates a pygame surface and draws the chat on it :return: the surface with the chat on it """ surface: pygame.Surface = pygame.Surface((self.width, self.height)) + surface.fill(DARKER_BLUE) + header = self.get_header() + surface.blit(header, (0, 10)) return surface def process_event(self, event: pygame.event.Event): diff --git a/degeon_py/config.py b/degeon_py/config.py index e6f9e3f..091c688 100644 --- a/degeon_py/config.py +++ b/degeon_py/config.py @@ -3,6 +3,7 @@ import pygame pygame.init() font = pygame.font.Font('CRC35.otf', 25) +font_large = pygame.font.Font('CRC35.otf', 35) RED = 0xFF0000 BLUE = 0x0000FF diff --git a/degeon_py/degeon.py b/degeon_py/degeon.py index ef718d8..4d3aa9c 100644 --- a/degeon_py/degeon.py +++ b/degeon_py/degeon.py @@ -44,7 +44,8 @@ class Degeon: chats_surface = self.chat_selector.render() screen.blit(chats_surface, (0, 0)) if self.active_chat is not None: - pass + active_chat_surface = self.active_chat.render() + screen.blit(active_chat_surface, (self.active_chat.delta_x, 0)) else: text_surface: pygame.Surface = font.render('<- Select chat in the menu', True, WHITE) screen.blit(text_surface,