File: Block.cpp

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (154 lines) | stat: -rw-r--r-- 3,978 bytes parent folder | download | duplicates (3)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154


/* 
A* -------------------------------------------------------------------
B* This file contains source code for the PyMOL computer program
C* Copyright (c) Schrodinger, LLC. 
D* -------------------------------------------------------------------
E* It is unlawful to modify or remove this copyright notice.
F* -------------------------------------------------------------------
G* Please see the accompanying LICENSE file for further information. 
H* -------------------------------------------------------------------
I* Additional authors of this source file include:
-* 
-* 
-*
Z* -------------------------------------------------------------------
*/
#include"os_python.h"
#include"os_predef.h"
#include"os_gl.h"

#include"Block.h"
#include"main.h"
#include"CGO.h"

int Block::getWidth() const {
    return rect.right - rect.left;
}

/*========================================================================*/
int Block::getHeight() const {
    return rect.top - rect.bottom;
}

/*========================================================================*/
void Block::fill(CGO *orthoCGO)
{
  if(m_G->HaveGUI && m_G->ValidContext) {
    if (orthoCGO){
      CGOBegin(orthoCGO, GL_TRIANGLE_STRIP);
      CGOVertex(orthoCGO, rect.right, rect.top, 0.f);
      CGOVertex(orthoCGO, rect.right, rect.bottom, 0.f);
      CGOVertex(orthoCGO, rect.left, rect.top, 0.f);
      CGOVertex(orthoCGO, rect.left, rect.bottom, 0.f);
      CGOEnd(orthoCGO);
    } else {
      glBegin(GL_POLYGON);
      glVertex2i(rect.right, rect.top);
      glVertex2i(rect.right, rect.bottom);
      glVertex2i(rect.left, rect.bottom);
      glVertex2i(rect.left, rect.top);
      glEnd();
    }
  }
}


/*========================================================================*/
void Block::drawLeftEdge(CGO *orthoCGO)
{
  if(m_G->HaveGUI && m_G->ValidContext) {
    if (orthoCGO){
      CGOColor(orthoCGO, .3f, .3f, .3f);
      CGOBegin(orthoCGO, GL_TRIANGLE_STRIP);
      CGOVertex(orthoCGO, rect.left, rect.bottom, 0.f);
      CGOVertex(orthoCGO, rect.left + 1.f, rect.bottom, 0.f);
      CGOVertex(orthoCGO, rect.left, rect.top, 0.f);
      CGOVertex(orthoCGO, rect.left + 1.f, rect.top, 0.f);
      CGOEnd(orthoCGO);
    } else {
      if(m_G->HaveGUI && m_G->ValidContext) {
	glColor3f(0.3, 0.3, 0.3);
	glBegin(GL_LINES);
	glVertex2i(rect.left, rect.bottom);
	glVertex2i(rect.left, rect.top);
	glEnd();
      }
    }
  }
}

/*========================================================================*/
void Block::drawTopEdge()
{
#ifndef PURE_OPENGL_ES_2
  if(m_G->HaveGUI && m_G->ValidContext) {
    glColor3f(0.3, 0.3, 0.3);
    glBegin(GL_LINES);
    glVertex2i(rect.right, rect.top);
    glVertex2i(rect.left, rect.top);
    glEnd();
  }
#endif
}


/*========================================================================*/
void Block::setMargin(int t, int l, int b, int r)
{
  margin.top = t;
  margin.left = l;
  margin.bottom = b;
  margin.right = r;
}

/*========================================================================*/
void Block::reshape(int width, int height)
{
  rect.top = (height - margin.top);
  rect.left = margin.left;
  rect.bottom = margin.bottom;
  rect.right = (width - margin.right);
}

/*========================================================================*/
void Block::translate(int dx, int dy)
{
  rect.top += dy;
  rect.left += dx;
  rect.bottom += dy;
  rect.right += dx;
}


/*========================================================================*/
void Block::recursiveDraw(CGO* orthoCGO)
{
  if (active) {
    draw(orthoCGO);
  }
}

bool Block::recursiveFastDraw(CGO* orthoCGO)
{
  bool ret = false;
  if (active) {
    ret |= fastDraw(orthoCGO);
  }
  return ret;
}

Block* Block::recursiveFind(int x, int y)
{
  if (!active || !rectXYInside(x, y)) {
    return nullptr;
  }
  return this;
}

bool Block::rectXYInside(int x, int y) const
{
  return ((y <= rect.top) && (y >= rect.bottom) &&
          (x <= rect.right) && (x >= rect.left));
}