diff --git a/stella/src/debugger/gui/ContextMenu.hxx b/stella/src/debugger/gui/ContextMenu.hxx index 400d98134..20e26a5d0 100644 --- a/stella/src/debugger/gui/ContextMenu.hxx +++ b/stella/src/debugger/gui/ContextMenu.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: ContextMenu.hxx,v 1.1 2005-08-31 19:15:10 stephena Exp $ +// $Id: ContextMenu.hxx,v 1.2 2005-08-31 22:34:43 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -50,6 +50,7 @@ class ContextMenu : public Dialog, public CommandSender void setList(const StringList& list); const string& getSelectedString() const; + int getSelected() const { return _selectedItem; } protected: void handleMouseDown(int x, int y, int button, int clickCount); diff --git a/stella/src/debugger/gui/DebuggerDialog.cxx b/stella/src/debugger/gui/DebuggerDialog.cxx index 70cadb930..d3154686e 100644 --- a/stella/src/debugger/gui/DebuggerDialog.cxx +++ b/stella/src/debugger/gui/DebuggerDialog.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: DebuggerDialog.cxx,v 1.2 2005-08-31 19:15:10 stephena Exp $ +// $Id: DebuggerDialog.cxx,v 1.3 2005-08-31 22:34:43 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -54,6 +54,9 @@ DebuggerDialog::DebuggerDialog(OSystem* osystem, DialogContainer* parent, addTabArea(); addStatusArea(); addRomArea(); + + // Inform the output widget about its associated zoom widget + myTiaOutput->setZoomWidget(myTiaZoom); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/debugger/gui/TiaOutputWidget.cxx b/stella/src/debugger/gui/TiaOutputWidget.cxx index 9c71b577c..96f72a080 100644 --- a/stella/src/debugger/gui/TiaOutputWidget.cxx +++ b/stella/src/debugger/gui/TiaOutputWidget.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: TiaOutputWidget.cxx,v 1.1 2005-08-30 17:51:26 stephena Exp $ +// $Id: TiaOutputWidget.cxx,v 1.2 2005-08-31 22:34:43 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -23,19 +23,34 @@ #include "FrameBuffer.hxx" #include "Widget.hxx" #include "GuiObject.hxx" +#include "ContextMenu.hxx" +#include "TiaZoomWidget.hxx" #include "TiaOutputWidget.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TiaOutputWidget::TiaOutputWidget(GuiObject* boss, int x, int y, int w, int h) : Widget(boss, x, y, w, h), - CommandSender(boss) + CommandSender(boss), + myMenu(NULL), + myZoom(NULL) { + // Create context menu for commands + myMenu = new ContextMenu(this, instance()->consoleFont()); + + StringList l; + l.push_back("Fill to scanline"); + l.push_back("Set breakpoint"); + l.push_back("Set zoom position"); + + myMenu->setList(l); + } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TiaOutputWidget::~TiaOutputWidget() { + delete myMenu; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -67,13 +82,45 @@ void TiaOutputWidget::advance(int frames) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TiaOutputWidget::handleMouseDown(int x, int y, int button, int clickCount) { + // FIXME - these coords aren't yet accurate, but that doesn't stop + // us from implementing the functionality int xstart = atoi(instance()->console().properties().get("Display.XStart").c_str()); int ystart = atoi(instance()->console().properties().get("Display.YStart").c_str()); -cerr << "TiaOutputWidget button press:" << endl - << "x = " << x << ", y = " << y << endl - << "xstart = " << xstart << ", ystart = " << ystart << endl - << endl; + // Grab right mouse button for zoom context menu + if(button == 2) + { + myClickX = x + getAbsX(); + myClickY = y + getAbsY(); + + myMenu->setPos(myClickX, myClickY); + myMenu->show(); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TiaOutputWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) +{ + switch(cmd) + { + case kCMenuItemSelectedCmd: + switch(myMenu->getSelected()) + { + case 0: + cerr << "Fill to scanline\n"; + break; + + case 1: + cerr << "Set breakpoint\n"; + break; + + case 2: + if(myZoom) + myZoom->setPos(myClickX, myClickY); + break; + } + break; + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/debugger/gui/TiaOutputWidget.hxx b/stella/src/debugger/gui/TiaOutputWidget.hxx index f37d43386..8c935e74d 100644 --- a/stella/src/debugger/gui/TiaOutputWidget.hxx +++ b/stella/src/debugger/gui/TiaOutputWidget.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: TiaOutputWidget.hxx,v 1.1 2005-08-30 17:51:26 stephena Exp $ +// $Id: TiaOutputWidget.hxx,v 1.2 2005-08-31 22:34:43 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -23,6 +23,8 @@ #define TIA_OUTPUT_WIDGET_HXX class GuiObject; +class ContextMenu; +class TiaZoomWidget; #include "Widget.hxx" #include "Command.hxx" @@ -34,8 +36,8 @@ class TiaOutputWidget : public Widget, public CommandSender TiaOutputWidget(GuiObject *boss, int x, int y, int w, int h); virtual ~TiaOutputWidget(); - void handleMouseDown(int x, int y, int button, int clickCount); void loadConfig(); + void setZoomWidget(TiaZoomWidget* w) { myZoom = w; } // Eventually, these methods will enable access to the onscreen TIA image // For example, clicking an area may cause an action @@ -45,14 +47,22 @@ class TiaOutputWidget : public Widget, public CommandSender virtual void handleMouseWheel(int x, int y, int direction); virtual bool handleKeyDown(int ascii, int keycode, int modifiers); virtual bool handleKeyUp(int ascii, int keycode, int modifiers); - virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); */ void advanceScanline(int lines); void advance(int frames); protected: + void handleMouseDown(int x, int y, int button, int clickCount); + void handleCommand(CommandSender* sender, int cmd, int data, int id); + void drawWidget(bool hilite); bool wantsFocus() { return false; } + + private: + ContextMenu* myMenu; + TiaZoomWidget* myZoom; + + int myClickX, myClickY; }; #endif diff --git a/stella/src/debugger/gui/TiaZoomWidget.cxx b/stella/src/debugger/gui/TiaZoomWidget.cxx index 4f693d17d..81ce4822a 100644 --- a/stella/src/debugger/gui/TiaZoomWidget.cxx +++ b/stella/src/debugger/gui/TiaZoomWidget.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: TiaZoomWidget.cxx,v 1.1 2005-08-31 19:15:10 stephena Exp $ +// $Id: TiaZoomWidget.cxx,v 1.2 2005-08-31 22:34:43 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -23,6 +23,7 @@ #include "FrameBuffer.hxx" #include "Widget.hxx" #include "GuiObject.hxx" +#include "ContextMenu.hxx" #include "TiaZoomWidget.hxx" @@ -30,7 +31,7 @@ TiaZoomWidget::TiaZoomWidget(GuiObject* boss, int x, int y) : Widget(boss, x, y, 16, 16), CommandSender(boss), - myZoomLevel(2) + myMenu(NULL) { _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS; @@ -38,11 +39,29 @@ TiaZoomWidget::TiaZoomWidget(GuiObject* boss, int x, int y) _h = 120; addFocusWidget(this); + + // Initialize positions + myZoomLevel = 2; + myNumCols = ((_w - 4) >> 1) / myZoomLevel; + myNumRows = (_h - 4) / myZoomLevel; + myXoff = 0; + myYoff = 0; + + // Create context menu for zoom levels + myMenu = new ContextMenu(this, instance()->consoleFont()); + + StringList l; + l.push_back("2x zoom"); + l.push_back("4x zoom"); + l.push_back("8x zoom"); + + myMenu->setList(l); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TiaZoomWidget::~TiaZoomWidget() { + delete myMenu; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -51,30 +70,112 @@ void TiaZoomWidget::loadConfig() setDirty(); draw(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TiaZoomWidget::setPos(int x, int y) +{ + myXoff = x; + myYoff = y; + + recalc(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TiaZoomWidget::zoom(int level) { + if(myZoomLevel == level) + return; + myZoomLevel = level; + myNumCols = ((_w - 4) >> 1) / myZoomLevel; + myNumRows = (_h - 4) / myZoomLevel; + recalc(); +} - // Redraw the zoomed image - loadConfig(); +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TiaZoomWidget::recalc() +{ + // Don't go past end of framebuffer + int imageWidth = instance()->console().mediaSource().width(); + int imageHeight = instance()->console().mediaSource().height(); + + if(myXoff < 0) + myXoff = 0; + else if(myXoff > imageWidth - myNumCols) + myXoff = imageWidth - myNumCols; + else if(myYoff < 0) + myYoff = 0; + else if(myYoff > imageHeight - myNumRows) + myYoff = imageHeight - myNumRows; + + setDirty(); draw(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TiaZoomWidget::handleMouseDown(int x, int y, int button, int clickCount) { + // Grab right mouse button for zoom context menu + if(button == 2) + { + myMenu->setPos(x + getAbsX(), y + getAbsY()); + myMenu->show(); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TiaZoomWidget::handleKeyDown(int ascii, int keycode, int modifiers) { - return false; + bool handled = false; + + switch (keycode) + { + case 256+17: // up arrow + myYoff -= 4; + handled = true; + break; + + case 256+18: // down arrow + myYoff += 4; + handled = true; + break; + + case 256+20: // left arrow + myXoff -= 2; + handled = true; + break; + + case 256+19: // right arrow + myXoff += 2; + handled = true; + break; + } + + if(handled) + recalc(); + + return handled; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TiaZoomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) { + switch(cmd) + { + case kCMenuItemSelectedCmd: + { + int item = myMenu->getSelected(), level = 0; + if(item == 0) + level = 2; + else if(item == 1) + level = 4; + else if(item == 2) + level = 8; + + if(level > 0) + zoom(level); + break; + } + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -89,63 +190,25 @@ void TiaZoomWidget::drawWidget(bool hilite) // Draw the zoomed image // This probably isn't as efficient as it can be, but it's a small area // and I don't have time to make it faster :) - uInt8* currentFrame = myOSystem->console().mediaSource().currentFrameBuffer(); - - int numCols = ((_w - 4) >> 1) / myZoomLevel; - int numRows = (_h - 4) / myZoomLevel; + uInt8* currentFrame = instance()->console().mediaSource().currentFrameBuffer(); + const int pitch = instance()->console().mediaSource().width(), + width = myZoomLevel << 1, + height = myZoomLevel; int x, y, col, row; - for(y = 0, row = 0; y < numRows; ++y, row += myZoomLevel) + for(y = myYoff, row = 0; y < myNumRows+myYoff; ++y, row += height) { - for(x = 0, col = 0; x < numCols; ++x, col += (myZoomLevel << 1)) + for(x = myXoff, col = 0; x < myNumCols+myXoff; ++x, col += width) { SDL_Rect temp; temp.x = _x + col; temp.y = _y + row; - temp.w = myZoomLevel << 1; - temp.h = myZoomLevel; + temp.w = width; + temp.h = height; - fb.fillRect(_x + col + 2, _y + row + 2, myZoomLevel << 1, myZoomLevel, - (OverlayColor)currentFrame[x*y]); + fb.fillRect(_x + col + 2, _y + row + 2, width, height, + (OverlayColor)currentFrame[y*pitch + x]); } } - -/* - - - - - // Copy the mediasource framebuffer to the RGB texture - uInt8* currentFrame = mediasrc.currentFrameBuffer(); - uInt8* previousFrame = mediasrc.previousFrameBuffer(); - uInt32 width = mediasrc.width(); - uInt32 height = mediasrc.height(); - uInt16* buffer = (uInt16*) myTexture->pixels; - - register uInt32 y; - for(y = 0; y < height; ++y ) - { - const uInt32 bufofsY = y * width; - const uInt32 screenofsY = y * myTexture->w; - - register uInt32 x; - for(x = 0; x < width; ++x ) - { - const uInt32 bufofs = bufofsY + x; - uInt8 v = currentFrame[bufofs]; - if(v != previousFrame[bufofs] || theRedrawTIAIndicator) - { - // If we ever get to this point, we know the current and previous - // buffers differ. In that case, make sure the changes are - // are drawn in postFrameUpdate() - theRedrawTIAIndicator = true; - - // x << 1 is times 2 ( doubling width ) - const uInt32 pos = screenofsY + (x << 1); - buffer[pos] = buffer[pos+1] = (uInt16) myPalette[v]; - } - } - } -*/ } diff --git a/stella/src/debugger/gui/TiaZoomWidget.hxx b/stella/src/debugger/gui/TiaZoomWidget.hxx index 90c57b642..9cff16d5d 100644 --- a/stella/src/debugger/gui/TiaZoomWidget.hxx +++ b/stella/src/debugger/gui/TiaZoomWidget.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: TiaZoomWidget.hxx,v 1.1 2005-08-31 19:15:10 stephena Exp $ +// $Id: TiaZoomWidget.hxx,v 1.2 2005-08-31 22:34:43 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -23,6 +23,7 @@ #define TIA_ZOOM_WIDGET_HXX class GuiObject; +class ContextMenu; #include "Widget.hxx" #include "Command.hxx" @@ -35,6 +36,7 @@ class TiaZoomWidget : public Widget, public CommandSender virtual ~TiaZoomWidget(); void loadConfig(); + void setPos(int x, int y); protected: void handleMouseDown(int x, int y, int button, int clickCount); @@ -46,9 +48,14 @@ class TiaZoomWidget : public Widget, public CommandSender private: void zoom(int level); + void recalc(); private: + ContextMenu* myMenu; + int myZoomLevel; + int myNumCols, myNumRows; + int myXoff, myYoff; }; #endif