GTK GUI :

- Initial work to allow multiple dislay drivers


git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@489 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2008-04-21 16:46:22 +00:00
parent 9d19c9b9f6
commit 3090c69c7b
8 changed files with 234 additions and 153 deletions

View File

@ -140,6 +140,7 @@ SET(SRC_GTK
src/gtk/filters.cpp
src/gtk/joypadconfig.cpp
src/gtk/screenarea.cpp
src/gtk/screenarea-gtk.cpp
src/gtk/tools.cpp
src/gtk/window.cpp
src/gtk/sndPortAudio.cpp

175
src/gtk/screenarea-gtk.cpp Normal file
View File

@ -0,0 +1,175 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// 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, 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.
#include "screenarea-gtk.h"
#include <string.h>
namespace VBA
{
ScreenAreaGtk::ScreenAreaGtk(int _iWidth, int _iHeight, int _iScale) :
ScreenArea(_iWidth, _iHeight, _iScale),
m_puiPixels(NULL),
m_puiDelta(NULL)
{
vUpdateSize();
}
ScreenAreaGtk::~ScreenAreaGtk()
{
if (m_puiPixels != NULL)
{
delete[] m_puiPixels;
}
if (m_puiDelta != NULL)
{
delete[] m_puiDelta;
}
}
void ScreenAreaGtk::vDrawPixels(u8 * _puiData)
{
if (m_vFilterIB != NULL)
{
m_vFilterIB(_puiData + m_iAreaWidth * 2 + 4,
m_iAreaWidth * 2 + 4,
m_iWidth,
m_iHeight);
}
if (m_iScale == 1)
{
u32 * puiSrc = (u32 *)_puiData + m_iWidth + 1;
u32 * puiPixel = m_puiPixels;
for (int y = 0; y < m_iHeight; y++)
{
for (int x = 0; x < m_iWidth; x++)
{
*puiPixel++ = *puiSrc++;
}
puiSrc++;
}
}
else if (m_iScale == 2 && m_vFilter2x != NULL)
{
m_vFilter2x(_puiData + m_iAreaWidth * 2 + 4,
m_iAreaWidth * 2 + 4,
m_puiDelta,
(u8 *)m_puiPixels,
m_iRowStride,
m_iWidth,
m_iHeight);
}
else
{
u32 * puiSrc = (u32 *)_puiData + m_iWidth + 1;
u32 * puiSrc2;
u32 * puiPixel = m_puiPixels;
for (int y = 0; y < m_iHeight; y++)
{
for (int j = 0; j < m_iScale; j++)
{
puiSrc2 = puiSrc;
for (int x = 0; x < m_iWidth; x++)
{
for (int i = 0; i < m_iScale; i++)
{
*puiPixel++ = *puiSrc2;
}
puiSrc2++;
}
}
puiSrc = puiSrc2 + 1;
}
}
queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight);
}
void ScreenAreaGtk::vDrawColor(u32 _uiColor)
{
_uiColor = GUINT32_TO_BE(_uiColor) << 8;
u32 * puiPixel = m_puiPixels;
u32 * puiEnd = m_puiPixels + m_iAreaWidth * m_iAreaHeight;
while (puiPixel != puiEnd)
{
*puiPixel++ = _uiColor;
}
queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight);
}
void ScreenAreaGtk::vUpdateSize()
{
if (m_puiPixels != NULL)
{
delete[] m_puiPixels;
}
if (m_puiDelta != NULL)
{
delete[] m_puiDelta;
}
m_iAreaWidth = m_iScale * m_iWidth;
m_iAreaHeight = m_iScale * m_iHeight;
m_iRowStride = m_iAreaWidth * 4;
m_puiPixels = new u32[m_iAreaWidth * m_iAreaHeight];
m_puiDelta = new u8[(m_iWidth + 2) * (m_iHeight + 2) * 4];
memset(m_puiDelta, 255, (m_iWidth + 2) * (m_iHeight + 2) * 4);
set_size_request(m_iAreaWidth, m_iAreaHeight);
}
bool ScreenAreaGtk::on_expose_event(GdkEventExpose * _pstEvent)
{
if (_pstEvent->area.x + _pstEvent->area.width > m_iAreaWidth
|| _pstEvent->area.y + _pstEvent->area.height > m_iAreaHeight)
{
return false;
}
guchar * puiAreaPixels = (guchar *)m_puiPixels;
if (_pstEvent->area.x != 0)
{
puiAreaPixels += _pstEvent->area.x << 2;
}
if (_pstEvent->area.y != 0)
{
puiAreaPixels += _pstEvent->area.y * m_iRowStride;
}
get_window()->draw_rgb_32_image(get_style()->get_fg_gc(get_state()),
_pstEvent->area.x,
_pstEvent->area.y,
_pstEvent->area.width,
_pstEvent->area.height,
Gdk::RGB_DITHER_MAX,
puiAreaPixels,
m_iRowStride);
return true;
}
} // namespace VBA

