PieDock 1.6.0

src/PieMenu.h

00001 /*
00002  *   O         ,-
00003  *  ° o    . -´  '     ,-
00004  *   °  .´        ` . ´,´
00005  *     ( °   ))     . (
00006  *      `-;_    . -´ `.`.
00007  *          `._'       ´
00008  *
00009  * Copyright (c) 2007-2010 Markus Fisch <mf@markusfisch.de>
00010  *
00011  * Licensed under the MIT license:
00012  * http://www.opensource.org/licenses/mit-license.php
00013  */
00014 #ifndef _PieDock_PieMenu_
00015 #define _PieDock_PieMenu_
00016 
00017 #include "Application.h"
00018 #include "Surface.h"
00019 #include "Blender.h"
00020 #include "Icon.h"
00021 #include "Menu.h"
00022 
00023 #include <vector>
00024 #include <math.h>
00025 
00026 namespace PieDock
00027 {
00033     class PieMenu : public Menu
00034     {
00035         public:
00036             PieMenu( Application *, Surface & );
00037             virtual ~PieMenu() {}
00038             inline const bool cursorInCenter() const {
00039                 return (getSelected() == 0); }
00040             inline const int &getRadius() const { return maxRadius; }
00041             inline Blender *getBlender() { return &blender; }
00042             inline void invalidate() { lastX = lastY = -1; }
00043             virtual bool update( std::string = "", Window = 0 );
00044             virtual bool isObsolete( int, int );
00045             virtual void draw( int, int );
00046             virtual void turn( double );
00047             virtual void turn( int );
00048             virtual void setTwistForSelection();
00049 
00050         protected:
00058             inline virtual double getAngleDifference( double a, double b )
00059             {
00060                 double c = a-b;
00061                 double d;
00062 
00063                 if( a > b )
00064                     d = a-(b+radiansPerCircle);
00065                 else
00066                     d = a-(b-radiansPerCircle);
00067 
00068                 if( fabs( c ) < fabs( d ) )
00069                     return c;
00070 
00071                 return d;
00072             }
00073 
00080             inline virtual double getValidAngle( double a )
00081             {
00082                 if( a < -M_PI )
00083                     a += radiansPerCircle;
00084                 else if( a > M_PI )
00085                     a -= radiansPerCircle;
00086 
00087                 return a;
00088             }
00089 
00090         private:
00091             static const double radiansPerCircle;
00092             static const double turnSteps[];
00093 
00094             Blender blender;
00095             int size;
00096             int maxRadius;
00097             int radius;
00098             double twist;
00099             int centerX;
00100             int centerY;
00101             int lastX;
00102             int lastY;
00103             double *turnStack;
00104             double *turnBy;
00105     };
00106 }
00107 
00108 #endif