File: window.cpp

package info (click to toggle)
tulip 4.8.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 179,264 kB
  • ctags: 64,517
  • sloc: cpp: 600,444; ansic: 36,311; makefile: 22,136; python: 1,304; sh: 946; yacc: 522; xml: 337; pascal: 157; php: 66; lex: 55
file content (167 lines) | stat: -rw-r--r-- 4,800 bytes parent folder | download | duplicates (2)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
 *
 * This file is part of Tulip (www.tulip-software.org)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux
 *
 * Tulip is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Tulip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 */
#ifndef WINDOWGLYPH_H
#define WINDOWGLYPH_H

#include <tulip/Glyph.h>
#include <tulip/GlRect.h>
#include <tulip/GlLabel.h>
#include <tulip/GlPolyQuad.h>
#include <tulip/GlQuad.h>
#include <tulip/GlTextureManager.h>
#include <tulip/GlGraphRenderingParameters.h>
#include <tulip/ColorProperty.h>
#include <tulip/GlGraphInputData.h>
#include <tulip/TlpTools.h>
#include <tulip/TulipViewSettings.h>

using namespace tlp;
using namespace std;

namespace tlp {

class Window : public Glyph {
public:
  GLYPHINFORMATION("2D - Window", "David Auber", "28/05/2010", "Window with a title bar", "1.0", NodeShape::Window)
  Window(const tlp::PluginContext *context);
  virtual void getIncludeBoundingBox(BoundingBox &boundingBox,node);
  virtual void getTextBoundingBox(BoundingBox &boundingBox,node);
  virtual void draw(node n, float lod);
  virtual Coord getAnchor(const Coord &vector) const;

private:
  Color _rectColor;
  Color _textColor;
  const float _borderWidth;
  GlPolyQuad _border;
  GlQuad _center;
  GlQuad _titleRec;
  BoundingBox _bb;
  BoundingBox _textbb;
};

/*
 *
0------------1 -0.5, 0.5      0.5, 0.5
|\          /|
| 4--------5 |
| |  TXT   | |
| 9--------8 |-0.5 + _borderWith   0.5, 0.5-bo
| |  FREE  | |
| 7--------6 |
|/          \|
3------------2  -0.5,-0.5        0.5, -0.5
*/

PLUGIN(Window)

Window::Window(const tlp::PluginContext* context):
  Glyph(context),
  _rectColor(205, 205, 205, 255),
  _textColor(205, 205, 205, 255),
  _borderWidth(0.02f),
  _border(TulipBitmapDir + "halfCylinderTexture.png") {

  const float textheight = 0.05f;

  Coord v[10];
  v[0].set(-0.5, 0.5, 0);
  v[1].set( 0.5, 0.5, 0);
  v[2].set( 0.5,-0.5, 0);
  v[3].set(-0.5,-0.5, 0);
  v[4].set(-0.5 + _borderWidth, 0.5 - _borderWidth, 0);
  v[5].set( 0.5 - _borderWidth, 0.5 - _borderWidth, 0);
  v[6].set( 0.5 - _borderWidth,-0.5 + _borderWidth, 0);
  v[7].set(-0.5 + _borderWidth,-0.5 + _borderWidth, 0);
  v[8].set( 0.5 - _borderWidth, 0.5 - _borderWidth - textheight *2.f, 0);
  v[9].set(-0.5 + _borderWidth, 0.5 - _borderWidth - textheight *2.f, 0);

  _bb.expand(v[6]);
  _bb.expand(v[9]);
  _bb.expand(v[8]);
  _bb.expand(v[7]);

  _border.addQuadEdge(v[0], v[4], _textColor);
  _border.addQuadEdge(v[1], v[5], _textColor);
  _border.addQuadEdge(v[2], v[6], _textColor);
  _border.addQuadEdge(v[3], v[7], _textColor);
  _border.addQuadEdge(v[0], v[4], _textColor);

  _titleRec.setPosition(0, v[4]);
  _titleRec.setPosition(1, v[5]);
  _titleRec.setPosition(2, v[8]);
  _titleRec.setPosition(3, v[9]);
  _titleRec.setTextureName(TulipBitmapDir + "titlebarGradient.png");


  _textbb.expand(v[4]);
  _textbb.expand(v[8]);
  _textbb.expand(v[5]);
  _textbb.expand(v[9]);

  _center.setPosition(0, v[9]);
  _center.setPosition(1, v[8]);
  _center.setPosition(2, v[6]);
  _center.setPosition(3, v[7]);


}
//=====================================================
void Window::getIncludeBoundingBox(BoundingBox &boundingBox,node) {
  boundingBox = _bb;
}
//=====================================================
void Window::getTextBoundingBox(BoundingBox &boundingBox,node) {
  boundingBox = _textbb;
}
//=====================================================
void Window::draw(node n, float lod) {
  ColorProperty* color = glGraphInputData->getElementColor();
  ColorProperty* colorBorder = glGraphInputData->getElementBorderColor();
  string textureName = glGraphInputData->getElementTexture()->getNodeValue(n);

  if(textureName!="")
    textureName=glGraphInputData->parameters->getTexturePath()+textureName;

  _border.setColor(colorBorder->getNodeValue(n));
  _titleRec.setColor(colorBorder->getNodeValue(n));

  _center.setFillColor(color->getNodeValue(n));
  _center.setTextureName(textureName);
  _center.draw(lod, NULL);
  _titleRec.draw(lod, NULL);
  _border.draw(lod, NULL);
}
//=====================================================
Coord Window::getAnchor(const Coord &vector) const {
  Coord v(vector);
  float x, y, z, fmax;
  v.get(x, y, z);
  v.setZ(0.0f);
  fmax = std::max(fabsf(x), fabsf(y));

  if (fmax > 0.0f)
    return v * (0.5f / fmax);
  else
    return v;
}

} // end of namespace tlp

#endif // WINDOWGLYPH_H