diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/Makefile.am | 5 | ||||
-rw-r--r-- | src/client/input.cc | 9 | ||||
-rw-r--r-- | src/client/input.h | 3 | ||||
-rw-r--r-- | src/client/view.cc | 62 |
4 files changed, 69 insertions, 10 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 0d74532..8022dfa 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -8,6 +8,5 @@ libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS) noinst_LTLIBRARIES = libclient.la noinst_HEADERS = camera.h chat.h client.h console.h input.h keyboard.h video.h \ view.h -libclient_la_LIBADD = $(top_builddir)/src/core/libcore.la \ - $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/render/librender.la $(top_builddir)/src/sys/libsys.la +libclient_la_LIBADD = $(top_builddir)/src/render/librender.la \ + $(top_builddir)/src/core/libcore.la diff --git a/src/client/input.cc b/src/client/input.cc index 1a61424..88d1dd3 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -28,6 +28,10 @@ float local_thrust; // last controlled entity unsigned int last_control = 0; +// mouse cursor position +int mouse_x = 0; +int mouse_y = 0; + void init() { con_print << "Initializing input..." << std::endl; @@ -117,6 +121,11 @@ void frame(float seconds) while (SDL_PollEvent(&event)) { switch (event.type) { + case SDL_MOUSEMOTION: + mouse_x = event.motion.x; + mouse_y = event.motion.y; + break; + case SDL_KEYUP: if (event.key.keysym.sym == SDLK_PRINT) { video::screenshot(); diff --git a/src/client/input.h b/src/client/input.h index daca0d6..9d47eb8 100644 --- a/src/client/input.h +++ b/src/client/input.h @@ -22,6 +22,9 @@ void shutdown(); /// handle one frame of input events void frame(float seconds); +extern int mouse_x; +extern int mouse_y; + } // namespace input } // namespace client diff --git a/src/client/view.cc b/src/client/view.cc index a19f98a..c31cc12 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -15,6 +15,7 @@ #include "client/camera.h" #include "client/chat.h" #include "client/console.h" +#include "client/input.h" #include "client/video.h" #include "render/draw.h" #include "render/render.h" @@ -25,6 +26,9 @@ namespace client { +core::Cvar *draw_stats = 0; +core::Cvar *draw_crosshaircolor = 0; + namespace view { @@ -33,6 +37,9 @@ float fps = 0; void init() { camera::init(); + + draw_stats = core::Cvar::get("draw_stats", "0", core::Cvar::Archive); + draw_crosshaircolor = core::Cvar::get("draw_crosshaircolor", "1 1 1", core::Cvar::Archive); } void shutdown() @@ -93,7 +100,6 @@ void draw_loader() { using namespace render; - gl::enable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, render::textures[0]); // bitmaps/loader.tga gl::color(1.0f, 1.0f, 1.0f, 1.0f); @@ -111,8 +117,6 @@ void draw_loader() glTexCoord2f(0.0f, 1.0f); gl::vertex(0,video::height,0); gl::end(); - - gl::disable(GL_TEXTURE_2D); } void draw_status() @@ -123,7 +127,6 @@ void draw_status() return; glBindTexture(GL_TEXTURE_2D, render::textures[1]); // bitmaps/conchars.tga - gl::enable(GL_TEXTURE_2D); // print the status in the upper left corner gl::color(1.0f, 1.0f, 1.0f, 1.0f); @@ -144,7 +147,7 @@ void draw_status() draw_text(CHARWIDTH, 4, status); // print stats if desired - if (render::r_drawstats && render::r_drawstats->value()) { + if (draw_stats && draw_stats->value()) { std::stringstream stats; stats << "fps " << std::setw(6) << fps << "\n"; if (core::application()->connected()) { @@ -184,11 +187,49 @@ void draw_status() if (core::localcontrol()) { status.str(""); status << " dir " << std::setfill('0') << std::setw(3) << roundf(core::localcontrol()->direction()) << - " speed " << std::setfill(' ') << std::setw(5) << std::fixed << std::setprecision(2) << core::localcontrol()->speed(); + " speed " << std::setfill(' ') << std::setw(5) << std::fixed << std::setprecision(2) << core::localcontrol()->speed() << " - " << input::mouse_x << "+" << input::mouse_y; + draw_text(CHARWIDTH, video::height - CHARHEIGHT -4, status); } - gl::disable(GL_TEXTURE_2D); +} + +void draw_cursor() +{ + if (!core::localcontrol() || console::visible()) + return; + + float crosshair_size = 48.0f; + float x = input::mouse_x - (crosshair_size /2); + float y = input::mouse_y - (crosshair_size /2); + + using namespace render; + + glBindTexture(GL_TEXTURE_2D, render::textures[2]); // bitmaps/crosshairs.tga + + math::Color color; + if (draw_crosshaircolor && draw_crosshaircolor->value()) { + std::stringstream colorstr(draw_crosshaircolor->str()); + colorstr >> color; + } + color.a = 0.5f; + + gl::color(color); + gl::begin(gl::Quads); + + glTexCoord2f(0,0 ); + gl::vertex(x,y,0.0f); + + glTexCoord2f(1, 0); + gl::vertex(x+crosshair_size, y, 0.0f); + + glTexCoord2f(1, 1); + gl::vertex(x+crosshair_size, y+crosshair_size, 0.0f); + + glTexCoord2f(0, 1); + gl::vertex(x, y+crosshair_size, 0.0f); + + gl::end(); } void frame(float seconds) @@ -234,6 +275,8 @@ void frame(float seconds) gl::matrixmode(GL_MODELVIEW); gl::loadidentity(); + gl::enable(GL_TEXTURE_2D); + if (!core::application()->connected()) { // draw the loader bitmap draw_loader(); @@ -245,6 +288,11 @@ void frame(float seconds) // draw the status line draw_status(); + + // draw the mouse cursor + draw_cursor(); + + gl::disable(GL_TEXTURE_2D); } } //namespace view |