From: Shamus Hammons Date: Wed, 22 Jun 2011 04:05:05 +0000 (+0000) Subject: Various improvements to the GUI, including Power and Pause buttons, Load X-Git-Tag: 2.0.0~34^2~20 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=481bb094f715443e52695fc46307785e61556c0d;p=virtualjaguar Various improvements to the GUI, including Power and Pause buttons, Load cartridge actually works now. Artwork improvements. Bugfixes related to loading software from zips that contain more than one file. --- diff --git a/res/cart-blank.png b/res/cart-blank.png index fe8c575..976a23d 100644 Binary files a/res/cart-blank.png and b/res/cart-blank.png differ diff --git a/res/controller.png b/res/controller.png new file mode 100644 index 0000000..fdac71f Binary files /dev/null and b/res/controller.png differ diff --git a/res/insert.png b/res/insert.png new file mode 100644 index 0000000..7342009 Binary files /dev/null and b/res/insert.png differ diff --git a/res/label-blank.png b/res/label-blank.png index 46538f6..6ef1128 100644 Binary files a/res/label-blank.png and b/res/label-blank.png differ diff --git a/res/pause.png b/res/pause.png new file mode 100644 index 0000000..1032cb9 Binary files /dev/null and b/res/pause.png differ diff --git a/res/software.png b/res/software.png new file mode 100644 index 0000000..6ce06c5 Binary files /dev/null and b/res/software.png differ diff --git a/res/upper-left.png b/res/upper-left.png new file mode 100644 index 0000000..d2f5f34 Binary files /dev/null and b/res/upper-left.png differ diff --git a/res/upper-right.png b/res/upper-right.png new file mode 100644 index 0000000..49b68cb Binary files /dev/null and b/res/upper-right.png differ diff --git a/res/vj-icon.png b/res/vj-icon.png new file mode 100644 index 0000000..fc304e1 Binary files /dev/null and b/res/vj-icon.png differ diff --git a/src/file.cpp b/src/file.cpp index 8c1a703..81b5e08 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -40,63 +40,58 @@ uint32 JaguarLoadROM(uint8 * rom, char * path) #warning "!!! FIX !!! Should have sanity checking for ROM size to prevent buffer overflow!" uint32 romSize = 0; -WriteLog("JaguarLoadROM: Attempting to load file '%s'...", path); + WriteLog("JaguarLoadROM: Attempting to load file '%s'...", path); char * ext = strrchr(path, '.'); -if (ext == NULL) - WriteLog("FAILED!\n"); -else - WriteLog("Succeeded in finding extension (%s)!\n", ext); - if (ext != NULL) + // No filename extension == YUO FAIL IT (it is loading the file). + // This is naive, but it works. But should probably come up with something a little + // more robust, to prevent problems with dopes trying to exploit this. + if (ext == NULL) { - WriteLog("VJ: Loading \"%s\"...", path); - - if (strcasecmp(ext, ".zip") == 0) - { - // Handle ZIP file loading here... - WriteLog("(ZIPped)..."); + WriteLog("FAILED!\n"); + return 0; + } - if (load_zipped_file(0, 0, path, NULL, &rom, &romSize) == -1) - { - WriteLog("Failed!\n"); - return 0; - } - } - else - { -/* FILE * fp = fopen(path, "rb"); + WriteLog("Succeeded in finding extension (%s)!\n", ext); + WriteLog("VJ: Loading \"%s\"...", path); - if (fp == NULL) - { - WriteLog("Failed!\n"); - return 0; - } + if (strcasecmp(ext, ".zip") == 0) + { + // Handle ZIP file loading here... + WriteLog("(ZIPped)..."); - fseek(fp, 0, SEEK_END); - romSize = ftell(fp); - fseek(fp, 0, SEEK_SET); - fread(rom, 1, romSize, fp); - fclose(fp);*/ + uint8_t * buffer = NULL; + romSize = GetFileFromZIP(path, FT_SOFTWARE, buffer); - // Handle gzipped files transparently [Adam Green]... + if (romSize == 0) + { + WriteLog("Failed!\n"); + return 0; + } - gzFile fp = gzopen(path, "rb"); + memcpy(rom, buffer, romSize); + delete[] buffer; + } + else + { + // Handle gzipped files transparently [Adam Green]... - if (fp == NULL) - { - WriteLog("Failed!\n"); - return 0; - } + gzFile fp = gzopen(path, "rb"); - romSize = gzfilelength(fp); - gzseek(fp, 0, SEEK_SET); - gzread(fp, rom, romSize); - gzclose(fp); + if (fp == NULL) + { + WriteLog("Failed!\n"); + return 0; } - WriteLog("OK (%i bytes)\n", romSize); + romSize = gzfilelength(fp); + gzseek(fp, 0, SEEK_SET); + gzread(fp, rom, romSize); + gzclose(fp); } + WriteLog("OK (%i bytes)\n", romSize); + return romSize; } @@ -136,6 +131,7 @@ bool JaguarLoadFile(char * path) char * ext = strrchr(path, '.'); // Get the file's extension for non-cartridge checking //NOTE: Should fix JaguarLoadROM() to replace .zip with what's *in* the zip (.abs, .j64, etc.) +#warning "!!! Need more robust file type checking in JaguarLoadROM() !!!" if (strcasecmp(ext, ".rom") == 0) { // File extension ".ROM": Alpine image that loads/runs at $802000 @@ -360,9 +356,13 @@ static bool CheckExtension(const char * filename, const char * ext) // // Get file from .ZIP // Returns the size of the file inside the .ZIP file that we're looking at +// NOTE: If the thing we're looking for is found, it allocates it in the passed in buffer. +// Which means we have to deallocate it later. // uint32 GetFileFromZIP(const char * zipFile, FileType type, uint8 * &buffer) { +// NOTE: We could easily check for this by discarding anything that's larger than the RAM/ROM +// size of the Jaguar console. #warning "!!! FIX !!! Should have sanity checking for ROM size to prevent buffer overflow!" const char ftStrings[5][32] = { "Software", "EEPROM", "Label", "Box Art", "Controller Overlay" }; ZIP * zip = openzip(0, 0, zipFile); @@ -378,6 +378,10 @@ uint32 GetFileFromZIP(const char * zipFile, FileType type, uint8 * &buffer) zipent * ze = &zip->ent; bool found = false; + // Here we simply rely on the file extension to tell the truth, but we know + // that extensions lie like sons-a-bitches. So this is naive, we need to do + // something a little more robust to keep bad things from happening here. +#warning "!!! Checking for image by extension can be fooled !!!" if ((type == FT_LABEL) && (CheckExtension(ze->name, ".png") || CheckExtension(ze->name, ".jpg") || CheckExtension(ze->name, ".gif"))) { found = true; @@ -399,17 +403,21 @@ uint32 GetFileFromZIP(const char * zipFile, FileType type, uint8 * &buffer) if (found) { WriteLog("FILE: Uncompressing..."); +// Insert file size sanity check here... buffer = new uint8[ze->uncompressed_size]; if (readuncompresszip(zip, ze, (char *)buffer) == 0) { WriteLog("success! (%u bytes)\n", ze->uncompressed_size); + closezip(zip); return ze->uncompressed_size; } else { WriteLog("FAILED!\n"); delete[] buffer; + buffer = NULL; + closezip(zip); return 0; } } diff --git a/src/gui/filepicker.cpp b/src/gui/filepicker.cpp index f2ed0ac..d7f1507 100644 --- a/src/gui/filepicker.cpp +++ b/src/gui/filepicker.cpp @@ -140,7 +140,10 @@ printf("VSB size: %u, %u\n", sbSize3.width(), sbSize3.height()); data->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); dataLayout->addWidget(data); - insertCart = new QPushButton(QIcon(":/res/generic.png"), "", this); +//#warning "!!! Icon size for pushbutton is tiny !!!" + insertCart = new QPushButton(this); + insertCart->setIconSize(QSize(40, 40)); + insertCart->setIcon(QIcon(":/res/insert.png")); insertCart->setDefault(true); // We want this button to be the default insertCart->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); dataLayout->addWidget(insertCart); @@ -171,6 +174,11 @@ New sizes: 373x172 (label), 420x340 (cart) connect(insertCart, SIGNAL(clicked()), this, SLOT(LoadButtonPressed())); } +QString FilePickerWindow::GetSelectedPrettyName(void) +{ + return prettyFilename; +} + // // This slot gets called by the FileThread's run() function when it finds a // match in the filesystem to a ROM on our CRC list. @@ -228,6 +236,7 @@ void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModel //currentFile = s; //373x172 is label size... +//365x168 now... if (!label.isNull()) { /* @@ -243,8 +252,14 @@ void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModel //QImage scaledImg = label.scaled(373, 172, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); //painter.drawPixmap(23, 87, QPixmap::fromImage(scaledImg)); // Now, looks like it is... - painter.drawPixmap(23, 87, QPixmap::fromImage(label)); +// painter.drawPixmap(23, 87, QPixmap::fromImage(label)); + painter.drawPixmap(27, 89, QPixmap::fromImage(label)); // painter.drawPixmap(23, 87, 373, 172, QPixmap::fromImage(label)); + +// Well, heck. This should be done to the label *before* we get here. + painter.drawPixmap(27, 89, QPixmap::fromImage(QImage(":/res/upper-left.png"))); + painter.drawPixmap(27+355, 89, QPixmap::fromImage(QImage(":/res/upper-right.png"))); + painter.end(); cartImage->setPixmap(QPixmap::fromImage(cart)); } @@ -255,7 +270,8 @@ void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModel // redraw regardless. QImage cart(":/res/cart-blank.png"); QPainter painter(&cart); - painter.drawPixmap(23, 87, QPixmap::fromImage(QImage(":/res/label-blank.png"))); +// painter.drawPixmap(23, 87, QPixmap::fromImage(QImage(":/res/label-blank.png"))); + painter.drawPixmap(27, 89, QPixmap::fromImage(QImage(":/res/label-blank.png"))); painter.end(); cartImage->setPixmap(QPixmap::fromImage(cart)); } @@ -263,6 +279,7 @@ void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModel //1048576 //2097152 //4194304 + prettyFilename = romList[i].name; title->setText(QString("

