Kaydet (Commit) bb1d4f8c authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Make the image continuously resize back and forth in both cases

Change-Id: Ia543e5355c8d6a7712bf6f10c989945ff830627d
üst 02119a79
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
*/ */
#include <math.h>
#include <GL/glew.h> #include <GL/glew.h>
#include <glm/gtx/bit.hpp> #include <glm/gtx/bit.hpp>
...@@ -59,13 +61,21 @@ namespace { ...@@ -59,13 +61,21 @@ namespace {
class MyWorkWindow : public WorkWindow class MyWorkWindow : public WorkWindow
{ {
private:
protected: protected:
double nStartTime; double mnStartTime;
int nPaintCount; int mnPaintCount;
public: public:
Graphic maGraphic;
Bitmap *mpBitmap;
FixedBitmap *mpFixedBitmap;
MyWorkWindow( vcl::Window* pParent, WinBits nWinStyle ); MyWorkWindow( vcl::Window* pParent, WinBits nWinStyle );
void LoadGraphic( const OUString& sImageFile );
virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE; virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
virtual void Resize() SAL_OVERRIDE; virtual void Resize() SAL_OVERRIDE;
}; };
...@@ -75,7 +85,6 @@ class MyOpenGLWorkWindow : public MyWorkWindow ...@@ -75,7 +85,6 @@ class MyOpenGLWorkWindow : public MyWorkWindow
public: public:
bool mbHaveTexture; bool mbHaveTexture;
OpenGLWindow *mpOpenGLWindow; OpenGLWindow *mpOpenGLWindow;
Graphic maGraphic;
GLuint mnTextureName; GLuint mnTextureName;
float mnTextureAspect; float mnTextureAspect;
...@@ -89,14 +98,40 @@ public: ...@@ -89,14 +98,40 @@ public:
MyWorkWindow::MyWorkWindow( vcl::Window* pParent, WinBits nWinStyle ) : MyWorkWindow::MyWorkWindow( vcl::Window* pParent, WinBits nWinStyle ) :
WorkWindow( pParent, nWinStyle ) WorkWindow( pParent, nWinStyle )
{ {
nPaintCount = 0; mnPaintCount = 0;
nStartTime = getTimeNow(); mnStartTime = getTimeNow();
EnableInput(); EnableInput();
} }
void MyWorkWindow::LoadGraphic( const OUString& sImageFile )
{
SvFileStream aFileStream( sImageFile, STREAM_READ );
GraphicFilter aGraphicFilter(false);
if (aGraphicFilter.ImportGraphic(maGraphic, sImageFile, aFileStream) != 0)
{
SAL_WARN("vcl.icontest", "Could not import image '" << sImageFile << "'");
return;
}
}
void MyWorkWindow::Paint( const Rectangle& rRect ) void MyWorkWindow::Paint( const Rectangle& rRect )
{ {
std::cerr << "==> Paint! " << nPaintCount++ << " (vcl) " << GetSizePixel() << " " << getTimeNow() - nStartTime << std::endl; std::cerr << "==> Paint! " << mnPaintCount++ << " (vcl) " << GetSizePixel() << " " << getTimeNow() - mnStartTime << std::endl;
Size aGraphicSize( maGraphic.GetSizePixel() );
float aspect = ((float) aGraphicSize.Width()) / aGraphicSize.Height();
Size aSize;
if( aspect >= ((float) WIDTH) / HEIGHT )
aSize = Size( WIDTH, HEIGHT/aspect );
else
aSize = Size( WIDTH * aspect, HEIGHT );
aSize.setWidth( aSize.Width() * (1 + (0.1*sin(mnPaintCount/60.))) );
aSize.setHeight( aSize.Height() * (1 + (0.1*sin(mnPaintCount/50.))) );
GraphicConversionParameters aConv( aSize );
Bitmap aEmpty;
mpFixedBitmap->SetBitmap( aEmpty );
mpBitmap = new Bitmap( maGraphic.GetBitmap( aConv ) );
mpFixedBitmap->SetBitmap( *mpBitmap );
mpFixedBitmap->SetSizePixel( aSize );
WorkWindow::Paint( rRect ); WorkWindow::Paint( rRect );
Invalidate( INVALIDATE_CHILDREN ); Invalidate( INVALIDATE_CHILDREN );
} }
...@@ -199,7 +234,7 @@ void MyOpenGLWorkWindow::LoadTexture() ...@@ -199,7 +234,7 @@ void MyOpenGLWorkWindow::LoadTexture()
void MyOpenGLWorkWindow::Paint( const Rectangle& ) void MyOpenGLWorkWindow::Paint( const Rectangle& )
{ {
std::cerr << "==> Paint! "<< nPaintCount++ << " (OpenGL) " << GetSizePixel() << " " << getTimeNow() - nStartTime << std::endl; std::cerr << "==> Paint! "<< mnPaintCount++ << " (OpenGL) " << GetSizePixel() << " " << getTimeNow() - mnStartTime << std::endl;
OpenGLContext& aCtx = mpOpenGLWindow->getContext(); OpenGLContext& aCtx = mpOpenGLWindow->getContext();
aCtx.requestLegacyContext(); aCtx.requestLegacyContext();
CHECK_GL_ERROR(); CHECK_GL_ERROR();
...@@ -207,7 +242,7 @@ void MyOpenGLWorkWindow::Paint( const Rectangle& ) ...@@ -207,7 +242,7 @@ void MyOpenGLWorkWindow::Paint( const Rectangle& )
if (!mbHaveTexture) if (!mbHaveTexture)
LoadTexture(); LoadTexture();
aCtx.setWinSize( Size( WIDTH, HEIGHT ) ); aCtx.setWinSize( Size( WIDTH+1, HEIGHT+1 ) );
CHECK_GL_ERROR(); CHECK_GL_ERROR();
aCtx.makeCurrent(); aCtx.makeCurrent();
...@@ -238,11 +273,11 @@ void MyOpenGLWorkWindow::Paint( const Rectangle& ) ...@@ -238,11 +273,11 @@ void MyOpenGLWorkWindow::Paint( const Rectangle& )
glTexCoord2f(0, 0); glTexCoord2f(0, 0);
glVertex3f(0, 0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(0, 1); glTexCoord2f(0, 1);
glVertex3f(0, 1, 0); glVertex3f(0, 1 + (0.1*sin(mnPaintCount/50.)), 0);
glTexCoord2f(1, 1); glTexCoord2f(1, 1);
glVertex3f(1, 1, 0); glVertex3f(1 + (0.1*sin(mnPaintCount/60.)), 1 + (0.1*sin(mnPaintCount/50.)), 0);
glTexCoord2f(1, 0); glTexCoord2f(1, 0);
glVertex3f(1, 0, 0); glVertex3f(1 + (0.1*sin(mnPaintCount/60.)), 0, 0);
glEnd(); glEnd();
CHECK_GL_ERROR(); CHECK_GL_ERROR();
...@@ -319,30 +354,10 @@ void IconTestApp::DoItWithVcl( const OUString& sImageFile) ...@@ -319,30 +354,10 @@ void IconTestApp::DoItWithVcl( const OUString& sImageFile)
pWindow->SetText(OUString("VCL Image Test")); pWindow->SetText(OUString("VCL Image Test"));
SvFileStream aFileStream( sImageFile, STREAM_READ ); pWindow->LoadGraphic( sImageFile );
GraphicFilter aGraphicFilter(false); pWindow->mpFixedBitmap = new FixedBitmap( pWindow );
Graphic aGraphic; pWindow->mpFixedBitmap->SetPosPixel( Point( 0, 0 ) );
if (aGraphicFilter.ImportGraphic(aGraphic, sImageFile, aFileStream) != 0) pWindow->mpFixedBitmap->Show();
{
SAL_WARN("vcl.icontest", "Could not import image '" << sImageFile << "'");
return;
}
Size aGraphicSize( aGraphic.GetSizePixel() );
float aspect = ((float) aGraphicSize.Width()) / aGraphicSize.Height();
SAL_INFO("vcl.icontest", sImageFile << ": size: " << aGraphicSize << " aspect: " << aspect);
Size aSize;
if( aspect >= ((float) WIDTH) / HEIGHT )
aSize = Size( WIDTH, HEIGHT/aspect );
else
aSize = Size( WIDTH * aspect, HEIGHT );
GraphicConversionParameters aConv( aSize );
Bitmap *pBitmap = new Bitmap( aGraphic.GetBitmap( aConv ) );
FixedBitmap *pFixedBitmap = new FixedBitmap( pWindow );
pFixedBitmap->SetBitmap( *pBitmap );
pFixedBitmap->SetSizePixel( aSize );
pFixedBitmap->SetPosPixel( Point( 0, 0 ) );
pFixedBitmap->Show();
pWindow->Hide(); pWindow->Hide();
pWindow->Show(); pWindow->Show();
...@@ -369,13 +384,8 @@ void IconTestApp::DoItWithOpenGL(const OUString& sImageFile) ...@@ -369,13 +384,8 @@ void IconTestApp::DoItWithOpenGL(const OUString& sImageFile)
pWindow->SetText(OUString("OpenGL Image Test")); pWindow->SetText(OUString("OpenGL Image Test"));
SvFileStream aFileStream( sImageFile, STREAM_READ ); pWindow->LoadGraphic( sImageFile );
GraphicFilter aGraphicFilter(false);
if (aGraphicFilter.ImportGraphic(pWindow->maGraphic, sImageFile, aFileStream) != 0)
{
SAL_WARN("vcl.icontest", "Could not import image '" << sImageFile << "'");
return;
}
Size aGraphicSize( pWindow->maGraphic.GetSizePixel() ); Size aGraphicSize( pWindow->maGraphic.GetSizePixel() );
float aspect = ((float) aGraphicSize.Width()) / aGraphicSize.Height(); float aspect = ((float) aGraphicSize.Width()) / aGraphicSize.Height();
SAL_INFO("vcl.icontest", sImageFile << ": size: " << aGraphicSize << " aspect: " << aspect); SAL_INFO("vcl.icontest", sImageFile << ": size: " << aGraphicSize << " aspect: " << aspect);
......
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