From 9c3baab33a0fa48e7379f0485116452779a1cd37 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 5 Oct 2008 19:05:50 +0000 Subject: interface with ui library --- configure.in | 2 +- doc/models.html | 16 ++--- osirion.kdevelop | 2 +- src/Makefile.am | 4 +- src/client/Makefile.am | 4 +- src/client/client.cc | 6 ++ src/client/video.cc | 7 ++ src/client/view.cc | 171 +++++++++++++++++++++++++++---------------------- src/render/Makefile.am | 4 +- src/render/draw.cc | 2 +- src/render/gl.cc | 10 ++- src/render/gl.h | 5 ++ src/render/textures.cc | 1 + 13 files changed, 140 insertions(+), 94 deletions(-) diff --git a/configure.in b/configure.in index 1f6ada3..6dc6ab0 100644 --- a/configure.in +++ b/configure.in @@ -290,7 +290,7 @@ AM_CONDITIONAL(BUILD_DEDICATED, test "x$BUILD_CLIENT" = xno) AC_OUTPUT(Makefile src/Makefile src/audio/Makefile src/auxiliary/Makefile \ src/client/Makefile src/core/Makefile src/filesystem/Makefile src/game/Makefile \ src/game/base/Makefile src/game/intro/Makefile src/math/Makefile src/model/Makefile \ - src/render/Makefile src/server/Makefile src/sys/Makefile) + src/render/Makefile src/server/Makefile src/sys/Makefile src/ui/Makefile) dnl --------------------------------------------------------------- dnl Configuration summary diff --git a/doc/models.html b/doc/models.html index d2dfdba..9e03330 100644 --- a/doc/models.html +++ b/doc/models.html @@ -96,9 +96,9 @@

The limits of map coordinates are placed on +/-16384 map units. Placing brushes outside these bounds will have unpredictable results. The map - will be scaled down to make 1024 map units correspond to 1 game unit. + will be scaled down to make 1024 units in radiant correspond to 1 game unit. One game unit corresponds to 100m in-game. 16 units in radiant will - therefor be 1.5625 meters. + therefor correspond to 1.5625 meters in-game.

The front of a model points along the positive X-axis, the positive Z-axis is up, the positive Y-axis is left. In GtkRadiant, the nose of @@ -185,26 +185,26 @@

The flare value indicates what texture will be used to draw the light. The flare value is translated to a texture name, bitmaps/fx/flare??. - The default flare textures is flare00. + The default flare texture is flare00.

The light value is used to determine the size of the flare. The engine default is 100, resulting in rather large flares.

The default color is white, but the color can be set through radiant's - color menu (K key). If the entity option (spawnflag 2) is set, the + color menu (K key). If the entity option (spawnflag 2) is set, the color value will be ignored and the light will be rendered with the color of the entity it is attached to.

- The strobe option (spawnflag 1) will create a blinking light. A number + The strobe option (spawnflag 1) will create a blinking light. A number of options can be set to manipulate the flashing behaviour. By default a strobe light will be half a second on, half a second off.

- The frequency value changes the number of flashes per second. + The frequency value changes the number of flashes per second.

- The offset value changes the moment the light will be on. Offset is + The offset value changes the moment the light will be on. Offset is measured in seconds.

- The time value sets the fraction of the time the light will be on. + The time value sets the fraction of time the light will be on. The default is 0.5.

