Skip to content

Commit

Permalink
Reduce the complexity of some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed Nov 21, 2023
1 parent 849f686 commit 4e8a87c
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/solaris.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: Repository checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Test on Solaris 11.4
uses: vmactions/solaris-vm@v0
Expand Down
123 changes: 78 additions & 45 deletions final/fwidget_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ uInt8 var::b1_print_trans_mask{};

} // namespace internal

//----------------------------------------------------------------------
struct TransparentShadowData
{
// Using-declaration
using FTermArea = FVTerm::FTermArea;

// Data members
FTermArea& area;
uInt width{};
uInt height{};
uInt shadow_width{};
uInt shadow_height{};
FChar transparent_char{};
FChar color_overlay_char{};
FChar* area_pos{};
};


// Function forward declarations
//----------------------------------------------------------------------
void drawRightShadow (TransparentShadowData&);
void drawBottomShadow (TransparentShadowData&);


// FWidget non-member functions
//----------------------------------------------------------------------
void initByte1PrintTransMask()
Expand Down Expand Up @@ -353,67 +377,76 @@ void drawTransparentShadow (FWidget* w)
return;

auto& area = *w->getPrintArea();
const auto width = uInt(area.size.width);
const auto height = uInt(area.size.height);
const auto shadow_width = uInt(area.shadow.width);
const auto shadow_height = uInt(area.shadow.height);
const auto& wc = FWidget::getColorTheme();

const FChar transparent_char
TransparentShadowData data
{
{ { L'\0', L'\0', L'\0', L'\0', L'\0' } },
{ { L'\0', L'\0', L'\0', L'\0', L'\0' } },
FColor::Default,
FColor::Default,
{ { 0x00, 0x20, 0x00, 0x00} } // byte 0..3 (byte 1 = 0x32 = transparent)
area,
uInt(area.size.width),
uInt(area.size.height),
uInt(area.shadow.width),
uInt(area.shadow.height),
{
{ { L'\0', L'\0', L'\0', L'\0', L'\0' } },
{ { L'\0', L'\0', L'\0', L'\0', L'\0' } },
FColor::Default,
FColor::Default,
{ { 0x00, 0x20, 0x00, 0x00} } // byte 0..3 (byte 1 = 0x32 = transparent)
},
{
{ { L'\0', L'\0', L'\0', L'\0', L'\0' } },
{ { L'\0', L'\0', L'\0', L'\0', L'\0' } },
wc->shadow.fg,
wc->shadow.bg,
{ { 0x00, 0x40, 0x00, 0x00} } // byte 0..3 (byte 1 = 0x64 = color_overlay)
},
&area.getFChar(area.size.width, 0)
};

const FChar color_overlay_char
{
{ { L'\0', L'\0', L'\0', L'\0', L'\0' } },
{ { L'\0', L'\0', L'\0', L'\0', L'\0' } },
wc->shadow.fg,
wc->shadow.bg,
{ { 0x00, 0x40, 0x00, 0x00} } // byte 0..3 (byte 1 = 0x64 = color_overlay)
};
drawRightShadow(data);
drawBottomShadow(data);
area.has_changes = true;

auto* area_pos = &area.getFChar(int(width), 0);
auto& area_changes = area.changes;
if ( FVTerm::getFOutput()->isMonochron() )
w->setReverse(false);
}

