Bazaar/FTGL_Demo : fixed in windows

git-svn-id: svn://ultimatepp.org/upp/trunk@3879 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
micio 2011-09-17 21:30:40 +00:00
parent 068d181239
commit 1d4b8b21f1
3 changed files with 720 additions and 711 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,70 +1,70 @@
#ifndef _FTGL_Demo_FTGLCtrl_h_
#define _FTGL_Demo_FTGLCtrl_h_
#include <CtrlLib/CtrlLib.h>
#include <GLCtrl/GLCtrl.h>
#include <FTGL/ftgl.h>
#include "TrackBall.h"
using namespace Upp;
class FTGLCtrl : public GLCtrl
{
private:
TrackBall trackBall;
typedef enum { FTGL_BITMAP, FTGL_PIXMAP, FTGL_OUTLINE, FTGL_POLYGON, FTGL_EXTRUDE, FTGL_TEXTURE, NumStyles } Styles;
typedef enum { EDITING = 1, INTERACTIVE } Modes;
Modes mode;
Vector<String> fontFiles;
int currentFont;
// array containing all fonts
Array<FTFont> fonts;
int totalFonts;
One<FTPixmapFont> infoFont;
Array<FTLayout> layouts;
int currentLayout;
bool hasLayout(void) { return currentLayout >= 0 && currentLayout < layouts.GetCount(); }
// displayed string
String myString;
void SetUpLighting();
void SetUpFonts(int numFontFiles);
void RenderFontmetrics();
void RenderFontInfo();
void SetCamera();
void Paint0(void);
int GetStyle() { return currentFont % NumStyles; }
int GetFace() { return currentFont / NumStyles; }
float OX;
float OY;
float initialLineLength;
protected:
virtual void GLPaint();
virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags) { return trackBall.MouseEvent(event, p, zdelta, keyflags); }
virtual bool Key(dword key, int count);
virtual void Layout();
public:
typedef FTGLCtrl CLASSNAME;
void SetFontFiles(Vector<String> const &files);
FTGLCtrl();
};
#endif
#ifndef _FTGL_Demo_FTGLCtrl_h_
#define _FTGL_Demo_FTGLCtrl_h_
#include <CtrlLib/CtrlLib.h>
#include <GLCtrl/GLCtrl.h>
#include <FTGL/ftgl.h>
#include "TrackBall.h"
using namespace Upp;
class FTGLCtrl : public GLCtrl
{
private:
TrackBall trackBall;
typedef enum { FTGL_BITMAP, FTGL_PIXMAP, FTGL_OUTLINE, FTGL_POLYGON, FTGL_EXTRUDE, FTGL_TEXTURE, NumStyles } Styles;
typedef enum { EDITING = 1, INTERACTIVE } Modes;
Modes mode;
Vector<String> fontFiles;
int currentFont;
// array containing all fonts
Array<FTFont> fonts;
int totalFonts;
One<FTPixmapFont> infoFont;
Array<FTLayout> layouts;
int currentLayout;
bool hasLayout(void) { return currentLayout >= 0 && currentLayout < layouts.GetCount(); }
// displayed string
String myString;
void SetUpLighting();
void SetUpFonts(int numFontFiles);
void RenderFontmetrics();
void RenderFontInfo();
void SetCamera();
void Paint0(void);
int GetStyle() { return currentFont % NumStyles; }
int GetFace() { return currentFont / NumStyles; }
float OX;
float OY;
float initialLineLength;
protected:
virtual void GLPaint();
virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags);
virtual bool Key(dword key, int count);
virtual void Layout();
public:
typedef FTGLCtrl CLASSNAME;
void SetFontFiles(Vector<String> const &files);
FTGLCtrl();
};
#endif

View file

