/*
 * This file is part of the openKropki project.
 * It provides abstract drawing functions based on SDL and SDL_gfx.
 *
 * Copyright (C) 2014-2020 Mateusz Viste
 *
 * MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef GRAPH_H_SENTINEL
  #define GRAPH_H_SENTINEL

  enum ui_event_types_t {
    Event_NONE = 0,
    Event_CLICK = 1,
    Event_SWEEP = 2,
    Event_SCROLL = 3,
    Event_CURSORMOVE = 4,
    Event_KEYPRESS = 5,
    Event_UNKNOWN = 254,
    Event_QUIT = 255
  };

  struct ui_event_t {
    enum ui_event_types_t type;
    int x;      /* x coordinate (for mouse events) */
    int y;      /* y coordinate (for mouse events) */
    int button; /* mouse button (1 or 2) or keyboard key */
  };

  /* struct used in lists to build a menu */
  struct ui_menu_description_t {
    struct gra_sprite *sprite[2]; /* first sprite is the one to be displayed, the second one is for on-mouseover (optional - if NULL then entry is not clickable) */
    unsigned char clickid;  /* what value should be returned when clicked on this item */
    unsigned char propxpos; /* proportional (0-100% x position or 255 for "centered") */
    unsigned char propypos; /* proportional (0-100% y position or 255 for "immediately under the last one) */
  };

  enum ui_mousecursor_t {
    UI_CURSOR_NORMAL,
    UI_CURSOR_WAIT
  };

  #define UI_MENU_EXIT -1
  #define UI_MENU_BACK -2

  int ui_setparams(int x, int y, int tkratkaSize, int tkratkaThickness, int tkratkaKolor, int tplayer1color, int tplayer2color, int tkartkaBackgroundColor, int twallThickness, int tkropkaRadius);
  void graph_drawscores(int p1, int p2);
  void ui_drawKartka(int width, int height, const int *scrollvector);
  void graph_drawKropka(int x, int y, int player, int activeflag, const int *scrollvector);
  void graph_drawWall(int x1, int y1, int x2, int y2, int player, const int *scrollvector);
  void graph_free(void);
  void graph_mousemap(int mx, int my, int *dotx, int *doty, const int *scrollvector);
  void graph_refresh(void);
  void ui_drawscores(const int *scores, const char *msg, int msgplayercolor);
  void ui_getevent(struct ui_event_t *ev, int nofilter);
  unsigned long ui_getticks(void);

  /* build a menu and await for a choice. each menu object (clickable or not) is defined as a ui_menu_description_t struct.
     returns the "clickid" of the clickable item that has been selected, or:
       UI_MENU_EXIT for a close window action
       UI_MENU_BACK for a "back" action (escape key) */
  int ui_menu(const struct ui_menu_description_t *menu, int menucount);

  void ui_init(int width, int height);
  void ui_applyfaderect(int size);
  void ui_throwmsg(const char *msg);
  void ui_delay(unsigned int ms);
  void ui_changecursor(enum ui_mousecursor_t curid);
#endif
