GTK GUI :

The window can now be resized when using the Xv output. The display stretches to fit the window with aspect ratio correction.
This commit is contained in:
bgk 2008-04-23 11:54:54 +00:00
parent 66720378c9
commit d1d115dbe8
7 changed files with 61 additions and 28 deletions

View File

@ -103,15 +103,13 @@ void ScreenAreaGtk::vDrawPixels(u8 * _puiData)
queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight); queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight);
} }
void ScreenAreaGtk::vDrawColor(u32 _uiColor) void ScreenAreaGtk::vDrawBlackScreen()
{ {
_uiColor = GUINT32_TO_BE(_uiColor) << 8;
u32 * puiPixel = m_puiPixels; u32 * puiPixel = m_puiPixels;
u32 * puiEnd = m_puiPixels + m_iAreaWidth * m_iAreaHeight; u32 * puiEnd = m_puiPixels + m_iAreaWidth * m_iAreaHeight;
while (puiPixel != puiEnd) while (puiPixel != puiEnd)
{ {
*puiPixel++ = _uiColor; *puiPixel++ = 0;
} }
queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight); queue_draw_area(0, 0, m_iAreaWidth, m_iAreaHeight);

View File

@ -31,7 +31,7 @@ public:
ScreenAreaGtk(int _iWidth, int _iHeight, int _iScale = 1); ScreenAreaGtk(int _iWidth, int _iHeight, int _iScale = 1);
virtual ~ScreenAreaGtk(); virtual ~ScreenAreaGtk();
void vDrawPixels(u8 * _puiData); void vDrawPixels(u8 * _puiData);
void vDrawColor(u32 _uiColor); // 0xRRGGBB void vDrawBlackScreen();
protected: protected:
bool on_expose_event(GdkEventExpose * _pstEvent); bool on_expose_event(GdkEventExpose * _pstEvent);

View File

@ -31,11 +31,15 @@
namespace VBA namespace VBA
{ {
template<typename T> T min( T x, T y ) { return x < y ? x : y; }
template<typename T> T max( T x, T y ) { return x > y ? x : y; }
ScreenAreaXv::ScreenAreaXv(int _iWidth, int _iHeight, int _iScale) : ScreenAreaXv::ScreenAreaXv(int _iWidth, int _iHeight, int _iScale) :
ScreenArea(_iWidth, _iHeight, _iScale), ScreenArea(_iWidth, _iHeight, _iScale),
m_puiPixels(0), m_puiPixels(0),
m_puiDelta(0), m_puiDelta(0),
m_iFilterScale(1) m_iAreaTop(0),
m_iAreaLeft(0)
{ {
XvAdaptorInfo *pAdaptors; XvAdaptorInfo *pAdaptors;
unsigned int iNumAdaptors; unsigned int iNumAdaptors;
@ -161,19 +165,23 @@ void ScreenAreaXv::vDrawPixels(u8 * _puiData)
m_pXvImage, m_pXvImage,
0, 0, 0, 0,
iScaledWidth, iScaledHeight, iScaledWidth, iScaledHeight,
0, 0, m_iAreaLeft, m_iAreaTop,
m_iAreaWidth + 4, m_iAreaHeight + 4, m_iAreaWidth + 4, m_iAreaHeight + 4,
True); True);
gdk_display_sync(gtk_widget_get_display(pDrawingArea)); gdk_display_sync(gtk_widget_get_display(pDrawingArea));
} }
void ScreenAreaXv::vDrawColor(u32 _uiColor) void ScreenAreaXv::vDrawBlackScreen()
{ {
modify_bg(get_state(), Gdk::Color("black"));
} }
void ScreenAreaXv::vUpdateSize() void ScreenAreaXv::vUpdateSize()
{ {
const int iScaledWidth = m_iFilterScale * m_iWidth;
const int iScaledHeight = m_iFilterScale * m_iHeight;
if (m_puiPixels != NULL) if (m_puiPixels != NULL)
{ {
delete[] m_puiPixels; delete[] m_puiPixels;
@ -189,21 +197,14 @@ void ScreenAreaXv::vUpdateSize()
XShmDetach(m_pDisplay, &m_oShm); XShmDetach(m_pDisplay, &m_oShm);
} }
m_iFilterScale = 1; vOnWidgetResize();
if (m_iScale == 2 && m_vFilter2x != NULL)
{
m_iFilterScale = 2;
}
m_iAreaWidth = m_iScale * m_iWidth;
m_iAreaHeight = m_iScale * m_iHeight;
m_pXvImage = XvShmCreateImage(m_pDisplay, m_pXvImage = XvShmCreateImage(m_pDisplay,
m_iXvPortId, m_iXvPortId,
m_iFormat, m_iFormat,
0, 0,
m_iFilterScale * m_iWidth + 4, iScaledWidth + 4,
m_iFilterScale * m_iHeight + 4, iScaledHeight + 4,
&m_oShm); &m_oShm);
m_oShm.shmid = shmget(IPC_PRIVATE, m_pXvImage->data_size, IPC_CREAT | 0777); m_oShm.shmid = shmget(IPC_PRIVATE, m_pXvImage->data_size, IPC_CREAT | 0777);
@ -214,12 +215,12 @@ void ScreenAreaXv::vUpdateSize()
XShmAttach(m_pDisplay, &m_oShm); XShmAttach(m_pDisplay, &m_oShm);
m_puiPixels = new u32[m_iAreaWidth * m_iAreaHeight]; m_puiPixels = new u32[iScaledWidth * iScaledHeight];
m_puiDelta = new u8[(m_iWidth + 2) * (m_iHeight + 2) * 4]; m_puiDelta = new u8[(m_iWidth + 2) * (m_iHeight + 2) * 4];
memset(m_puiDelta, 255, (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); set_size_request(m_iScale * m_iWidth, m_iScale* m_iHeight);
} }
void ScreenAreaXv::vRGB32toYUY2 (unsigned char* dest_ptr, void ScreenAreaXv::vRGB32toYUY2 (unsigned char* dest_ptr,
@ -280,4 +281,20 @@ void ScreenAreaXv::vRGB32toYUY2 (unsigned char* dest_ptr,
} }
} }
void ScreenAreaXv::vOnWidgetResize()
{
double dAspectRatio = m_iWidth / (double)m_iHeight;
m_iAreaHeight = min<int>(get_height(), get_width() / dAspectRatio);
m_iAreaWidth = min<int>(get_width(), get_height() * dAspectRatio);
m_iAreaTop = (get_height() - m_iAreaHeight) / 2;
m_iAreaLeft = (get_width() - m_iAreaWidth) / 2;
}
bool ScreenAreaXv::on_configure_event(GdkEventConfigure * event)
{
vOnWidgetResize();
}
} // namespace VBA } // namespace VBA

