more Qt formatting
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "hack.h"
|
#include "hack.h"
|
||||||
#include "tile2x11.h"
|
#include "tile2x11.h" /* x11tiles is potential fallback for nhtiles.bmp */
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "qt_pre.h"
|
#include "qt_pre.h"
|
||||||
@@ -40,7 +40,7 @@ NetHackQtGlyphs::NetHackQtGlyphs()
|
|||||||
{
|
{
|
||||||
const char* tile_file = PIXMAPDIR "/nhtiles.bmp";
|
const char* tile_file = PIXMAPDIR "/nhtiles.bmp";
|
||||||
|
|
||||||
if ( iflags.wc_tile_file )
|
if (iflags.wc_tile_file)
|
||||||
tile_file = iflags.wc_tile_file;
|
tile_file = iflags.wc_tile_file;
|
||||||
|
|
||||||
if (!img.load(tile_file)) {
|
if (!img.load(tile_file)) {
|
||||||
@@ -64,11 +64,11 @@ NetHackQtGlyphs::NetHackQtGlyphs()
|
|||||||
tiles_per_row = 40;
|
tiles_per_row = 40;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( iflags.wc_tile_width )
|
if (iflags.wc_tile_width)
|
||||||
tilefile_tile_W = iflags.wc_tile_width;
|
tilefile_tile_W = iflags.wc_tile_width;
|
||||||
else
|
else
|
||||||
tilefile_tile_W = img.width() / tiles_per_row;
|
tilefile_tile_W = img.width() / tiles_per_row;
|
||||||
if ( iflags.wc_tile_height )
|
if (iflags.wc_tile_height)
|
||||||
tilefile_tile_H = iflags.wc_tile_height;
|
tilefile_tile_H = iflags.wc_tile_height;
|
||||||
else
|
else
|
||||||
tilefile_tile_H = tilefile_tile_W;
|
tilefile_tile_H = tilefile_tile_W;
|
||||||
@@ -79,59 +79,57 @@ NetHackQtGlyphs::NetHackQtGlyphs()
|
|||||||
void NetHackQtGlyphs::drawGlyph(QPainter& painter, int glyph, int x, int y)
|
void NetHackQtGlyphs::drawGlyph(QPainter& painter, int glyph, int x, int y)
|
||||||
{
|
{
|
||||||
int tile = glyph2tile[glyph];
|
int tile = glyph2tile[glyph];
|
||||||
int px = (tile%tiles_per_row)*width();
|
int px = (tile % tiles_per_row) * width();
|
||||||
int py = tile/tiles_per_row*height();
|
int py = tile / tiles_per_row * height();
|
||||||
|
|
||||||
painter.drawPixmap(
|
painter.drawPixmap(x, y, pm, px, py, width(), height());
|
||||||
x,
|
|
||||||
y,
|
|
||||||
pm,
|
|
||||||
px,py,
|
|
||||||
width(),height()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
void NetHackQtGlyphs::drawCell(QPainter& painter, int glyph, int cellx, int celly)
|
|
||||||
|
void NetHackQtGlyphs::drawCell(QPainter& painter, int glyph,
|
||||||
|
int cellx, int celly)
|
||||||
{
|
{
|
||||||
drawGlyph(painter,glyph,cellx*width(),celly*height());
|
drawGlyph(painter, glyph, cellx * width(), celly * height());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap NetHackQtGlyphs::glyph(int glyph)
|
QPixmap NetHackQtGlyphs::glyph(int glyph)
|
||||||
{
|
{
|
||||||
int tile = glyph2tile[glyph];
|
int tile = glyph2tile[glyph];
|
||||||
int px = (tile%tiles_per_row)*tilefile_tile_W;
|
int px = (tile % tiles_per_row) * tilefile_tile_W;
|
||||||
int py = tile/tiles_per_row*tilefile_tile_H;
|
int py = tile / tiles_per_row * tilefile_tile_H;
|
||||||
|
|
||||||
return QPixmap::fromImage(img.copy(px, py, tilefile_tile_W, tilefile_tile_H));
|
return QPixmap::fromImage(img.copy(px, py,
|
||||||
|
tilefile_tile_W, tilefile_tile_H));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetHackQtGlyphs::setSize(int w, int h)
|
void NetHackQtGlyphs::setSize(int w, int h)
|
||||||
{
|
{
|
||||||
if ( size == QSize(w,h) )
|
if (size == QSize(w, h))
|
||||||
return;
|
return;
|
||||||
|
size = QSize(w, h);
|
||||||
bool was1 = size == pm1.size();
|
|
||||||
size = QSize(w,h);
|
|
||||||
if (!w || !h)
|
if (!w || !h)
|
||||||
return; // Still not decided
|
return; // Still not decided
|
||||||
|
|
||||||
if ( size == pm1.size() ) {
|
if (size == pm1.size()) { // not zoomed
|
||||||
pm = pm1;
|
pm = pm1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( size == pm2.size() ) {
|
if (size == pm2.size()) { // zoomed
|
||||||
pm = pm2;
|
pm = pm2;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w==tilefile_tile_W && h==tilefile_tile_H) {
|
bool was1 = (size == pm1.size());
|
||||||
|
if (w == tilefile_tile_W && h == tilefile_tile_H) {
|
||||||
pm.convertFromImage(img);
|
pm.convertFromImage(img);
|
||||||
} else {
|
} else {
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
QImage scaled = img.scaled(
|
QImage scaled = img.scaled(
|
||||||
w*img.width()/tilefile_tile_W,
|
w * img.width() / tilefile_tile_W,
|
||||||
h*img.height()/tilefile_tile_H,
|
h * img.height() / tilefile_tile_H,
|
||||||
Qt::IgnoreAspectRatio,
|
Qt::IgnoreAspectRatio,
|
||||||
Qt::FastTransformation
|
Qt::FastTransformation
|
||||||
);
|
);
|
||||||
pm.convertFromImage(scaled,Qt::ThresholdDither|Qt::PreferDither);
|
pm.convertFromImage(scaled, Qt::ThresholdDither | Qt::PreferDither);
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
(was1 ? pm2 : pm1) = pm;
|
(was1 ? pm2 : pm1) = pm;
|
||||||
|
|||||||
Reference in New Issue
Block a user