forked from poechsel/LEIA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
124 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
#include "sdlwidget.h" | ||
|
||
SDLWidget::SDLWidget(QWidget *parent) : QWidget(parent) | ||
SDLWidget::SDLWidget(QWidget *parent) : | ||
QWidget(parent), Screen() | ||
|
||
{ | ||
char windowid[64]; | ||
#ifdef Q_WS_WIN | ||
_pixels = new QRgb[WIDTH*HEIGHT]; | ||
_image = QImage((uchar*)_pixels, WIDTH, HEIGHT, QImage::Format_ARGB32); | ||
this->setMinimumHeight(HEIGHT); | ||
this->setMinimumWidth(WIDTH); | ||
this->resize(2*WIDTH, 2*HEIGHT); | ||
for (int i = 0; i < WIDTH * HEIGHT; ++i) | ||
_pixels[i] = 0xff00000; | ||
|
||
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); | ||
} | ||
|
||
SDLWidget::~SDLWidget() { | ||
delete[] _pixels; | ||
} | ||
|
||
void SDLWidget::paintEvent(QPaintEvent *event) { | ||
QPainter painter(this); | ||
qDebug()<<"paint event\n"; | ||
QImage image = QImage((uchar*)_pixels, WIDTH, HEIGHT, QImage::Format_ARGB32); | ||
|
||
sprintf(windowid, "SDL_WINDOWID=0x%lx", reinterpret_cast<qlonglong>(winId())); | ||
#elif defined Q_WS_X11 | ||
sprintf(windowid, "SDL_WINDOWID=0x%lx", winId()); | ||
#else | ||
qFatal("Fatal: cast du winId() inconnu pour votre plate-forme; toute information est la bienvenue!"); | ||
#endif | ||
SDL_putenv(windowid); | ||
painter.drawImage(0, 0, image); | ||
} | ||
|
||
void SDLWidget::updateContent(uword *memory) { | ||
qDebug()<<"drawing\n"; | ||
for (unsigned int i = MEM_SCREEN_BEGIN; i <= 0xFFFF; ++i) { | ||
word pixel = (memory) ? memory[i] : 0; | ||
uint32_t blue = pixel & ((1<<5)-1); | ||
uint32_t green = (pixel>>5) & ((1<<5)-1); | ||
uint32_t red = (pixel>>10) ; | ||
_pixels[i - MEM_SCREEN_BEGIN] = ((red << (2+16)) + (green << (3+8)) + (blue << 3)) | 0xff000000; | ||
} | ||
this->update(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters