from tidal import *
from app import App
import lodepng

# TôBach^Slipstream 27/06/22
# i did think about getting it to change colours but it's a bit of a faff

class png:
    def __init__(self, w, h, buf):
        self.w = w
        self.h = h
        self.buf = buf
    
    @staticmethod
    def load(filename):
        return png(*lodepng.decode565(filename))
    
    def draw(self,x, y):
        display.blit_buffer(self.buf, x, y, self.w, self.h)


class dvdlogo(App):
    
    def on_activate(self):
        super().on_activate()
        display.fill(BLACK)
        self.dvdlogo = png.load("apps/dvd_logo/dvdlogo.png")
        self.dvd_x=0
        self.dvd_y=0
        self.dvd_dx=1
        self.dvd_dy=1
        self.draw_dvd()
    
    def draw_dvd(self):
        #display.fill(BLACK)
        png = self.dvdlogo
        png.draw(self.dvd_x, self.dvd_y)
        
        if self.dvd_x>82 or self.dvd_x<0:
            self.dvd_dx=self.dvd_dx*-1
        
        self.dvd_x=self.dvd_x+self.dvd_dx
        
        if self.dvd_y>205 or self.dvd_y<0:
            self.dvd_dy=self.dvd_dy*-1
        
        self.dvd_y=self.dvd_y+self.dvd_dy
        
        self.after(20, self.draw_dvd)

main = dvdlogo