File: textboard.cc

package info (click to toggle)
din 5.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,152 kB
  • ctags: 2,490
  • sloc: cpp: 9,369; sh: 6,563; ansic: 2,977; tcl: 1,770; makefile: 285
file content (118 lines) | stat: -rw-r--r-- 3,058 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
/*
 * This file is part of din.
 *
 * din is copyright (c) 2006 - 2012 S Jagannathan <jag@dinisnoise.org>
 * For more information, please visit http://dinisnoise.org
 *
 * din is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * din 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.
 *
 * You should have received a copy of the GNU General Public License along
 * with din.  If not, see <http://www.gnu.org/licenses/>.
 *
*/

#include "textboard.h"
#include "dingl.h"
#include "font.h"
#include "basic_editor.h"

#include <iostream>
using namespace std;

void textboard::draw () {
  glMatrixMode (GL_PROJECTION);
  glPushMatrix ();
  glLoadIdentity ();
  extern viewport view;
  glOrtho (0, view.xmax, 0, view.ymax, -1, 1);
  for (int i = 0, j = texts.size(); i < j; ++i) {
    text& t = texts[i];

    glColor3f (0.2, 0.2, 0.2);
    if (t.type == text::vlabel) {
      glBegin (GL_LINES);
        glVertex2i (t.vx, 0);
        glVertex2i (t.vx, view.ymax);
      glEnd ();
    } else if (t.type == text::hlabel) {
      glBegin (GL_LINES);
        glVertex2i (0, t.vy);
        glVertex2i (view.xmax, t.vy);
      glEnd ();
    }

    glColor3f (t.r, t.g, t.b);
    draw_string (t.txt, t.vx, t.vy);
  }
  glPopMatrix ();
}

void textboard::clear () {
  unsigned int i = 0;
  while (i < texts.size ()) {
    text& ti = texts[i];
    if (ti.state == text::temporary) texts.erase (texts.begin() + i); else ++i;
  }
}

void textboard::erase (const string& s) {
  unsigned int i = 0;
  while (i < texts.size ()) {
    text& ti = texts[i];
    if (ti.txt == s) {
			texts.erase (texts.begin() + i); 
			break;
		} else ++i;
  }
}

void textboard::refresh (basic_editor* b) {
  for (int i = 0, j = texts.size (); i < j; ++i) {
    text& ti = texts[i];
    extern viewport view;
    float wx, wy; b->obj2win (ti.wx, ti.wy, wx, wy);
    win2view (wx, wy, ti.vx, ti.vy, b->win, view);
    if (ti.type == text::hlabel) {
      ti.vx = 3;
    } else if (ti.type == text::vlabel) {
      ti.vy = 3;
    }
  }
}

void textboard::load (ifstream& file) {

  string ignore, txt;
  float r, g, b, wx, wy;
  int type, ntexts;

  file >> ignore >> ntexts;
  for (int i = 0; i < ntexts; ++i) {
    file >> txt >> wx >> wy >> r >> g >> b >> type;
    add (text (txt, wx, wy, r, g, b, text::permanent, type));
  }

}

void textboard::save (ofstream& file) {

  static const char spc = ' ';

  int ntexts = texts.size ();
  file << "num_labels " << ntexts << endl;
  for (int i = 0, j = texts.size (); i < j; ++i) {
    text& ti = texts[i];
    if (ti.type != text::none) {
      file << ti.txt << spc << ti.wx << spc << ti.wy << spc << ti.r << spc << ti.g << spc << ti.b << spc << ti.type << endl;
    }
  }

}