2017-11-24 16:46:58 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/examples/pdcurses/charset_main.c
|
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-11-24 16:46:58 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-11-24 16:46:58 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-11-24 16:46:58 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "graphics/curses.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define FIRST_CH 0x20
|
|
|
|
#define LAST_CH 0x7e
|
|
|
|
#define NUM_CH (LAST_CH - FIRST_CH + 1)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static short color_table[] =
|
|
|
|
{
|
|
|
|
COLOR_RED, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
|
|
|
|
COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
{
|
|
|
|
chtype ch;
|
|
|
|
int lastch;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int xoffset;
|
|
|
|
int yoffset;
|
|
|
|
int row;
|
|
|
|
int col;
|
|
|
|
int i;
|
2019-01-05 20:28:06 +01:00
|
|
|
#ifdef CONFIG_PDCURSES_MULTITHREAD
|
|
|
|
FAR struct pdc_context_s *ctx = PDC_ctx();
|
|
|
|
#endif
|
2017-11-24 16:46:58 +01:00
|
|
|
|
|
|
|
/* Initialize */
|
|
|
|
|
|
|
|
traceon();
|
|
|
|
initscr();
|
|
|
|
noecho();
|
|
|
|
|
|
|
|
/* Setup colors */
|
|
|
|
|
|
|
|
if (has_colors())
|
|
|
|
{
|
|
|
|
start_color();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
init_pair(i, color_table[i], COLOR_BLACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up geometry */
|
2017-11-30 19:04:38 +01:00
|
|
|
/* First get the maximum width */
|
2017-11-24 16:46:58 +01:00
|
|
|
|
|
|
|
width = COLS - 2;
|
|
|
|
if (width > NUM_CH)
|
|
|
|
{
|
|
|
|
width = NUM_CH;
|
|
|
|
}
|
|
|
|
|
2017-11-30 19:04:38 +01:00
|
|
|
/* Get the height associated with the maximum width */
|
2017-11-24 16:46:58 +01:00
|
|
|
|
|
|
|
height = (NUM_CH + width - 1) / width;
|
|
|
|
lastch = LAST_CH;
|
|
|
|
|
|
|
|
if (height > LINES)
|
|
|
|
{
|
|
|
|
height = LINES;
|
|
|
|
lastch = FIRST_CH + width * height - 1;
|
|
|
|
}
|
|
|
|
|
2017-11-30 19:04:38 +01:00
|
|
|
/* Reduce the width if it will give us a more balanced layout */
|
|
|
|
|
|
|
|
while (height < (LINES / 2) && width > (COLS / 2))
|
|
|
|
{
|
|
|
|
int numch = lastch - FIRST_CH + 1;
|
|
|
|
|
|
|
|
width >>= 1;
|
|
|
|
height = (numch + width - 1) / width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Center the rectangle containing the font set */
|
|
|
|
|
|
|
|
xoffset = (COLS - width) / 2;
|
2017-11-24 16:46:58 +01:00
|
|
|
yoffset = (LINES - height) / 2;
|
|
|
|
|
2017-11-30 19:04:38 +01:00
|
|
|
/* Now display the character set using that geometry */
|
2017-11-24 16:46:58 +01:00
|
|
|
|
|
|
|
ch = FIRST_CH;
|
|
|
|
for (row = yoffset; row < yoffset + height; row++)
|
|
|
|
{
|
|
|
|
for (col = xoffset; col < xoffset + width; col++)
|
|
|
|
{
|
|
|
|
mvaddch(row, col, ch);
|
|
|
|
if (++ch > lastch)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
endwin();
|
|
|
|
return 0;
|
|
|
|
}
|