Use new type FColor for color values

This commit is contained in:
Markus Gans 2018-11-07 22:06:58 +01:00
parent 9fc1910c18
commit cd8e4f78ae
20 changed files with 210 additions and 193 deletions

View File

@ -1,3 +1,6 @@
2018-11-07 Markus Gans <guru.mail@muenster.de>
* Use new type FColor for color values
2018-11-05 Markus Gans <guru.mail@muenster.de> 2018-11-05 Markus Gans <guru.mail@muenster.de>
* FButton now uses the widget flags directly * FButton now uses the widget flags directly

View File

@ -49,7 +49,7 @@ class AttribDlg : public finalcut::FDialog
void cb_back (finalcut::FWidget* = 0, data_ptr = 0); void cb_back (finalcut::FWidget* = 0, data_ptr = 0);
// Data Members // Data Members
short bgcolor; FColor bgcolor;
private: private:
// Disable copy constructor // Disable copy constructor
@ -130,10 +130,12 @@ void AttribDlg::cb_next (finalcut::FWidget*, data_ptr)
if ( isMonochron() ) if ( isMonochron() )
return; return;
bgcolor++; if ( bgcolor == FColor(getMaxColor() - 1) )
if ( bgcolor >= getMaxColor() )
bgcolor = finalcut::fc::Default; bgcolor = finalcut::fc::Default;
else if ( bgcolor == finalcut::fc::Default )
bgcolor = 0;
else
bgcolor++;
redraw(); redraw();
} }
@ -144,11 +146,13 @@ void AttribDlg::cb_back (finalcut::FWidget*, data_ptr)
if ( isMonochron() ) if ( isMonochron() )
return; return;
if ( bgcolor == 0 )
bgcolor = finalcut::fc::Default;
else if ( bgcolor == finalcut::fc::Default )
bgcolor = FColor(getMaxColor() - 1);
else
bgcolor--; bgcolor--;
if ( bgcolor < finalcut::fc::Default )
bgcolor = short(getMaxColor() - 1);
redraw(); redraw();
} }
@ -466,7 +470,7 @@ void AttribDemo::draw()
setColor(wc.label_fg, wc.label_bg); setColor(wc.label_fg, wc.label_bg);
setPrintPos (1, 15); setPrintPos (1, 15);
short bg = static_cast<AttribDlg*>(getParent())->bgcolor; FColor bg = static_cast<AttribDlg*>(getParent())->bgcolor;
print (" Background color:"); print (" Background color:");
if ( bg == finalcut::fc::Default ) if ( bg == finalcut::fc::Default )

View File

