summaryrefslogtreecommitdiff
path: root/Dalos
diff options
context:
space:
mode:
Diffstat (limited to 'Dalos')
-rw-r--r--Dalos/Console.cc8
-rw-r--r--Dalos/Console.h15
-rw-r--r--Dalos/Dalos.cc180
-rw-r--r--Dalos/Hexview.cc200
-rw-r--r--Dalos/Hexview.h59
5 files changed, 275 insertions, 187 deletions
diff --git a/Dalos/Console.cc b/Dalos/Console.cc
index f4d914b..ac72b2f 100644
--- a/Dalos/Console.cc
+++ b/Dalos/Console.cc
@@ -1,6 +1,6 @@
/*
* Dalos
- * Copyright (C) 2004 Nicolas "Pixel" Noble
+ * Copyright (C) 2003-2005 Nicolas "Pixel" Noble
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Console.cc,v 1.3 2004-12-26 02:45:55 pixel Exp $ */
+/* $Id: Console.cc,v 1.4 2004-12-26 03:29:09 pixel Exp $ */
#include <SDL.h>
#include <SDL_thread.h>
@@ -129,7 +129,7 @@ class ReadLineInternals : public Base {
}
};
-void console_keyevent::down(SDL_keysym k) {
+void console::console_keyevent::down(SDL_keysym k) {
if (CurrentConsole->GetVisible()) {
SDL_mutexP(key_vect_mutex);
switch (k.sym) {
@@ -208,7 +208,7 @@ void console_keyevent::down(SDL_keysym k) {
}
}
-void console_keyevent::up(SDL_keysym k) {
+void console::console_keyevent::up(SDL_keysym k) {
if (old_handler)
old_handler->up(k);
}
diff --git a/Dalos/Console.h b/Dalos/Console.h
index 65e8357..f7af59b 100644
--- a/Dalos/Console.h
+++ b/Dalos/Console.h
@@ -1,6 +1,6 @@
/*
* Dalos
- * Copyright (C) 2004 Nicolas "Pixel" Noble
+ * Copyright (C) 2003-2005 Nicolas "Pixel" Noble
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Console.h,v 1.3 2004-12-26 02:45:55 pixel Exp $ */
+/* $Id: Console.h,v 1.4 2004-12-26 03:29:10 pixel Exp $ */
#ifndef __CONSOLE_H__
#define __CONSOLE_H__
@@ -30,14 +30,13 @@
#include <engine.h>
#include <widgets.h>
-class console_keyevent : public mogltk::engine::keyevent {
- public:
- virtual void down(SDL_keysym k);
- virtual void up(SDL_keysym k);
-};
-
class console : public mogltk::widget {
public:
+ class console_keyevent : public mogltk::engine::keyevent {
+ public:
+ virtual void down(SDL_keysym k);
+ virtual void up(SDL_keysym k);
+ };
console(mogltk::shape * sh, mogltk::widget * father, int y, int _nlines);
virtual ~console();
void add_line(const String & s);
diff --git a/Dalos/Dalos.cc b/Dalos/Dalos.cc
index 3697fc1..6ab2153 100644
--- a/Dalos/Dalos.cc
+++ b/Dalos/Dalos.cc
@@ -1,6 +1,6 @@
/*
* Dalos
- * Copyright (C) 2004 Nicolas "Pixel" Noble
+ * Copyright (C) 2003-2005 Nicolas "Pixel" Noble
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Dalos.cc,v 1.11 2004-12-26 02:45:55 pixel Exp $ */
+/* $Id: Dalos.cc,v 1.12 2004-12-26 03:29:10 pixel Exp $ */
#include <SDL.h>
#include <SDL_thread.h>
@@ -40,6 +40,7 @@
#include <luapsx.h>
#include <Console.h>
+#include <Hexview.h>
#include "cd-tool-hc.h"
@@ -53,10 +54,6 @@ bool do_lua_break = false;
CODE_BEGINS
-class hexview;
-
-hexview * hexviewer;
-
mogltk::widgets::Root * Root;
mogltk::widget * Frame, * MainPanel;
mogltk::widgets::Menu * MainMenu;
@@ -186,63 +183,6 @@ static int LuaThread(void * d) {
}
}
-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()) { }
@@ -270,116 +210,6 @@ class myprinter : public printer_t {
SDL_mutex * lock;
};
-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), 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) {
- if (_shift < 0)
- _shift = 0;
- shift = _shift;
- }
- int get_shift() {
- return shift;
- }
- 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() - shift * 6, GetAY());
-
- max_o = min(h->GetSize(), offset + nlines * width);
-
- for (i = start_o = offset, j = 0, l = 0; i < max_o; i++) {
- if ((j % width) == 0) {
- mogltk::FixedFont->printf("%08X ", i + virtual_base);
- }
- 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 - shift) * 6, GetAY() + l * 13);
- if (data[j - width + c] >= 0x20)
- // Have better font support here...
- mogltk::FixedFont->putentry(data[j - width + c] - 0x20);
- }
- l++;
- mogltk::FixedFont->putcursor(GetAX() - shift * 6, GetAY() + l * 13);
- start_o = i;
- }
- }
- }
- protected:
- virtual void resize_notify() {
- nlines = Father()->GetH() / 13;
- resize(Father()->GetW(), Father()->GetH());
- }
- private:
- Handle * h;
- int width, offset, nlines;
- int offset_loaded, size_loaded, virtual_base;
- int shift;
- Uint8 * data;
-};
-
class frame : public mogltk::widget {
public:
frame(mogltk::shape * sh, mogltk::widget * father) :
@@ -513,8 +343,8 @@ virtual int startup() throw (GeneralException) {
new timer();
// Setting up the key event handlers
- new hexview_keyevent;
- new console_keyevent; // Should be one of the last
+ new hexview::hexview_keyevent;
+ new console::console_keyevent; // Should be one of the last
// And launching the main loop
Root->mainloop();
diff --git a/Dalos/Hexview.cc b/Dalos/Hexview.cc
new file mode 100644
index 0000000..0b3fc28
--- /dev/null
+++ b/Dalos/Hexview.cc
@@ -0,0 +1,200 @@
+/*
+ * Dalos
+ * Copyright (C) 2003-2005 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: Hexview.cc,v 1.1 2004-12-26 03:29:10 pixel Exp $ */
+
+#include <SDL.h>
+
+#include <font.h>
+
+#include "Hexview.h"
+
+void hexview::hexview_keyevent::down(SDL_keysym k) {
+ if (!CurrentHexview || !CurrentHexview->GetVisible()) {
+ if (old_handler)
+ old_handler->down(k);
+ return;
+ }
+ switch (k.sym) {
+ case SDLK_DOWN:
+ CurrentHexview->change_offset(CurrentHexview->get_offset() + CurrentHexview->get_width());
+ break;
+ case SDLK_UP:
+ CurrentHexview->change_offset(CurrentHexview->get_offset() - CurrentHexview->get_width());
+ break;
+ case SDLK_RIGHT:
+ if (KMOD_ALT & k.mod) {
+ CurrentHexview->change_width(CurrentHexview->get_width() + 1);
+ } else if (KMOD_CTRL & k.mod) {
+ CurrentHexview->change_shift(CurrentHexview->get_shift() - 1);
+ } else {
+ CurrentHexview->change_offset(CurrentHexview->get_offset() + 1);
+ }
+ break;
+ case SDLK_LEFT:
+ if (KMOD_ALT & k.mod) {
+ CurrentHexview->change_width(CurrentHexview->get_width() - 1);
+ } else if (KMOD_CTRL & k.mod) {
+ CurrentHexview->change_shift(CurrentHexview->get_shift() + 1);
+ } else {
+ CurrentHexview->change_offset(CurrentHexview->get_offset() - 1);
+ }
+ break;
+ case SDLK_PAGEDOWN:
+ CurrentHexview->change_offset(CurrentHexview->get_offset() + CurrentHexview->get_width() * CurrentHexview->get_nlines());
+ break;
+ case SDLK_PAGEUP:
+ CurrentHexview->change_offset(CurrentHexview->get_offset() - CurrentHexview->get_width() * CurrentHexview->get_nlines());
+ break;
+ case SDLK_HOME:
+ CurrentHexview->change_offset(0);
+ break;
+ case SDLK_END:
+ CurrentHexview->change_offset(CurrentHexview->get_size() - 1);
+ break;
+ default:
+ if (old_handler)
+ old_handler->down(k);
+ return;
+ }
+}
+
+void hexview::hexview_keyevent::up(SDL_keysym k) {
+ if (old_handler)
+ old_handler->up(k);
+}
+
+hexview::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), virtual_base(0), shift(0)
+{
+ nlines = GetH() / 13; CurrentHexview = this;
+}
+
+hexview::~hexview() {
+ free(data);
+ CurrentHexview = 0;
+}
+
+void hexview::set_virtual_base(int _virtual_base) {
+ virtual_base = _virtual_base;
+}
+
+int hexview::get_nlines() {
+ return nlines;
+}
+
+int hexview::get_size() {
+ if (!h)
+ return 0;
+ return h->GetSize();
+}
+
+void hexview::change_width(int _width) {
+ if (_width <= 0)
+ _width = 1;
+ if (width != _width) {
+ free(data);
+ width = _width;
+ }
+}
+
+int hexview::get_width() {
+ return width;
+}
+
+void hexview::change_offset(int _offset) {
+ if ((_offset < 0) || !h)
+ _offset = 0;
+ if (h && (_offset >= h->GetSize()))
+ _offset = h->GetSize() - 1;
+ offset = _offset;
+}
+
+int hexview::get_offset() {
+ return offset;
+}
+
+void hexview::change_shift(int _shift) {
+ if (_shift < 0)
+ _shift = 0;
+ shift = _shift;
+}
+
+int hexview::get_shift() {
+ return shift;
+}
+
+void hexview::bind_handle(Handle * _h) {
+ h = _h;
+}
+
+Uint8 * hexview::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;
+}
+
+void hexview::draw() {
+ int i, max_o, j, k, start_o, l, c;
+
+ if (!h)
+ return;
+
+ get_data();
+
+ mogltk::FixedFont->setcolor(WHITE);
+ 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++) {
+ if ((j % width) == 0) {
+ mogltk::FixedFont->printf("%08X ", i + virtual_base);
+ }
+ 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 - shift) * 6, GetAY() + l * 13);
+ if (data[j - width + c] >= 0x20)
+ // Have better font support here...
+ mogltk::FixedFont->putentry(data[j - width + c] - 0x20);
+ }
+ l++;
+ mogltk::FixedFont->putcursor(GetAX() - shift * 6, GetAY() + l * 13);
+ start_o = i;
+ }
+ }
+}
+
+void hexview::resize_notify() {
+ nlines = Father()->GetH() / 13;
+ resize(Father()->GetW(), Father()->GetH());
+}
diff --git a/Dalos/Hexview.h b/Dalos/Hexview.h
new file mode 100644
index 0000000..4caf67b
--- /dev/null
+++ b/Dalos/Hexview.h
@@ -0,0 +1,59 @@
+/*
+ * Dalos
+ * Copyright (C) 2003-2005 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: Hexview.h,v 1.1 2004-12-26 03:29:10 pixel Exp $ */
+
+#ifndef __HEXVIEW_H__
+#define __HEXVIEW_H__
+
+#include <engine.h>
+#include <widgets.h>
+
+class hexview : public mogltk::widget {
+ public:
+ class hexview_keyevent : public mogltk::engine::keyevent {
+ public:
+ virtual void down(SDL_keysym k);
+ virtual void up(SDL_keysym k);
+ };
+ hexview(mogltk::shape * sh, mogltk::widget * father);
+ virtual ~hexview();
+ void set_virtual_base(int _virtual_base);
+ int get_nlines();
+ int get_size();
+ void change_width(int _width);
+ int get_width();
+ void change_offset(int _offset);
+ int get_offset();
+ void change_shift(int _shift);
+ int get_shift();
+ void bind_handle(Handle * _h);
+ Uint8 * get_data();
+ virtual void draw();
+ protected:
+ virtual void resize_notify();
+ private:
+ Handle * h;
+ int width, offset, nlines;
+ int offset_loaded, size_loaded, virtual_base;
+ int shift;
+ Uint8 * data;
+} * CurrentHexview;
+
+#endif