if ( shadow_width > 0 ) // Draw right shadow
//----------------------------------------------------------------------
inline void drawRightShadow (TransparentShadowData& d)
{
if ( d.shadow_width > 0 ) // Draw right shadow
{
std::fill (area_pos, area_pos + shadow_width, transparent_char);
area_changes[0].xmin = std::min(area_changes[0].xmin, width);
area_changes[0].xmax = width + shadow_width - 1;
area_changes[0].trans_count += shadow_width;
std::fill (d.area_pos, d.area_pos + d.shadow_width, d.transparent_char);
d.area.changes[0].xmin = std::min(d.area.changes[0].xmin, d.width);
d.area.changes[0].xmax = d.width + d.shadow_width - 1;
d.area.changes[0].trans_count += d.shadow_width;

for (std::size_t y{1}; y < height; y++)
for (std::size_t y{1}; y < d.height; y++)
{
area_pos += shadow_width + width;
area_changes[y].xmin = std::min(area_changes[y].xmin, width);
area_changes[y].xmax = width + shadow_width - 1;
area_changes[y].trans_count += shadow_width;
std::fill (area_pos, area_pos + shadow_width, color_overlay_char);
d.area_pos += d.shadow_width + d.width;
d.area.changes[y].xmin = std::min(d.area.changes[y].xmin, d.width);
d.area.changes[y].xmax = d.width + d.shadow_width - 1;
d.area.changes[y].trans_count += d.shadow_width;
std::fill (d.area_pos, d.area_pos + d.shadow_width, d.color_overlay_char);
}

area_pos += shadow_width;
d.area_pos += d.shadow_width;
}
}

for (std::size_t y{height}; y < height + shadow_height; y++) // Draw bottom shadow
//----------------------------------------------------------------------
inline void drawBottomShadow (TransparentShadowData& d)
{
for (std::size_t y{d.height}; y < d.height + d.shadow_height; y++) // Draw bottom shadow
{
area_changes[y].xmin = 0;
area_changes[y].xmax = width + shadow_width - 1;
area_changes[y].trans_count += width + shadow_width;
std::fill (area_pos, area_pos + shadow_width, transparent_char);
area_pos += shadow_width;
std::fill (area_pos, area_pos + width, color_overlay_char);
area_pos += width;
d.area.changes[y].xmin = 0;
d.area.changes[y].xmax = d.width + d.shadow_width - 1;
d.area.changes[y].trans_count += d.width + d.shadow_width;
std::fill (d.area_pos, d.area_pos + d.shadow_width, d.transparent_char);
d.area_pos += d.shadow_width;
std::fill (d.area_pos, d.area_pos + d.width, d.color_overlay_char);
d.area_pos += d.width;
}

area.has_changes = true;

if ( FVTerm::getFOutput()->isMonochron() )
w->setReverse(false);
}

//----------------------------------------------------------------------
Expand Down
12 changes: 9 additions & 3 deletions final/util/flogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2020-2022 Markus Gans *
* Copyright 2020-2023 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -106,8 +106,14 @@ void FLogger::printLogLine (const std::string& msg)

const auto& prefix = [this, &log_level] ()
{
if ( timestamp )
return getTimeString() + " [" + log_level + "] ";
{
std::lock_guard<std::mutex> lock_guard(print_mutex);

if ( timestamp )
return getTimeString() + " [" + log_level + "] ";

// Release mutex at end of scope
}

return "[" + log_level + "] ";
}();
Expand Down
30 changes: 21 additions & 9 deletions final/util/flogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2020-2022 Markus Gans *
* Copyright 2020-2023 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -104,32 +104,44 @@ inline auto FLogger::getClassName() const -> FString
//----------------------------------------------------------------------
inline void FLogger::info (const std::string& msg)
{
std::lock_guard<std::mutex> lock_guard(print_mutex);
setLevel() = LogLevel::Info;
{
std::lock_guard<std::mutex> lock_guard(print_mutex);
setLevel() = LogLevel::Info;
// Release mutex at end of scope
}
printLogLine (msg);
}

//----------------------------------------------------------------------
inline void FLogger::warn (const std::string& msg)
{
std::lock_guard<std::mutex> lock_guard(print_mutex);
setLevel() = LogLevel::Warn;
{
std::lock_guard<std::mutex> lock_guard(print_mutex);
setLevel() = LogLevel::Warn;
// Release mutex at end of scope
}
printLogLine (msg);
}

//----------------------------------------------------------------------
inline void FLogger::error (const std::string& msg)
{
std::lock_guard<std::mutex> lock_guard(print_mutex);
setLevel() = LogLevel::Error;
{
std::lock_guard<std::mutex> lock_guard(print_mutex);
setLevel() = LogLevel::Error;
// Release mutex at end of scope
}
printLogLine (msg);
}

