From 280cacae2889bb2b838cda2926af3d9e90c540a9 Mon Sep 17 00:00:00 2001 From: pixel Date: Sun, 25 Jul 2004 10:20:36 +0000 Subject: Adding a short HexViewer --- Dalos/Dalos.cc | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 7 deletions(-) diff --git a/Dalos/Dalos.cc b/Dalos/Dalos.cc index b22cfff..9af9710 100644 --- a/Dalos/Dalos.cc +++ b/Dalos/Dalos.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Dalos.cc,v 1.4 2004-07-24 06:52:03 pixel Exp $ */ +/* $Id: Dalos.cc,v 1.5 2004-07-25 10:20:36 pixel Exp $ */ #include #include @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -420,11 +421,11 @@ class console : public mogltk::widget { virtual void draw() { int cursor_pos, start, line_length, line_pos, cur_page; - mogltk::ColorP::Max.A = 120; + mogltk::ColorP::Max.A = 180; std::vector::iterator i; // Background - Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2(), BLUE); + Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2(), DODGERBLUE); Shaper()->obox(GetAX(), GetAY(), GetAX2(), GetAY2(), BLUE); mogltk::ColorP::Max.A = 255; @@ -455,12 +456,12 @@ class console : public mogltk::widget { start += 16; } - mogltk::ColorP::Max.A = 200; + mogltk::ColorP::Max.A = 220; if (lua_started) { - Shaper()->box(GetAX(), GetAY() + (nlines - 1) * 13, GetAX() + 6, GetAY() + nlines * 13, GREEN); + Shaper()->box(GetAX(), GetAY() + (nlines - 1) * 13, GetAX() + 6, GetAY() + nlines * 13, FORESTGREEN); } else { - Shaper()->box(GetAX() + 6 * (cursor_pos + 2), GetAY() + (nlines - 1) * 13, GetAX() + 6 * (cursor_pos + 3) - 1, GetAY() + nlines * 13, GREEN); + Shaper()->box(GetAX() + 6 * (cursor_pos + 2), GetAY() + (nlines - 1) * 13, GetAX() + 6 * (cursor_pos + 3) - 1, GetAY() + nlines * 13, FORESTGREEN); mogltk::ColorP::Max.A = 255; mogltk::FixedFont->putcursor(GetAX(), GetAY() + (nlines - 1) * 13); @@ -477,6 +478,69 @@ class console : public mogltk::widget { SDL_mutex * protect_add_line; }; +class hexview : public mogltk::widget { + public: + hexview(mogltk::shape * sh, mogltk::widget * father) : + widget(father, 0, 0, father->GetW(), father->GetH(), 0, "hexview", sh), h(0), width(16), offset(0), offset_loaded(-1), size_loaded(0), data(0) + { nlines = GetH() / 13; } + virtual ~hexview() { free(data); } + void bind_handle(Handle * _h) { + h = _h; + } + Uint8 * get_data() { + if (!data) { + data = (Uint8 *) malloc(nlines * width); + } + + if ((offset_loaded == offset) && (size_loaded == (nlines * width))) + return data; + + h->seek(offset); + h->read(data, nlines * width); + + offset_loaded = offset; + size_loaded = nlines * width; + + return data; + } + virtual void draw() { + int i, max_o, j, k, start_o, l, c; + + if (!h) + return; + + get_data(); + + mogltk::FixedFont->setcolor(WHITE); + mogltk::FixedFont->putcursor(GetAX(), GetAY()); + + max_o = min(h->GetSize(), offset + nlines * width); + + for (i = start_o = offset, j = 0, l = 0; i < max_o; i++, j) { + if ((j % width) == 0) { + mogltk::FixedFont->printf("%08X ", i); + } + mogltk::FixedFont->printf("%02X ", data[i]); + j++; + if ((j % width) == 0) { + for (k = start_o, c = 0; k < start_o + width; k++, c++) { + mogltk::FixedFont->putcursor(GetAX() + (c + width * 3 + 14) * 6, GetAY() + l * 13); + if (data[k] >= 0x20) + mogltk::FixedFont->putentry(data[k] - 0x20); + } + l++; + mogltk::FixedFont->putcursor(GetAX(), GetAY() + l * 13); + start_o = i; + } + } + } + private: + Handle * h; + int width, offset, nlines; + int offset_loaded, size_loaded; + Uint8 * data; +}; + class frame : public mogltk::widget { public: frame(mogltk::shape * sh, mogltk::widget * father) : @@ -548,7 +612,7 @@ class about : public mogltk::widgets::action { } about_dialog; virtual int startup() throw (GeneralException) { - verbosity = M_WARNING; + verbosity = M_INFO; try { new Archive(argv[0], ARCHIVE_EXECUTABLE); } @@ -571,6 +635,9 @@ virtual int startup() throw (GeneralException) { Root = new mogltk::widgets::Root(sh); MainMenu = new mogltk::widgets::Menu(sh, Root); Frame = new frame(sh, new mogltk::widgets::Frame(sh, Root, 0, MainMenu->GetH(), Root->GetW() - 1, Root->GetH() - MainMenu->GetH() - 1)); + + (new hexview(sh, Frame))->bind_handle(new Input(argv[0])); + Console = new console(sh, Frame, 0, 8); Console->move(0, Frame->GetH() - Console->GetH()); Console->add_line("Dalos v0.1 - LUA console"); -- cgit v1.2.3