Commit 8f6906a6 authored by Johannes Bergmeier's avatar Johannes Bergmeier

- Changed roxdoku to use the svg for texture-generation

svn path=/trunk/KDE/kdegames/ksudoku/; revision=796311
parent 42404369
#include "renderer.h"
#include "renderer.h"
#include <KSvgRenderer>
#include <KStandardDirs>
......@@ -68,6 +68,11 @@ void Renderer::fillNameHashes() {
m_specialNames << "cell";
m_specialNames << "cell_mistake";
m_specialNames << "cursor";
m_special3dNames << "cell3d";
m_special3dNames << "cell3d_preset";
m_special3dNames << "cell3d";
m_special3dNames << "cell3d_mistake";
m_special3dNames << "cursor";
// TODO get this hardcoded values from the SVG file
// m_markerName << "markers9" << "markers9" //...
}
......@@ -75,18 +80,18 @@ void Renderer::fillNameHashes() {
QPixmap Renderer::renderBackground(const QSize& size) const {
if(!m_renderer->isValid() || size.isEmpty()) return QPixmap();
QPixmap pix;
QString cacheName = QString("background_%1x%2").arg(size.width()).arg(size.height());
if(!m_cache->find(cacheName, pix))
{
pix = QPixmap(size);
pix.fill(Qt::transparent);
QPainter p(&pix);
m_renderer->render(&p, "background");
p.end();
m_cache->insert(cacheName, pix);
}
return pix;
QPixmap pix;
QString cacheName = QString("background_%1x%2").arg(size.width()).arg(size.height());
if(!m_cache->find(cacheName, pix))
{
pix = QPixmap(size);
pix.fill(Qt::transparent);
QPainter p(&pix);
m_renderer->render(&p, "background");
p.end();
m_cache->insert(cacheName, pix);
}
return pix;
}
/** Moves a point from its relative position to the base rect (0,0,1,1) to a relative position to rect @p to */
......@@ -127,7 +132,7 @@ QPixmap Renderer::renderSpecial(SpecialType type, int size) const {
m_cache->insert(cacheName, pix);
}
return pix;
return pix;
}
QPixmap Renderer::renderSymbol(int symbol, int size) const {
......@@ -154,7 +159,7 @@ QPixmap Renderer::renderSymbol(int symbol, int size) const {
m_cache->insert(cacheName, pix);
}
return pix;
return pix;
}
QPixmap Renderer::renderSymbolOn(QPixmap pixmap, int symbol, int color) const {
......@@ -207,7 +212,7 @@ QPixmap Renderer::renderMarker(int symbol, int range, int size) const {
m_cache->insert(cacheName, pix);
}
return pix;
return pix;
}
QPixmap Renderer::renderMarkerOn(QPixmap pixmap, int symbol, int range, int color) const {
......@@ -255,4 +260,29 @@ QPixmap Renderer::renderBorder(int border, GroupTypes type, int size) const {
return pix;
}
QPixmap Renderer::renderSpecial3D(SpecialType type, int size) const {
if(!m_renderer->isValid() || size == 0) return QPixmap();
QString cacheName = QString("special_%1_%2").arg(m_special3dNames[type]).arg(size);
QPixmap pix;
if(!m_cache->find(cacheName, pix)) {
pix = QPixmap(size, size);
pix.fill(Qt::transparent);
QPainter p(&pix);
// NOTE fix for Qt's QSvgRenderer size reporting bug
QRectF r(m_renderer->boundsOnElement(m_special3dNames[type]));
QRectF from(r.adjusted(+0.5,+0.5,-0.5,-0.5));
QRectF to(QRectF(0,0,size,size));
r.setTopLeft(fromRectToRect(r.topLeft(), from, to));
r.setBottomRight(fromRectToRect(r.bottomRight(), from, to));
m_renderer->render(&p, m_special3dNames[type], r);
p.end();
m_cache->insert(cacheName, pix);
}
return pix;
}
}
......@@ -80,6 +80,8 @@ public:
QPixmap renderMarker(int symbol, int range, int size) const;
QPixmap renderMarkerOn(QPixmap pixmap, int symbol, int range, int color) const;
QPixmap renderSpecial3D(SpecialType type, int size) const;
private:
Renderer();
~Renderer();
......@@ -95,6 +97,7 @@ private:
QVector<QString> m_borderNames;
QVector<QString> m_borderTypes;
QVector<QString> m_specialNames;
QVector<QString> m_special3dNames;
QVector<QString> m_markerNames;
KSvgRenderer* m_renderer;
KPixmapCache* m_cache;
......
......@@ -33,6 +33,8 @@
#include "settings.h"
#include "renderer.h"
namespace ksudoku{
......@@ -128,43 +130,22 @@ void RoxdokuView::initializeGL()
setMouseTracking(true);
QPixmap* pixs;
for(int o=0; o<2; o++)
for(int i=0; i<=9+o*16; i++)
{
int sz = 32;
pixs = new QPixmap(sz,sz);
QPainter p(pixs);
QFont f;
f.setPointSizeF((sz * 80) / 128);
p.setFont(f);
p.fillRect(rect(), QColor(255,255,255));
if(i==0)
p.drawText(0,0,sz,sz, Qt::AlignCenter, QString(QChar(' ')));
else{
QString s = QChar('0'*(o==0) + ('a'-1)*(o==1) +i);
if(s == "9" || s == "6" || s == "b" || s == "d") s += '.';
p.drawText(0,0,sz,sz, Qt::AlignCenter, s);
int sz = 64;
QPixmap pic = Renderer::instance()->renderSpecial3D(SpecialCell, sz);
if(i != 0) {
pic = Renderer::instance()->renderSymbolOn(pic, i, 0);
}
p.setPen(QPen(QColor(0,0,0), 2));
p.drawRect ( 0, 0, sz, sz );
p.end();
QImage pix = convertToGLFormat(pixs->toImage());
QImage pix = convertToGLFormat(pic.toImage());
glGenTextures(1, &texture[o][i]);
glBindTexture(GL_TEXTURE_2D, texture[o][i]);
glTexImage2D(GL_TEXTURE_2D, 0,4, sz,sz, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) pix.bits());
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
delete pixs;
}
/*glEnable(GL_LIGHTING); //UNCOMMENT FOR LIGHTS
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
glEnable(GL_COLOR_MATERIAL); */
}
void RoxdokuView::mouseDoubleClickEvent ( QMouseEvent * /*e*/ )
......
......@@ -42,12 +42,12 @@
bordercolor="#666666"
pagecolor="#ffffff"
id="base"
inkscape:zoom="11.313709"
inkscape:cx="245.8467"
inkscape:cy="28.676153"
inkscape:zoom="1.4142136"
inkscape:cx="266.2731"
inkscape:cy="164.21556"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:current-layer="cell_markers9"
inkscape:current-layer="svg2"
showgrid="true"
inkscape:snap-global="true">
<inkscape:grid
......@@ -9036,4 +9036,83 @@
id="path3505" />
</g>
</g>
<g
id="cell3d">
<g
id="g4267">
<rect
style="opacity:1;fill:#888a85;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4245"
width="40"
height="40"
x="280"
y="310" />
</g>
<path
inkscape:tile-cy="300.37498"
inkscape:tile-cx="19.5"
inkscape:tile-h="35.00004"
inkscape:tile-w="35"
d="M 283,345 C 283,344 283,315.99996 283,314.99996 C 283,313.99996 284,312.99996 285,312.99996 C 286,312.99996 314,312.99996 315,312.99996 C 316,312.99996 317,313.99996 317,314.99996 C 317,315.99996 317,344 317,345 C 317,346 316,347 315,347 C 314,347 286,347 285,347 C 284,347 283,346 283,345 z"
style="fill:#bbbeb7;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="path4249" />
<rect
y="341"
x="292"
height="3"
width="17"
id="rect4265"
style="opacity:1;fill:#ffffff;fill-opacity:0.94117647;stroke:none;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<g
id="cell3d_symbols">
<g
transform="translate(50,0)"
id="g4278">
<rect
style="opacity:1;fill:#888a85;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4280"
width="40"
height="40"
x="280"
y="310" />
</g>
<path
inkscape:tile-cy="300.37498"
inkscape:tile-cx="19.5"
inkscape:tile-h="35.00004"
inkscape:tile-w="35"
d="M 333,345 C 333,344 333,315.99996 333,314.99996 C 333,313.99996 334,312.99996 335,312.99996 C 336,312.99996 364,312.99996 365,312.99996 C 366,312.99996 367,313.99996 367,314.99996 C 367,315.99996 367,344 367,345 C 367,346 366,347 365,347 C 364,347 336,347 335,347 C 334,347 333,346 333,345 z"
style="fill:#bbbeb7;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="path4282" />
<rect
y="341"
x="342"
height="3"
width="17"
id="rect4285"
style="fill:#ffffff;fill-opacity:0.94117647;stroke:none;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<g
transform="translate(150,0)"
id="symbol3d_1"
inkscape:label="#g3642">
<rect
transform="translate(210,-140)"
style="opacity:1;fill:none;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4261"
width="20"
height="20"
x="-20"
y="460" />
<path
transform="translate(210,-140)"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;display:inline"
d="M -9.0715,460.39459 L -5.76522,460.39459 L -5.76522,479.71297 L -9.75556,479.71297 L -9.75556,465.86985 L -15,468.65913 L -15,465.25 L -11.57971,463.49379 C -10.36361,462.59847 -9.52754,461.56541 -9.0715,460.39459 z"
id="path4263"
inkscape:tile-w="4.617"
inkscape:tile-h="10.7525"
inkscape:tile-cx="21.246839"
inkscape:tile-cy="13.927869" />
</g>
</g>
</svg>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment