summaryrefslogtreecommitdiff
path: root/Dalos/Dalos.cc
diff options
context:
space:
mode:
authorpixel <pixel>2004-12-26 03:29:09 +0000
committerpixel <pixel>2004-12-26 03:29:09 +0000
commitdcd5161f4721d77d37e45f4281e8882bea2cd879 (patch)
treee682ae7911273484b1aa44d4a8cdc157fc548a58 /Dalos/Dalos.cc
parentcf676c6c981d98535e25b2cdcb2768d5f2fac67d (diff)
Putting hexview away, and changed copyrights a bit.
Diffstat (limited to 'Dalos/Dalos.cc')
-rw-r--r--Dalos/Dalos.cc180
1 files changed, 5 insertions, 175 deletions
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();