tahoma2d/toonz/sources/include/tw/glarea.h

146 lines
3.5 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef GLAREA_INCLUDED
#define GLAREA_INCLUDED
//#include "traster.h"
#include "tw/tw.h"
#undef DVAPI
#undef DVVAR
#ifdef TWIN_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
class TStopWatch;
2016-06-15 18:43:10 +12:00
class DVAPI TGLArea : public TWidget {
void swapBuffers();
TStopWatch *m_stopwatch;
double m_framePerSecond;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void computeOcclusingRegion();
void deleteOcclusingRegion();
// void redrawUncoveredArea(const TPoint &);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::vector<TRect> *m_arrayOfRectToRedraw;
2016-03-19 06:57:51 +13:00
protected:
// int m_lx, m_ly;
// double m_angle;
#define PEZZA_DISABLE_REDRAW
#if defined(MACOSX) && defined(PEZZA_DISABLE_REDRAW)
2016-06-15 18:43:10 +12:00
bool m_disableRedraw;
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
TPoint m_lastPos;
TPointD m_pan; // world origin (win coords) (n. m_pan*2 are integer)
TPointD
m_zoomFactor; // "world pixel" dimension (win coords) (integer if >=1)
TDimensionD m_pixelSize; // 1/zoomFactor; win pixel dimension (world coords)
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double m_zoomLevel; // m_zoomFactor = e^m_zoomLevel
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// supported extensions
static bool m_bgraSupported;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_isInsideScreen;
void onGLContextCreated();
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
class PickItem {
public:
UINT m_label;
UINT m_zMin;
UINT m_zMax;
PickItem(UINT label, UINT zmin, UINT zmax)
: m_label(label), m_zMin(zmin), m_zMax(zmax) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
~PickItem() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
private:
// not implemented
PickItem();
};
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TGLArea(TWidget *parent, string name = "GLArea");
~TGLArea();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void repaint();
void configureNotify(const TDimension &);
void create();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void paintIncrementally();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// void rectwrite(const TRaster32P &ras, const TPoint &p);
void over(const TRaster32P &ras, const TPoint &p);
void over(const TRasterGR8P &ras, const TPoint &p);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
inline TPointD win2world(const TPointD &p) const;
inline TPointD world2win(const TPointD &p) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
inline TAffine getWin2WorldMatrix() const;
inline TAffine getWorld2WinMatrix() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void scroll(const TPoint &d); // viewport coordinates
void lookAt(
const TPointD &d); // world coordinates of the desired window center
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// n. zoomCenter : viewport coords
void setZoomLevel(double zlevel, const TPoint &zoomCenter);
void changeZoomLevel(double d, const TPoint &center);
virtual void onZoomChange() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void fitToWindow(const TRectD &worldRect);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void middleButtonDown(const TMouseEvent &e);
void middleButtonDrag(const TMouseEvent &e);
void middleButtonUp(const TMouseEvent &e);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void draw();
virtual void drawIncrementally();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void drawForPick() { draw(); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void pick(const TPoint &point, vector<PickItem> &items);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double getFramePerSecond() const { return m_framePerSecond; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static bool isBGRASupported() { return m_bgraSupported; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool unProject(TPointD &output,
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TPoint &mousePos, const T3DPointD &planeOrigin,
const T3DPointD &u, const T3DPointD &v) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void makeCurrent(); // Gl context
bool m_dontSwapBuffers;
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
inline TPointD TGLArea::win2world(const TPointD &p) const {
TPointD q = p - m_pan;
return TPointD(m_pixelSize.lx * q.x, m_pixelSize.ly * q.y);
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
inline TPointD TGLArea::world2win(const TPointD &p) const {
return m_pan + TPointD(p.x * m_zoomFactor.x, p.y * m_zoomFactor.y);
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
inline TAffine TGLArea::getWin2WorldMatrix() const {
return TScale(m_pixelSize.lx, m_pixelSize.ly) * TTranslation(-m_pan);
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
inline TAffine TGLArea::getWorld2WinMatrix() const {
return TTranslation(m_pan) * TScale(m_zoomFactor.x, m_zoomFactor.y);
2016-03-19 06:57:51 +13:00
}
#endif