Merge branch 'master' of git.ucc.asn.au:ipdf/code
[ipdf/code.git] / src / screen.cpp
index 09cd0b5..07d3f94 100644 (file)
@@ -2,6 +2,8 @@
 #include "screen.h"
 
 #include "SDL_opengl.h"
+#include <fcntl.h> // for access(2)
+#include <unistd.h> // for access(2)
 
 using namespace IPDF;
 using namespace std;
@@ -82,7 +84,7 @@ bool Screen::PumpEvents()
                        m_last_mouse_y = evt.button.y;
                        if (m_mouse_handler)
                        {
-                               m_mouse_handler(evt.button.x, evt.button.y, evt.button.state, 0);
+                               m_mouse_handler(evt.button.x, evt.button.y, evt.button.state?evt.button.button:0, 0);
                        }
                        break;
                case SDL_MOUSEWHEEL:
@@ -100,6 +102,7 @@ bool Screen::PumpEvents()
                                filename[0] = (char)evt.key.keysym.sym;
                                ScreenShot(filename);
                        }
+                       break;
                }
                default:
                        break;
@@ -139,8 +142,7 @@ void Screen::ScreenShot(const char * filename) const
        unsigned char * pixels = new unsigned char[w*h*4];
        if (pixels == NULL)
                Fatal("Failed to allocate %d x %d x 4 = %d pixel array", w, h, w*h*4);
-       glReadBuffer(GL_FRONT);
-       glPixelStorei(GL_PACK_ALIGNMENT, 1);
+
        for (int y = 0; y < h; ++y)
        {
                glReadPixels(0,h-y-1,w, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[y*w*4]);
@@ -171,6 +173,11 @@ void Screen::ScreenShot(const char * filename) const
  */
 void Screen::RenderBMP(const char * filename) const
 {
+       if (access(filename, R_OK) == -1)
+       {
+               Error("No such file \"%s\" - Nothing to render - You might have done this deliberately?", filename);
+               return;
+       }
        SDL_Surface * bmp = SDL_LoadBMP(filename);
        if (bmp == NULL)
                Fatal("Failed to load BMP from %s - %s", filename, SDL_GetError());

UCC git Repository :: git.ucc.asn.au