[go: up one dir, main page]

Menu

[r71]: / main.cpp  Maximize  Restore  History

Download this file

156 lines (118 with data), 3.8 kB

  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
/*
Copyright (c) 2005-2007 Lode Vandevenne
All rights reserved.
This file is part of Lode's Programming Interface.
Lode's Programming Interface 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 3 of the License, or
(at your option) any later version.
Lode's Programming Interface 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 Lode's Programming Interface. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This is an example file that uses lpi to create a GUI.
A game example may be added later in the form of the "Tower Wars" project.
*/
//copypastable compile commands
/*
g++ *.cpp -lSDL -lGL
g++ *.cpp -lSDL -lGL -ansi -pedantic
g++ *.cpp -lSDL -lGL -Wall -Wextra -pedantic -ansi
g++ *.cpp -lSDL -lGL -Wall -Wextra -pedantic -ansi -O3
./a.out
-g3
-pg
gdb
valgrind
gprof > gprof.txt
*/
#include <SDL/SDL.h>
#include "lpi_color.h"
#include "lpi_file.h"
#include "lpi_event.h"
#include "lpi_general.h"
#include "lpi_text.h"
#include "lpi_texture.h"
#include "lpi_screen.h"
#include "lpi_gui.h"
#include "lpi_draw2dgl.h"
#include "lpi_audio.h"
#include "lpi_bignums.h"
#include "lpi_tools.h"
#include "lodepng.h"
#include "lodewav.h"
#include <vector>
#include <iostream>
#include <cmath>
int main(int, char*[]) //the arguments have to be given here, or DevC++ can't link to SDL for some reason
{
lpi::screen(1024, 768, 0, "lpi GUI demo");
lpi::gui::Container c;
lpi::gui::Button sound_button;
sound_button.makeTextPanel(20, 500, "sound");
c.pushTop(&sound_button);
lpi::gui::Scrollbar hbar;
hbar.makeHorizontal(716, 220, 200);
c.pushTop(&hbar);
lpi::gui::Scrollbar vbar;
vbar.makeVertical(700, 20, 200);
c.pushTop(&vbar);
lpi::gui::Slider sli;
sli.makeVertical(650, 20, 200);
c.pushTop(&sli);
lpi::gui::Checkbox cb;
cb.make(500, 20);
c.pushTop(&cb);
lpi::gui::BulletList bl;
bl.make(500, 80, 8, 0, 24);
c.pushTop(&bl);
lpi::gui::Button tb;
tb.makeText(20, 540, "Text Button");
c.pushTop(&tb);
lpi::gui::Button tb_unittest;
tb_unittest.makeText(20, 550, "Unit Test");
c.pushTop(&tb_unittest);
lpi::gui::Window w;
w.make(50, 50, 300, 300);
w.addTop();
w.addTitle("Window 1");
w.addCloseButton();
w.setColor(lpi::RGBA_White(192));
c.pushTop(&w);
lpi::gui::Button wb;
wb.makeTextPanel(0, 0, "window button");
wb.autoTextSize(4);
wb.centerText();
w.pushTopAt(&wb, 20, 20);
lpi::gui::Window w2;
w2.make(100, 100, 300, 300);
w2.addTop();
w2.addTitle("Window 2");
w2.addCloseButton();
w2.addResizer();
w2.setColor(lpi::RGBA_Red(192));
c.pushTop(&w2);
lpi::gui::Checkbox wcb;
wcb.make(0, 0);
w2.pushTopAt(&wcb, 20, 20);
std::vector<double> sound(30000);
for(size_t i = 0; i < 30000; i++) sound[i] = 0.3 * std::sin(i / (30.0 * (40000.0-i)/30000.0));
lpi::audioOpen(44100, 2048);
while(lpi::frame(true, true))
{
lpi::print("lpi GUI demo");
lpi::drawGradientDisk(600, 400, 100, lpi::ColorRGB(128, 255, 128, 255), lpi::ColorRGB(255, 128, 128, 128));
lpi::gui::builtInTexture[37].draw(0, 50);
c.draw();
c.handle();
if(sound_button.pressed()) lpi::audioPlay(sound);
if(tb_unittest.pressed()) lpi::gui::unitTest();
lpi::redraw();
lpi::cls(lpi::RGB_Darkgreen);
}
return 0;
}