@ -1,98 +1,102 @@
#include "TrackBall.h"
#include "trackball.h"
#include <GL/glut.h>
void TrackBall::_Animate(void)
{
add_quats(lastquat, curquat, curquat);
owner->Refresh();
owner->Sync();
if(enableAnimCb)
owner->SetTimeCallback(10, THISBACK(_Animate));
}
void TrackBall::_StartMotion(int x, int y, Time time)
{
enableAnimCb = false;
tracking = true;
lastTime = time;
beginx = x;
beginy = y;
}
void TrackBall::_StopMotion(Time time)
{
tracking = false;
if (time == lastTime && animate)
{
enableAnimCb = true;
_Animate();
}
else
if (animate)
enableAnimCb = false;
}
void TrackBall::Animate(bool a)
{
animate = a;
}
void TrackBall::Matrix(void)
{
GLfloat m[4][4];
build_rotmatrix(m, curquat);
glMultMatrixf(&m[0][0]);
}
void TrackBall::Reshape(int w, int h)
{
width = w;
height = h;
}
// mouse event handler
Image TrackBall::MouseEvent(int event, Point p, int zdelta, dword keyflags)
{
// mouse up/down starts and stop motion
if ((event & Ctrl::BUTTON) == button && (event & Ctrl::ACTION) == Ctrl::DOWN)
_StartMotion(p.x, p.y, GetSysTime());
else
if ((event & Ctrl::BUTTON) == button && (event & Ctrl::ACTION) == Ctrl::UP)
_StopMotion(GetSysTime());
// mouse move do the animation, if we're tracking
else if((event & Ctrl::ACTION) == Ctrl::MOUSEMOVE)
{
if (tracking)
{
trackball(
lastquat,
(2.0 * beginx - width) / width,
(height - 2.0 * beginy) / height,
(2.0 * p.x - width) / width,
(height - 2.0 * p.y) / height
);
beginx = p.x;
beginy = p.y;
animate = true;
lastTime = GetSysTime();
_Animate();
}
}
return Image();
}
TrackBall::TrackBall(Ctrl *ow)
{
owner = ow;
button = Ctrl::LEFT;
tracking = false;
animate = false;
trackball(curquat, 0.0, 0.0, 0.0, 0.0);
enableAnimCb = false;
}
#include "TrackBall.h"
#include "trkball.h"
#ifdef PLATFORM_POSIX
#include <GL/glut.h>
#elif defined(WIN32)
#include <gl/glu.h>
#endif
void TrackBall::_Animate(void)
{
add_quats(lastquat, curquat, curquat);
owner->Refresh();
if(enableAnimCb)
owner->SetTimeCallback(10, THISBACK(_Animate));
}
void TrackBall::_StartMotion(int x, int y, Time time)
{
enableAnimCb = false;
tracking = true;
lastTime = time;
beginx = x;
beginy = y;
}
void TrackBall::_StopMotion(Time time)
{
tracking = false;
if (time == lastTime && animate)
{
enableAnimCb = true;
_Animate();
}
else
if (animate)
enableAnimCb = false;
}
void TrackBall::Animate(bool a)
{
animate = a;
}
void TrackBall::Matrix(void)
{
GLfloat m[4][4];
build_rotmatrix(m, curquat);
glMultMatrixf(&m[0][0]);
}
void TrackBall::Reshape(int w, int h)
{
width = w;
height = h;
}
// mouse event handler
Image TrackBall::MouseEvent(int event, Point p, int zdelta, dword keyflags)
{
// mouse up/down starts and stop motion
if ((event & Ctrl::BUTTON) == button && (event & Ctrl::ACTION) == Ctrl::DOWN)
_StartMotion(p.x, p.y, GetSysTime());
else
if ((event & Ctrl::BUTTON) == button && (event & Ctrl::ACTION) == Ctrl::UP)
_StopMotion(GetSysTime());
// mouse move do the animation, if we're tracking
else if((event & Ctrl::ACTION) == Ctrl::MOUSEMOVE)
{
if (tracking)
{
trackball(
lastquat,
(2.0 * beginx - width) / width,
(height - 2.0 * beginy) / height,
(2.0 * p.x - width) / width,
(height - 2.0 * p.y) / height
);
beginx = p.x;
beginy = p.y;
animate = true;
lastTime = GetSysTime();
_Animate();
}
}
return Image::Hand();
}
TrackBall::TrackBall(Ctrl *ow)
{
owner = ow;
button = Ctrl::LEFT;
tracking = false;
animate = false;
trackball(curquat, 0.0, 0.0, 0.0, 0.0);
enableAnimCb = false;
}