View File

@ -37,7 +37,10 @@ public:
ScreenAreaXv(int _iWidth, int _iHeight, int _iScale = 1); ScreenAreaXv(int _iWidth, int _iHeight, int _iScale = 1);
virtual ~ScreenAreaXv(); virtual ~ScreenAreaXv();
void vDrawPixels(u8 * _puiData); void vDrawPixels(u8 * _puiData);
void vDrawColor(u32 _uiColor); // 0xRRGGBB void vDrawBlackScreen();
protected:
bool on_configure_event(GdkEventConfigure * event);
private: private:
Display *m_pDisplay; Display *m_pDisplay;
@ -48,9 +51,11 @@ private:
XShmSegmentInfo m_oShm; XShmSegmentInfo m_oShm;
u32 * m_puiPixels; u32 * m_puiPixels;
u8 * m_puiDelta; u8 * m_puiDelta;
int m_iFilterScale; int m_iAreaTop;
int m_iAreaLeft;
void vUpdateSize(); void vUpdateSize();
void vOnWidgetResize();
void vRGB32toYUY2 (unsigned char* dest_ptr, void vRGB32toYUY2 (unsigned char* dest_ptr,
int dest_width, int dest_width,
int dest_height, int dest_height,

View File

@ -26,7 +26,8 @@ namespace VBA
ScreenArea::ScreenArea(int _iWidth, int _iHeight, int _iScale) : ScreenArea::ScreenArea(int _iWidth, int _iHeight, int _iScale) :
m_vFilter2x(NULL), m_vFilter2x(NULL),
m_vFilterIB(NULL), m_vFilterIB(NULL),
m_bShowCursor(true) m_bShowCursor(true),
m_iFilterScale(1)
{ {
g_assert(_iWidth >= 1 && _iHeight >= 1 && _iScale >= 1); g_assert(_iWidth >= 1 && _iHeight >= 1 && _iScale >= 1);
@ -85,6 +86,13 @@ void ScreenArea::vSetScale(int _iScale)
void ScreenArea::vSetFilter2x(EFilter2x _eFilter2x) void ScreenArea::vSetFilter2x(EFilter2x _eFilter2x)
{ {
m_vFilter2x = pvGetFilter2x(_eFilter2x, FilterDepth32); m_vFilter2x = pvGetFilter2x(_eFilter2x, FilterDepth32);
m_iFilterScale = 1;
if (m_iScale == 2 && m_vFilter2x != NULL)
{
m_iFilterScale = 2;
}
vUpdateSize(); vUpdateSize();
} }

View File

@ -39,7 +39,7 @@ public:
void vSetFilter2x(EFilter2x _eFilter2x); void vSetFilter2x(EFilter2x _eFilter2x);
void vSetFilterIB(EFilterIB _eFilterIB); void vSetFilterIB(EFilterIB _eFilterIB);
virtual void vDrawPixels(u8 * _puiData) = 0; virtual void vDrawPixels(u8 * _puiData) = 0;
virtual void vDrawColor(u32 _uiColor) = 0; // 0xRRGGBB virtual void vDrawBlackScreen() = 0;
protected: protected:
virtual bool on_motion_notify_event(GdkEventMotion * _pstEvent); virtual bool on_motion_notify_event(GdkEventMotion * _pstEvent);
@ -50,6 +50,7 @@ protected:
int m_iWidth; int m_iWidth;
int m_iHeight; int m_iHeight;
int m_iScale; int m_iScale;
int m_iFilterScale;
int m_iAreaWidth; int m_iAreaWidth;
int m_iAreaHeight; int m_iAreaHeight;
Filter2x m_vFilter2x; Filter2x m_vFilter2x;

View File

@ -856,10 +856,11 @@ Window::~Window()
void Window::vInitScreenArea() void Window::vInitScreenArea()
{ {
Gtk::Container * poC; Gtk::Alignment * poC;
bool bUseXv; bool bUseXv;
poC = dynamic_cast<Gtk::Container *>(m_poXml->get_widget("ScreenContainer")); poC = dynamic_cast<Gtk::Alignment *>(m_poXml->get_widget("ScreenContainer"));
poC->set(Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, 0.0, 0.0);
bUseXv = m_poDisplayConfig->oGetKey<bool>("use_Xv"); bUseXv = m_poDisplayConfig->oGetKey<bool>("use_Xv");
if (bUseXv) if (bUseXv)
@ -867,6 +868,9 @@ void Window::vInitScreenArea()
try try
{ {
m_poScreenArea = Gtk::manage(new ScreenAreaXv(m_iScreenWidth, m_iScreenHeight)); m_poScreenArea = Gtk::manage(new ScreenAreaXv(m_iScreenWidth, m_iScreenHeight));
// The Xv screen area can handle resizes
poC->set(Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, 1.0, 1.0);
} }
catch (std::exception e) catch (std::exception e)
{ {
@ -1518,7 +1522,7 @@ void Window::vDrawScreen()
void Window::vDrawDefaultScreen() void Window::vDrawDefaultScreen()
{ {
m_poScreenArea->vDrawColor(0x000000); // Black m_poScreenArea->vDrawBlackScreen();
} }
void Window::vSetDefaultTitle() void Window::vSetDefaultTitle()