// Copyright (c) Sean Walton 1999-2006 All rights reserved // // Standard disclaimer: you use it --> you're responsible // Standard license: you can use it in any way, but keep // my copyright attached. #include "BBAsciiTable.h" ///-------------------------------------------------------------------------------------- /// #define COLUMNS 16 #define MAXCHARS 256 #define CHARWIDTH 9 #define LABELOFFSET 15 void BBAsciiTable::Paint(Graphics& g) { char temps[5]; int x=0, y=0; for ( int c = 0; c < COLUMNS; c++ ) { RimSprintf(temps, sizeof(temps), "%X", c); g.DrawString(c*CHARWIDTH+CHARWIDTH/2+LABELOFFSET, y, temps, strlen(temps), GetFont(), LCD_CENTERED); } XYRect rect(0, 0, DISPLAYWIDTH, RowHeight); g.Invert(rect); for ( c = 0; c < MAXCHARS; c++ ) { if ( (c & (COLUMNS-1)) == 0 ) { y += RowHeight; RimSprintf(temps, sizeof(temps), "%02X:", c); g.DrawString(0, y, temps, strlen(temps), GetFont(), 0); x = LABELOFFSET; } RimSprintf(temps, sizeof(temps), "%c", c); g.DrawString(x, y, temps, strlen(temps), GetFont(), 0); x += CHARWIDTH; } } int BBAsciiTable::OnScroll(int axis, int directionMagnitude) { ToolTop = false; if ( axis == 1) directionMagnitude *= COLUMNS; Cursor += directionMagnitude; if ( Cursor < 0 ) { ToolTop = true; Cursor = 0; return -1; } else if ( Cursor >= MAXCHARS ) { Cursor = MAXCHARS-1; return 1; } return 0; } XYRect BBAsciiTable::GetFocusRect(void) const { XYRect rect; if ( !ToolTop ) { rect.width = CHARWIDTH+1; rect.height = RowHeight; rect.x = LABELOFFSET+(Cursor & (COLUMNS-1))*CHARWIDTH-1; rect.y = (Cursor/COLUMNS+1) * rect.height; } return rect; }