mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Improvements to the skincurses plugin
This commit is contained in:
parent
d354d01af7
commit
f031563400
@ -146,6 +146,9 @@ VDR Plugin 'skincurses' Revision History
|
|||||||
|
|
||||||
- Changes for ncurses version 6 (thanks to Ulrick Eckhardt).
|
- Changes for ncurses version 6 (thanks to Ulrick Eckhardt).
|
||||||
|
|
||||||
2020-05-10: Version 2.4.2
|
2020-05-11: Version 2.4.2
|
||||||
|
|
||||||
- Fixed 'Changes for ncurses version 6'.
|
- Fixed 'Changes for ncurses version 6'.
|
||||||
|
- Reacting to changes in screen size.
|
||||||
|
- Simplified color handling.
|
||||||
|
- Using 'stdscr' directly instead of an additional window.
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* See the README file for copyright information and how to reach the author.
|
* See the README file for copyright information and how to reach the author.
|
||||||
*
|
*
|
||||||
* $Id: skincurses.c 4.5 2020/05/10 09:04:31 kls Exp $
|
* $Id: skincurses.c 4.6 2020/05/11 10:23:15 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
@ -60,9 +60,7 @@ static int ScOsdHeight = 20;
|
|||||||
class cCursesOsd : public cOsd {
|
class cCursesOsd : public cOsd {
|
||||||
private:
|
private:
|
||||||
WINDOW *savedRegion;
|
WINDOW *savedRegion;
|
||||||
WINDOW *window;
|
cVector<int> colorPairs;
|
||||||
enum { MaxColorPairs = 16 };
|
|
||||||
int colorPairs[MaxColorPairs];
|
|
||||||
void SetColor(int colorFg, int colorBg = clrBackground);
|
void SetColor(int colorFg, int colorBg = clrBackground);
|
||||||
public:
|
public:
|
||||||
cCursesOsd(int Left, int Top);
|
cCursesOsd(int Left, int Top);
|
||||||
@ -79,39 +77,34 @@ cCursesOsd::cCursesOsd(int Left, int Top)
|
|||||||
{
|
{
|
||||||
savedRegion = NULL;
|
savedRegion = NULL;
|
||||||
|
|
||||||
memset(colorPairs, 0x00, sizeof(colorPairs));
|
|
||||||
start_color();
|
start_color();
|
||||||
leaveok(stdscr, true);
|
leaveok(stdscr, true);
|
||||||
|
refresh(); // to react on changes to screen size
|
||||||
|
|
||||||
window = stdscr;
|
int begy, begx;
|
||||||
syncok(window, true);
|
int maxy, maxx;
|
||||||
|
getmaxyx(stdscr, maxy, maxx);
|
||||||
|
getbegyx(stdscr, begy, begx);
|
||||||
|
ScOsdWidth = maxx - begx;
|
||||||
|
ScOsdHeight = maxy - begy;
|
||||||
}
|
}
|
||||||
|
|
||||||
cCursesOsd::~cCursesOsd()
|
cCursesOsd::~cCursesOsd()
|
||||||
{
|
{
|
||||||
if (window) {
|
erase();
|
||||||
werase(window);
|
Flush();
|
||||||
Flush();
|
|
||||||
window = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cCursesOsd::SetColor(int colorFg, int colorBg)
|
void cCursesOsd::SetColor(int colorFg, int colorBg)
|
||||||
{
|
{
|
||||||
int color = (colorBg << 16) | colorFg | 0x80000000;
|
int color = (colorBg << 16) | colorFg | 0x80000000;
|
||||||
for (int i = 0; i < MaxColorPairs; i++) {
|
int i = colorPairs.IndexOf(color);
|
||||||
if (!colorPairs[i]) {
|
if (i < 0) {
|
||||||
colorPairs[i] = color;
|
colorPairs.Append(color);
|
||||||
init_pair(i + 1, colorFg, colorBg);
|
i = colorPairs.Size() - 1;
|
||||||
//XXX??? attron(COLOR_PAIR(WHITE_ON_BLUE));
|
init_pair(i + 1, colorFg, colorBg);
|
||||||
wattrset(window, COLOR_PAIR(i + 1));
|
}
|
||||||
break;
|
attrset(COLOR_PAIR(i + 1));
|
||||||
}
|
|
||||||
else if (color == colorPairs[i]) {
|
|
||||||
wattrset(window, COLOR_PAIR(i + 1));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cCursesOsd::SaveRegion(int x1, int y1, int x2, int y2)
|
void cCursesOsd::SaveRegion(int x1, int y1, int x2, int y2)
|
||||||
@ -122,13 +115,13 @@ void cCursesOsd::SaveRegion(int x1, int y1, int x2, int y2)
|
|||||||
}
|
}
|
||||||
savedRegion = newwin(y2 - y1 + 1, x2 - x1 + 1, y1, x1);
|
savedRegion = newwin(y2 - y1 + 1, x2 - x1 + 1, y1, x1);
|
||||||
if (savedRegion)
|
if (savedRegion)
|
||||||
copywin(window, savedRegion, y1, x1, 0, 0, y2 - y1, x2 - x1, false);
|
copywin(stdscr, savedRegion, y1, x1, 0, 0, y2 - y1, x2 - x1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cCursesOsd::RestoreRegion(void)
|
void cCursesOsd::RestoreRegion(void)
|
||||||
{
|
{
|
||||||
if (savedRegion) {
|
if (savedRegion) {
|
||||||
overwrite(savedRegion, window);
|
overwrite(savedRegion, stdscr);
|
||||||
delwin(savedRegion);
|
delwin(savedRegion);
|
||||||
savedRegion = NULL;
|
savedRegion = NULL;
|
||||||
}
|
}
|
||||||
@ -168,18 +161,22 @@ void cCursesOsd::DrawText(int x, int y, const char *s, tColor ColorFg, tColor Co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetColor(ColorFg, ColorBg);
|
SetColor(ColorFg, ColorBg);
|
||||||
wmove(window, y, x); // ncurses wants 'y' before 'x'!
|
mvaddnstr(y, x, s, Width ? Width : ScOsdWidth - x);
|
||||||
waddnstr(window, s, Width ? Width : ScOsdWidth - x);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cCursesOsd::DrawRectangle(int x1, int y1, int x2, int y2, tColor Color)
|
void cCursesOsd::DrawRectangle(int x1, int y1, int x2, int y2, tColor Color)
|
||||||
{
|
{
|
||||||
SetColor(Color, Color);
|
SetColor(Color, Color);
|
||||||
for (int y = y1; y <= y2; y++) {
|
int dx = x2 - x1;
|
||||||
wmove(window, y, x1); // ncurses wants 'y' before 'x'!
|
int dy = y2 - y1;
|
||||||
whline(window, ' ', x2 - x1 + 1);
|
if (dx >= dy) {
|
||||||
}
|
for (int y = y1; y <= y2; y++)
|
||||||
wsyncup(window); // shouldn't be necessary because of 'syncok()', but w/o it doesn't work
|
mvhline(y, x1, ' ', dx + 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (int x = x1; x <= x2; x++)
|
||||||
|
mvvline(y1, x, ' ', dy + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cCursesOsd::Flush(void)
|
void cCursesOsd::Flush(void)
|
||||||
@ -827,16 +824,8 @@ bool cPluginSkinCurses::ProcessArgs(int argc, char *argv[])
|
|||||||
bool cPluginSkinCurses::Initialize(void)
|
bool cPluginSkinCurses::Initialize(void)
|
||||||
{
|
{
|
||||||
// Initialize any background activities the plugin shall perform.
|
// Initialize any background activities the plugin shall perform.
|
||||||
WINDOW *w = initscr();
|
if (initscr())
|
||||||
int begy, begx;
|
|
||||||
int maxy, maxx;
|
|
||||||
getmaxyx(w, maxy,maxx);
|
|
||||||
getbegyx(w, begy,begx);
|
|
||||||
if (w) {
|
|
||||||
ScOsdWidth = maxx - begx;
|
|
||||||
ScOsdHeight = maxy - begy;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user