/**
 * Copyright (c) 2021 Dominic Masters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#include "framedtextmenu.h"

void framedTextMenuInit(framedtextmenu_t *menu, font_t *font, texture_t *text) {
  frameInit(&menu->frame);
  textMenuInit(&menu->menu, font);
  menu->frame.texture = text;
  menu->menu.grid.borderX = FRAME_BORDER_SIZE;
  menu->menu.grid.borderY = FRAME_BORDER_SIZE;
  menu->menu.grid.gutterX = FRAMED_TEXT_MENU_GUTTER_DEFAULT;
  menu->menu.grid.gutterY = FRAMED_TEXT_MENU_GUTTER_DEFAULT;
}

void framedTextMenuResize(framedtextmenu_t *menu, float width, float height) {
  if(menu->menu.grid.width == width && menu->menu.grid.height == height) {
    return;
  }
  gridResize(&menu->menu.grid, width, height);
  frameSetSize(&menu->frame, width, height);
}

void framedTextMenuUpdate(framedtextmenu_t *menu, engine_t *engine) {
  menuUpdate(&menu->menu.menu, engine);
}

void framedTextMenuRender(
  framedtextmenu_t *menu, shader_t *shader, float x, float y
) {
  frameRender(&menu->frame, shader, x, y);
  textMenuRender(&menu->menu, shader, x, y);
}

void framedTextMenuDispose(framedtextmenu_t *menu) {
  textMenuDispse(&menu->menu);
  frameDispose(&menu->frame);
}