File: SampleShell.C

package info (click to toggle)
gmod 3.1-8.3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,340 kB
  • ctags: 808
  • sloc: cpp: 7,764; makefile: 76
file content (145 lines) | stat: -rw-r--r-- 2,659 bytes parent folder | download | duplicates (7)
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
// -*-C++-*-
// This file is part of the gmod package
// Copyright (C) 1997 by Andrew J. Robinson

#include <stdio.h>

#include "SampleShell.h"

#ifdef USE_X

SampleShell::SampleShell(QWidget *w) : QWidget(w, "sampleShell")
{
  setMinimumSize(70, 40);
  setCaption("Xgmod Samples");

  sampleList = new QListBox(this, "sampleList");
  sampleList->setGeometry(5, 5, 200, 160);
  
  closeButton = new QPushButton(this, "closeButton");
  closeButton->setText("Close");
  closeButton->setGeometry(75, 200, 60, 25);
  connect(closeButton, SIGNAL(clicked()), this, SLOT(closeSampleShell()));

  resize(210, 200);
}

void
SampleShell::showSampleShell()
{
  show();
}

void
SampleShell::closeSampleShell()
{
  close();
}

void
SampleShell::resizeEvent(QResizeEvent *)
{
  closeButton->move((width() - 60) / 2, height() - 30);
  sampleList->resize(width() - 10, height() - 40);
}

void
SampleShell::setSamples(Sample **samples, int nrSamples)
{
  int i;
  char sampleName[SAMPNAME_LEN + 6];

  sampleList->setAutoUpdate(FALSE);
  sampleList->clear();

  for (i = 0; i < nrSamples; i++)
    {
      if (samples[i]->ok())
	sprintf(sampleName, "[%03d] ", i);
      else
	strcpy(sampleName, "[xxx] ");

      strcat(sampleName, samples[i]->name());
      sampleList->insertItem(sampleName);
    }

  sampleList->repaint();
  sampleList->setAutoUpdate(TRUE);
}

#ifndef DEPEND
#include "SampleShell.moc"
#endif

#else /* !USE_X */

#ifndef USE_NCURSES

SampleShell::SampleShell(int background, int showEmpty)
  : background_(background), showEmpty_(showEmpty)
{
}

#else

SampleShell::SampleShell(int background)
  : background_(background), sampleWin_(0)
{
}

#endif

void
SampleShell::setSamples(Sample **samples, int nrSamples)
{
  if (!background_)
    {
      int i;

#ifdef USE_NCURSES
      if (sampleWin_)
	delwin(sampleWin_);

      sampleWin_ = newpad(nrSamples, COLS);
      scrollok(sampleWin_, FALSE);
      sampleLines_ = LINES - 6;
      
  //    if (sampleLines_ > nrSamples)
  //	sampleLines_ = nrSamples;

      for (i = 0; i < nrSamples; i++)
	samples[i]->printInfo(sampleWin_, i);

      nrSamples_ = nrSamples;
      firstVisible_ = 0;

      prefresh(sampleWin_, 0, 0, 4, 0, 4 + sampleLines_ - 1, COLS - 1);
#else
      for (i = 0; i < nrSamples; i++)
	samples[i]->printInfo(i, showEmpty_);
#endif  
    }
}

#ifdef USE_NCURSES

void
SampleShell::scrollSamples(int direction)
{
  if (direction > 0)
    {
      if (firstVisible_ < (nrSamples_ - sampleLines_))
	firstVisible_++;
    }
  else
    {
      if (firstVisible_ > 0)
	  firstVisible_--;
    }

  prefresh(sampleWin_, firstVisible_, 0, 4, 0, 4 + sampleLines_ - 1, COLS - 1);
}

#endif

#endif