Skip to content

Commit 6617d49

Browse files
committed
Small code improvements
1 parent 4a8a150 commit 6617d49

8 files changed

Lines changed: 25 additions & 33 deletions

File tree

final/fapplication.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,7 @@ inline void FApplication::findKeyboardWidget() const
667667

668668
if ( focus )
669669
{
670-
if ( move_size )
671-
widget = move_size;
672-
else
673-
widget = focus;
670+
widget = move_size ? move_size : focus;
674671
}
675672
else
676673
{
@@ -1365,12 +1362,9 @@ auto FApplication::isEventProcessable ( FObject* receiver
13651362

13661363
if ( getModalDialogCounter() > 0 )
13671364
{
1368-
const FWidget* window;
1369-
1370-
if ( widget->isWindowWidget() )
1371-
window = widget;
1372-
else
1373-
window = FWindow::getWindowWidget(widget);
1365+
const FWidget* window = widget->isWindowWidget()
1366+
? widget
1367+
: FWindow::getWindowWidget(widget);
13741368

13751369
// block events for widgets in non modal windows
13761370
if ( window

final/fwidget_functions.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,17 +802,24 @@ void drawGenericBox ( FWidget* w, const FRect& r
802802
if ( ! w || ! w->getPrintArea() || r.getWidth() < 3 )
803803
return;
804804

805+
// Get references to frequently accessed variables
805806
auto& area = *w->getPrintArea();
807+
auto& area_changes = area.changes;
806808
auto fchar = FVTermAttribute::getAttribute();
809+
810+
// Prepare the first character to draw the box
807811
fchar.attr.bit.char_width = 1;
808812
fchar.ch[0] = box_char[0];
809813
fchar.ch[1] = L'\0';
810814
const auto is_transparent = (fchar.attr.byte[1] & internal::var::b1_print_trans_mask) != 0;
815+
816+
// Adjust box position to match print area
811817
auto box = r;
812818
box.move (-1, -1);
813819
const auto x_offset = uInt(w->woffset.getX1() + w->getX() - area.offset_left - 1);
814820
const auto y_offset = uInt(w->woffset.getY1() + w->getY() - area.offset_top - 1);
815-
auto& area_changes = area.changes;
821+
822+
// Draw the top line of the box
816823
auto* area_pos = &area.getFChar(int(x_offset) + box.getX1(), int(y_offset) + box.getY1());
817824
*area_pos = fchar;
818825
++area_pos;
@@ -822,11 +829,14 @@ void drawGenericBox ( FWidget* w, const FRect& r
822829
area_pos += line_length;
823830
fchar.ch[0] = box_char[2];
824831
*area_pos = fchar;
832+
833+
// Update area_changes for the top line
825834
auto y = y_offset + uInt(box.getY1());
826835
area_changes[y].xmin = std::min(area_changes[y].xmin, x_offset + uInt(box.getX1()));
827836
area_changes[y].xmax = std::max(area_changes[y].xmax, x_offset + uInt(box.getX2()));
828837
area_changes[y].trans_count += uInt(is_transparent) * box.getWidth();
829838

839+
// Draw the sides of the box
830840
for (y = y_offset + uInt(box.getY1()) + 1; y < y_offset + uInt(box.getY2()); y++)
831841
{
832842
area_pos = &area.getFChar(int(x_offset) + box.getX1(), int(y));
@@ -835,11 +845,13 @@ void drawGenericBox ( FWidget* w, const FRect& r
835845
area_pos += box.getWidth() - 1;
836846
fchar.ch[0] = box_char[4];
837847
*area_pos = fchar;
848+
// Update area_changes for the sides
838849
area_changes[y].xmin = std::min(area_changes[y].xmin, x_offset + uInt(box.getX1()));
839850
area_changes[y].xmax = std::max(area_changes[y].xmax, x_offset + uInt(box.getX2()));
840851
area_changes[y].trans_count += uInt(is_transparent) * box.getWidth();
841852
}
842853

854+
// Draw the bottom line of the box
843855
area_pos = &area.getFChar(int(x_offset) + box.getX1(), int(y));
844856
fchar.ch[0] = box_char[5];
845857
*area_pos = fchar;
@@ -849,6 +861,8 @@ void drawGenericBox ( FWidget* w, const FRect& r
849861
area_pos += line_length;
850862
fchar.ch[0] = box_char[7];
851863
*area_pos = fchar;
864+
865+
// Update area_changes for the bottom line
852866
y = y_offset + uInt(box.getY2());
853867
area_changes[y].xmin = std::min(area_changes[y].xmin, x_offset + uInt(box.getX1()));
854868
area_changes[y].xmax = std::max(area_changes[y].xmax, x_offset + uInt(box.getX2()));

final/output/tty/foptiattr.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,7 @@ auto FOptiAttr::isNormal (const FChar& ch) -> bool
485485
//----------------------------------------------------------------------
486486
void FOptiAttr::initialize()
487487
{
488-
if ( max_color < 8 )
489-
monochron = true;
490-
else
491-
monochron = false;
488+
monochron = max_color < 8;
492489

493490
if ( caused_reset_attributes(F_exit_bold_mode.cap) )
494491
F_exit_bold_mode.caused_reset = true;

final/output/tty/fterm.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,7 @@ auto FTerm::setUTF8 (bool enable) -> bool // UTF-8 (Unicode)
314314
if ( data.isUTF8() == enable )
315315
return enable;
316316

317-
if ( enable )
318-
data.setUTF8(true);
319-
else
320-
data.setUTF8(false);
317+
data.setUTF8(enable);
321318

322319
#if defined(__linux__)
323320
FTermLinux::getInstance().setUTF8 (enable);

final/output/tty/ftermcap.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,7 @@ void FTermcap::termcapNumerics()
430430
if ( max_color < 0 )
431431
max_color = 1;
432432

433-
if ( max_color < 8 )
434-
fterm_data.setMonochron(true);
435-
else
436-
fterm_data.setMonochron(false);
433+
fterm_data.setMonochron(max_color < 8);
437434

438435
// Get initial spacing for hardware tab stop
439436
tabstop = getNumber("it");

final/output/tty/ftermoutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ void FTermOutput::cursorWrap() const
11411141
}
11421142

11431143
//----------------------------------------------------------------------
1144-
auto FTermOutput::updateTerminalLine (uInt y) -> bool
1144+
inline auto FTermOutput::updateTerminalLine (uInt y) -> bool
11451145
{
11461146
// Updates pending changes from line y to the terminal
11471147

final/output/tty/sgr_optimizer.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,7 @@ inline void SGRoptimizer::handleSGRterminating ( const std::vector<parameter>::c
160160
write_pos++;
161161
}
162162

163-
if ( count != size )
164-
seq[write_pos] = ';';
165-
else
166-
seq[write_pos] = 'm';
167-
163+
seq[write_pos] = count != size ? ';' : 'm';
168164
write_pos++;
169165
}
170166

final/widget/fbutton.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,7 @@ void FButton::draw()
641641
if ( hotkeypos != NOT_SET )
642642
column_width--;
643643

644-
if ( getHeight() >= 2 )
645-
vcenter_offset = (getHeight() - 1) / 2;
646-
else
647-
vcenter_offset = 0;
644+
vcenter_offset = getHeight() >= 2 ? (getHeight() - 1) / 2 : 0;
648645

649646
// Print left margin
650647
drawMarginLeft();

0 commit comments

Comments
 (0)