-
-
Notifications
You must be signed in to change notification settings - Fork 12.1k
/
guichan.rb
209 lines (185 loc) 路 6.98 KB
/
guichan.rb
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
class Guichan < Formula
desc "Small, efficient C++ GUI library designed for games"
homepage "https://guichan.sourceforge.net/"
url "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/guichan/guichan-0.8.2.tar.gz"
sha256 "eedf206eae5201eaae027b133226d0793ab9a287bfd74c5f82c7681e3684eeab"
revision 1
bottle do
sha256 cellar: :any, arm64_sonoma: "f9946ca2ce53833770ba41ce2f9fc5b630e46d595b1aaf893e8be3a302841dda"
sha256 cellar: :any, arm64_ventura: "ff8971a12e820a77df5f570dbe145fb5f1046d851d713d8f26f89030429ea93a"
sha256 cellar: :any, arm64_monterey: "917384f24bef699687d0cdd48867f03733db6aeee593537da519360e250fd22e"
sha256 cellar: :any, arm64_big_sur: "3acc3607e1930e9864934244b269370ffc35081c10138daf9b61254195bacc7f"
sha256 cellar: :any, sonoma: "e5a2bcb4611579d22df6474a8986d6127478a4ab9b14dc4bca10cbeb490bd9b1"
sha256 cellar: :any, ventura: "5415af4555a0b2bbacc69dfba87485659a55dc3d7a80c24599a172036235da5d"
sha256 cellar: :any, monterey: "1ef2ef362f796f72ba510c5e1878e8b290846bec405e7b5240e8485971ae6950"
sha256 cellar: :any, big_sur: "2d4f9b296640bffe66b4eb09642ab499517d050821de8299da838937f8611542"
sha256 cellar: :any, catalina: "93a5e8526479a48a82a7890393b2e8871e3cb2e4dae4fae4bddb964177fe784e"
sha256 cellar: :any_skip_relocation, x86_64_linux: "654afd1dcf4f1fa523bba39ded7799d50ec10918eeece0aa5274ba123de17cea"
end
# Uses deprecated SDL 1.2-based `sdl_image`. Also, the homepage redirects to
# a 404 error page and only remaining site is the Google Code archive.
# Last release on 2009-10-05
disable! date: "2023-10-16", because: :unmaintained
depends_on "sdl_image"
on_linux do
depends_on "mesa"
depends_on "mesa-glu"
end
resource "fixedfont.bmp" do
url "https://guichan.sourceforge.net/oldsite/images/fixedfont.bmp"
sha256 "fc6144c8fefa27c207560820450abb41378c705a0655f536ce33e44a5332c5cc"
end
# Fix -flat_namespace being used on Big Sur and later.
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/03cf8088210822aa2c1ab544ed58ea04c897d9c4/libtool/configure-pre-0.4.2.418-big_sur.diff"
sha256 "83af02f2aa2b746bb7225872cab29a253264be49db0ecebb12f841562d9a2923"
end
def install
gl_lib = OS.mac? ? "-framework OpenGL" : "-lGL"
ENV.append "CPPFLAGS", "-I#{Formula["sdl_image"].opt_include}/SDL"
ENV.append "LDFLAGS", "-lSDL -lSDL_image #{gl_lib}"
inreplace "src/opengl/Makefile.in", "-no-undefined", " "
inreplace "src/sdl/Makefile.in", "-no-undefined", " "
system "./configure", "--disable-debug",
"--disable-dependency-tracking",
"--disable-silent-rules",
"--prefix=#{prefix}"
system "make", "install"
end
test do
testpath.install resource("fixedfont.bmp")
(testpath/"helloworld.cpp").write <<~EOS
#include <iostream>
#include <guichan.hpp>
#include <guichan/sdl.hpp>
#include "SDL/SDL.h"
bool running = true;
SDL_Surface* screen;
SDL_Event event;
gcn::SDLInput* input; // Input driver
gcn::SDLGraphics* graphics; // Graphics driver
gcn::SDLImageLoader* imageLoader; // For loading images
gcn::Gui* gui; // A Gui object - binds it all together
gcn::Container* top; // A top container
gcn::ImageFont* font; // A font
gcn::Label* label; // And a label for the Hello World text
void init()
{
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
imageLoader = new gcn::SDLImageLoader();
gcn::Image::setImageLoader(imageLoader);
graphics = new gcn::SDLGraphics();
graphics->setTarget(screen);
input = new gcn::SDLInput();
top = new gcn::Container();
top->setDimension(gcn::Rectangle(0, 0, 640, 480));
gui = new gcn::Gui();
gui->setGraphics(graphics);
gui->setInput(input);
gui->setTop(top);
font = new gcn::ImageFont("fixedfont.bmp", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
gcn::Widget::setGlobalFont(font);
label = new gcn::Label("Hello World");
label->setPosition(280, 220);
top->add(label);
}
void halt()
{
delete label;
delete font;
delete top;
delete gui;
delete input;
delete graphics;
delete imageLoader;
}
void checkInput()
{
while(SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_ESCAPE)
{
running = false;
}
if (event.key.keysym.sym == SDLK_f)
{
if (event.key.keysym.mod & KMOD_CTRL)
{
// Works with X11 only
SDL_WM_ToggleFullScreen(screen);
}
}
}
else if(event.type == SDL_QUIT)
{
running = false;
}
input->pushInput(event);
}
}
void run()
{
while(running)
{
checkInput();
gui->logic();
gui->draw();
SDL_Flip(screen);
}
}
int main(int argc, char **argv)
{
try
{
init();
run();
halt();
}
catch (gcn::Exception e)
{
std::cerr << e.getMessage() << std::endl;
return 1;
}
catch (std::exception e)
{
std::cerr << "Std exception: " << e.what() << std::endl;
return 1;
}
catch (...)
{
std::cerr << "Unknown exception" << std::endl;
return 1;
}
return 0;
}
EOS
flags = [
"-I#{HOMEBREW_PREFIX}/include/SDL",
"-L#{Formula["sdl12-compat"].opt_lib}",
"-L#{Formula["sdl_image"].opt_lib}",
"-lSDL", "-lSDLmain", "-lSDL_image",
"-L#{lib}", "-lguichan", "-lguichan_sdl"
]
if OS.mac?
flags += [
"-framework", "Foundation",
"-framework", "CoreGraphics",
"-framework", "Cocoa",
"-lobjc", "-lc++"
]
else
flags << "-lstdc++"
end
system ENV.cc, "helloworld.cpp", ENV.cppflags,
*flags, "-o", "helloworld"
helloworld = fork do
system testpath/"helloworld"
end
Process.kill("TERM", helloworld)
end
end