Fix some crashes in unused tile editor.

tileedit is the program I use to edit tile files (directly).
This commit is contained in:
warwick
2002-01-22 08:44:37 +00:00
parent dab3df306f
commit 3c0c8b0516
+8 -2
View File
@@ -180,9 +180,10 @@ void TrivialTileEditor::setColor( QRgb rgb )
{ {
pen = rgb; pen = rgb;
for (penpixel = 0; for (penpixel = 0;
penpixel<img.numColors()-1 && img.color(penpixel)!=pen.rgb(); penpixel<img.numColors()-1 && (img.color(penpixel)&0xffffff)!=(pen.rgb()&0xffffff);
penpixel++) penpixel++)
continue; continue;
qDebug("penpixel=%d, pen=%x",penpixel,pen.rgb());
} }
void TrivialTileEditor::setImage( const QImage& i ) void TrivialTileEditor::setImage( const QImage& i )
@@ -217,6 +218,8 @@ void TrivialTileEditor::paintPoint(QPainter& painter, QPoint p)
void TrivialTileEditor::mousePressEvent(QMouseEvent* e) void TrivialTileEditor::mousePressEvent(QMouseEvent* e)
{ {
QPoint p = imagePoint(e->pos()); QPoint p = imagePoint(e->pos());
if ( !img.rect().contains(p) )
return;
uchar& pixel = img.scanLine(p.y())[p.x()]; uchar& pixel = img.scanLine(p.y())[p.x()];
if ( e->button() == LeftButton ) { if ( e->button() == LeftButton ) {
pixel = penpixel; pixel = penpixel;
@@ -226,7 +229,8 @@ void TrivialTileEditor::mousePressEvent(QMouseEvent* e)
emit pick( img.color(pixel) ); emit pick( img.color(pixel) );
} else if ( e->button() == MidButton ) { } else if ( e->button() == MidButton ) {
QPainter painter(this); QPainter painter(this);
fill(painter,p,pixel); if ( pixel != penpixel )
fill(painter,p,pixel);
} }
} }
@@ -253,6 +257,8 @@ void TrivialTileEditor::mouseReleaseEvent(QMouseEvent* e)
void TrivialTileEditor::mouseMoveEvent(QMouseEvent* e) void TrivialTileEditor::mouseMoveEvent(QMouseEvent* e)
{ {
QPoint p = imagePoint(e->pos()); QPoint p = imagePoint(e->pos());
if ( !img.rect().contains(p) )
return;
uchar& pixel = img.scanLine(p.y())[p.x()]; uchar& pixel = img.scanLine(p.y())[p.x()];
pixel = penpixel; pixel = penpixel;
QPainter painter(this); QPainter painter(this);