FColor fix

This commit is contained in:
Markus Gans 2018-11-13 02:51:41 +01:00
parent 9b3f30f006
commit e40a233d64
23 changed files with 193 additions and 111 deletions

View File

@ -316,8 +316,7 @@ Calc::Calc (FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Calc::~Calc() Calc::~Calc()
{ { }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::drawDispay() void Calc::drawDispay()

View File

@ -40,8 +40,8 @@ class ColorChooser : public finalcut::FWidget
~ColorChooser(); ~ColorChooser();
// Accessors // Accessors
short getForeground(); FColor getForeground();
short getBackground(); FColor getBackground();
private: private:
// Disable copy constructor // Disable copy constructor
@ -56,8 +56,8 @@ class ColorChooser : public finalcut::FWidget
virtual void onMouseDown (finalcut::FMouseEvent*); virtual void onMouseDown (finalcut::FMouseEvent*);
// Data Members // Data Members
short fg_color; FColor fg_color;
short bg_color; FColor bg_color;
finalcut::FLabel headline; finalcut::FLabel headline;
}; };
#pragma pack(pop) #pragma pack(pop)
@ -75,8 +75,8 @@ ColorChooser::ColorChooser (finalcut::FWidget* parent)
if ( parent ) if ( parent )
{ {
short fg = parent->getForegroundColor(); FColor fg = parent->getForegroundColor();
short bg = parent->getBackgroundColor(); FColor bg = parent->getBackgroundColor();
setForegroundColor(fg); setForegroundColor(fg);
setBackgroundColor(bg); setBackgroundColor(bg);
headline.setForegroundColor(fg); headline.setForegroundColor(fg);
@ -112,9 +112,9 @@ void ColorChooser::onMouseDown (finalcut::FMouseEvent* ev)
if ( mouse_x >= xmin && mouse_x <= xmax && mouse_y == y ) if ( mouse_x >= xmin && mouse_x <= xmax && mouse_y == y )
{ {
if ( ev->getButton() == finalcut::fc::LeftButton ) if ( ev->getButton() == finalcut::fc::LeftButton )
bg_color = short(c); bg_color = FColor(c);
else if ( ev->getButton() == finalcut::fc::RightButton ) else if ( ev->getButton() == finalcut::fc::RightButton )
fg_color = short(c); fg_color = FColor(c);
redraw(); redraw();
emitCallback("clicked"); emitCallback("clicked");
@ -128,7 +128,7 @@ void ColorChooser::draw()
setColor(); setColor();
finalcut::FWidget::drawBorder (1, 2, 8, 11); finalcut::FWidget::drawBorder (1, 2, 8, 11);
for (short c = 0; c < 16; c++) for (FColor c = 0; c < 16; c++)
{ {
setPrintPos (2 + (c / 8) * 3, 3 + c % 8); setPrintPos (2 + (c / 8) * 3, 3 + c % 8);
@ -151,13 +151,13 @@ void ColorChooser::draw()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline short ColorChooser::getForeground() inline FColor ColorChooser::getForeground()
{ {
return fg_color; return fg_color;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline short ColorChooser::getBackground() inline FColor ColorChooser::getBackground()
{ {
return bg_color; return bg_color;
} }
@ -183,8 +183,8 @@ class Brushes : public finalcut::FWidget
wchar_t getBrush(); wchar_t getBrush();
// Mutators // Mutators
void setForeground (short); void setForeground (FColor);
void setBackground (short); void setBackground (FColor);
private: private:
// Disable copy constructor // Disable copy constructor
@ -200,8 +200,8 @@ class Brushes : public finalcut::FWidget
// Data Members // Data Members
wchar_t brush; wchar_t brush;
short fg_color; FColor fg_color;
short bg_color; FColor bg_color;
finalcut::FLabel headline; finalcut::FLabel headline;
}; };
#pragma pack(pop) #pragma pack(pop)
@ -220,8 +220,8 @@ Brushes::Brushes (finalcut::FWidget* parent)
if ( parent ) if ( parent )
{ {
short fg = parent->getForegroundColor(); FColor fg = parent->getForegroundColor();
short bg = parent->getBackgroundColor(); FColor bg = parent->getBackgroundColor();
setForegroundColor(fg); setForegroundColor(fg);
setBackgroundColor(bg); setBackgroundColor(bg);
headline.setForegroundColor(fg); headline.setForegroundColor(fg);
@ -291,13 +291,13 @@ inline wchar_t Brushes::getBrush()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void Brushes::setForeground (short color) inline void Brushes::setForeground (FColor color)
{ {
fg_color = color; fg_color = color;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void Brushes::setBackground (short color) inline void Brushes::setBackground (FColor color)
{ {
bg_color = color; bg_color = color;
} }

View File

@ -243,7 +243,7 @@ void AttribDemo::printColorLine()
{ {
AttribDlg* parent = static_cast<AttribDlg*>(getParent()); AttribDlg* parent = static_cast<AttribDlg*>(getParent());
for (short color = 0; color < colors; color++) for (FColor color = 0; color < colors; color++)
{ {
setColor (color, parent->bgcolor); setColor (color, parent->bgcolor);
print (" # "); print (" # ");

View File

@ -75,7 +75,7 @@ void Timer::onTimer (finalcut::FTimerEvent* ev)
if ( getPrintPos().getY() == int(getDesktopHeight()) ) if ( getPrintPos().getY() == int(getDesktopHeight()) )
is_last_line = true; is_last_line = true;
setColor (short(1 + timer_id), finalcut::fc::Default); setColor (FColor(1 + timer_id), finalcut::fc::Default);
print() << "Timer event, id " << timer_id << '\n'; print() << "Timer event, id " << timer_id << '\n';
if ( is_last_line ) if ( is_last_line )

View File

@ -28,6 +28,81 @@
#include <final/final.h> #include <final/final.h>
// Function prototypes
long StringToLong (const finalcut::FString&);
bool sortAscending (const finalcut::FObject*, const finalcut::FObject*);
bool sortDescending (const finalcut::FObject*, const finalcut::FObject*);
// non-member functions
//----------------------------------------------------------------------
long StringToLong (const finalcut::FString& str)
{
finalcut::FString NumString = str;
NumString = NumString.replace(",", "");
NumString = NumString.replace('.', "");
long number = NumString.toLong();
return number;
}
//----------------------------------------------------------------------
bool sortAscending ( const finalcut::FObject* lhs
, const finalcut::FObject* rhs )
{
const finalcut::FListViewItem* l_item = static_cast<const finalcut::FListViewItem*>(lhs);
const finalcut::FListViewItem* r_item = static_cast<const finalcut::FListViewItem*>(rhs);
const int column = l_item->getSortColumn();
switch ( column )
{
case 2:
{
const long l_number = StringToLong(l_item->getText(column));
const long r_number = StringToLong(r_item->getText(column));
return bool( l_number < r_number ); // lhs < rhs
}
case 3:
{
std::setlocale(LC_NUMERIC, "C");
const double l_number = l_item->getText(column).toDouble();
const double r_number = r_item->getText(column).toDouble();
return bool( l_number < r_number ); // lhs < rhs
}
}
return false;
}
//----------------------------------------------------------------------
bool sortDescending ( const finalcut::FObject* lhs
, const finalcut::FObject* rhs )
{
const finalcut::FListViewItem* l_item = static_cast<const finalcut::FListViewItem*>(lhs);
const finalcut::FListViewItem* r_item = static_cast<const finalcut::FListViewItem*>(rhs);
const int column = l_item->getSortColumn();
switch ( column )
{
case 2:
{
const long l_number = StringToLong(l_item->getText(column));
const long r_number = StringToLong(r_item->getText(column));
return bool( l_number > r_number ); // lhs > rhs
}
case 3:
{
std::setlocale(LC_NUMERIC, "C");
const double l_number = l_item->getText(column).toDouble();
const double r_number = r_item->getText(column).toDouble();
return bool( l_number > r_number ); // lhs > rhs
}
}
return false;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class Treeview // class Treeview
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -239,6 +314,13 @@ Treeview::Treeview (finalcut::FWidget* parent)
listView.setColumnAlignment (2, finalcut::fc::alignRight); listView.setColumnAlignment (2, finalcut::fc::alignRight);
listView.setColumnAlignment (3, finalcut::fc::alignRight); listView.setColumnAlignment (3, finalcut::fc::alignRight);
// Set the type of sorting
listView.setColumnSortType (1, finalcut::fc::by_name);
listView.setColumnSortType (2, finalcut::fc::user_defined);
listView.setColumnSortType (3, finalcut::fc::user_defined);
listView.setUserAscendingCompare(sortAscending);
listView.setUserDescendingCompare(sortDescending);
// Activate tree view // Activate tree view
listView.setTreeView(); listView.setTreeView();

View File

@ -255,7 +255,7 @@ void FButton::setText (const FString& txt)
void FButton::hide() void FButton::hide()
{ {
std::size_t s, f, size; std::size_t s, f, size;
short fg, bg; FColor fg, bg;
FWidget* parent_widget = getParentWidget(); FWidget* parent_widget = getParentWidget();
FWidget::hide(); FWidget::hide();

View File

@ -190,7 +190,7 @@ bool FButtonGroup::hasCheckedButton() const
void FButtonGroup::hide() void FButtonGroup::hide()
{ {
std::size_t size; std::size_t size;
short fg, bg; FColor fg, bg;
FWidget::hide(); FWidget::hide();
FWidget* parent_widget = getParentWidget(); FWidget* parent_widget = getParentWidget();

View File

@ -241,7 +241,7 @@ void FLabel::setText (const FString& txt)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLabel::hide() void FLabel::hide()
{ {
short fg, bg; FColor fg, bg;
std::size_t size; std::size_t size;
FWidget* parent_widget = getParentWidget(); FWidget* parent_widget = getParentWidget();

View File

@ -282,7 +282,7 @@ void FLineEdit::setLabelOrientation(const label_o o)
void FLineEdit::hide() void FLineEdit::hide()
{ {
std::size_t s, size; std::size_t s, size;
short fg, bg; FColor fg, bg;
FWidget* parent_widget = getParentWidget(); FWidget* parent_widget = getParentWidget();
FWidget::hide(); FWidget::hide();

View File

@ -241,7 +241,7 @@ void FListBox::setText (const FString& txt)
void FListBox::hide() void FListBox::hide()
{ {
std::size_t n, size; std::size_t n, size;
short fg, bg; FColor fg, bg;
FWidget* parent_widget = getParentWidget(); FWidget* parent_widget = getParentWidget();
FWidget::hide(); FWidget::hide();

View File

@ -1057,12 +1057,13 @@ void FListView::onMouseDown (FMouseEvent* ev)
, mouse_x = ev->getX() , mouse_x = ev->getX()
, mouse_y = ev->getY(); , mouse_y = ev->getY();
if ( mouse_x > 1 && mouse_x < int(getWidth()) && mouse_y == 1 ) if ( mouse_x > 1 && mouse_x < int(getWidth()) )
{
if ( mouse_y == 1 )
{ {
clicked_column_pos = ev->getPos(); clicked_column_pos = ev->getPos();
} }
else if ( mouse_x > 1 && mouse_x < int(getWidth()) else if ( mouse_y > 1 && mouse_y < int(getHeight()) )
&& mouse_y > 1 && mouse_y < int(getHeight()) )
{ {
int new_pos = first_visible_line.getPosition() + mouse_y - 2; int new_pos = first_visible_line.getPosition() + mouse_y - 2;
@ -1091,6 +1092,7 @@ void FListView::onMouseDown (FMouseEvent* ev)
flush_out(); flush_out();
} }
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::onMouseUp (FMouseEvent* ev) void FListView::onMouseUp (FMouseEvent* ev)
@ -1103,19 +1105,20 @@ void FListView::onMouseUp (FMouseEvent* ev)
int mouse_x = ev->getX(); int mouse_x = ev->getX();
int mouse_y = ev->getY(); int mouse_y = ev->getY();
if ( mouse_x > 1 && mouse_x < int(getWidth()) if ( mouse_x > 1 && mouse_x < int(getWidth()) )
&& mouse_y == 1 && clicked_column_pos == ev->getPos() ) {
if ( mouse_y == 1 && clicked_column_pos == ev->getPos() )
{ {
mouseColumnClicked(); mouseColumnClicked();
} }
else if ( mouse_x > 1 && mouse_x < int(getWidth()) else if ( mouse_y > 1 && mouse_y < int(getHeight()) )
&& mouse_y > 1 && mouse_y < int(getHeight()) )
{ {
if ( tree_view ) if ( tree_view )
{ {
FListViewItem* item = getCurrentItem(); FListViewItem* item = getCurrentItem();
if ( item->isExpandable() && clicked_expander_pos == ev->getPos() ) if ( item->isExpandable()
&& clicked_expander_pos == ev->getPos() )
{ {
if ( item->isExpand() ) if ( item->isExpand() )
item->collapse(); item->collapse();
@ -1132,6 +1135,7 @@ void FListView::onMouseUp (FMouseEvent* ev)
processChanged(); processChanged();
} }
} }
}
clicked_expander_pos.setPoint(-1, -1); clicked_expander_pos.setPoint(-1, -1);
clicked_column_pos.setPoint(-1, -1); clicked_column_pos.setPoint(-1, -1);
@ -1789,9 +1793,9 @@ inline void FListView::drawSortIndicator ( std::size_t& length
length++; length++;
if ( sort_order == fc::ascending ) if ( sort_order == fc::ascending )
headerline << wchar_t(fc::BlackDownPointingTriangle); // ▼
else if ( sort_order == fc::descending )
headerline << wchar_t(fc::BlackUpPointingTriangle); // ▲ headerline << wchar_t(fc::BlackUpPointingTriangle); // ▲
else if ( sort_order == fc::descending )
headerline << wchar_t(fc::BlackDownPointingTriangle); // ▼
if ( length < column_width ) if ( length < column_width )
{ {
@ -1819,7 +1823,7 @@ void FListView::drawColumnText (headerItems::const_iterator& iter)
std::size_t txt_length = txt.getLength(); std::size_t txt_length = txt.getLength();
std::size_t column_width = leading_space + width; std::size_t column_width = leading_space + width;
headerItems::const_iterator first = header.begin(); headerItems::const_iterator first = header.begin();
int column = std::distance(first, iter) + 1; int column = int(std::distance(first, iter)) + 1;
bool has_sort_indicator = bool ( sort_column == column bool has_sort_indicator = bool ( sort_column == column
&& ! hide_sort_indicator ); && ! hide_sort_indicator );

View File

@ -63,7 +63,7 @@ void FMenuBar::resetMenu()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuBar::hide() void FMenuBar::hide()
{ {
short fg, bg; FColor fg, bg;
FWindow::hide(); FWindow::hide();
fg = wc.term_fg; fg = wc.term_fg;
bg = wc.term_bg; bg = wc.term_bg;

View File

@ -578,7 +578,7 @@ FColor FOptiAttr::vga2ansi (FColor color)
color = 0; color = 0;
else if ( color < 16 ) else if ( color < 16 )
{ {
static const short lookup_table[] = static const FColor lookup_table[] =
{ {
0, 4, 2, 6, 1, 5, 3, 7, 0, 4, 2, 6, 1, 5, 3, 7,
8, 12, 10, 14, 9, 13, 11, 15 8, 12, 10, 14, 9, 13, 11, 15

View File

@ -99,7 +99,7 @@ bool FProgressbar::setShadow (bool on)
void FProgressbar::hide() void FProgressbar::hide()
{ {
std::size_t s, size; std::size_t s, size;
short fg, bg; FColor fg, bg;
FWidget* parent_widget = getParentWidget(); FWidget* parent_widget = getParentWidget();
FWidget::hide(); FWidget::hide();

View File

@ -196,7 +196,7 @@ bool FStatusBar::hasActivatedKey()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStatusBar::hide() void FStatusBar::hide()
{ {
short fg, bg; FColor fg, bg;
FWindow::hide(); FWindow::hide();
fg = wc.term_fg; fg = wc.term_fg;
bg = wc.term_bg; bg = wc.term_bg;

View File

@ -196,7 +196,7 @@ void FTextView::scrollTo (int x, int y)
void FTextView::hide() void FTextView::hide()
{ {
std::size_t n, size; std::size_t n, size;
short fg, bg; FColor fg, bg;
FWidget* parent_widget = getParentWidget(); FWidget* parent_widget = getParentWidget();
FWidget::hide(); FWidget::hide();

View File

@ -213,7 +213,7 @@ void FToggleButton::setText (const FString& txt)
void FToggleButton::hide() void FToggleButton::hide()
{ {
std::size_t size; std::size_t size;
short fg, bg; FColor fg, bg;
FWidget* parent_widget = getParentWidget(); FWidget* parent_widget = getParentWidget();
FWidget::hide(); FWidget::hide();

View File

@ -164,16 +164,13 @@ void FVTerm::setPrintCursor (int x, int y)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FColor FVTerm::rgb2ColorIndex (short r, short g, short b) FColor FVTerm::rgb2ColorIndex (uInt8 r, uInt8 g, uInt8 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
if ( r < 0 || g < 0 || b < 0 || r > 0xff || g > 0xff || b > 0xff ) FColor ri = (((r * 5) + 127) / 255) * 36;
return 0; FColor gi = (((g * 5) + 127) / 255) * 6;
FColor bi = (((b * 5) + 127) / 255);
short ri = (((r * 5) + 127) / 255) * 36;
short gi = (((g * 5) + 127) / 255) * 6;
short bi = (((b * 5) + 127) / 255);
return 16 + ri + gi + bi; return 16 + ri + gi + bi;
} }

View File

@ -168,13 +168,13 @@ class FButton : public FWidget
std::size_t center_offset; std::size_t center_offset;
std::size_t vcenter_offset; std::size_t vcenter_offset;
std::size_t txtlength; std::size_t txtlength;
short button_fg; FColor button_fg;
short button_bg; FColor button_bg;
short button_hotkey_fg; FColor button_hotkey_fg;
short button_focus_fg; FColor button_focus_fg;
short button_focus_bg; FColor button_focus_bg;
short button_inactive_fg; FColor button_inactive_fg;
short button_inactive_bg; FColor button_inactive_bg;
}; };
#pragma pack(pop) #pragma pack(pop)

View File

@ -157,8 +157,8 @@ class FLabel : public FWidget
bool multiline; bool multiline;
FString text; FString text;
fc::text_alignment alignment; fc::text_alignment alignment;
short emphasis_color; FColor emphasis_color;
short ellipsis_color; FColor ellipsis_color;
bool emphasis; bool emphasis;
bool reverse_mode; bool reverse_mode;
FWidget* accel_widget; FWidget* accel_widget;

View File

@ -165,7 +165,7 @@ class FMessageBox : public FDialog
FStringList text_split; FStringList text_split;
std::size_t max_line_width; std::size_t max_line_width;
bool center_text; bool center_text;
short emphasis_color; FColor emphasis_color;
uInt num_buttons; uInt num_buttons;
uInt text_num_lines; uInt text_num_lines;
int button_digit[3]; int button_digit[3];

View File

@ -129,8 +129,8 @@ class FVTerm
// Accessors // Accessors
virtual const char* getClassName() const; virtual const char* getClassName() const;
static short getTermForegroundColor(); static FColor getTermForegroundColor();
static short getTermBackgroundColor(); static FColor getTermBackgroundColor();
term_area* getVWin() const; term_area* getVWin() const;
FPoint getPrintCursor(); FPoint getPrintCursor();
static charData getAttribute(); static charData getAttribute();
@ -153,7 +153,7 @@ class FVTerm
void showCursor(); void showCursor();
void setPrintCursor (const FPoint&); void setPrintCursor (const FPoint&);
void setPrintCursor (int, int); void setPrintCursor (int, int);
FColor rgb2ColorIndex (short, short, short); FColor rgb2ColorIndex (uInt8, uInt8, uInt8);
void setColor (FColor, FColor); void setColor (FColor, FColor);
static void setNormal(); static void setNormal();
@ -605,11 +605,11 @@ inline const char* FVTerm::getClassName() const
{ return "FVTerm"; } { return "FVTerm"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline short FVTerm::getTermForegroundColor() inline FColor FVTerm::getTermForegroundColor()
{ return next_attribute.fg_color; } { return next_attribute.fg_color; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline short FVTerm::getTermBackgroundColor() inline FColor FVTerm::getTermBackgroundColor()
{ return next_attribute.bg_color; } { return next_attribute.bg_color; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -185,8 +185,8 @@ class FWidget : public FVTerm, public FObject
static FMenuBar* getMenuBar(); static FMenuBar* getMenuBar();
static FStatusBar* getStatusBar(); static FStatusBar* getStatusBar();
FString getStatusbarMessage() const; FString getStatusbarMessage() const;
short getForegroundColor() const; // get the primary FColor getForegroundColor() const; // get the primary
short getBackgroundColor() const; // widget colors FColor getBackgroundColor() const; // widget colors
int getX() const; // positioning int getX() const; // positioning
int getY() const; int getY() const;
const FPoint getPos() const; const FPoint getPos() const;
@ -571,11 +571,11 @@ inline FString FWidget::getStatusbarMessage() const
{ return statusbar_message; } { return statusbar_message; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline short FWidget::getForegroundColor() const inline FColor FWidget::getForegroundColor() const
{ return foreground_color; } { return foreground_color; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline short FWidget::getBackgroundColor() const inline FColor FWidget::getBackgroundColor() const
{ return background_color; } { return background_color; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------