Merge branch 'master' of git.ucc.asn.au:ipdf/code
authorDavid Gow <[email protected]>
Wed, 9 Apr 2014 12:17:14 +0000 (20:17 +0800)
committerDavid Gow <[email protected]>
Wed, 9 Apr 2014 12:17:14 +0000 (20:17 +0800)
src/Makefile
src/main.h
src/real.h
src/screen.cpp
src/screen.h
src/tests/realtofloat.cpp
src/view.cpp
src/view.h

index 4874002..d7247ce 100644 (file)
@@ -5,6 +5,7 @@ MAIN = main.o
 OBJ = log.o document.o view.o screen.o
 LIB_x86_64 = ../contrib/lib/libSDL2-2.0.so.0 -lGL
 LIB_i386 = ../contrib/lib32/libSDL2-2.0.so.0 -lGL
+LIB_unknown = $(LIB_x86_64)
 MAINRPATH_x86_64 = -Wl,-rpath,'$$ORIGIN/../contrib/lib'
 MAINRPATH_i386 = -Wl,-rpath,'$$ORIGIN/../contrib/lib32'
 TESTRPATH_x86_64 = -Wl,-rpath,'$$ORIGIN/../../contrib/lib'
@@ -13,12 +14,15 @@ OBJPATHS = $(OBJ:%=../obj/%)
 DEPS := $(OBJPATHS:%.o=%.d)
 CFLAGS_x86_64 := -I../contrib/include/SDL2 -I`pwd`
 CFLAGS_i386 := -I../contrib/include32/SDL2 -I`pwd`
+CFLAGS_unknown = $(CFLAGS_x86_64)
+
 LIB := $(LIB_$(ARCH))
 MAINRPATH := $(MAINRPATH_$(ARCH))
 TESTRPATH := $(TESTRPATH_$(ARCH))
 CFLAGS := $(CFLAGS_$(ARCH))
 
 
+
 LINKOBJ = $(OBJPATHS)
 
 RM = rm -f
index c7d5eca..2346119 100644 (file)
@@ -35,6 +35,11 @@ inline void MainLoop(Document & doc)
                }
                oldx = x;
                oldy = y;
+               
+               if (wheel)
+               {
+                       view.ScaleAroundPoint(Real(x)/Real(scr.ViewportWidth()),Real(y)/Real(scr.ViewportHeight()), expf(-wheel/20.f));
+               }
        }
        );
        while (scr.PumpEvents())
index a7f56be..5703671 100644 (file)
@@ -6,9 +6,9 @@
 namespace IPDF
 {
 
-//#define REAL_FLOAT
+#define REAL_SINGLE
 //#define REAL_DOUBLE
-#define REAL_HALF
+//#define REAL_HALF
 
 #ifdef REAL_SINGLE
        typedef float Real;
index d924c06..9ee15b4 100644 (file)
@@ -58,6 +58,8 @@ bool Screen::PumpEvents()
                        }
                        break;
                case SDL_MOUSEMOTION:
+                       m_last_mouse_x = evt.motion.x;
+                       m_last_mouse_y = evt.motion.y;
                        if (m_mouse_handler)
                        {
                                m_mouse_handler(evt.motion.x, evt.motion.y,evt.motion.state, 0);
@@ -65,11 +67,19 @@ bool Screen::PumpEvents()
                        break;
                case SDL_MOUSEBUTTONDOWN:
                case SDL_MOUSEBUTTONUP:
+                       m_last_mouse_x = evt.button.x;
+                       m_last_mouse_y = evt.button.y;
                        if (m_mouse_handler)
                        {
                                m_mouse_handler(evt.button.x, evt.button.y, evt.button.state, 0);
                        }
                        break;
+               case SDL_MOUSEWHEEL:
+                       if (m_mouse_handler)
+                       {
+                               m_mouse_handler(m_last_mouse_x, m_last_mouse_y, 0, evt.wheel.y);
+                       }
+                       break;
                default:
                        break;
                }
index 8452efc..4d92cb3 100644 (file)
@@ -47,6 +47,8 @@ namespace IPDF
                void ResizeViewport(int width, int height);
                
                MouseHandler m_mouse_handler;
+               int m_last_mouse_x;
+               int m_last_mouse_y;
 
                int m_viewport_width;
                int m_viewport_height;
index 32ee20b..c475ea9 100644 (file)
@@ -12,9 +12,9 @@ int main(int argc, char ** argv)
        {
                float test = test_min + (test_max-test_min)*((float)(rand() % (int)1e6)/1e6);
                Real real(test);
-               float thiserror = abs(test - real.value);
+               float thiserror = abs(test - Float(real));
                error += thiserror;
-               Debug("#%u: |test %.20f - real %.20f| = %.20f [mean %f]", i, test, real.value, thiserror, error/(i+1));
+               Debug("#%u: |test %.20f - real %.20f| = %.20f [mean %f]", i, test, Float(real), thiserror, error/(i+1));
        }
 
        if (error/test_count > error_thresh)
index 4425ebe..969bbb3 100644 (file)
@@ -7,10 +7,34 @@ using namespace std;
 
 void View::Translate(Real x, Real y)
 {
+       x *= m_bounds.w;
+       y *= m_bounds.h;
        m_bounds.x += x;
        m_bounds.y += y;
 }
 
+void View::ScaleAroundPoint(Real x, Real y, Real scaleAmt)
+{
+       // Convert to local coords.
+       x *= m_bounds.w;
+       y *= m_bounds.h;
+       x += m_bounds.x;
+       y += m_bounds.y;
+       
+       Debug("Mouse wheel event %f %f %f\n", Float(x), Float(y), Float(scaleAmt));
+       
+       Real top = y - m_bounds.y;
+       Real left = x - m_bounds.x;
+       
+       top *= scaleAmt;
+       left *= scaleAmt;
+       
+       m_bounds.x = x - left;
+       m_bounds.y = y - top;
+       m_bounds.w *= scaleAmt;
+       m_bounds.h *= scaleAmt;
+}
+
 void View::Render()
 {
        static bool debug_output_done = false;
index cc09a89..6b63799 100644 (file)
@@ -15,6 +15,7 @@ namespace IPDF
                        void Render();
                        
                        void Translate(Real x, Real y);
+                       void ScaleAroundPoint(Real x, Real y, Real scaleAmt);
                
                private:
                        Document & m_document;

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