/*
 * Screen_01.c
 *
 * Created: Fri Apr 02 2021 14:34:01
 *  Author Chris
 */

// ============================================================================================
// Includes
#include "../Screens.h"
#include "../UI_Control.h"
#include "../Display_Default_Configurations.h"

#include "../Display.h"
#include "../Display_Objects.h"

#include "../Version.h"

#include "pico/types.h"
#include "pico/time.h"


// ============================================================================================
// Defines


// ============================================================================================
// Variables
extern const unsigned char 	_Font_DejaVu_Sans_Mono_6x12[];
extern const unsigned char 	_Font_DejaVu_Sans_Mono_7x15[];
extern const unsigned char 	_Font_DejaVu_Sans_Mono_Bold_7x15[];
extern const unsigned char 	_Font_DejaVu_Sans_Mono_Bold_15x26[];

static uint					_Up_Time_s;
static Object_ID			_Object_Up_Time_s;
static Object_ID			_Object_Frame_Counter;


// ============================================================================================
// Function Declarations
void Screen_Setup_Settings_About(Screen_Transition_Direction direction_out, Screen_Transition_Direction direction_in, Easing type, uint32_t frame_duration);

static void Screen_Tick					(void);
static void Screen_Click				(uint button_return_value);
static void Screen_Action_CW			(Object_ID object_id);
static void Screen_Action_CCW			(Object_ID object_id);
static void Screen_On_Object_Focused	(Object_ID object_id);
static void Screen_On_Object_Defocused	(Object_ID object_id);
static void Screen_On_Object_Select		(Object_ID object_id);
static void Screen_On_Object_Deselect	(Object_ID object_id);


/*******************************************************************
	Functions
*******************************************************************/
void Screen_Setup_Settings_About(Screen_Transition_Direction direction_out, Screen_Transition_Direction direction_in, Easing type, uint32_t frame_duration)
{
	_Screen_Tick					= Screen_Tick;
	_Screen_Click					= Screen_Click;
	_Screen_Action_CW				= Screen_Action_CW;
	_Screen_Action_CCW				= Screen_Action_CCW;
	_Screen_On_Objects_Focused 		= Screen_On_Object_Focused;
	_Screen_On_Objects_Defocused 	= Screen_On_Object_Defocused;
	_Screen_On_Object_Select		= Screen_On_Object_Select;
	_Screen_On_Object_Deselect		= Screen_On_Object_Deselect;

	Display_Objects_Clear();
	Display_Screen_Transition_Start(direction_out, direction_in, type, frame_duration);

	Font_ID Font_12_0 		= Display_Objects_Add_Font(_Font_DejaVu_Sans_Mono_6x12, 0);
	Font_ID Font_15_1		= Display_Objects_Add_Font(_Font_DejaVu_Sans_Mono_7x15, 1);
	Font_ID Font_Bold_15_1 	= Display_Objects_Add_Font(_Font_DejaVu_Sans_Mono_Bold_7x15, 1);
	Font_ID Font_Bold_26_1 	= Display_Objects_Add_Font(_Font_DejaVu_Sans_Mono_Bold_15x26, 0);
	
	Font_ID Font_Title = Font_15_1;
	Font_ID Font_Value = Font_Bold_15_1;
	Font_ID Font_Heading = Font_Bold_26_1;

	//////////////////////////////
	// Add Display Objects here //
	//////////////////////////////
	uint16_t Y = 35;

	Display_Objects_Add_Text(CENTER_MIDDLE, BOTH_IN_PERCENT, 50, 20, NOT_SELECTABLE, "MIDI Lighter", Font_Heading, DISPLAY_COLOR_WHITE, NO_STYLE, NO_ANIMATION);

	// === Up Time ===
	Display_Objects_Add_Text(CENTER_BOTTOM, BOTH_IN_PERCENT, 50, Y-1, NOT_SELECTABLE, "Up Time", Font_Title, DISPLAY_COLOR_LIGHTGREY, NO_STYLE, NO_ANIMATION);
	_Object_Up_Time_s = Display_Objects_Add_Integer(CENTER_TOP, BOTH_IN_PERCENT, 50, Y, NOT_SELECTABLE, &_Up_Time_s, "%us", Font_Value, DISPLAY_COLOR_WHITE, NO_STYLE, NO_ANIMATION);
	Y += 20;

	// === Frame Counter ===
	Display_Objects_Add_Text(CENTER_BOTTOM, BOTH_IN_PERCENT, 50, Y-1, NOT_SELECTABLE, "#Frames", Font_Title, DISPLAY_COLOR_LIGHTGREY, NO_STYLE, NO_ANIMATION);
	_Object_Frame_Counter = Display_Objects_Add_Integer(CENTER_TOP, BOTH_IN_PERCENT, 50, Y, NOT_SELECTABLE, (int*)Display_Get_Frame_Counter_Reference(), "%u", Font_Value, DISPLAY_COLOR_WHITE, NO_STYLE, NO_ANIMATION);
	Y += 20;

	// === Version ===
	Display_Objects_Add_Text(CENTER_BOTTOM, BOTH_IN_PERCENT, 50, Y-1, NOT_SELECTABLE, "Version", Font_Title, DISPLAY_COLOR_LIGHTGREY, NO_STYLE, NO_ANIMATION);
	Display_Objects_Add_Text(CENTER_TOP, BOTH_IN_PERCENT, 50, Y, NOT_SELECTABLE, VERSION_BUILD_STRING, Font_Value, DISPLAY_COLOR_WHITE, NO_STYLE, NO_ANIMATION);
	Y += 20;

	// === Text ===
	Display_Objects_Add_Text(CENTER_BOTTOM, BOTH_IN_PERCENT, 50, 95, NOT_SELECTABLE, "Click to return", Font_12_0, DISPLAY_COLOR_LIGHTGREY, NO_STYLE, NO_ANIMATION);
	

	_Up_Time_s = to_ms_since_boot(get_absolute_time()) / 1000u;
}

void Screen_Tick(void)
{
	_Up_Time_s = to_ms_since_boot(get_absolute_time()) / 1000u;

	Display_Objects_Update_Coordinates(_Object_Up_Time_s, CENTER_TOP, BOTH_IN_PERCENT, 50, 35);
	Display_Objects_Update_Coordinates(_Object_Frame_Counter, CENTER_TOP, BOTH_IN_PERCENT, 50, 35 + 20);
}

void Screen_Click(uint button_return_value)
{

}

void Screen_Action_CW(Object_ID object_id)
{
	
}

void Screen_Action_CCW(Object_ID object_id)
{
	
}

void Screen_On_Object_Focused(Object_ID object_id)
{

}

void Screen_On_Object_Defocused	(Object_ID object_id)
{

}

void Screen_On_Object_Select(Object_ID object_id)
{
	Screen_Setup_Settings(TRANSITION_DOWN, TRANSITION_DOWN, SCREEN_TRANSITION_DEFAULT_EASING, SCREEN_TRANSITION_DEFAULT_FRAMES, 5);
}

void Screen_On_Object_Deselect(Object_ID object_id)
{

}

/*******************************************************************
	Internal Functions
*******************************************************************/