Lights will only be rendered if the model is within detail range. diff --git a/osirion.kdevelop b/osirion.kdevelop index 39c38aa..0f07ee0 100644 --- a/osirion.kdevelop +++ b/osirion.kdevelop @@ -21,7 +21,7 @@ - src/game/intro/libintro.la + src/ui/libui.la debug diff --git a/src/Makefile.am b/src/Makefile.am index aad662b..738bcaa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,8 +4,8 @@ SUFFIXES = .rc .rc.o: windres $< -o $@ -SUBDIRS = sys auxiliary math filesystem model core server audio render client \ - game +SUBDIRS = sys math auxiliary filesystem model core server audio render ui \ + client game noinst_HEADERS = config.h diff --git a/src/client/Makefile.am b/src/client/Makefile.am index b3261b5..09046d9 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -14,5 +14,5 @@ libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS) noinst_HEADERS = action.h chat.h client.h console.h input.h joystick.h key.h \ keyboard.h targets.h video.h view.h -libclient_la_LIBADD = $(top_builddir)/src/render/librender.la \ - $(top_builddir)/src/core/libcore.la +libclient_la_LIBADD = $(top_builddir)/src/core/libcore.la \ + $(top_builddir)/src/render/librender.la $(top_builddir)/src/ui/libui.la diff --git a/src/client/client.cc b/src/client/client.cc index ca88f88..b218166 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -21,6 +21,7 @@ #include "core/core.h" #include "core/zone.h" #include "render/render.h" +#include "ui/ui.h" namespace client { @@ -105,6 +106,9 @@ void Client::init(int count, char **arguments) // initialize SDL, but do not initialize any subsystems SDL_Init(0); + // initialize user interface + ui::init(); + // Initialize the video subsystem if (!video::init()) { quit(1); @@ -199,6 +203,8 @@ void Client::shutdown() video::shutdown(); + ui::shutdown(); + core::Application::shutdown(); quit(0); diff --git a/src/client/video.cc b/src/client/video.cc index ef1f82e..4046260 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -20,6 +20,7 @@ #include "core/core.h" #include "filesystem/filesystem.h" #include "sys/sys.h" +#include "ui/ui.h" #include @@ -70,6 +71,12 @@ void reset() // recalculate the video aspect render::Camera::set_aspect(width, height); + // resize user interface + if (ui::root()) { + ui::root()->set_size((float) width, (float) height); + ui::root()->resize_event(); + } + // reset the view view::reset(); } diff --git a/src/client/view.cc b/src/client/view.cc index 03ce42b..2667938 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -22,6 +22,7 @@ #include "core/core.h" #include "math/mathlib.h" #include "sys/sys.h" +#include "ui/ui.h" namespace client { @@ -578,7 +579,7 @@ void draw_status() void draw_cursor() { - if (!core::localcontrol() || console()->visible()) + if (console()->visible()) return; float angle = 0; @@ -588,83 +589,92 @@ void draw_cursor() bool cursor_animated = false; math::Color color(1.0, 0.5); - if (render::Camera::mode() == render::Camera::Overview) { - render::Textures::bind("bitmaps/pointers/aim"); + if(ui::root()->active()) { + render::Textures::bind("bitmaps/pointers/pointer"); - } else { - // draw center cursor in Cockpit and Track mode - if ((input::mouse_control || input::joystick_control) && - (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { - - if (ui_pointercolor) { - std::stringstream colorstr(ui_pointercolor->str()); - colorstr >> color; - } - - render::Textures::bind("bitmaps/pointers/center"); - float cx = (video::width - pointer_size) /2; - float cy = (video::height - pointer_size) /2; - - render::gl::color(color); - render::gl::begin(render::gl::Quads); - - glTexCoord2f(0,0 ); - render::gl::vertex(cx,cy,0.0f); - - glTexCoord2f(1, 0); - render::gl::vertex(cx+pointer_size, cy, 0.0f); - - glTexCoord2f(1, 1); - render::gl::vertex(cx+pointer_size, cy+pointer_size, 0.0f); - - glTexCoord2f(0, 1); - render::gl::vertex(cx, cy+pointer_size, 0.0f); - - render::gl::end(); - } - - if (targets::hover()) { - - if (ui_pointerhovercolor) { - std::stringstream colorstr(ui_pointerhovercolor->str()); - colorstr >> color; - } - render::Textures::bind("bitmaps/pointers/target"); - - cursor_animated = true; - - if (input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) { - x = (video::width - pointer_size) /2; - y = (video::height - pointer_size) /2; - } - - } else if (input::mouse_control) { - - if (ui_pointercolor) { - std::stringstream colorstr(ui_pointercolor->str()); - colorstr >> color; - } - - render::Textures::bind("bitmaps/pointers/control"); - - if (!input::mouse_deadzone) { - x = input::mouse_position_x() - (pointer_size /2); - y = input::mouse_position_y() - (pointer_size /2); - - } else { - x = (video::width - pointer_size) /2; - y = (video::height - pointer_size) /2; - } + } else if (core::localcontrol()) { + if (render::Camera::mode() == render::Camera::Overview) { + render::Textures::bind("bitmaps/pointers/aim"); + } else { - if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) && (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { - color.assign(1.0, 0.0); + // draw center cursor in Cockpit and Track mode + if ((input::mouse_control || input::joystick_control) && + (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { + + if (ui_pointercolor) { + std::stringstream colorstr(ui_pointercolor->str()); + colorstr >> color; + } + + render::Textures::bind("bitmaps/pointers/center"); + float cx = (video::width - pointer_size) /2; + float cy = (video::height - pointer_size) /2; + + render::gl::color(color); + render::gl::begin(render::gl::Quads); + + glTexCoord2f(0,0 ); + render::gl::vertex(cx,cy,0.0f); + + glTexCoord2f(1, 0); + render::gl::vertex(cx+pointer_size, cy, 0.0f); + + glTexCoord2f(1, 1); + render::gl::vertex(cx+pointer_size, cy+pointer_size, 0.0f); + + glTexCoord2f(0, 1); + render::gl::vertex(cx, cy+pointer_size, 0.0f); + + render::gl::end(); + } + + if (targets::hover()) { + + if (ui_pointerhovercolor) { + std::stringstream colorstr(ui_pointerhovercolor->str()); + colorstr >> color; + } + render::Textures::bind("bitmaps/pointers/target"); + + cursor_animated = true; + + if (input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) { + x = (video::width - pointer_size) /2; + y = (video::height - pointer_size) /2; + } + + } else if (input::mouse_control) { + + if (ui_pointercolor) { + std::stringstream colorstr(ui_pointercolor->str()); + colorstr >> color; + } + + render::Textures::bind("bitmaps/pointers/control"); + + if (!input::mouse_deadzone) { + x = input::mouse_position_x() - (pointer_size /2); + y = input::mouse_position_y() - (pointer_size /2); + + } else { + x = (video::width - pointer_size) /2; + y = (video::height - pointer_size) /2; + } + } else { - color.assign(1.0, 0.5); + if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) && (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { + color.assign(1.0, 0.0); + } else { + color.assign(1.0, 0.5); + } + render::Textures::bind("bitmaps/pointers/aim"); } - render::Textures::bind("bitmaps/pointers/aim"); + } + } else { + return; } if (cursor_animated) { @@ -772,13 +782,16 @@ void frame(float seconds) if (core::application()->load("intro")) { current_zone = 0; core::application()->connect(""); - if (!console()->visible()) - console()->toggle(); } + } else { + /* + if (!core::game()->interactive() && !ui::root()->active()) { + ui::root()->show_window("main"); + } + */ } if (core::application()->connected() && core::game()->serverframetime()) { - if (core::localplayer()->zone() != current_zone) { if (current_zone) clear_zone(current_zone); @@ -799,14 +812,20 @@ void frame(float seconds) // switch to orthographic projection to draw the GUI gl::matrixmode(GL_PROJECTION); gl::loadidentity(); - glOrtho(0, video::width, video::height, 0, -1024.0f, 1024.0f); + glOrtho(0, video::width, video::height, 0, -16.0f, 16.0f); gl::matrixmode(GL_MODELVIEW); gl::loadidentity(); + // draw the user interface + gl::color(1.0f, 1.0f, 1.0f, 1.0f); + gl::disable(GL_TEXTURE_2D); + + ui::frame(); + + // draw the hud - TODO move as much as possible into ui:: gl::enable(GL_BLEND); gl::enable(GL_TEXTURE_2D); - gl::color(1.0f, 1.0f, 1.0f, 1.0f); if (!core::application()->connected()) { diff --git a/src/render/Makefile.am b/src/render/Makefile.am index 27ad8bb..dd2f5f8 100644 --- a/src/render/Makefile.am +++ b/src/render/Makefile.am @@ -10,6 +10,6 @@ endif librender_la_LDFLAGS = -avoid-version -no-undefined @GL_LIBS@ librender_la_LIBADD = $(top_builddir)/src/math/libmath.la librender_la_SOURCES = camera.cc draw.cc dust.cc gl.cc image.cc jpgfile.cc \ - pngfile.cc render.cc text.cc textures.cc tga.cc + pngfile.cc primitives.cc render.cc text.cc textures.cc tga.cc noinst_HEADERS = camera.h draw.h dust.h gl.h image.h render.h text.h textures.h \ - tga.h pngfile.h jpgfile.h + tga.h pngfile.h jpgfile.h primitives.h diff --git a/src/render/draw.cc b/src/render/draw.cc index c74f65f..6de398a 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -749,7 +749,7 @@ void draw_pass_model_fx(float elapsed) math::Axis flare_axis; - size_t circle_texture = Textures::load("bitmaps/fx/circle00"); + size_t circle_texture = Textures::load("bitmaps/fx/circle01"); size_t current_texture = Textures::bind("bitmaps/fx/flare00"); gl::enable(GL_TEXTURE_2D); diff --git a/src/render/gl.cc b/src/render/gl.cc index 5540af0..47a0420 100644 --- a/src/render/gl.cc +++ b/src/render/gl.cc @@ -7,7 +7,7 @@ #include "render/gl.h" #include "math/matrix4f.h" - +using math::Vector2f; using math::Vector3f; using math::Color; @@ -120,6 +120,14 @@ void scale(const float x, const float y, const float z) { glScalef(x, y, z); } +void vertex(const Vector2f& vector) { + glVertex2fv(vector.ptr()); +} + +void vertex(const float x, const float y) { + glVertex2f(x, y); +} + void vertex(const Vector3f& vector) { glVertex3fv(vector.ptr()); } diff --git a/src/render/gl.h b/src/render/gl.h index fb8bdf2..6e32e35 100644 --- a/src/render/gl.h +++ b/src/render/gl.h @@ -10,6 +10,7 @@ #include "GL/gl.h" #include "GL/glu.h" +#include "math/vector2f.h" #include "math/vector3f.h" #include "math/matrix4f.h" #include "math/axis.h" @@ -105,6 +106,10 @@ namespace gl void vertex(const float x, const float y, const float z); + void vertex(const math::Vector2f& vector); + + void vertex(const float x, const float y); + /// glNormal void normal(const math::Vector3f & vector); diff --git a/src/render/textures.cc b/src/render/textures.cc index b6b7f05..bf0cc84 100644 --- a/src/render/textures.cc +++ b/src/render/textures.cc @@ -44,6 +44,7 @@ void Textures::init() load("bitmaps/loader"); // crosshairs + load("bitmaps/pointers/pointer"); load("bitmaps/pointers/aim"); load("bitmaps/pointers/center"); load("bitmaps/pointers/control"); -- cgit v1.2.3