50
src/gtk/screenarea-gtk.h Normal file
View File

@ -0,0 +1,50 @@
// -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// 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, 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.
#ifndef __VBA_SCREENAREA_GTK_H__
#define __VBA_SCREENAREA_GTK_H__
#include "screenarea.h"
namespace VBA
{
class ScreenAreaGtk : public ScreenArea
{
public:
ScreenAreaGtk(int _iWidth, int _iHeight, int _iScale = 1);
virtual ~ScreenAreaGtk();
void vDrawPixels(u8 * _puiData);
void vDrawColor(u32 _uiColor); // 0xRRGGBB
protected:
bool on_expose_event(GdkEventExpose * _pstEvent);
private:
int m_iRowStride;
u32 * m_puiPixels;
u8 * m_puiDelta;
void vUpdateSize();
};
} // namespace VBA
#endif // __VBA_SCREENAREA_GTK_H__

View File

@ -24,8 +24,6 @@ namespace VBA
{
ScreenArea::ScreenArea(int _iWidth, int _iHeight, int _iScale) :
m_puiPixels(NULL),
m_puiDelta(NULL),
m_vFilter2x(NULL),
m_vFilterIB(NULL),
m_bShowCursor(true)
@ -35,7 +33,6 @@ ScreenArea::ScreenArea(int _iWidth, int _iHeight, int _iScale) :
m_iWidth = _iWidth;
m_iHeight = _iHeight;
m_iScale = _iScale;
vUpdateSize();
set_events(Gdk::EXPOSURE_MASK
| Gdk::POINTER_MOTION_MASK
@ -56,16 +53,6 @@ ScreenArea::ScreenArea(int _iWidth, int _iHeight, int _iScale) :
ScreenArea::~ScreenArea()
{
if (m_puiPixels != NULL)
{
delete[] m_puiPixels;
}
if (m_puiDelta != NULL)
{
delete[] m_puiDelta;
}
if (m_poEmptyCursor != NULL)
{
delete m_poEmptyCursor;
@ -105,103 +92,6 @@ void ScreenArea::vSetFilterIB(EFilterIB _eFilterIB)
m_vFilterIB = pvGetFilterIB(_eFilterIB, FilterDepth32);
}
void ScreenArea::vDrawPixels(u8 * _puiData)
{
if (m_vFilterIB != NULL)
{
m_vFilterIB(_puiData + m_iAreaWidth * 2 + 4,
m_iAreaWidth * 2 + 4,
m_iWidth,
m_iHeight);
}
if (m_iScale == 1)
{
u32 * puiSrc = (u32 *)_puiData + m_iWidth + 1;
u32 * puiPixel = m_puiPixels;
for (int y = 0; y < m_iHeight; y++)
{
for (int x = 0; x < m_iWidth; x++)
{
*puiPixel++ = *puiSrc++;
}
puiSrc++;
}
}
else if (m_iScale == 2 && m_vFilter2x != NULL)
{
m_vFilter2x(_puiData + m_iAreaWidth * 2 + 4,
m_iAreaWidth * 2 + 4,
m_puiDelta,
(u8 *)m_puiPixels,
m_iRowStride,
m_iWidth,
m_iHeight);
}
else
{
u32 * puiSrc = (u32 *)_puiData + m_iWidth + 1;
u32 * puiSrc2;
u32 * puiPixel = m_puiPixels;
for (int y = 0; y < m_iHeight; y++)
{
for (int j = 0; j < m_iScale; j++)
{
puiSrc2 = puiSrc;
for (int x = 0; x < m_iWidth; x++)
{
for (int i = 0; i < m_iScale; i++)
{
*puiPixel++ = *puiSrc2;
}
puiSrc2++;
}
}
puiSrc = puiSrc2 + 1;
}
}
queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight);
}
void ScreenArea::vDrawColor(u32 _uiColor)
{
_uiColor = GUINT32_TO_BE(_uiColor) << 8;
u32 * puiPixel = m_puiPixels;
u32 * puiEnd = m_puiPixels + m_iAreaWidth * m_iAreaHeight;
while (puiPixel != puiEnd)
{
*puiPixel++ = _uiColor;
}
queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight);
}
void ScreenArea::vUpdateSize()
{
if (m_puiPixels != NULL)
{
delete[] m_puiPixels;
}
if (m_puiDelta != NULL)
{
delete[] m_puiDelta;
}
m_iAreaWidth = m_iScale * m_iWidth;
m_iAreaHeight = m_iScale * m_iHeight;
m_iRowStride = m_iAreaWidth * 4;
m_puiPixels = new u32[m_iAreaWidth * m_iAreaHeight];
m_puiDelta = new u8[(m_iWidth + 2) * (m_iHeight + 2) * 4];
memset(m_puiDelta, 255, (m_iWidth + 2) * (m_iHeight + 2) * 4);
set_size_request(m_iAreaWidth, m_iAreaHeight);
}
void ScreenArea::vStartCursorTimeout()
{
m_oCursorSig.disconnect();
@ -227,37 +117,6 @@ void ScreenArea::vShowCursor()
m_bShowCursor = true;
}
bool ScreenArea::on_expose_event(GdkEventExpose * _pstEvent)
{
if (_pstEvent->area.x + _pstEvent->area.width > m_iAreaWidth
|| _pstEvent->area.y + _pstEvent->area.height > m_iAreaHeight)
{
return false;
}
guchar * puiAreaPixels = (guchar *)m_puiPixels;
if (_pstEvent->area.x != 0)
{
puiAreaPixels += _pstEvent->area.x << 2;
}
if (_pstEvent->area.y != 0)
{
puiAreaPixels += _pstEvent->area.y * m_iRowStride;
}
get_window()->draw_rgb_32_image(get_style()->get_fg_gc(get_state()),
_pstEvent->area.x,
_pstEvent->area.y,
_pstEvent->area.width,
_pstEvent->area.height,
Gdk::RGB_DITHER_MAX,
puiAreaPixels,
m_iRowStride);
return true;
}
bool ScreenArea::on_motion_notify_event(GdkEventMotion * _pstEvent)
{
if (! m_bShowCursor)

View File

@ -38,25 +38,21 @@ public:
void vSetScale(int _iScale);
void vSetFilter2x(EFilter2x _eFilter2x);
void vSetFilterIB(EFilterIB _eFilterIB);
void vDrawPixels(u8 * _puiData);
void vDrawColor(u32 _uiColor); // 0xRRGGBB
virtual void vDrawPixels(u8 * _puiData) = 0;
virtual void vDrawColor(u32 _uiColor) = 0; // 0xRRGGBB
protected:
virtual bool on_expose_event(GdkEventExpose * _pstEvent);
virtual bool on_expose_event(GdkEventExpose * _pstEvent) = 0;
virtual bool on_motion_notify_event(GdkEventMotion * _pstEvent);
virtual bool on_enter_notify_event(GdkEventCrossing * _pstEvent);
virtual bool on_leave_notify_event(GdkEventCrossing * _pstEvent);
virtual bool bOnCursorTimeout();
private:
int m_iWidth;
int m_iHeight;
int m_iScale;
int m_iAreaWidth;
int m_iAreaHeight;
int m_iRowStride;
u32 * m_puiPixels;
u8 * m_puiDelta;
Filter2x m_vFilter2x;
FilterIB m_vFilterIB;
@ -64,7 +60,7 @@ private:
Gdk::Cursor * m_poEmptyCursor;
sigc::connection m_oCursorSig;
void vUpdateSize();
virtual void vUpdateSize() = 0;
void vStartCursorTimeout();
void vStopCursorTimeout();
void vHideCursor();

View File

@ -97,7 +97,7 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
Gtk::Container * poC;
poC = dynamic_cast<Gtk::Container *>(_poXml->get_widget("ScreenContainer"));
m_poScreenArea = Gtk::manage(new ScreenArea(m_iScreenWidth, m_iScreenHeight));
m_poScreenArea = Gtk::manage(new ScreenAreaGtk(m_iScreenWidth, m_iScreenHeight));
poC->add(*m_poScreenArea);
vDrawDefaultScreen();
m_poScreenArea->show();

View File

@ -33,7 +33,7 @@
#include "../System.h"
#include "configfile.h"
#include "screenarea.h"
#include "screenarea-gtk.h"
#include "filters.h"
#include "input.h"
#include "joypadconfig.h"
@ -232,7 +232,7 @@ private:
Gtk::FileChooserDialog * m_poFileOpenDialog;
ScreenArea * m_poScreenArea;
ScreenAreaGtk * m_poScreenArea;
Gtk::Menu * m_poRecentMenu;
Gtk::MenuItem * m_poRecentResetItem;
Gtk::CheckMenuItem * m_poFilePauseItem;

View File

@ -1235,7 +1235,7 @@ void Window::vOnHelpAbout()
oAboutDialog.set_comments(_("Nintendo GameBoy Advance emulator."));
oAboutDialog.set_license("GPL");
oAboutDialog.set_website("http://vba-m.ngemu.com");
oAboutDialog.set_website("http://vba-m.ngemu.com/");
std::list<Glib::ustring> list_authors;
list_authors.push_back("Forgotten");