File: wgl.h

package info (click to toggle)
python-visual 3.2.9-4.1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,796 kB
  • ctags: 2,664
  • sloc: cpp: 11,958; sh: 8,185; python: 3,709; ansic: 480; makefile: 311
file content (112 lines) | stat: -rw-r--r-- 2,844 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef VISUAL_WGL_H
#define VISUAL_WGL_H

// Copyright (c) 2000, 2001, 2002, 2003 by David Scherer and others.
// See the file license.txt for complete license terms.
// See the file authors.txt for a complete list of contributors.

// wgl - Windows platform-specific GL and windowing code

#include "vector.h"

#include <vector>
#include <utility>
#include <map>
#include <string>

#include "platform.h"
#include "glcontext.h"
#include <GL/gl.h>
#include <GL/glu.h>

namespace visual
{

struct wglFont : glFont 
{
  public:
    // Documentation for these functions is in glFont, not here.
    virtual double getWidth(const char* string);
    virtual double ascent();
    virtual double descent();
    virtual void draw(const char* string);
    virtual void release();

    // for the use of wglContext only:
    wglFont( struct wglContext& cx, HFONT font );
    virtual ~wglFont();
    void addref() {refcount++;}

  private:
    struct wglContext& cx;
    int listBase;
    HFONT hfont;
    int lu_ascent, lu_descent;  // in Windows "logical units"
    int refcount;
};

struct wglContext : glContext 
{
  public:
    void lockMouse();
    void unlockMouse();
    void showMouse();
    void hideMouse();
    int  getMouseButtons();
    int  getMouseButtonsChanged();
    int getShiftKey();
    int getAltKey();
    int getCtrlKey();
    vector  getMouseDelta();
    vector  getMousePos();
    std::string getKeys();

    wglContext();
    ~wglContext();

    bool initWindow( const char* title, int x, int y, int width, int height, int flags );
    bool changeWindow( const char* title, int x, int y, int width, int height, int flags );
    bool isOpen();
    void cleanup();
  
    void makeCurrent();
    void makeNotCurrent();
    void swapBuffers();

    vector origin();   // top left of entire window (or, same as initWindow())
    vector corner();   // bottom right of entire window (or, same as initWindow())
    int width();       // of GL area
    int height();      // of GL area

    std::string lastError() { return error_message; }
    bool   mustPaint;

    glFont* getFont( const char* description, double size);

  private:
    std::map< std::pair< std::string, double>, wglFont* > fontCache;
    friend struct wglWindowClass;
    struct wglWindowClass& cls;
    HWND  hWnd;
    HDC   hdc, lasthdc;
    HGLRC hglrc, lastglrc;
    std::string error_message;

    int buttonState, buttonChanged;
    int Kshift, Kalt, Kctrl; //true if down when mouse event happens
    vector mousePos;
    vector mouseDelta;
    bool mouseLocked;
    std::vector< std::string> keys;

    int current;  // incremented by makeCurrent(), decremented by makeNotCurrent()

    LRESULT winMessage( HWND, UINT, WPARAM, LPARAM );
    void error( std::string where);

    friend struct wglFont;    
};

} // !namespace visual

#endif // !VISUAL_WGL_H