%1

").arg(romList[i].name)); //Kludge for now, we'll have to fix this later... QString fileType = QString(romList[i].flags & FF_ROM ? "%1MB Cartridge" : "%1*** UNKNOWN ***") diff --git a/src/gui/filepicker.h b/src/gui/filepicker.h index 3ab470b..5ffafde 100644 --- a/src/gui/filepicker.h +++ b/src/gui/filepicker.h @@ -18,6 +18,7 @@ class FilePickerWindow: public QWidget public: FilePickerWindow(QWidget * parent = 0); + QString GetSelectedPrettyName(void); public slots: void AddFileToList(unsigned long index); @@ -33,6 +34,7 @@ class FilePickerWindow: public QWidget private: QString currentFile; + QString prettyFilename; QListWidget * fileList2; FileThread * fileThread; FileListModel * model; diff --git a/src/gui/filethread.cpp b/src/gui/filethread.cpp index dd1a540..112e848 100644 --- a/src/gui/filethread.cpp +++ b/src/gui/filethread.cpp @@ -99,6 +99,7 @@ printf("FileThread: Aborting!!!\n"); uint32 crc = crc32_calcCheckSum(buffer, size); uint32 index = FindCRCIndexInFileList(crc); // These two are NOT interchangeable! +//Hm, confusing. It looks like in file.cpp it uses operater new() to create the buffer... // delete[] buffer; free(buffer); @@ -133,9 +134,11 @@ QImage * imageCopy = new QImage(); QImage label; bool success = label.loadFromData(buffer, size); img = new QImage(); - *img = label.scaled(373, 172, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +// *img = label.scaled(373, 172, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + *img = label.scaled(365, 168, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); //printf("FT: Label %s: %ux%u.\n", (success ? "succeeded" : "did not succeed"), img->width(), img->height()); // These two are NOT interchangeable! +//Hm, confusing. It looks like in file.cpp it uses operater new() to create the buffer... // delete[] buffer; free(buffer); } diff --git a/src/gui/mainwin.cpp b/src/gui/mainwin.cpp index 4f9dcce..c0f215e 100644 --- a/src/gui/mainwin.cpp +++ b/src/gui/mainwin.cpp @@ -63,16 +63,18 @@ // We'll make the VJ core modular so that it doesn't matter what GUI is in // use, we can drop it in anywhere and use it as-is. -MainWin::MainWin(): showUntunedTankCircuit(true) +MainWin::MainWin(): running(false), powerButtonOn(false), showUntunedTankCircuit(true), + cartridgeLoaded(false) { videoWidget = new GLWidget(this); setCentralWidget(videoWidget); - setWindowIcon(QIcon(":/res/vj.xpm")); + setWindowIcon(QIcon(":/res/vj-icon.png")); setWindowTitle("Virtual Jaguar v2.0.0"); ReadSettings(); setUnifiedTitleAndToolBarOnMac(true); +#warning "!!! Save/Restore window location for FilePickerWindow !!!" aboutWin = new AboutWindow(this); filePickWin = new FilePickerWindow(this); @@ -87,9 +89,17 @@ MainWin::MainWin(): showUntunedTankCircuit(true) connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close())); powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this); - powerAct->setStatusTip(tr("Toggle running state")); + powerAct->setStatusTip(tr("Powers Jaguar on/off")); powerAct->setCheckable(true); - connect(powerAct, SIGNAL(triggered()), this, SLOT(ToggleRunState())); + powerAct->setChecked(false); + powerAct->setDisabled(true); + connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState())); + + pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this); + pauseAct->setStatusTip(tr("Toggles the running state")); + pauseAct->setCheckable(true); + pauseAct->setDisabled(true); + connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState())); zoomActs = new QActionGroup(this); @@ -129,7 +139,8 @@ MainWin::MainWin(): showUntunedTankCircuit(true) aboutAct->setStatusTip(tr("Blatant self-promotion")); connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin())); - filePickAct = new QAction(QIcon(":/res/generic.png"), tr("&Insert Cartridge..."), this); +#warning "!!! Set up a decent keyboard shortcut for Insert Cartridge !!!" + filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this); filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar")); connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart())); @@ -141,6 +152,7 @@ MainWin::MainWin(): showUntunedTankCircuit(true) fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(filePickAct); fileMenu->addAction(powerAct); + fileMenu->addAction(pauseAct); fileMenu->addAction(quitAppAct); helpMenu = menuBar()->addMenu(tr("&Help")); @@ -148,6 +160,7 @@ MainWin::MainWin(): showUntunedTankCircuit(true) toolbar = addToolBar(tr("Stuff")); toolbar->addAction(powerAct); + toolbar->addAction(pauseAct); toolbar->addAction(filePickAct); toolbar->addSeparator(); toolbar->addAction(x1Act); @@ -380,6 +393,30 @@ doGPUDis = true;//*/ } #endif +void MainWin::TogglePowerState(void) +{ + powerButtonOn = !powerButtonOn; + + if (!powerButtonOn) + { + pauseAct->setChecked(false); + pauseAct->setDisabled(true); + showUntunedTankCircuit = true; + running = true; + } + else + { + showUntunedTankCircuit = (cartridgeLoaded ? false : true); + pauseAct->setDisabled(!cartridgeLoaded); +//This is crappy!!! !!! FIX !!! +//Is this even needed any more? Hmm. Maybe. Dunno. +//Seems like it is... But then again, maybe not. Have to test it to see. + WriteLog("GUI: Resetting Jaguar...\n"); + JaguarReset(); + running = true; + } +} + void MainWin::ToggleRunState(void) { running = !running; @@ -459,13 +496,26 @@ void MainWin::LoadSoftware(QString file) { running = false; // Prevent bad things(TM) from happening... SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack... - showUntunedTankCircuit = (JaguarLoadFile(file.toAscii().data()) ? false : true); + cartridgeLoaded = (JaguarLoadFile(file.toAscii().data()) ? true : false); + +#if 0 + showUntunedTankCircuit = !cartridgeLoaded; //This is crappy!!! !!! FIX !!! //Is this even needed any more? Hmm. Maybe. Dunno. //Seems like it is... But then again, maybe not. Have to test it to see. WriteLog("GUI: Resetting Jaguar...\n"); JaguarReset(); running = true; +#else + powerAct->setDisabled(false); + powerAct->setChecked(true); + powerButtonOn = false; + TogglePowerState(); +#endif + + QString newTitle = QString("Virtual Jaguar 2.0.0 - Now playing: %1") + .arg(filePickWin->GetSelectedPrettyName()); + setWindowTitle(newTitle); } void MainWin::ResizeMainWindow(void) diff --git a/src/gui/mainwin.h b/src/gui/mainwin.h index 820b860..78a37b9 100644 --- a/src/gui/mainwin.h +++ b/src/gui/mainwin.h @@ -30,6 +30,7 @@ class MainWin: public QMainWindow private slots: void Open(void); void Timer(void); + void TogglePowerState(void); void ToggleRunState(void); void SetZoom100(void); void SetZoom200(void); @@ -55,7 +56,9 @@ class MainWin: public QMainWindow QTimer * timer; bool running; int zoomLevel; + bool powerButtonOn; bool showUntunedTankCircuit; + bool cartridgeLoaded; QMenu * fileMenu; QMenu * helpMenu; @@ -66,6 +69,7 @@ class MainWin: public QMainWindow QAction * quitAppAct; QAction * powerAct; + QAction * pauseAct; QAction * x1Act; QAction * x2Act; QAction * x3Act; diff --git a/src/gui/virtualjaguar.qrc b/src/gui/virtualjaguar.qrc index 4f7e92a..a29ef87 100644 --- a/src/gui/virtualjaguar.qrc +++ b/src/gui/virtualjaguar.qrc @@ -1,7 +1,8 @@ - ../../res/vj.xpm + ../../res/vj-icon.png ../../res/power.png + ../../res/pause.png ../../res/zoom100.png ../../res/zoom200.png ../../res/zoom300.png @@ -9,6 +10,10 @@ ../../res/cart-blank.png ../../res/label-blank.png ../../res/vj_title_small.png - ../../res/labels/rayman.jpg + ../../res/controller.png + ../../res/insert.png + ../../res/software.png + ../../res/upper-left.png + ../../res/upper-right.png