Skip to content

Commit

Permalink
Label Finder icons with decimal
Browse files Browse the repository at this point in the history
Finder icons are shown in a column, with the index number on the
left.  The icon metadata appears in the Notes tab, with the same
index value.  Showing this as a decimal value feels beter than
showing it as hex.

Fonts and shape-table grid labels remain in hex.  There's a good
argument to be made that shape tables should also be shown in decimal,
but hex labels work better for a 2D grid.
  • Loading branch information
fadden committed Jun 19, 2024
1 parent 61f8ecd commit a4a5a03
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion FileConv/Gfx/BitmapFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ private static IConvOutput RenderFontGrid(GSFontHeader gsHeader, MacFontHeader m
bob.SetGeometry(cellWidth, macHeader.FRectHeight, 16);
bob.SetRange(macHeader.FirstChar, macHeader.LastChar - macHeader.FirstChar + 2);
bob.SetColors(FONT_PALETTE, COLOR_LABEL, COLOR_CELL_BG, COLOR_FRAME, COLOR_FRAME);
bob.SetLabels(hasLeftLabels: true, hasTopLabels: true, leftLabelIsRow: false);
bob.SetLabels(hasLeftLabels: true, hasTopLabels: true, leftLabelIsRow: false, 16);
ImageGrid grid;
try {
grid = bob.Create(); // this will throw if bitmap would be too big
Expand Down
2 changes: 1 addition & 1 deletion FileConv/Gfx/GSFinderIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static IConvOutput RenderIconGrid(IconFile iconFile, Notes loadNotes) {
bob.SetGeometry(maxIconWidth, maxIconHeight, NUM_COLS);
bob.SetRange(0, iconFile.IconRecords.Count * NUM_COLS);
bob.SetColors(ICON_PALETTE, COLOR_FRAME, COLOR_BKGND, COLOR_FRAME, COLOR_FRAME);
bob.SetLabels(hasLeftLabels: true, hasTopLabels: false, leftLabelIsRow: true);
bob.SetLabels(hasLeftLabels: true, hasTopLabels: false, leftLabelIsRow: true, 10);
ImageGrid grid;
try {
grid = bob.Create(); // this will throw if bitmap would be too big
Expand Down
40 changes: 23 additions & 17 deletions FileConv/Gfx/ImageGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal class ImageGrid {
private bool mHasLeftLabels; // if true, draw labels on left
private bool mHasTopLabels; // if true, draw labels across top
private bool mLeftLabelIsRow; // if true, left labels are *row* num (vs. item)
private int mLabelRadix; // label radix, 10 or 16

/// <summary>
/// Bitmap that we render into.
Expand Down Expand Up @@ -77,7 +78,7 @@ public ImageGrid Create() {
return new ImageGrid(FirstIndex, NumItems,
CellWidth, CellHeight, MaxPerRow,
Palette, LabelFgColor, LabelBgColor, BorderColor, PadCellColor,
HasLeftLabels, HasTopLabels, LeftLabelIsRow);
HasLeftLabels, HasTopLabels, LeftLabelIsRow, LabelRadix);
}

public int FirstIndex { get; private set; } = -1;
Expand All @@ -93,6 +94,7 @@ public ImageGrid Create() {
public bool HasLeftLabels { get; private set; }
public bool HasTopLabels { get; private set; }
public bool LeftLabelIsRow { get; private set; }
public int LabelRadix { get; private set; }

/// <summary>
/// Sets the geometry entries. Mandatory
Expand Down Expand Up @@ -150,10 +152,14 @@ public void SetColors(Palette8 palette, byte labelFgColor, byte labelBgColor,
/// <param name="hasTopLabels">If true, show labels across top.</param>
/// <param name="leftLabelIsRow">If true, the left label is the row number
/// rather than the item number.</param>
public void SetLabels(bool hasLeftLabels, bool hasTopLabels, bool leftLabelIsRow) {
/// <param name="labelRadix">Label radix, must be 10 or 16.</param>
public void SetLabels(bool hasLeftLabels, bool hasTopLabels, bool leftLabelIsRow,
int labelRadix) {
Debug.Assert(labelRadix == 10 || labelRadix == 16);
HasLeftLabels = hasLeftLabels;
HasTopLabels = hasTopLabels;
LeftLabelIsRow = leftLabelIsRow;
LabelRadix = labelRadix;
}
}

Expand All @@ -163,7 +169,7 @@ public void SetLabels(bool hasLeftLabels, bool hasTopLabels, bool leftLabelIsRow
private ImageGrid(int firstIndex, int numItems, int cellWidth, int cellHeight,
int maxPerRow, Palette8 palette, byte labelFgColor, byte labelBgColor,
byte borderColor, byte padCellColor, bool hasLeftLabels, bool hasTopLabels,
bool leftLabelIsRow) {
bool leftLabelIsRow, int labelRadix) {
// If the items are smaller than the frame labels, increase the size.
if (cellWidth < LABEL_CHAR_WIDTH) {
cellWidth = LABEL_CHAR_WIDTH;
Expand All @@ -184,6 +190,7 @@ private ImageGrid(int firstIndex, int numItems, int cellWidth, int cellHeight,
mHasLeftLabels = hasLeftLabels;
mHasTopLabels = hasTopLabels;
mLeftLabelIsRow = leftLabelIsRow;
mLabelRadix = labelRadix;

mStartIndex = firstIndex - (firstIndex % mMaxPerRow);
int lastIndex = firstIndex + numItems - 1;
Expand All @@ -193,10 +200,11 @@ private ImageGrid(int firstIndex, int numItems, int cellWidth, int cellHeight,
// Width must include the left-side label, plus one space for padding, and a full
// row of cells separated with grid lines.
int numDigits;
string labelFmt = (mLabelRadix == 16) ? "x" : ""; // log10 or log16 of max num
if (leftLabelIsRow) {
numDigits = mNumRows.ToString("x").Length;
numDigits = mNumRows.ToString(labelFmt).Length;
} else {
numDigits = lastIndex.ToString("x").Length; // a/k/a log16(lastIndex)
numDigits = lastIndex.ToString(labelFmt).Length;
}

mGridLeft = 0;
Expand Down Expand Up @@ -235,6 +243,7 @@ private ImageGrid(int firstIndex, int numItems, int cellWidth, int cellHeight,
private void DrawLabels(int numDigits, int endIndex) {
Debug.Assert(mStartIndex % mMaxPerRow == 0);
Debug.Assert(endIndex % mMaxPerRow == 0);
string labelFmt = (mLabelRadix == 16) ? "X" : "";

if (mHasLeftLabels) {
// Draw the labels down the left edge.
Expand All @@ -249,22 +258,19 @@ private void DrawLabels(int numDigits, int endIndex) {
startRow += (mCellHeight - LABEL_CHAR_HEIGHT) / 2; // center
int numRows = (endIndex - mStartIndex) / mMaxPerRow;
for (int row = 0; row < numRows; row++) {
int ypos = startRow + (mCellHeight + GRID_THICKNESS) * row;
int xpos = EDGE_PAD + (numDigits - 1) * LABEL_CHAR_WIDTH;
int rowLabel;
// Generate the label string.
string rowLabelStr;
if (mLeftLabelIsRow) {
rowLabel = row;
rowLabelStr = row.ToString(labelFmt);
} else {
rowLabel = mStartIndex + row * mMaxPerRow;
rowLabelStr = (mStartIndex + row * mMaxPerRow).ToString(labelFmt);
}

// Draw label digits, right to left.
for (int dg = 0; dg < numDigits; dg++) {
char digit = sHexDigit[rowLabel & 0x0f];
Bitmap.DrawChar(digit, xpos, ypos, mLabelFg, mLabelBg);

xpos -= LABEL_CHAR_WIDTH;
rowLabel >>= 4;
int ypos = startRow + (mCellHeight + GRID_THICKNESS) * row;
int xpos = EDGE_PAD;
foreach (char ch in rowLabelStr) {
Bitmap.DrawChar(ch, xpos, ypos, mLabelFg, mLabelBg);
xpos += LABEL_CHAR_WIDTH;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion FileConv/Gfx/ShapeTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private static IConvOutput RenderShapes(byte[] buf) {
bob.SetGeometry(maxWidth, maxHeight, gridCols);
bob.SetRange(1, shapeCount);
bob.SetColors(SHAPE_PALETTE, COLOR_LABEL, COLOR_BG, COLOR_FRAME, COLOR_FRAME);
bob.SetLabels(hasLeftLabels: true, hasTopLabels: true, leftLabelIsRow: false);
bob.SetLabels(hasLeftLabels: true, hasTopLabels: true, leftLabelIsRow: false, 16);
ImageGrid grid;
try {
grid = bob.Create(); // this will throw if bitmap would be too big
Expand Down
2 changes: 1 addition & 1 deletion cp2_wpf/Actions/OverwriteQueryDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
xmlns:local="clr-namespace:cp2_wpf.Actions"
mc:Ignorable="d"
Title="Overwrite Existing File?"
SizeToContent="Height" Width="600" ResizeMode="NoResize"
SizeToContent="Height" Width="500" ResizeMode="NoResize"
ShowInTaskbar="False" WindowStartupLocation="CenterOwner">

<Grid Margin="8">
Expand Down

0 comments on commit a4a5a03

Please sign in to comment.