summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dalos/Dalos.cc132
1 files changed, 118 insertions, 14 deletions
diff --git a/Dalos/Dalos.cc b/Dalos/Dalos.cc
index 9af9710..0186cb3 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.5 2004-07-25 10:20:36 pixel Exp $ */
+/* $Id: Dalos.cc,v 1.6 2004-08-01 13:03:47 pixel Exp $ */
#include <SDL.h>
#include <SDL_thread.h>
@@ -64,6 +64,10 @@ std::vector<Uint16> key_vect;
CODE_BEGINS
+class hexview;
+
+hexview * hexviewer;
+
class console;
console * Console;
@@ -364,6 +368,63 @@ class console_keyevent : public mogltk::engine::keyevent {
}
};
+class hexview_keyevent : public mogltk::engine::keyevent {
+ public:
+ virtual void down(SDL_keysym k) {
+ if (!Application->hexviewer || !Application->hexviewer->GetVisible()) {
+ if (old_handler)
+ old_handler->down(k);
+ return;
+ }
+ switch (k.sym) {
+ case SDLK_DOWN:
+ Application->hexviewer->change_offset(Application->hexviewer->get_offset() + Application->hexviewer->get_width());
+ break;
+ case SDLK_UP:
+ Application->hexviewer->change_offset(Application->hexviewer->get_offset() - Application->hexviewer->get_width());
+ break;
+ case SDLK_RIGHT:
+ if (KMOD_ALT & k.mod) {
+ Application->hexviewer->change_width(Application->hexviewer->get_width() + 1);
+ } else if (KMOD_CTRL & k.mod) {
+ Application->hexviewer->change_shift(Application->hexviewer->get_shift() - 1);
+ } else {
+ Application->hexviewer->change_offset(Application->hexviewer->get_offset() + 1);
+ }
+ break;
+ case SDLK_LEFT:
+ if (KMOD_ALT & k.mod) {
+ Application->hexviewer->change_width(Application->hexviewer->get_width() - 1);
+ } else if (KMOD_CTRL & k.mod) {
+ Application->hexviewer->change_shift(Application->hexviewer->get_shift() + 1);
+ } else {
+ Application->hexviewer->change_offset(Application->hexviewer->get_offset() - 1);
+ }
+ break;
+ case SDLK_PAGEDOWN:
+ Application->hexviewer->change_offset(Application->hexviewer->get_offset() + Application->hexviewer->get_width() * Application->hexviewer->get_nlines());
+ break;
+ case SDLK_PAGEUP:
+ Application->hexviewer->change_offset(Application->hexviewer->get_offset() - Application->hexviewer->get_width() * Application->hexviewer->get_nlines());
+ break;
+ case SDLK_HOME:
+ Application->hexviewer->change_offset(0);
+ break;
+ case SDLK_END:
+ Application->hexviewer->change_offset(Application->hexviewer->get_size() - 1);
+ break;
+ default:
+ if (old_handler)
+ old_handler->down(k);
+ return;
+ }
+ }
+ virtual void up(SDL_keysym k) {
+ if (old_handler)
+ old_handler->up(k);
+ }
+};
+
class myprinter : public printer_t {
public:
myprinter() : lock(SDL_CreateMutex()) { }
@@ -481,9 +542,47 @@ class console : public mogltk::widget {
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); }
+ 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), virtual_base(0), shift(0)
+ { nlines = GetH() / 13; Application->hexviewer = this; }
+ virtual ~hexview() { free(data); Application->hexviewer = 0; }
+ void set_virtual_base(int _virtual_base) {
+ virtual_base = _virtual_base;
+ }
+ int get_nlines() {
+ return nlines;
+ }
+ int get_size() {
+ if (!h)
+ return 0;
+ return h->GetSize();
+ }
+ void change_width(int _width) {
+ if (_width <= 0)
+ _width = 1;
+ if (width != _width) {
+ free(data);
+ width = _width;
+ }
+ }
+ int get_width() {
+ return width;
+ }
+ void change_offset(int _offset) {
+ if ((_offset < 0) || !h)
+ _offset = 0;
+ if (h && (_offset >= h->GetSize()))
+ _offset = h->GetSize() - 1;
+ offset = _offset;
+ }
+ int get_offset() {
+ return offset;
+ }
+ void change_shift(int _shift) {
+ shift = _shift;
+ }
+ int get_shift() {
+ return shift;
+ }
void bind_handle(Handle * _h) {
h = _h;
}
@@ -512,24 +611,24 @@ class hexview : public mogltk::widget {
get_data();
mogltk::FixedFont->setcolor(WHITE);
- mogltk::FixedFont->putcursor(GetAX(), GetAY());
+ mogltk::FixedFont->putcursor(GetAX() - shift * 6, GetAY());
max_o = min(h->GetSize(), offset + nlines * width);
- for (i = start_o = offset, j = 0, l = 0; i < max_o; i++, j) {
+ for (i = start_o = offset, j = 0, l = 0; i < max_o; i++) {
if ((j % width) == 0) {
- mogltk::FixedFont->printf("%08X ", i);
+ mogltk::FixedFont->printf("%08X ", i + virtual_base);
}
- mogltk::FixedFont->printf("%02X ", data[i]);
+ mogltk::FixedFont->printf("%02X ", data[j]);
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);
+ mogltk::FixedFont->putcursor(GetAX() + (c + width * 3 + 14 - shift) * 6, GetAY() + l * 13);
+ if (data[j - width + c] >= 0x20)
+ mogltk::FixedFont->putentry(data[j - width + c] - 0x20);
}
l++;
- mogltk::FixedFont->putcursor(GetAX(), GetAY() + l * 13);
+ mogltk::FixedFont->putcursor(GetAX() - shift * 6, GetAY() + l * 13);
start_o = i;
}
}
@@ -537,7 +636,8 @@ class hexview : public mogltk::widget {
private:
Handle * h;
int width, offset, nlines;
- int offset_loaded, size_loaded;
+ int offset_loaded, size_loaded, virtual_base;
+ int shift;
Uint8 * data;
};
@@ -660,7 +760,11 @@ virtual int startup() throw (GeneralException) {
new timer();
- new console_keyevent;
+ // Setting up the key event handlers
+ new hexview_keyevent;
+ new console_keyevent; // Should be one of the last
+
+ // And launching the main loop
Root->mainloop();
// Should cleanup here...