/*******************************************************************************************
*
*   DebugTerminal v1.0.0 - Tool Description
*
*   MODULE USAGE:
*       #define GUI_DEBUGTERMINAL_IMPLEMENTATION
*       #include "gui_DebugTerminal.h"
*
*       INIT: GuiDebugTerminalState state = InitGuiDebugTerminal();
*       DRAW: GuiDebugTerminal(&state);
*
*   LICENSE: Propietary License
*
*   Copyright (c) 2022 SleepeeSoftware. All Rights Reserved.
*
*   Unauthorized copying of this file, via any medium is strictly prohibited
*   This project is proprietary and confidential unless the owner allows
*   usage in any other form by expresely written permission.
*
**********************************************************************************************/

#include "raylib.h"

// WARNING: raygui implementation is expected to be defined before including this header
#undef RAYGUI_IMPLEMENTATION
#include "raygui.h"

#include <string.h>     // Required for: strcpy()

#ifndef GUI_DEBUGTERMINAL_H
#define GUI_DEBUGTERMINAL_H

typedef struct {
    // Define anchors
    Vector2 anchor01;            // ANCHOR ID:1
    
    // Define controls variables
    bool WindowBox000Active;            // WindowBox: WindowBox000
    Rectangle TerminalOutputPanelScrollView;
    Vector2 TerminalOutputPanelScrollOffset;
    Vector2 TerminalOutputPanelBoundsOffset;            // ScrollPanel: TerminalOutputPanel
    bool TerminalInputBoxEditMode;
    char TerminalInputBoxText[128];            // TextBox: TerminalInputBox

    // Define rectangles
    Rectangle layoutRecs[4];

    // Custom state variables (depend on development software)
    // NOTE: This variables should be added manually if required

} GuiDebugTerminalState;

#ifdef __cplusplus
extern "C" {            // Prevents name mangling of functions
#endif

//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
//...

//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
// ...

//----------------------------------------------------------------------------------
// Module Functions Declaration
//----------------------------------------------------------------------------------
GuiDebugTerminalState InitGuiDebugTerminal(void);
void GuiDebugTerminal(GuiDebugTerminalState *state);
static void Button003();                // Button: Button003 logic

#ifdef __cplusplus
}
#endif

#endif // GUI_DEBUGTERMINAL_H

/***********************************************************************************
*
*   GUI_DEBUGTERMINAL IMPLEMENTATION
*
************************************************************************************/
#if defined(GUI_DEBUGTERMINAL_IMPLEMENTATION)

#include "raygui.h"

//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
//...

//----------------------------------------------------------------------------------
// Internal Module Functions Definition
//----------------------------------------------------------------------------------
//...

//----------------------------------------------------------------------------------
// Module Functions Definition
//----------------------------------------------------------------------------------
GuiDebugTerminalState InitGuiDebugTerminal(void)
{
    GuiDebugTerminalState state = { 0 };

    // Init anchors
    state.anchor01 = (Vector2){ 48, 24 };            // ANCHOR ID:1
    
    // Initilize controls variables
    state.WindowBox000Active = true;            // WindowBox: WindowBox000
    state.TerminalOutputPanelScrollView = (Rectangle){ 0, 0, 0, 0 };
    state.TerminalOutputPanelScrollOffset = (Vector2){ 0, 0 };
    state.TerminalOutputPanelBoundsOffset = (Vector2){ 0, 0 };            // ScrollPanel: TerminalOutputPanel
    state.TerminalInputBoxEditMode = false;
    strcpy(state.TerminalInputBoxText, "");            // TextBox: TerminalInputBox

    // Init controls rectangles
    state.layoutRecs[0] = (Rectangle){ state.anchor01.x + 0, state.anchor01.y + 0, 984, 624 };// WindowBox: WindowBox000
    state.layoutRecs[1] = (Rectangle){ state.anchor01.x + 24, state.anchor01.y + 48, 936, 448 };// ScrollPanel: TerminalOutputPanel
    state.layoutRecs[2] = (Rectangle){ state.anchor01.x + 24, state.anchor01.y + 528, 840, 24 };// TextBox: TerminalInputBox
    state.layoutRecs[3] = (Rectangle){ state.anchor01.x + 840, state.anchor01.y + 576, 96, 24 };// Button: Button003

    // Custom variables initialization

    return state;
}
// Button: Button003 logic
static void Button003()
{
    // TODO: Implement control logic
}


void GuiDebugTerminal(GuiDebugTerminalState *state)
{
    // Const text
    const char *WindowBox000Text = "Debug Terminal";    // WINDOWBOX: WindowBox000
    const char *Button003Text = "Submit";    // BUTTON: Button003
    
    // Draw controls
    if (state->WindowBox000Active)
    {
        state->WindowBox000Active = !GuiWindowBox(state->layoutRecs[0], WindowBox000Text);
        GuiScrollPanel((Rectangle){state->layoutRecs[1].x, state->layoutRecs[1].y, state->layoutRecs[1].width - state->TerminalOutputPanelBoundsOffset.x, state->layoutRecs[1].height - state->TerminalOutputPanelBoundsOffset.y }, TerminalOutputPanelText, state->layoutRecs[1], &state->TerminalOutputPanelScrollOffset, &state->TerminalOutputPanelScrollView);
        if (GuiTextBox(state->layoutRecs[2], state->TerminalInputBoxText, 128, state->TerminalInputBoxEditMode)) state->TerminalInputBoxEditMode = !state->TerminalInputBoxEditMode;
        if (GuiButton(state->layoutRecs[3], Button003Text)) Button003(); 
    }
}

#endif // GUI_DEBUGTERMINAL_IMPLEMENTATION
