From 08835c016d1a872666a4a2e1996e96080aa390f5 Mon Sep 17 00:00:00 2001 From: stephena Date: Wed, 31 Aug 2005 19:15:10 +0000 Subject: [PATCH] Added ContextMenu dialog, which is basically quite similar to PopupDialog and 'pops up' a listing of commands that can emit signals which the parent class will act on. Added a ContextMenu to RomWidget, containing some common commands. These commands don't actually do anything yet. The GUI code now differentiates between left and right mouse buttons. Most classes still treat both the same, but in the case of the ContextMenu added to RomWidget, it's activated only by the RMB. Added first pass of TiaZoomWidget, which displays a zoomed area of the TIA image. It's not quite working correctly yet, but I think I know what the problem is. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@754 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/debugger/Debugger.cxx | 5 +- stella/src/debugger/Debugger.hxx | 6 +- stella/src/debugger/gui/ContextMenu.cxx | 204 +++++++++++++++++++++ stella/src/debugger/gui/ContextMenu.hxx | 80 ++++++++ stella/src/debugger/gui/DebuggerDialog.cxx | 17 +- stella/src/debugger/gui/DebuggerDialog.hxx | 5 +- stella/src/debugger/gui/RomListWidget.cxx | 57 ++++-- stella/src/debugger/gui/RomListWidget.hxx | 7 +- stella/src/debugger/gui/TiaInfoWidget.cxx | 31 ++-- stella/src/debugger/gui/TiaInfoWidget.hxx | 4 +- stella/src/debugger/gui/TiaZoomWidget.cxx | 151 +++++++++++++++ stella/src/debugger/gui/TiaZoomWidget.hxx | 54 ++++++ stella/src/debugger/gui/module.mk | 2 + stella/src/gui/Dialog.cxx | 6 +- stella/src/gui/DialogContainer.cxx | 15 +- stella/src/gui/GuiObject.hxx | 18 +- stella/src/gui/Widget.cxx | 5 +- stella/src/gui/Widget.hxx | 7 +- 18 files changed, 609 insertions(+), 65 deletions(-) create mode 100644 stella/src/debugger/gui/ContextMenu.cxx create mode 100644 stella/src/debugger/gui/ContextMenu.hxx create mode 100644 stella/src/debugger/gui/TiaZoomWidget.cxx create mode 100644 stella/src/debugger/gui/TiaZoomWidget.hxx diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index 3510fe3ff..eecf08de7 100644 --- a/stella/src/debugger/Debugger.cxx +++ b/stella/src/debugger/Debugger.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: Debugger.cxx,v 1.89 2005-08-26 16:44:16 stephena Exp $ +// $Id: Debugger.cxx,v 1.90 2005-08-31 19:15:10 stephena Exp $ //============================================================================ #include "bspf.hxx" @@ -40,6 +40,7 @@ #include "TiaInfoWidget.hxx" #include "TiaOutputWidget.hxx" +#include "TiaZoomWidget.hxx" #include "Expression.hxx" #include "YaccParser.hxx" @@ -92,6 +93,7 @@ Debugger::Debugger(OSystem* osystem) myTiaDebug(NULL), myTiaInfo(NULL), myTiaOutput(NULL), + myTiaZoom(NULL), equateList(NULL), breakPoints(NULL), readTraps(NULL), @@ -148,6 +150,7 @@ void Debugger::initialize() myPrompt = dd->prompt(); myTiaInfo = dd->tiaInfo(); myTiaOutput = dd->tiaOutput(); + myTiaZoom = dd->tiaZoom(); // set up any breakpoint that was on the command line // (and remove the key from the settings, so they won't get set again) diff --git a/stella/src/debugger/Debugger.hxx b/stella/src/debugger/Debugger.hxx index 22e464fcf..6a3a8a4e7 100644 --- a/stella/src/debugger/Debugger.hxx +++ b/stella/src/debugger/Debugger.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: Debugger.hxx,v 1.72 2005-08-26 16:44:16 stephena Exp $ +// $Id: Debugger.hxx,v 1.73 2005-08-31 19:15:10 stephena Exp $ //============================================================================ #ifndef DEBUGGER_HXX @@ -27,6 +27,7 @@ class RamDebug; class TIADebug; class TiaInfoWidget; class TiaOutputWidget; +class TiaZoomWidget; class Expression; #include @@ -76,7 +77,7 @@ typedef uInt16 (Debugger::*DEBUGGER_WORD_METHOD)(); for all debugging operations in Stella (parser, 6502 debugger, etc). @author Stephen Anthony - @version $Id: Debugger.hxx,v 1.72 2005-08-26 16:44:16 stephena Exp $ + @version $Id: Debugger.hxx,v 1.73 2005-08-31 19:15:10 stephena Exp $ */ class Debugger : public DialogContainer { @@ -352,6 +353,7 @@ class Debugger : public DialogContainer TiaInfoWidget* myTiaInfo; TiaOutputWidget* myTiaOutput; + TiaZoomWidget* myTiaZoom; EquateList *equateList; PackedBitArray *breakPoints; diff --git a/stella/src/debugger/gui/ContextMenu.cxx b/stella/src/debugger/gui/ContextMenu.cxx new file mode 100644 index 000000000..d2ad8a638 --- /dev/null +++ b/stella/src/debugger/gui/ContextMenu.cxx @@ -0,0 +1,204 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: ContextMenu.cxx,v 1.1 2005-08-31 19:15:10 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#include "OSystem.hxx" +#include "FrameBuffer.hxx" +#include "Dialog.hxx" +#include "DialogContainer.hxx" +#include "ContextMenu.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +ContextMenu::ContextMenu(GuiObject* boss, const GUI::Font& font) + : Dialog(boss->instance(), boss->parent(), 0, 0, 16, 16), + CommandSender(boss), + _selectedItem(-1), + _rowHeight(font.getLineHeight()) +{ + setFont(font); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +ContextMenu::~ContextMenu() +{ + _entries.clear(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::show() +{ + _selectedItem = -1; + parent()->addDialog(this); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::setList(const StringList& list) +{ + _entries = list; + + // Resize to largest string + int maxwidth = 0; + for(unsigned int i = 0; i < _entries.size(); ++i) + { + int length = _font->getStringWidth(_entries[i]); + if(length > maxwidth) + maxwidth = length; + } + + _w = maxwidth + 8; + _h = _rowHeight * _entries.size() + 4; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +const string& ContextMenu::getSelectedString() const +{ + return (_selectedItem >= 0) ? _entries[_selectedItem] : EmptyString; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::handleMouseDown(int x, int y, int button, int clickCount) +{ + if(button == 1) + sendSelection(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::handleMouseWheel(int x, int y, int direction) +{ + if(direction < 0) + moveUp(); + else if(direction > 0) + moveDown(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::handleMouseMoved(int x, int y, int button) +{ + // Compute over which item the mouse is... + int item = findItem(x, y); + if(item == -1) + return; + + // ...and update the selection accordingly + setSelection(item); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::handleKeyDown(int ascii, int keycode, int modifiers) +{ + switch(keycode) + { + case '\n': // enter/return + case '\r': + sendSelection(); + break; + case 256+17: // up arrow + moveUp(); + break; + case 256+18: // down arrow + moveDown(); + break; + case 256+22: // home + setSelection(0); + break; + case 256+23: // end + setSelection(_entries.size()-1); + break; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +int ContextMenu::findItem(int x, int y) const +{ + if(x >= 0 && x < _w && y >= 0 && y < _h) + return (y-4) / _rowHeight; + + return -1; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::setSelection(int item) +{ + if(item != _selectedItem) + { + // Change selection + _selectedItem = item; + setDirty(); draw(); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::sendSelection() +{ + sendCommand(kCMenuItemSelectedCmd, _selectedItem, -1); + + // We remove the dialog when the user has selected an item + parent()->removeDialog(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::moveUp() +{ + int item = _selectedItem; + if(item > 0) + setSelection(--item); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::moveDown() +{ + int item = _selectedItem; + if(item < (int)_entries.size() - 1) + setSelection(++item); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ContextMenu::drawDialog() +{ + // Normally we add widgets and let Dialog::draw() take care of this + // logic. But for some reason, this Dialog was written differently + // by the ScummVM guys, so I'm not going to mess with it. + if(_dirty) + { +// cerr << "ContextMenu::drawDialog()" << endl; + FrameBuffer& fb = instance()->frameBuffer(); + + fb.fillRect(_x+1, _y+1, _w-2, _h-2, kBGColor); + fb.box(_x, _y, _w, _h, kColor, kShadowColor); + + // Draw the entries + int count = _entries.size(); + for(int i = 0; i < count; i++) + { + bool hilite = i == _selectedItem; + int x = _x + 2; + int y = _y + 2 + i * _rowHeight; + int w = _w - 4; + string& name = _entries[i]; + + fb.fillRect(x, y, w, _rowHeight, hilite ? kTextColorHi : kBGColor); + + fb.drawString(_font, name, x + 1, y + 2, w - 2, + hilite ? kBGColor : kTextColor); + } + _dirty = false; + fb.addDirtyRect(_x, _y, _w, _h); + } +} diff --git a/stella/src/debugger/gui/ContextMenu.hxx b/stella/src/debugger/gui/ContextMenu.hxx new file mode 100644 index 000000000..400d98134 --- /dev/null +++ b/stella/src/debugger/gui/ContextMenu.hxx @@ -0,0 +1,80 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team +// +// 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 $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#ifndef CONTEXT_MENU_HXX +#define CONTEXT_MENU_HXX + +#include "Dialog.hxx" +#include "Command.hxx" +#include "Array.hxx" +#include "GuiUtils.hxx" +#include "bspf.hxx" + +enum { + kCMenuItemSelectedCmd = 'CMsl' +}; + +/** + * Popup context menu which, when clicked, "pop up" a list of items and + * lets the user pick on of them. + * + * Implementation wise, when the user selects an item, then a kCMenuItemSelectedCmd + * is broadcast, with data being equal to the tag value of the selected entry. + */ +class ContextMenu : public Dialog, public CommandSender +{ + public: + ContextMenu(GuiObject* boss, const GUI::Font& font); + virtual ~ContextMenu(); + + /** Show context menu onscreen */ + void show(); + + void setList(const StringList& list); + const string& getSelectedString() const; + + protected: + void handleMouseDown(int x, int y, int button, int clickCount); + void handleMouseWheel(int x, int y, int direction); + void handleMouseMoved(int x, int y, int button); + void handleKeyDown(int ascii, int keycode, int modifiers); + + void drawDialog(); + + private: + void drawMenuEntry(int entry, bool hilite); + + int findItem(int x, int y) const; + void setSelection(int item); + + void moveUp(); + void moveDown(); + + void sendSelection(); + + protected: + StringList _entries; + + int _selectedItem; + int _rowHeight; +}; + +#endif diff --git a/stella/src/debugger/gui/DebuggerDialog.cxx b/stella/src/debugger/gui/DebuggerDialog.cxx index 8d1612ccf..70cadb930 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.1 2005-08-30 17:51:26 stephena Exp $ +// $Id: DebuggerDialog.cxx,v 1.2 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -22,8 +22,9 @@ #include "Widget.hxx" #include "Dialog.hxx" #include "TabWidget.hxx" -#include "TiaOutputWidget.hxx" #include "TiaInfoWidget.hxx" +#include "TiaOutputWidget.hxx" +#include "TiaZoomWidget.hxx" #include "PromptWidget.hxx" #include "CpuWidget.hxx" #include "RamWidget.hxx" @@ -66,6 +67,7 @@ void DebuggerDialog::loadConfig() myTab->loadConfig(); myTiaInfo->loadConfig(); myTiaOutput->loadConfig(); + myTiaZoom->loadConfig(); myCpu->loadConfig(); myRam->loadConfig(); myRom->loadConfig(); @@ -168,9 +170,14 @@ void DebuggerDialog::addTabArea() void DebuggerDialog::addStatusArea() { GUI::Rect r = instance()->debugger().getStatusBounds(); - myTiaInfo = new TiaInfoWidget(this, r.left, r.top, r.width(), r.height()); -// FIXME - remove width and height from TiaInfo, let it figure out its -// own dimensions + int xpos, ypos; + + xpos = r.left; ypos = r.top; + myTiaInfo = new TiaInfoWidget(this, xpos, ypos); + + ypos += myTiaInfo->getHeight() + 10; + myTiaZoom = new TiaZoomWidget(this, xpos, ypos); + addToFocusList(myTiaZoom->getFocusList()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/debugger/gui/DebuggerDialog.hxx b/stella/src/debugger/gui/DebuggerDialog.hxx index 83e020abf..3ea349fc1 100644 --- a/stella/src/debugger/gui/DebuggerDialog.hxx +++ b/stella/src/debugger/gui/DebuggerDialog.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: DebuggerDialog.hxx,v 1.1 2005-08-30 17:51:26 stephena Exp $ +// $Id: DebuggerDialog.hxx,v 1.2 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -31,6 +31,7 @@ class RomWidget; class TabWidget; class TiaInfoWidget; class TiaOutputWidget; +class TiaZoomWidget; #include "Dialog.hxx" #include "PromptWidget.hxx" @@ -45,6 +46,7 @@ class DebuggerDialog : public Dialog PromptWidget* prompt() { return myPrompt; } TiaInfoWidget* tiaInfo() { return myTiaInfo; } TiaOutputWidget* tiaOutput() { return myTiaOutput; } + TiaZoomWidget* tiaZoom() { return myTiaZoom; } virtual void loadConfig(); virtual void handleKeyDown(int ascii, int keycode, int modifiers); @@ -56,6 +58,7 @@ class DebuggerDialog : public Dialog PromptWidget* myPrompt; TiaInfoWidget* myTiaInfo; TiaOutputWidget* myTiaOutput; + TiaZoomWidget* myTiaZoom; CpuWidget* myCpu; RamWidget* myRam; RomWidget* myRom; diff --git a/stella/src/debugger/gui/RomListWidget.cxx b/stella/src/debugger/gui/RomListWidget.cxx index 267391e0a..9e5ddb609 100644 --- a/stella/src/debugger/gui/RomListWidget.cxx +++ b/stella/src/debugger/gui/RomListWidget.cxx @@ -13,48 +13,67 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: RomListWidget.cxx,v 1.1 2005-08-30 17:51:26 stephena Exp $ +// $Id: RomListWidget.cxx,v 1.2 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project //============================================================================ +#include "ContextMenu.hxx" #include "RomListWidget.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RomListWidget::RomListWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h) : CheckListWidget(boss, font, x, y, w, h), + myMenu(NULL), myHighlightedItem(-1) { + myMenu = new ContextMenu(this, instance()->consoleFont()); + + StringList l; + l.push_back("Add bookmark"); + l.push_back("Patch ROM"); + l.push_back("Save ROM"); + l.push_back("Set Breakpoint"); + l.push_back("Set PC"); + + myMenu->setList(l); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RomListWidget::~RomListWidget() { + delete myMenu; } -/* // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void RomListWidget::setList(const StringList& list, const BoolArray& state) +void RomListWidget::handleMouseDown(int x, int y, int button, int clickCount) { - _list = list; - _stateList = state; - - assert(_list.size() == _stateList.size()); - - // Enable all checkboxes - for(int i = 0; i < _rows; ++i) - _checkList[i]->setFlags(WIDGET_ENABLED); - - // Then turn off any extras - if((int)_stateList.size() < _rows) - for(int i = _stateList.size(); i < _rows; ++i) - _checkList[i]->clearFlags(WIDGET_ENABLED); - - ListWidget::recalc(); + // Grab right mouse button for context menu, send left to base class + if(button == 2) + { + myMenu->setPos(x + getAbsX(), y + getAbsY()); + myMenu->show(); + } + else + ListWidget::handleMouseDown(x, y, button, clickCount); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void RomListWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) +{ + switch(cmd) + { + case kCMenuItemSelectedCmd: + cerr << "RMB selected: " << myMenu->getSelectedString() << endl; + break; + + default: + ListWidget::handleCommand(sender, cmd, data, id); + break; + } } -*/ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void RomListWidget::drawWidget(bool hilite) diff --git a/stella/src/debugger/gui/RomListWidget.hxx b/stella/src/debugger/gui/RomListWidget.hxx index e3064a6e7..b46c87031 100644 --- a/stella/src/debugger/gui/RomListWidget.hxx +++ b/stella/src/debugger/gui/RomListWidget.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: RomListWidget.hxx,v 1.1 2005-08-30 17:51:26 stephena Exp $ +// $Id: RomListWidget.hxx,v 1.2 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -23,6 +23,7 @@ #define ROM_LIST_WIDGET_HXX class CheckboxWidget; +class ContextMenu; #include "CheckListWidget.hxx" @@ -36,10 +37,14 @@ class RomListWidget : public CheckListWidget virtual ~RomListWidget(); 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); GUI::Rect getEditRect() const; private: + ContextMenu* myMenu; int myHighlightedItem; }; diff --git a/stella/src/debugger/gui/TiaInfoWidget.cxx b/stella/src/debugger/gui/TiaInfoWidget.cxx index 071c837c4..53c7fd983 100644 --- a/stella/src/debugger/gui/TiaInfoWidget.cxx +++ b/stella/src/debugger/gui/TiaInfoWidget.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: TiaInfoWidget.cxx,v 1.1 2005-08-30 17:51:26 stephena Exp $ +// $Id: TiaInfoWidget.cxx,v 1.2 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -30,63 +30,70 @@ #include "TiaInfoWidget.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TiaInfoWidget::TiaInfoWidget(GuiObject* boss, int x, int y, int w, int h) - : Widget(boss, x, y, w, h), +TiaInfoWidget::TiaInfoWidget(GuiObject* boss, int x, int y) + : Widget(boss, x, y, 16, 16), CommandSender(boss) { + const GUI::Font& font = instance()->consoleFont(); + const int fontWidth = font.getMaxCharWidth(), + fontHeight = font.getFontHeight(), + lineHeight = font.getLineHeight(); int xpos = x, ypos = y, lwidth = 45; - const GUI::Font& font = instance()->font(); // Add frame info xpos = x + 10; ypos = y + 10; new StaticTextWidget(boss, xpos, ypos, lwidth, kLineHeight, "Frame:", kTextAlignLeft); xpos += lwidth; - myFrameCount = new EditTextWidget(boss, xpos, ypos-2, 45, kLineHeight, ""); + myFrameCount = new EditTextWidget(boss, xpos, ypos-2, 45, lineHeight, ""); myFrameCount->setFont(font); myFrameCount->setEditable(false); xpos = x + 10; ypos += kLineHeight + 5; new StaticTextWidget(boss, xpos, ypos, lwidth, kLineHeight, "F. Cycles:", kTextAlignLeft); xpos += lwidth; - myFrameCycles = new EditTextWidget(boss, xpos, ypos-2, 45, kLineHeight, ""); + myFrameCycles = new EditTextWidget(boss, xpos, ypos-2, 45, lineHeight, ""); myFrameCycles->setFont(font); myFrameCycles->setEditable(false); xpos = x + 20; ypos += kLineHeight + 5; - myVSync = new CheckboxWidget(boss, font, xpos, ypos-3, "VSync", 0); + myVSync = new CheckboxWidget(boss, instance()->font(), xpos, ypos-3, "VSync", 0); myVSync->setEditable(false); xpos = x + 20; ypos += kLineHeight + 5; - myVBlank = new CheckboxWidget(boss, font, xpos, ypos-3, "VBlank", 0); + myVBlank = new CheckboxWidget(boss, instance()->font(), xpos, ypos-3, "VBlank", 0); myVBlank->setEditable(false); xpos = x + 10 + 100; ypos = y + 10; new StaticTextWidget(boss, xpos, ypos, lwidth, kLineHeight, "Scanline:", kTextAlignLeft); xpos += lwidth; - myScanlineCount = new EditTextWidget(boss, xpos, ypos-2, 30, kLineHeight, ""); + myScanlineCount = new EditTextWidget(boss, xpos, ypos-2, 30, lineHeight, ""); myScanlineCount->setFont(font); myScanlineCount->setEditable(false); xpos = x + 10 + 100; ypos += kLineHeight + 5; new StaticTextWidget(boss, xpos, ypos, lwidth, kLineHeight, "S. Cycles:", kTextAlignLeft); xpos += lwidth; - myScanlineCycles = new EditTextWidget(boss, xpos, ypos-2, 30, kLineHeight, ""); + myScanlineCycles = new EditTextWidget(boss, xpos, ypos-2, 30, lineHeight, ""); myScanlineCycles->setFont(font); myScanlineCycles->setEditable(false); xpos = x + 10 + 100; ypos += kLineHeight + 5; new StaticTextWidget(boss, xpos, ypos, lwidth, kLineHeight, "Pixel Pos:", kTextAlignLeft); xpos += lwidth; - myPixelPosition = new EditTextWidget(boss, xpos, ypos-2, 30, kLineHeight, ""); + myPixelPosition = new EditTextWidget(boss, xpos, ypos-2, 30, lineHeight, ""); myPixelPosition->setFont(font); myPixelPosition->setEditable(false); xpos = x + 10 + 100; ypos += kLineHeight + 5; new StaticTextWidget(boss, xpos, ypos, lwidth, kLineHeight, "Color Clk:", kTextAlignLeft); xpos += lwidth; - myColorClocks = new EditTextWidget(boss, xpos, ypos-2, 30, kLineHeight, ""); + myColorClocks = new EditTextWidget(boss, xpos, ypos-2, 30, lineHeight, ""); myColorClocks->setFont(font); myColorClocks->setEditable(false); + + // Calculate actual dimensions + _w = 110 + 30 + lwidth; + _h = ypos + lineHeight; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/debugger/gui/TiaInfoWidget.hxx b/stella/src/debugger/gui/TiaInfoWidget.hxx index b8985c9d5..0a85e6fb0 100644 --- a/stella/src/debugger/gui/TiaInfoWidget.hxx +++ b/stella/src/debugger/gui/TiaInfoWidget.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: TiaInfoWidget.hxx,v 1.1 2005-08-30 17:51:26 stephena Exp $ +// $Id: TiaInfoWidget.hxx,v 1.2 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -32,7 +32,7 @@ class EditTextWidget; class TiaInfoWidget : public Widget, public CommandSender { public: - TiaInfoWidget(GuiObject *boss, int x, int y, int w, int h); + TiaInfoWidget(GuiObject *boss, int x, int y); virtual ~TiaInfoWidget(); void loadConfig(); diff --git a/stella/src/debugger/gui/TiaZoomWidget.cxx b/stella/src/debugger/gui/TiaZoomWidget.cxx new file mode 100644 index 000000000..4f693d17d --- /dev/null +++ b/stella/src/debugger/gui/TiaZoomWidget.cxx @@ -0,0 +1,151 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team +// +// 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 $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#include "OSystem.hxx" +#include "FrameBuffer.hxx" +#include "Widget.hxx" +#include "GuiObject.hxx" + +#include "TiaZoomWidget.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TiaZoomWidget::TiaZoomWidget(GuiObject* boss, int x, int y) + : Widget(boss, x, y, 16, 16), + CommandSender(boss), + myZoomLevel(2) +{ + _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS; + + _w = 200; + _h = 120; + + addFocusWidget(this); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TiaZoomWidget::~TiaZoomWidget() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TiaZoomWidget::loadConfig() +{ + setDirty(); draw(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TiaZoomWidget::zoom(int level) +{ + myZoomLevel = level; + + + // Redraw the zoomed image + loadConfig(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TiaZoomWidget::handleMouseDown(int x, int y, int button, int clickCount) +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool TiaZoomWidget::handleKeyDown(int ascii, int keycode, int modifiers) +{ + return false; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TiaZoomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TiaZoomWidget::drawWidget(bool hilite) +{ +//cerr << "TiaZoomWidget::drawWidget\n"; + FrameBuffer& fb = instance()->frameBuffer(); + + fb.fillRect(_x+1, _y+1, _w-2, _h-2, kBGColor); + fb.box(_x, _y, _w, _h, kColor, kShadowColor); + + // 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; + + int x, y, col, row; + for(y = 0, row = 0; y < numRows; ++y, row += myZoomLevel) + { + for(x = 0, col = 0; x < numCols; ++x, col += (myZoomLevel << 1)) + { + SDL_Rect temp; + + temp.x = _x + col; + temp.y = _y + row; + temp.w = myZoomLevel << 1; + temp.h = myZoomLevel; + + fb.fillRect(_x + col + 2, _y + row + 2, myZoomLevel << 1, myZoomLevel, + (OverlayColor)currentFrame[x*y]); + } + } + +/* + + + + + // 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 new file mode 100644 index 000000000..90c57b642 --- /dev/null +++ b/stella/src/debugger/gui/TiaZoomWidget.hxx @@ -0,0 +1,54 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team +// +// 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 $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#ifndef TIA_ZOOM_WIDGET_HXX +#define TIA_ZOOM_WIDGET_HXX + +class GuiObject; + +#include "Widget.hxx" +#include "Command.hxx" + + +class TiaZoomWidget : public Widget, public CommandSender +{ + public: + TiaZoomWidget(GuiObject *boss, int x, int y); + virtual ~TiaZoomWidget(); + + void loadConfig(); + + protected: + void handleMouseDown(int x, int y, int button, int clickCount); + bool handleKeyDown(int ascii, int keycode, int modifiers); + void handleCommand(CommandSender* sender, int cmd, int data, int id); + + void drawWidget(bool hilite); + bool wantsFocus() { return true; } + + private: + void zoom(int level); + + private: + int myZoomLevel; +}; + +#endif diff --git a/stella/src/debugger/gui/module.mk b/stella/src/debugger/gui/module.mk index 825523603..e957afb95 100644 --- a/stella/src/debugger/gui/module.mk +++ b/stella/src/debugger/gui/module.mk @@ -9,7 +9,9 @@ MODULE_OBJS := \ src/debugger/gui/TiaWidget.o \ src/debugger/gui/TiaInfoWidget.o \ src/debugger/gui/TiaOutputWidget.o \ + src/debugger/gui/TiaZoomWidget.o \ src/debugger/gui/ColorWidget.o \ + src/debugger/gui/ContextMenu.o \ src/debugger/gui/DataGridOpsWidget.o \ src/debugger/gui/DataGridWidget.o \ src/debugger/gui/DebuggerDialog.o \ diff --git a/stella/src/gui/Dialog.cxx b/stella/src/gui/Dialog.cxx index 85e738d9a..7ee49264e 100644 --- a/stella/src/gui/Dialog.cxx +++ b/stella/src/gui/Dialog.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: Dialog.cxx,v 1.28 2005-08-26 16:44:17 stephena Exp $ +// $Id: Dialog.cxx,v 1.29 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -75,7 +75,8 @@ void Dialog::open() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::close() { - if (_mouseWidget) { + if (_mouseWidget) + { _mouseWidget->handleMouseLeft(0); _mouseWidget = 0; } @@ -220,6 +221,7 @@ void Dialog::handleMouseDown(int x, int y, int button, int clickCount) _focusedWidget = Widget::setFocusForChain(this, getFocusList(), w, 0); } + if(w) w->handleMouseDown(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button, clickCount); } diff --git a/stella/src/gui/DialogContainer.cxx b/stella/src/gui/DialogContainer.cxx index 5b672827a..29f8eb064 100644 --- a/stella/src/gui/DialogContainer.cxx +++ b/stella/src/gui/DialogContainer.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: DialogContainer.cxx,v 1.17 2005-08-29 18:36:42 stephena Exp $ +// $Id: DialogContainer.cxx,v 1.18 2005-08-31 19:15:10 stephena Exp $ //============================================================================ #include "OSystem.hxx" @@ -184,6 +184,7 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, int x, int y, uInt8 // Send the event to the dialog box on the top of the stack Dialog* activeDialog = myDialogStack.top(); + int button = (b == EVENT_LBUTTONDOWN || b == EVENT_LBUTTONUP) ? 1 : 2; switch(b) { case EVENT_LBUTTONDOWN: @@ -213,20 +214,20 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, int x, int y, uInt8 // Now account for repeated mouse events (click and hold) myCurrentMouseDown.x = x; myCurrentMouseDown.y = y; - myCurrentMouseDown.button = 1; // in the future, we may differentiate buttons + myCurrentMouseDown.button = button; myClickRepeatTime = myTime + kClickRepeatInitialDelay; activeDialog->handleMouseDown(x - activeDialog->_x, y - activeDialog->_y, - 1, myLastClick.count); + button, myLastClick.count); break; case EVENT_LBUTTONUP: case EVENT_RBUTTONUP: activeDialog->handleMouseUp(x - activeDialog->_x, y - activeDialog->_y, - 1, myLastClick.count); - // Since all buttons are treated equally, we don't need to check which button - //if (button == myCurrentClickDown.button) - myCurrentMouseDown.button = -1; + button, myLastClick.count); + + if(button == myCurrentMouseDown.button) + myCurrentMouseDown.button = -1; break; case EVENT_WHEELUP: diff --git a/stella/src/gui/GuiObject.hxx b/stella/src/gui/GuiObject.hxx index 6a9e87b3d..e848833a3 100644 --- a/stella/src/gui/GuiObject.hxx +++ b/stella/src/gui/GuiObject.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: GuiObject.hxx,v 1.14 2005-08-10 12:23:42 stephena Exp $ +// $Id: GuiObject.hxx,v 1.15 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -22,12 +22,13 @@ #ifndef GUI_OBJECT_HXX #define GUI_OBJECT_HXX -class OSystem; class DialogContainer; class Widget; #include "Command.hxx" +#include "OSystem.hxx" #include "Array.hxx" +#include "Font.hxx" typedef GUI::Array WidgetArray; @@ -35,7 +36,7 @@ typedef GUI::Array WidgetArray; This is the base class for all GUI objects/widgets. @author Stephen Anthony - @version $Id: GuiObject.hxx,v 1.14 2005-08-10 12:23:42 stephena Exp $ + @version $Id: GuiObject.hxx,v 1.15 2005-08-31 19:15:10 stephena Exp $ */ class GuiObject : public CommandReceiver { @@ -51,6 +52,7 @@ class GuiObject : public CommandReceiver _w(w), _h(h), _dirty(true), + _font((GUI::Font*)&(osystem->font())), _firstWidget(0) {} virtual ~GuiObject() {} @@ -65,11 +67,15 @@ class GuiObject : public CommandReceiver virtual int getWidth() const { return _w; } virtual int getHeight() const { return _h; } - virtual void setWidth(int w) { _w = w; } - virtual void setHeight(int h) { _h = h; } + virtual void setPos(int x, int y) { _x = x; _y = y; } + virtual void setWidth(int w) { _w = w; } + virtual void setHeight(int h) { _h = h; } virtual void setDirty() { _dirty = true; } + virtual void setFont(const GUI::Font& font) { _font = (GUI::Font*) &font; } + virtual const GUI::Font* font() { return _font; } + virtual bool isVisible() const = 0; virtual void draw() = 0; @@ -93,6 +99,8 @@ class GuiObject : public CommandReceiver int _w, _h; bool _dirty; + GUI::Font* _font; + Widget* _firstWidget; WidgetArray _focusList; }; diff --git a/stella/src/gui/Widget.cxx b/stella/src/gui/Widget.cxx index 48c47a068..c983d10c8 100644 --- a/stella/src/gui/Widget.cxx +++ b/stella/src/gui/Widget.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: Widget.cxx,v 1.33 2005-08-24 13:18:02 stephena Exp $ +// $Id: Widget.cxx,v 1.34 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -39,8 +39,7 @@ Widget::Widget(GuiObject* boss, int x, int y, int w, int h) _id(-1), _flags(0), _hasFocus(false), - _color(kTextColor), - _font((GUI::Font*)&(boss->instance()->font())) + _color(kTextColor) { // Insert into the widget list of the boss _next = _boss->_firstWidget; diff --git a/stella/src/gui/Widget.hxx b/stella/src/gui/Widget.hxx index e8a07baeb..49c4a48cd 100644 --- a/stella/src/gui/Widget.hxx +++ b/stella/src/gui/Widget.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: Widget.hxx,v 1.35 2005-08-24 13:18:02 stephena Exp $ +// $Id: Widget.hxx,v 1.36 2005-08-31 19:15:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -71,7 +71,7 @@ enum { This is the base class for all widgets. @author Stephen Anthony - @version $Id: Widget.hxx,v 1.35 2005-08-24 13:18:02 stephena Exp $ + @version $Id: Widget.hxx,v 1.36 2005-08-31 19:15:10 stephena Exp $ */ class Widget : public GuiObject { @@ -116,8 +116,6 @@ class Widget : public GuiObject int getID() { return _id; } void setColor(OverlayColor color) { _color = color; } - void setFont(const GUI::Font& font) { _font = (GUI::Font*) &font; } - const GUI::Font* font() { return _font; } virtual void loadConfig() {} @@ -143,7 +141,6 @@ class Widget : public GuiObject int _flags; bool _hasFocus; OverlayColor _color; - GUI::Font* _font; public: static Widget* findWidgetInChain(Widget* start, int x, int y);