# Use this to define defaults that should be shared across all screens (background, data sync on non-displayed pages, etc)
import gui
from screen_utils import Screen
# from sounds import Speaker


class ScreenBase(Screen):

    bg_colour = [gui.DL_CLEAR_COLOR_RGB(255, 255, 255)]
    font_colour = [gui.DL_COLOR_RGB(0,0,0)]

    def __init__(self):
        super().__init__()
        self.header_colour = gui.RGB(0, 41, 66)
        self.title = [""]
        self.terminal = None

    def set_title(self, title):
        self.title[0] = title

    @classmethod
    def set_bg_colour(cls, colours, set_font = True):
        cls.bg_colour[0] = gui.DL_CLEAR_COLOR_RGB(colours[0], colours[1], colours[2])
        if set_font: 
            cls.font_colour[0] = gui.DL_COLOR_RGB(colours[0]^0xFF, colours[1]^0xFF, colours[2]^0xFF)

    @classmethod
    def set_font_colour(cls, colours, set_bg = True):
        cls.font_colour[0] = gui.DL_CLEAR_COLOR_RGB(colours[0], colours[1], colours[2])
        if set_bg: 
            cls.bg_colour[0] = gui.DL_COLOR_RGB(colours[0]^0xFF, colours[1]^0xFF, colours[2]^0xFF)

    def setup(self):
        super().setup()

        self.gui_list.append([
		    gui.DL_SAVE_CONTEXT(),
            gui.DL_CLEAR_COLOR(self.header_colour),
            gui.DL_CLEAR(1, 1, 1),
            gui.DL_SCISSOR_SIZE(800, 350),
            gui.DL_SCISSOR_XY(0, 65),
            ScreenBase.bg_colour,
            gui.DL_CLEAR(1, 1, 1),
            gui.DL_RESTORE_CONTEXT(),
        ])
        self.gui_list.append([gui.CTRL_TEXT, 30, 13, 8, 0, self.title])
        self.gui_list.append(ScreenBase.font_colour)
        # self.add_button_icons()

    def vsync_cb(self, l):
        super().vsync_cb(l)

    def draw(self):
        if self.terminal:
            self.gui_list.append(self.terminal.gui_l)
        super().draw()