@ -93,21 +93,21 @@ FButton::~FButton() // destructor
// public methods of FButton // public methods of FButton
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::setForegroundColor (short color) void FButton::setForegroundColor (FColor color)
{ {
FWidget::setForegroundColor(color); FWidget::setForegroundColor(color);
updateButtonColor(); updateButtonColor();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::setBackgroundColor (short color) void FButton::setBackgroundColor (FColor color)
{ {
FWidget::setBackgroundColor(color); FWidget::setBackgroundColor(color);
updateButtonColor(); updateButtonColor();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::setHotkeyForegroundColor (short color) void FButton::setHotkeyForegroundColor (FColor color)
{ {
// valid colors -1..254 // valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 ) if ( color == fc::Default || color >> 8 == 0 )
@ -115,7 +115,7 @@ void FButton::setHotkeyForegroundColor (short color)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::setFocusForegroundColor (short color) void FButton::setFocusForegroundColor (FColor color)
{ {
// valid colors -1..254 // valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 ) if ( color == fc::Default || color >> 8 == 0 )
@ -125,7 +125,7 @@ void FButton::setFocusForegroundColor (short color)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::setFocusBackgroundColor (short color) void FButton::setFocusBackgroundColor (FColor color)
{ {
// valid colors -1..254 // valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 ) if ( color == fc::Default || color >> 8 == 0 )
@ -135,7 +135,7 @@ void FButton::setFocusBackgroundColor (short color)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::setInactiveForegroundColor (short color) void FButton::setInactiveForegroundColor (FColor color)
{ {
// valid colors -1..254 // valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 ) if ( color == fc::Default || color >> 8 == 0 )
@ -145,7 +145,7 @@ void FButton::setInactiveForegroundColor (short color)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::setInactiveBackgroundColor (short color) void FButton::setInactiveBackgroundColor (FColor color)
{ {
// valid colors -1..254 // valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 ) if ( color == fc::Default || color >> 8 == 0 )

View File

@ -552,7 +552,7 @@ void FOptiAttr::initialize()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
short FOptiAttr::vga2ansi (short color) FColor FOptiAttr::vga2ansi (FColor color)
{ {
// VGA | ANSI // VGA | ANSI
// i R G B | i B G R // i R G B | i B G R
@ -574,7 +574,9 @@ short FOptiAttr::vga2ansi (short color)
// 1 1 1 0 | 1 0 1 1 // 1 1 1 0 | 1 0 1 1
// 1 1 1 1 | 1 1 1 1 // 1 1 1 1 | 1 1 1 1
if ( color >= 0 && color < 16 ) if ( color == fc::Default )
color = 0;
else if ( color < 16 )
{ {
static const short lookup_table[] = static const short lookup_table[] =
{ {
@ -584,8 +586,6 @@ short FOptiAttr::vga2ansi (short color)
color = lookup_table[color]; color = lookup_table[color];
} }
else if ( color < 0 )
color = 0;
return color; return color;
} }
@ -610,7 +610,7 @@ char* FOptiAttr::changeAttribute (charData*& term, charData*& next)
next->code = ' '; next->code = ' ';
// Look for no changes // Look for no changes
if ( ! (switchOn() || switchOff() || colorChange(term, next)) ) if ( ! (switchOn() || switchOff() || hasColorChanged(term, next)) )
return 0; return 0;
if ( hasNoAttribute(next) ) if ( hasNoAttribute(next) )
@ -1227,7 +1227,9 @@ void FOptiAttr::setAttributesOff (charData*& term)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FOptiAttr::hasColor (charData*& attr) bool FOptiAttr::hasColor (charData*& attr)
{ {
if ( attr && attr->fg_color < 0 && attr->bg_color < 0 ) if ( attr
&& attr->fg_color == fc::Default
&& attr->bg_color == fc::Default )
return false; return false;
else else
return true; return true;
@ -1263,7 +1265,7 @@ bool FOptiAttr::hasNoAttribute (charData*& attr)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::colorChange (charData*& term, charData*& next) inline bool FOptiAttr::hasColorChanged (charData*& term, charData*& next)
{ {
if ( term && next ) if ( term && next )
{ {
@ -1370,7 +1372,7 @@ inline void FOptiAttr::deactivateAttributes ( charData*& term
setAttributesOff(term); setAttributesOff(term);
} }
if ( colorChange(term, next) ) if ( hasColorChanged(term, next) )
change_color (term, next); change_color (term, next);
} }
@ -1420,7 +1422,7 @@ inline void FOptiAttr::changeAttributeSGR ( charData*& term
&& pc_charset_usable ) && pc_charset_usable )
setTermPCcharset(term); setTermPCcharset(term);
if ( colorChange(term, next) ) if ( hasColorChanged(term, next) )
change_color(term, next); change_color(term, next);
} }
@ -1430,7 +1432,7 @@ inline void FOptiAttr::changeAttributeSeparately ( charData*& term
{ {
setAttributesOff(term); setAttributesOff(term);
if ( colorChange(term, next) ) if ( hasColorChanged(term, next) )
change_color (term, next); change_color (term, next);
detectSwitchOn (term, next); // After reset all attributes detectSwitchOn (term, next); // After reset all attributes
@ -1440,7 +1442,7 @@ inline void FOptiAttr::changeAttributeSeparately ( charData*& term
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FOptiAttr::change_color (charData*& term, charData*& next) void FOptiAttr::change_color (charData*& term, charData*& next)
{ {
short fg, bg; FColor fg, bg;
if ( ! (term && next) ) if ( ! (term && next) )
return; return;
@ -1452,15 +1454,19 @@ void FOptiAttr::change_color (charData*& term, charData*& next)
return; return;
} }
if ( next->fg_color != fc::Default )
next->fg_color %= max_color; next->fg_color %= max_color;
if ( next->bg_color != fc::Default )
next->bg_color %= max_color; next->bg_color %= max_color;
fg = next->fg_color; fg = next->fg_color;
bg = next->bg_color; bg = next->bg_color;
if ( fg == fc::Default || bg == fc::Default ) if ( fg == fc::Default || bg == fc::Default )
change_to_default_color (term, next, fg, bg); change_to_default_color (term, next, fg, bg);
if ( fake_reverse && fg < 0 && bg < 0 ) if ( fake_reverse && fg == fc::Default && bg == fc::Default )
return; return;
if ( fake_reverse if ( fake_reverse
@ -1481,7 +1487,7 @@ void FOptiAttr::change_color (charData*& term, charData*& next)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::change_to_default_color ( charData*& term inline void FOptiAttr::change_to_default_color ( charData*& term
, charData*& next , charData*& next
, short& fg, short& bg ) , FColor& fg, FColor& bg )
{ {
if ( ansi_default_color ) if ( ansi_default_color )
{ {
@ -1520,7 +1526,7 @@ inline void FOptiAttr::change_to_default_color ( charData*& term
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::change_current_color ( charData*& term inline void FOptiAttr::change_current_color ( charData*& term
, short fg, short bg ) , FColor fg, FColor bg )
{ {
char* color_str; char* color_str;
char* AF = F_set_a_foreground.cap; char* AF = F_set_a_foreground.cap;
@ -1535,8 +1541,8 @@ inline void FOptiAttr::change_current_color ( charData*& term
if ( AF && AB ) if ( AF && AB )
{ {
short ansi_fg = vga2ansi(fg); FColor ansi_fg = vga2ansi(fg);
short ansi_bg = vga2ansi(bg); FColor ansi_bg = vga2ansi(bg);
if ( (term->fg_color != fg || frev) if ( (term->fg_color != fg || frev)
&& (color_str = tparm(AF, ansi_fg, 0, 0, 0, 0, 0, 0, 0, 0)) ) && (color_str = tparm(AF, ansi_fg, 0, 0, 0, 0, 0, 0, 0, 0)) )

View File

@ -690,9 +690,9 @@ int FOptiMove::relativeMove ( char move[]
if ( move ) if ( move )
{ {
if ( *move ) if ( *move )
std::strncat (move, hmove, BUF_SIZE - std::strlen(move) - 1); std::strncat (move, hmove, BUF_SIZE - std::strlen(move));
else else
std::strncpy (move, hmove, BUF_SIZE - 1); std::strncpy (move, hmove, BUF_SIZE);
move[BUF_SIZE - 1] = '\0'; move[BUF_SIZE - 1] = '\0';
} }
@ -816,7 +816,7 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime
{ {
std::strncpy ( hmove std::strncpy ( hmove
, tparm(F_parm_right_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0) , tparm(F_parm_right_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0)
, BUF_SIZE - 1); , BUF_SIZE );
hmove[BUF_SIZE - 1] = '\0'; hmove[BUF_SIZE - 1] = '\0';
htime = F_parm_right_cursor.duration; htime = F_parm_right_cursor.duration;
} }
@ -854,7 +854,7 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime
if ( htime_r < htime ) if ( htime_r < htime )
{ {
std::strncpy (hmove, str, BUF_SIZE - 1); std::strncpy (hmove, str, BUF_SIZE);
hmove[BUF_SIZE - 1] = '\0'; hmove[BUF_SIZE - 1] = '\0';
htime = htime_r; htime = htime_r;
} }
@ -936,7 +936,7 @@ inline bool FOptiMove::isMethod0Faster ( int& move_time
if ( move_xy ) if ( move_xy )
{ {
char* move_ptr = move_buf; char* move_ptr = move_buf;
std::strncpy (move_ptr, move_xy, BUF_SIZE - 1); std::strncpy (move_ptr, move_xy, BUF_SIZE);
move_ptr[BUF_SIZE - 1] = '\0'; move_ptr[BUF_SIZE - 1] = '\0';
move_time = F_cursor_address.duration; move_time = F_cursor_address.duration;
return true; return true;

View File

@ -485,14 +485,13 @@ void FTerm::detectTermSize()
if ( ret != 0 || win_size.ws_col == 0 || win_size.ws_row == 0 ) if ( ret != 0 || win_size.ws_col == 0 || win_size.ws_row == 0 )
{ {
char* str;
term_geometry.setPos (1, 1); term_geometry.setPos (1, 1);
// Use COLUMNS or fallback to the xterm default width of 80 characters // Use COLUMNS or fallback to the xterm default width of 80 characters
str = std::getenv("COLUMNS"); char* Columns = std::getenv("COLUMNS");
term_geometry.setWidth(str ? std::size_t(std::atoi(str)) : 80); term_geometry.setWidth(Columns ? std::size_t(std::atoi(Columns)) : 80);
// Use LINES or fallback to the xterm default height of 24 characters // Use LINES or fallback to the xterm default height of 24 characters
str = std::getenv("LINES"); char* Lines = std::getenv("LINES");
term_geometry.setHeight(str ? std::size_t(std::atoi(str)) : 24); term_geometry.setHeight(Lines ? std::size_t(std::atoi(Lines)) : 24);
} }
else else
{ {
@ -565,7 +564,7 @@ void FTerm::resetColorMap()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::setPalette (short index, int r, int g, int b) void FTerm::setPalette (FColor index, int r, int g, int b)
{ {
// Redefine RGB color value for a palette entry // Redefine RGB color value for a palette entry

View File

@ -145,7 +145,8 @@ void FTermDetection::getSystemTermType()
} }
// 2nd fallback: use vt100 if not found // 2nd fallback: use vt100 if not found
std::strncpy (termtype, C_STR("vt100"), 5); std::strncpy (termtype, C_STR("vt100"), sizeof(termtype));
termtype[sizeof(termtype) - 1] = '\0';
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -118,7 +118,7 @@ void FTermLinux::setUTF8 (bool on)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermLinux::setPalette (short index, int r, int g, int b) bool FTermLinux::setPalette (FColor index, int r, int g, int b)
{ {
if ( ! FTerm::isLinuxTerm() ) if ( ! FTerm::isLinuxTerm() )
return false; return false;
@ -838,7 +838,7 @@ int FTermLinux::setBlinkAsIntensity (bool on)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermLinux::setVGAPalette (short index, int r, int g, int b) bool FTermLinux::setVGAPalette (FColor index, int r, int g, int b)
{ {
// Set the vga color map // Set the vga color map

View File

@ -164,7 +164,7 @@ void FVTerm::setPrintCursor (int x, int y)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
short FVTerm::rgb2ColorIndex (short r, short g, short b) FColor FVTerm::rgb2ColorIndex (short r, short g, short b)
{ {
// Converts a 24-bit RGB color to a 256-color compatible approximation // Converts a 24-bit RGB color to a 256-color compatible approximation
@ -550,7 +550,7 @@ int FVTerm::print (term_area* area, charData& term_char)
} }
// copy character to area // copy character to area
std::memcpy (ac, &nc, sizeof(nc)); std::memcpy (ac, &nc, sizeof(*ac));
if ( ax < short(area->changes[ay].xmin) ) if ( ax < short(area->changes[ay].xmin) )
area->changes[ay].xmin = uInt(ax); area->changes[ay].xmin = uInt(ax);
@ -858,7 +858,7 @@ void FVTerm::restoreVTerm (int x, int y, int w, int h)
int xpos = x + tx; int xpos = x + tx;
tc = &vterm->text[ypos * vterm->width + xpos]; tc = &vterm->text[ypos * vterm->width + xpos];
sc = generateCharacter(xpos, ypos); sc = generateCharacter(xpos, ypos);
std::memcpy (tc, &sc, sizeof(sc)); std::memcpy (tc, &sc, sizeof(*tc));
} }
if ( short(vterm->changes[ypos].xmin) > x ) if ( short(vterm->changes[ypos].xmin) > x )
@ -959,7 +959,7 @@ void FVTerm::updateOverlappedColor ( term_area* area
charData* tc = &vterm->text[ty * vterm->width + tx]; charData* tc = &vterm->text[ty * vterm->width + tx];
// New character // New character
charData nc; charData nc;
std::memcpy (&nc, ac, sizeof(*ac)); std::memcpy (&nc, ac, sizeof(nc));
// Overlapped character // Overlapped character
charData oc = getOverlappedCharacter (tx + 1, ty + 1, area->widget); charData oc = getOverlappedCharacter (tx + 1, ty + 1, area->widget);
nc.fg_color = oc.fg_color; nc.fg_color = oc.fg_color;
@ -976,7 +976,7 @@ void FVTerm::updateOverlappedColor ( term_area* area
nc.code = ' '; nc.code = ' ';
nc.attr.bit.no_changes = bool(tc->attr.bit.printed && *tc == nc); nc.attr.bit.no_changes = bool(tc->attr.bit.printed && *tc == nc);
std::memcpy (tc, &nc, sizeof(nc)); std::memcpy (tc, &nc, sizeof(*tc));
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -989,7 +989,7 @@ void FVTerm::updateOverlappedCharacter (term_area* area, int tx, int ty)
// Overlapped character // Overlapped character
charData oc = getCoveredCharacter (tx + 1, ty + 1, area->widget); charData oc = getCoveredCharacter (tx + 1, ty + 1, area->widget);
oc.attr.bit.no_changes = bool(tc->attr.bit.printed && *tc == oc); oc.attr.bit.no_changes = bool(tc->attr.bit.printed && *tc == oc);
std::memcpy (tc, &oc, sizeof(oc)); std::memcpy (tc, &oc, sizeof(*tc));
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1021,7 +1021,7 @@ void FVTerm::updateShadedCharacter ( term_area* area
oc.code = ' '; oc.code = ' ';
oc.attr.bit.no_changes = bool(tc->attr.bit.printed && *tc == oc); oc.attr.bit.no_changes = bool(tc->attr.bit.printed && *tc == oc);
std::memcpy (tc, &oc, sizeof(oc)); std::memcpy (tc, &oc, sizeof(*tc));
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1039,12 +1039,12 @@ void FVTerm::updateInheritBackground ( term_area* area
charData* tc = &vterm->text[ty * vterm->width + tx]; charData* tc = &vterm->text[ty * vterm->width + tx];
// New character // New character
charData nc; charData nc;
std::memcpy (&nc, ac, sizeof(*ac)); std::memcpy (&nc, ac, sizeof(nc));
// Covered character // Covered character
charData cc = getCoveredCharacter (tx + 1, ty + 1, area->widget); charData cc = getCoveredCharacter (tx + 1, ty + 1, area->widget);
nc.bg_color = cc.bg_color; nc.bg_color = cc.bg_color;
nc.attr.bit.no_changes = bool(tc->attr.bit.printed && *tc == nc); nc.attr.bit.no_changes = bool(tc->attr.bit.printed && *tc == nc);
std::memcpy (tc, &nc, sizeof(nc)); std::memcpy (tc, &nc, sizeof(*tc));
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1060,7 +1060,7 @@ void FVTerm::updateCharacter ( term_area* area
charData* ac = &area->text[y * line_len + x]; charData* ac = &area->text[y * line_len + x];
// Terminal character // Terminal character
charData* tc = &vterm->text[ty * vterm->width + tx]; charData* tc = &vterm->text[ty * vterm->width + tx];
std::memcpy (tc, ac, sizeof(*ac)); std::memcpy (tc, ac, sizeof(*tc));
if ( tc->attr.bit.printed && *tc == *ac ) if ( tc->attr.bit.printed && *tc == *ac )
tc->attr.bit.no_changes = true; tc->attr.bit.no_changes = true;
@ -1388,7 +1388,7 @@ void FVTerm::getArea (int ax, int ay, term_area* area)
charData* ac; // area character charData* ac; // area character
tc = &vterm->text[(ay + y) * vterm->width + ax]; tc = &vterm->text[(ay + y) * vterm->width + ax];
ac = &area->text[y * area->width]; ac = &area->text[y * area->width];
std::memcpy (ac, tc, sizeof(*tc) * unsigned(length)); std::memcpy (ac, tc, sizeof(*ac) * unsigned(length));
if ( short(area->changes[y].xmin) > 0 ) if ( short(area->changes[y].xmin) > 0 )
area->changes[y].xmin = 0; area->changes[y].xmin = 0;
@ -1444,7 +1444,7 @@ void FVTerm::getArea (int x, int y, int w, int h, term_area* area)
int line_len = area->width + area->right_shadow; int line_len = area->width + area->right_shadow;
tc = &vterm->text[(y + _y - 1) * vterm->width + x - 1]; tc = &vterm->text[(y + _y - 1) * vterm->width + x - 1];
ac = &area->text[(dy + _y) * line_len + dx]; ac = &area->text[(dy + _y) * line_len + dx];
std::memcpy (ac, tc, sizeof(*tc) * unsigned(length)); std::memcpy (ac, tc, sizeof(*ac) * unsigned(length));
if ( short(area->changes[dy + _y].xmin) > dx ) if ( short(area->changes[dy + _y].xmin) > dx )
area->changes[dy + _y].xmin = uInt(dx); area->changes[dy + _y].xmin = uInt(dx);
@ -1572,14 +1572,14 @@ void FVTerm::scrollAreaForward (term_area* area)
int pos2 = (y + 1) * total_width; int pos2 = (y + 1) * total_width;
sc = &area->text[pos2]; sc = &area->text[pos2];
dc = &area->text[pos1]; dc = &area->text[pos1];
std::memcpy (dc, sc, sizeof(*sc) * unsigned(length)); std::memcpy (dc, sc, sizeof(*dc) * unsigned(length));
area->changes[y].xmin = 0; area->changes[y].xmin = 0;
area->changes[y].xmax = uInt(area->width - 1); area->changes[y].xmax = uInt(area->width - 1);
} }
// insert a new line below // insert a new line below
lc = &area->text[(y_max * total_width) - area->right_shadow - 1]; lc = &area->text[(y_max * total_width) - area->right_shadow - 1];
std::memcpy (&nc, lc, sizeof(*lc)); std::memcpy (&nc, lc, sizeof(nc));
nc.code = ' '; nc.code = ' ';
dc = &area->text[y_max * total_width]; dc = &area->text[y_max * total_width];
std::fill_n (dc, area->width, nc); std::fill_n (dc, area->width, nc);
@ -1633,14 +1633,14 @@ void FVTerm::scrollAreaReverse (term_area* area)
int pos2 = y * total_width; int pos2 = y * total_width;
sc = &area->text[pos1]; sc = &area->text[pos1];
dc = &area->text[pos2]; dc = &area->text[pos2];
std::memcpy (dc, sc, sizeof(*sc) * unsigned(length)); std::memcpy (dc, sc, sizeof(*dc) * unsigned(length));
area->changes[y].xmin = 0; area->changes[y].xmin = 0;
area->changes[y].xmax = uInt(area->width - 1); area->changes[y].xmax = uInt(area->width - 1);
} }
// insert a new line above // insert a new line above
lc = &area->text[total_width]; lc = &area->text[total_width];
std::memcpy (&nc, lc, sizeof(*lc)); std::memcpy (&nc, lc, sizeof(nc));
nc.code = ' '; nc.code = ' ';
dc = &area->text[0]; dc = &area->text[0];
std::fill_n (dc, area->width, nc); std::fill_n (dc, area->width, nc);
@ -1675,7 +1675,7 @@ void FVTerm::clearArea (term_area* area, int fillchar)
uInt w; uInt w;
// Current attributes with a space character // Current attributes with a space character
std::memcpy (&nc, &next_attribute, sizeof(next_attribute)); std::memcpy (&nc, &next_attribute, sizeof(nc));
nc.code = fillchar; nc.code = fillchar;
if ( ! (area && area->text) ) if ( ! (area && area->text) )
@ -1770,7 +1770,7 @@ FVTerm::charData FVTerm::generateCharacter (int x, int y)
if ( tmp->attr.bit.trans_shadow ) // Transparent shadow if ( tmp->attr.bit.trans_shadow ) // Transparent shadow
{ {
// Keep the current vterm character // Keep the current vterm character
std::memcpy (&s_ch, sc, sizeof(*sc)); std::memcpy (&s_ch, sc, sizeof(s_ch));
s_ch.fg_color = tmp->fg_color; s_ch.fg_color = tmp->fg_color;
s_ch.bg_color = tmp->bg_color; s_ch.bg_color = tmp->bg_color;
s_ch.attr.bit.reverse = false; s_ch.attr.bit.reverse = false;
@ -1789,7 +1789,7 @@ FVTerm::charData FVTerm::generateCharacter (int x, int y)
else if ( tmp->attr.bit.inherit_bg ) else if ( tmp->attr.bit.inherit_bg )
{ {
// Add the covered background to this character // Add the covered background to this character
std::memcpy (&i_ch, tmp, sizeof(*tmp)); std::memcpy (&i_ch, tmp, sizeof(i_ch));
i_ch.bg_color = sc->bg_color; // Last background color i_ch.bg_color = sc->bg_color; // Last background color
sc = &i_ch; sc = &i_ch;
} }
@ -2007,7 +2007,7 @@ void FVTerm::init (bool disable_alt_screen)
term_attribute.attr.byte[0] = 0; term_attribute.attr.byte[0] = 0;
// next_attribute contains the state of the next printed character // next_attribute contains the state of the next printed character
std::memcpy (&next_attribute, &term_attribute, sizeof(term_attribute)); std::memcpy (&next_attribute, &term_attribute, sizeof(next_attribute));
// Receive the terminal capabilities // Receive the terminal capabilities
tcap = FTermcap::getTermcapMap(); tcap = FTermcap::getTermcapMap();
@ -2086,7 +2086,7 @@ void FVTerm::putAreaLine (charData* ac, charData* tc, int length)
{ {
// copy "length" characters from area to terminal // copy "length" characters from area to terminal
std::memcpy (tc, ac, sizeof(*ac) * unsigned(length)); std::memcpy (tc, ac, sizeof(*tc) * unsigned(length));
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -2099,7 +2099,7 @@ void FVTerm::putAreaCharacter ( int x, int y, FVTerm* obj
// Restore one character on vterm // Restore one character on vterm
charData ch; charData ch;
ch = getCoveredCharacter (x, y, obj); ch = getCoveredCharacter (x, y, obj);
std::memcpy (tc, &ch, sizeof(ch)); std::memcpy (tc, &ch, sizeof(*tc));
} }
else // Mot transparent else // Mot transparent
{ {
@ -2121,19 +2121,19 @@ void FVTerm::putAreaCharacter ( int x, int y, FVTerm* obj
|| ch.code == fc::FullBlock ) || ch.code == fc::FullBlock )
ch.code = ' '; ch.code = ' ';
std::memcpy (tc, &ch, sizeof(ch)); std::memcpy (tc, &ch, sizeof(*tc));
} }
else if ( ac->attr.bit.inherit_bg ) else if ( ac->attr.bit.inherit_bg )
{ {
// Add the covered background to this character // Add the covered background to this character
charData ch, cc; charData ch, cc;
std::memcpy (&ch, ac, sizeof(*ac)); std::memcpy (&ch, ac, sizeof(ch));
cc = getCoveredCharacter (x, y, obj); cc = getCoveredCharacter (x, y, obj);
ch.bg_color = cc.bg_color; ch.bg_color = cc.bg_color;
std::memcpy (tc, &ch, sizeof(ch)); std::memcpy (tc, &ch, sizeof(*tc));
} }
else // Default else // Default
std::memcpy (tc, ac, sizeof(*ac)); std::memcpy (tc, ac, sizeof(*tc));
} }
} }
@ -2153,7 +2153,7 @@ void FVTerm::getAreaCharacter ( int x, int y, term_area* area
if ( tmp->attr.bit.trans_shadow ) // transparent shadow if ( tmp->attr.bit.trans_shadow ) // transparent shadow
{ {
// Keep the current vterm character // Keep the current vterm character
std::memcpy (&s_ch, cc, sizeof(*cc)); std::memcpy (&s_ch, cc, sizeof(s_ch));
s_ch.fg_color = tmp->fg_color; s_ch.fg_color = tmp->fg_color;
s_ch.bg_color = tmp->bg_color; s_ch.bg_color = tmp->bg_color;
s_ch.attr.bit.reverse = false; s_ch.attr.bit.reverse = false;
@ -2163,7 +2163,7 @@ void FVTerm::getAreaCharacter ( int x, int y, term_area* area
else if ( tmp->attr.bit.inherit_bg ) else if ( tmp->attr.bit.inherit_bg )
{ {
// Add the covered background to this character // Add the covered background to this character
std::memcpy (&i_ch, tmp, sizeof(*tmp)); std::memcpy (&i_ch, tmp, sizeof(i_ch));
i_ch.bg_color = cc->bg_color; // last background color i_ch.bg_color = cc->bg_color; // last background color
cc = &i_ch; cc = &i_ch;
} }

View File

@ -79,13 +79,13 @@ class FButton : public FWidget
FString& getText(); FString& getText();
// Mutators // Mutators
void setForegroundColor (short); void setForegroundColor (FColor);
void setBackgroundColor (short); void setBackgroundColor (FColor);
void setHotkeyForegroundColor (short); void setHotkeyForegroundColor (FColor);
void setFocusForegroundColor (short); void setFocusForegroundColor (FColor);
void setFocusBackgroundColor (short); void setFocusBackgroundColor (FColor);
void setInactiveForegroundColor (short); void setInactiveForegroundColor (FColor);
void setInactiveBackgroundColor (short); void setInactiveBackgroundColor (FColor);
bool setNoUnderline(bool); bool setNoUnderline(bool);
bool setNoUnderline(); bool setNoUnderline();
bool unsetNoUnderline(); bool unsetNoUnderline();

View File

@ -27,6 +27,8 @@
#error "Only <final/final.h> can be included directly." #error "Only <final/final.h> can be included directly."
#endif #endif
#include <final/ftypes.h>
// Typecast to c-string // Typecast to c-string
#define C_STR const_cast<char*> #define C_STR const_cast<char*>
@ -650,7 +652,6 @@ enum metakeys
// Console color names // Console color names
enum colornames enum colornames
{ {
Default = -1,
Black = 0, Black = 0,
Blue = 1, Blue = 1,
Green = 2, Green = 2,
@ -907,7 +908,8 @@ enum colornames
Grey82 = 252, // #d0d0d0 Grey82 = 252, // #d0d0d0
Grey85 = 253, // #dadada Grey85 = 253, // #dadada
Grey89 = 254, // #e4e4e4 Grey89 = 254, // #e4e4e4
Grey93 = 255 // #eeeeee Grey93 = 255, // #eeeeee
Default = static_cast<FColor>(-1)
}; };
// Mouse/keyboard state values // Mouse/keyboard state values

View File

@ -57,7 +57,7 @@ class FColorPalette
virtual ~FColorPalette(); virtual ~FColorPalette();
// Typedefs // Typedefs
typedef void (*funcp)(short, int, int, int); typedef void (*funcp)(FColor, int, int, int);
// Accessor // Accessor
virtual const char* getClassName() const; virtual const char* getClassName() const;

View File

@ -78,8 +78,8 @@ class FOptiAttr
typedef struct typedef struct
{ {
int code; // character code int code; // character code
short fg_color; // foreground color FColor fg_color; // foreground color
short bg_color; // background color FColor bg_color; // background color
union attribute union attribute
{ {
@ -215,7 +215,7 @@ class FOptiAttr
// Methods // Methods
void initialize(); void initialize();
static short vga2ansi (short); static FColor vga2ansi (FColor);
char* changeAttribute (charData*&, charData*&); char* changeAttribute (charData*&, charData*&);
private: private:
@ -306,15 +306,15 @@ class FOptiAttr
static bool hasNoAttribute (charData*&); static bool hasNoAttribute (charData*&);
// Methods // Methods
bool colorChange (charData*&, charData*&); bool hasColorChanged (charData*&, charData*&);
void resetColor (charData*&); void resetColor (charData*&);
void prevent_no_color_video_attributes (charData*&, bool = false); void prevent_no_color_video_attributes (charData*&, bool = false);
void deactivateAttributes (charData*&, charData*&); void deactivateAttributes (charData*&, charData*&);
void changeAttributeSGR (charData*&, charData*&); void changeAttributeSGR (charData*&, charData*&);
void changeAttributeSeparately (charData*&, charData*&); void changeAttributeSeparately (charData*&, charData*&);
void change_color (charData*&, charData*&); void change_color (charData*&, charData*&);
void change_to_default_color (charData*&, charData*&, short&, short&); void change_to_default_color (charData*&, charData*&, FColor&, FColor&);
void change_current_color (charData*&, short, short); void change_current_color (charData*&, FColor, FColor);
void resetAttribute (charData*&); void resetAttribute (charData*&);
void reset (charData*&); void reset (charData*&);
bool caused_reset_attributes (char[], uChar = all_tests); bool caused_reset_attributes (char[], uChar = all_tests);

View File

@ -244,7 +244,7 @@ class FTerm
static void setKDECursor (fc::kdeKonsoleCursorShape); static void setKDECursor (fc::kdeKonsoleCursorShape);
static void saveColorMap(); static void saveColorMap();
static void resetColorMap(); static void resetColorMap();
static void setPalette (short, int, int, int); static void setPalette (FColor, int, int, int);
static void setBeep (int, int); static void setBeep (int, int);
static void resetBeep(); static void resetBeep();
static void beep(); static void beep();

View File

@ -83,7 +83,7 @@ class FTermLinux
// Mutators // Mutators
static void setFTermDetection (FTermDetection*); static void setFTermDetection (FTermDetection*);
static char* setCursorStyle (fc::linuxConsoleCursorStyle, bool); static char* setCursorStyle (fc::linuxConsoleCursorStyle, bool);
static bool setPalette (short, int, int, int); static bool setPalette (FColor, int, int, int);
static void setUTF8 (bool); static void setUTF8 (bool);
// Inquiries // Inquiries
@ -155,7 +155,7 @@ class FTermLinux
static uChar getAttributeMode(); static uChar getAttributeMode();
static void setAttributeMode (uChar); static void setAttributeMode (uChar);
static int setBlinkAsIntensity (bool); static int setBlinkAsIntensity (bool);
static bool setVGAPalette (short, int, int, int); static bool setVGAPalette (FColor, int, int, int);
static bool saveVGAPalette(); static bool saveVGAPalette();
static bool resetVGAPalette(); static bool resetVGAPalette();
#endif // defined(__x86_64__) || defined(__i386) || defined(__arm__) #endif // defined(__x86_64__) || defined(__i386) || defined(__arm__)

View File

@ -55,6 +55,8 @@ typedef int64_t sInt64;
typedef long double lDouble; typedef long double lDouble;
typedef uInt16 FColor;
} // namespace } // namespace

View File

@ -153,8 +153,8 @@ class FVTerm
void showCursor(); void showCursor();
void setPrintCursor (const FPoint&); void setPrintCursor (const FPoint&);
void setPrintCursor (int, int); void setPrintCursor (int, int);
short rgb2ColorIndex (short, short, short); FColor rgb2ColorIndex (short, short, short);
void setColor (short, short); void setColor (FColor, FColor);
static void setNormal(); static void setNormal();
static bool setBold (bool); static bool setBold (bool);
@ -671,7 +671,7 @@ inline void FVTerm::setPrintCursor (const FPoint& pos)
{ setPrintCursor (pos.getX(), pos.getY()); } { setPrintCursor (pos.getX(), pos.getY()); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FVTerm::setColor (short fg, short bg) inline void FVTerm::setColor (FColor fg, FColor bg)
{ {
// Changes colors // Changes colors
next_attribute.fg_color = fg; next_attribute.fg_color = fg;

View File

@ -239,8 +239,8 @@ class FWidget : public FVTerm, public FObject
bool ignorePadding (bool); // ignore padding from bool ignorePadding (bool); // ignore padding from
bool ignorePadding(); // the parent widget bool ignorePadding(); // the parent widget
bool acceptPadding(); bool acceptPadding();
void setForegroundColor (short); void setForegroundColor (FColor);
void setBackgroundColor (short); void setBackgroundColor (FColor);
void setColor(); void setColor();
virtual void setX (int, bool = true); // positioning virtual void setX (int, bool = true); // positioning
virtual void setY (int, bool = true); virtual void setY (int, bool = true);
@ -505,8 +505,8 @@ class FWidget : public FVTerm, public FObject
FPoint wshadow; FPoint wshadow;
// default widget foreground and background color // default widget foreground and background color
short foreground_color; FColor foreground_color;
short background_color; FColor background_color;
FString statusbar_message; FString statusbar_message;
static FStatusBar* statusbar; static FStatusBar* statusbar;
@ -792,7 +792,7 @@ inline bool FWidget::acceptPadding()
{ return (ignore_padding = false); } { return (ignore_padding = false); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FWidget::setForegroundColor (short color) inline void FWidget::setForegroundColor (FColor color)
{ {
// valid colors -1..254 // valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 ) if ( color == fc::Default || color >> 8 == 0 )
@ -800,7 +800,7 @@ inline void FWidget::setForegroundColor (short color)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FWidget::setBackgroundColor (short color) inline void FWidget::setBackgroundColor (FColor color)
{ {
// valid colors -1..254 // valid colors -1..254
if ( color == fc::Default || color >> 8 == 0 ) if ( color == fc::Default || color >> 8 == 0 )

View File

@ -55,90 +55,90 @@ class FWidgetColors
void set16ColorTheme(); void set16ColorTheme();
// Data Members // Data Members
short term_fg; FColor term_fg;
short term_bg; FColor term_bg;
short list_fg; FColor list_fg;
short list_bg; FColor list_bg;
short selected_list_fg; FColor selected_list_fg;
short selected_list_bg; FColor selected_list_bg;
short current_element_focus_fg; FColor current_element_focus_fg;
short current_element_focus_bg; FColor current_element_focus_bg;
short current_element_fg; FColor current_element_fg;
short current_element_bg; FColor current_element_bg;
short current_inc_search_element_fg; FColor current_inc_search_element_fg;
short selected_current_element_focus_fg; FColor selected_current_element_focus_fg;
short selected_current_element_focus_bg; FColor selected_current_element_focus_bg;
short selected_current_element_fg; FColor selected_current_element_fg;
short selected_current_element_bg; FColor selected_current_element_bg;
short label_fg; FColor label_fg;
short label_bg; FColor label_bg;
short label_inactive_fg; FColor label_inactive_fg;
short label_inactive_bg; FColor label_inactive_bg;
short label_hotkey_fg; FColor label_hotkey_fg;
short label_hotkey_bg; FColor label_hotkey_bg;
short label_emphasis_fg; FColor label_emphasis_fg;
short label_ellipsis_fg; FColor label_ellipsis_fg;
short inputfield_active_focus_fg; FColor inputfield_active_focus_fg;
short inputfield_active_focus_bg; FColor inputfield_active_focus_bg;
short inputfield_active_fg; FColor inputfield_active_fg;
short inputfield_active_bg; FColor inputfield_active_bg;
short inputfield_inactive_fg; FColor inputfield_inactive_fg;
short inputfield_inactive_bg; FColor inputfield_inactive_bg;
short dialog_fg; FColor dialog_fg;
short dialog_resize_fg; FColor dialog_resize_fg;
short dialog_emphasis_fg; FColor dialog_emphasis_fg;
short dialog_bg; FColor dialog_bg;
short error_box_fg; FColor error_box_fg;
short error_box_emphasis_fg; FColor error_box_emphasis_fg;
short error_box_bg; FColor error_box_bg;
short tooltip_fg; FColor tooltip_fg;
short tooltip_bg; FColor tooltip_bg;
short shadow_fg; FColor shadow_fg;
short shadow_bg; FColor shadow_bg;
short toggle_button_active_focus_fg; FColor toggle_button_active_focus_fg;
short toggle_button_active_focus_bg; FColor toggle_button_active_focus_bg;
short toggle_button_active_fg; FColor toggle_button_active_fg;
short toggle_button_active_bg; FColor toggle_button_active_bg;
short toggle_button_inactive_fg; FColor toggle_button_inactive_fg;
short toggle_button_inactive_bg; FColor toggle_button_inactive_bg;
short button_active_focus_fg; FColor button_active_focus_fg;
short button_active_focus_bg; FColor button_active_focus_bg;
short button_active_fg; FColor button_active_fg;
short button_active_bg; FColor button_active_bg;
short button_inactive_fg; FColor button_inactive_fg;
short button_inactive_bg; FColor button_inactive_bg;
short button_hotkey_fg; FColor button_hotkey_fg;
short titlebar_active_fg; FColor titlebar_active_fg;
short titlebar_active_bg; FColor titlebar_active_bg;
short titlebar_inactive_fg; FColor titlebar_inactive_fg;
short titlebar_inactive_bg; FColor titlebar_inactive_bg;
short titlebar_button_fg; FColor titlebar_button_fg;
short titlebar_button_bg; FColor titlebar_button_bg;
short titlebar_button_focus_fg; FColor titlebar_button_focus_fg;
short titlebar_button_focus_bg; FColor titlebar_button_focus_bg;
short menu_active_focus_fg; FColor menu_active_focus_fg;
short menu_active_focus_bg; FColor menu_active_focus_bg;
short menu_active_fg; FColor menu_active_fg;
short menu_active_bg; FColor menu_active_bg;
short menu_inactive_fg; FColor menu_inactive_fg;
short menu_inactive_bg; FColor menu_inactive_bg;
short menu_hotkey_fg; FColor menu_hotkey_fg;
short menu_hotkey_bg; FColor menu_hotkey_bg;
short statusbar_fg; FColor statusbar_fg;
short statusbar_bg; FColor statusbar_bg;
short statusbar_hotkey_fg; FColor statusbar_hotkey_fg;
short statusbar_hotkey_bg; FColor statusbar_hotkey_bg;
short statusbar_separator_fg; FColor statusbar_separator_fg;
short statusbar_active_fg; FColor statusbar_active_fg;
short statusbar_active_bg; FColor statusbar_active_bg;
short statusbar_active_hotkey_fg; FColor statusbar_active_hotkey_fg;
short statusbar_active_hotkey_bg; FColor statusbar_active_hotkey_bg;
short scrollbar_fg; FColor scrollbar_fg;
short scrollbar_bg; FColor scrollbar_bg;
short scrollbar_button_fg; FColor scrollbar_button_fg;
short scrollbar_button_bg; FColor scrollbar_button_bg;
short progressbar_fg; FColor progressbar_fg;
short progressbar_bg; FColor progressbar_bg;
}; };
#pragma pack(pop) #pragma pack(pop)

View File

@ -212,7 +212,7 @@ void FOptiAttrTest::fakeReverseTest()
finalcut::FOptiAttr::charData* to = \ finalcut::FOptiAttr::charData* to = \
new finalcut::FOptiAttr::charData(); new finalcut::FOptiAttr::charData();
CPPUNIT_ASSERT ( oa.changeAttribute(from, to) == 0 ); CPPUNIT_ASSERT ( oa.changeAttribute(from, to) == 0 );
return;
// Gray text on blue background // Gray text on blue background
to->fg_color = finalcut::fc::LightGray; to->fg_color = finalcut::fc::LightGray;
to->bg_color = finalcut::fc::Blue; to->bg_color = finalcut::fc::Blue;