Andy's CarPlayer

/***************************************************************************
                          display.c  -  description
                             -------------------
    begin                : Mon Jan 31 2005
    copyright            : (C) 2005 by Andy
    email                : 
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

 #include 
 #include 
 #include 
 #include 
 

 #include "display.h"
 #include "main.h"
 #include "log.h"
 #include "tools.h"
 
void CRT_setup()
{

  int startx, starty, height, width;
  
  initscr();
  cbreak();
  keypad(stdscr, TRUE);
  immedok(stdscr, TRUE);
  start_color();

  init_pair(1, COLOR_CYAN, COLOR_BLACK);

  height = 6;
  width  = COLS;
  starty = ((LINES - height) / 2);
  startx = ((COLS - width) / 2);
    
  attron(COLOR_PAIR(1));
  printw("Press '0' to quit. COLS = %i, LINES = %i", COLS, LINES);
  attroff(COLOR_PAIR(1));


  player_win[INFO_SCREEN] = newwin(height, width, LINES - (height +1), 0);
  box(player_win[INFO_SCREEN], 0, 0);
  immedok(player_win[INFO_SCREEN], TRUE);
  
  player_win[MAIN_SCREEN] = newwin(15, 70, 1, 0);
  box(player_win[MAIN_SCREEN], 0, 0);
  immedok(player_win[MAIN_SCREEN], TRUE);
  
  mvwprintw(player_win[INFO_SCREEN], 1, 2, "Number of tracks %i ", MP3_system.number_of_tracks);
  mvwprintw(player_win[INFO_SCREEN], 2, 2, "Number of albums %i ", MP3_system.number_of_albums);
  mvwprintw(player_win[INFO_SCREEN], 3, 2, "Number of artists %i ", MP3_system.number_of_artists);

  wrefresh(player_win[INFO_SCREEN]);
}

void clear_win(WINDOW *win)
{
  wclear(win);
  box(win, 0, 0);
}

void end_windows()
{
    delwin(player_win[INFO_SCREEN]);

    endwin();
}

WINDOW *create_newwin(int height, int width, int startx, int starty)
{
  WINDOW *local_win;

  local_win = newwin(height, width, starty, startx);
  box(local_win, 0, 0);
  wrefresh(local_win);
  return local_win;
}

void init_win_params(WIN *p_win)
{
  p_win->height = 3;
  p_win->width  = 40;
  p_win->starty = ((LINES - p_win->height) / 2);
  p_win->startx = ((COLS - p_win->width) / 2);
  p_win->border.ls = ACS_VLINE;
  p_win->border.rs = ACS_VLINE;
  p_win->border.ts = ACS_HLINE;
  p_win->border.bs = ACS_HLINE;
  p_win->border.tl = ACS_ULCORNER;
  p_win->border.tr = ACS_URCORNER;
  p_win->border.bl = ACS_LLCORNER;
  p_win->border.br = ACS_LRCORNER;
}

void create_box(WIN *p_win, int _bool)
{
  int i, j;
  int x, y, w, h;

  x = p_win->startx;
  y = p_win->starty;
  h = p_win->height;
  w = p_win->width;

  if (_bool == TRUE)
  {
    mvaddch(y, x, p_win->border.tl);
    mvaddch(y, x + w, p_win->border.tr);
    mvaddch(y + h, x, p_win->border.bl);
    mvaddch(y + h, x + w, p_win->border.br);

    mvhline(y, x + 1, p_win->border.ts, w -1);
    mvhline(y + h, x + 1, p_win->border.bs, w -1);
    mvvline(y + 1, x, p_win->border.ls, h -1);
    mvvline(y + 1, x + w, p_win->border.rs, h -1);
  }
  else
    for (j = y; j <= y + h; ++j)
      for (i = x; i <= x + w; ++i)
        mvaddch(j, i, ' ');
  refresh();

}

void main_menu()
{
  clear_win(player_win[MAIN_SCREEN]);
  mvwprintw(player_win[MAIN_SCREEN], 1, 2, "1   Select Individual Track");
  mvwprintw(player_win[MAIN_SCREEN], 2, 2, "2   Random Play");
  mvwprintw(player_win[MAIN_SCREEN], 3, 2, "3   Select Artist");
  mvwprintw(player_win[MAIN_SCREEN], 4, 2, "4   Select Album");
  mvwprintw(player_win[MAIN_SCREEN], 5, 2, "5   Select Genre");
  mvwprintw(player_win[MAIN_SCREEN], 8, 2, "/   Rebuild random database");

  LCD_clear();
  tty_write("1", "1 Play Track");
  tty_write("2", "2 Random Play");
  tty_write("3", "3 Play an Artist");
  tty_write("4", "4 Play an Album");
//  tty_write("5", "5 Play a Genre");

  noecho();
  wtimeout(player_win[MAIN_SCREEN], 500);
}