@@ -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 ()));
0 commit comments