//----------------------------------------------------------------------
inline void FLogger::debug (const std::string& msg)
{
std::lock_guard<std::mutex> lock_guard(print_mutex);
setLevel() = LogLevel::Debug;
{
std::lock_guard<std::mutex> lock_guard(print_mutex);
setLevel() = LogLevel::Debug;
// Release mutex at end of scope
}
printLogLine (msg);
}

Expand Down
9 changes: 5 additions & 4 deletions final/widget/flistbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ inline auto FListBox::skipIncrementalSearch() -> bool
}

//----------------------------------------------------------------------
auto FListBox::isNonSelectMouseButtonPressed (FMouseEvent* ev) const -> bool
auto FListBox::isNonSelectMouseButtonPressed (const FMouseEvent* ev) const -> bool
{
if ( ev->getButton() != MouseButton::Left
&& ev->getButton() != MouseButton::Right )
Expand All @@ -1432,8 +1432,9 @@ auto FListBox::isNonSelectMouseButtonPressed (FMouseEvent* ev) const -> bool
}

//----------------------------------------------------------------------
void FListBox::handleMouseWithinListBounds ( FMouseEvent* ev,
MultiSelectionFunction multi_selection )
template <typename MultiSelectionFunction>
void FListBox::handleMouseWithinListBounds ( const FMouseEvent* ev,
const MultiSelectionFunction& multi_selection )
{
const std::size_t current_before = selection.current;
const int yoffset_before = scroll.yoffset;
Expand Down Expand Up @@ -1469,7 +1470,7 @@ void FListBox::handleMouseWithinListBounds ( FMouseEvent* ev,
}

//----------------------------------------------------------------------
void FListBox::handleMouseDragging (FMouseEvent* ev)
void FListBox::handleMouseDragging (const FMouseEvent* ev)
{
const int mouse_y = ev->getY();

Expand Down
12 changes: 6 additions & 6 deletions final/widget/flistbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ class FListBox : public FWidget
using KeyMap = std::unordered_map<FKey, std::function<void()>, EnumHash<FKey>>;
using KeyMapResult = std::unordered_map<FKey, std::function<bool()>, EnumHash<FKey>>;
using LazyInsert = std::function<void(FListBoxItem&, FDataAccess*, std::size_t)>;
using MultiSelectionFunction = std::function<void(std::size_t)>;

struct ListBoxData
{
Expand Down Expand Up @@ -335,7 +334,7 @@ class FListBox : public FWidget
// Inquiry
auto isHorizontallyScrollable() const -> bool;
auto isVerticallyScrollable() const -> bool;
auto isCurrentLine (int) -> bool;
auto isCurrentLine (int) const -> bool;

// Methods
void init();
Expand Down Expand Up @@ -388,9 +387,10 @@ class FListBox : public FWidget
void lastPos();
auto isWithinListBounds (const FPoint&) const -> bool;
auto skipIncrementalSearch() -> bool;
auto isNonSelectMouseButtonPressed (FMouseEvent*) const -> bool;
void handleMouseWithinListBounds (FMouseEvent*, MultiSelectionFunction);
void handleMouseDragging (FMouseEvent*);
auto isNonSelectMouseButtonPressed (const FMouseEvent*) const -> bool;
template <typename MultiSelectionFunction>
void handleMouseWithinListBounds (const FMouseEvent*, const MultiSelectionFunction&);
void handleMouseDragging (const FMouseEvent*);
void acceptSelection();
auto spacebarProcessing() -> bool;
auto changeSelectionAndPosition() -> bool;
Expand Down Expand Up @@ -651,7 +651,7 @@ inline auto FListBox::isVerticallyScrollable() const -> bool
{ return getCount() > getClientHeight(); }

//----------------------------------------------------------------------
inline auto FListBox::isCurrentLine (int y) -> bool
inline auto FListBox::isCurrentLine (int y) const -> bool
{ return y + scroll.yoffset + 1 == int(selection.current); }

//----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 4e8a87c

Please sign in to comment.