Change selection grid to maintain relative horizontal position when switching rows (#329)
* Change selection grid to maintain relative horizontal position when switching rows * clang-format * Fixed joker selling index error * Protect against division by 0 and removed redundant fixed point conversions.
This commit is contained in:
@@ -57,12 +57,15 @@ void selection_grid_move_selection_vert(SelectionGrid* selection_grid, int direc
|
||||
if (new_row_size <= 0)
|
||||
return;
|
||||
|
||||
if (selection.x >= new_row_size)
|
||||
{
|
||||
// TODO: Maintain relative horizontal position
|
||||
// Clip selection to row size
|
||||
new_selection.x = new_row_size - 1;
|
||||
}
|
||||
int old_row_size = selection_grid->rows[selection.y].get_size();
|
||||
|
||||
// Branchless set to 1 if 0 to avoid division by 0
|
||||
old_row_size += (old_row_size == 0);
|
||||
|
||||
// Maintain relative horizontal position
|
||||
// The operations are equivalent to fixed point if all the numbers were converted
|
||||
new_selection.x = fx2int(selection.x * ((int2fx(new_row_size) / old_row_size)));
|
||||
|
||||
if (selection.y >= 0 && selection.y < selection_grid->num_rows)
|
||||
{
|
||||
selection_grid->rows[selection.y]
|
||||
|
||||
Reference in New Issue
Block a user