# HG changeset patch # User John Tsiombikas # Date 1393273549 -7200 # Node ID 3aa12cdb9925268dec7c9df62990d26b51ad0dc9 initial commit diff -r 000000000000 -r 3aa12cdb9925 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Mon Feb 24 22:25:49 2014 +0200 @@ -0,0 +1,15 @@ +src = test.cc $(wildcard src/*.cc) +obj = $(src:.cc=.o) + +bin = test + +CFLAGS = -pedantic -Wall -g -Iinclude +CXXFLAGS = $(CFLAGS) +LDFLAGS = -lGL -lGLU -lglut + +$(bin): $(obj) + $(CXX) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(bin) diff -r 000000000000 -r 3aa12cdb9925 include/button.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/button.h Mon Feb 24 22:25:49 2014 +0200 @@ -0,0 +1,21 @@ +#ifndef GAMEUI_BUTTON_H_ +#define GAMEUI_BUTTON_H_ + +#include "widget.h" + +namespace gameui { + +class ButtonImpl; + +class Button { +private: + ButtonImpl *impl; + +public: + Button(); + virtual ~Button(); +}; + +} + +#endif // GAMEUI_BUTTON_H_ diff -r 000000000000 -r 3aa12cdb9925 include/gameui.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/gameui.h Mon Feb 24 22:25:49 2014 +0200 @@ -0,0 +1,8 @@ +#ifndef GAMEUI_H_ +#define GAMEUI_H_ + +#include "widget.h" +#include "button.h" +#include "label.h" + +#endif // GAMEUI_H_ diff -r 000000000000 -r 3aa12cdb9925 include/label.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/label.h Mon Feb 24 22:25:49 2014 +0200 @@ -0,0 +1,19 @@ +#ifndef GAMEUI_LABEL_H_ +#define GAMEUI_LABEL_H_ + +namespace gameui { + +class LabelImpl; + +class Label { +private: + LabelImpl *impl; + +public: + Label(); + virtual ~Label(); +}; + +} + +#endif // GAMEUI_LABEL_H_ diff -r 000000000000 -r 3aa12cdb9925 include/widget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/widget.h Mon Feb 24 22:25:49 2014 +0200 @@ -0,0 +1,63 @@ +#ifndef GAMEUI_WIDGET_H_ +#define GAMEUI_WIDGET_H_ + +namespace gameui { + +class Vec2 { +public: + float x, y; + + Vec2() : x(0), y(0) {} + Vec2(float xx, float yy) : x(xx), y(yy) {} +}; + +class BBox { +public: + Vec2 bmin, bmax; +}; + +class WidgetImpl; + +class Widget { +private: + WidgetImpl *impl; + +public: + enum VisState { + VST_HIDDEN, + VST_EASEIN, + VST_VISIBLE, + VST_EASEOUT + }; + enum ActiveState { + AST_INACTIVE, + AST_EASEIN, + AST_ACTIVE, + AST_EASEOUT + }; + + Widget(); + virtual ~Widget(); + + virtual void show(); + virtual void hide(); + virtual float get_visibility() const; + + virtual void activate(); + virtual void deactivate(); + virtual float get_active() const; + + virtual const BBox &get_box() const; + virtual const Vec2 &get_position() const; + virtual const Vec2 &get_size() const; + + virtual bool hit_test(const Vec2 &pt) const; + + virtual void draw() const = 0; +}; + +long get_cur_time(); + +} + +#endif // GAMEUI_WIDGET_H_ diff -r 000000000000 -r 3aa12cdb9925 src/gameui_impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gameui_impl.h Mon Feb 24 22:25:49 2014 +0200 @@ -0,0 +1,4 @@ +#ifndef GAMEUI_IMPL_H_ +#define GAMEUI_IMPL_H_ + +#endif // GAMEUI_IMPL_H_ diff -r 000000000000 -r 3aa12cdb9925 src/widget.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widget.cc Mon Feb 24 22:25:49 2014 +0200 @@ -0,0 +1,110 @@ +#include +#include +#include "widget.h" + +using namespace gameui; + +class WidgetImpl { +public: + std::string name_prefix; + std::string name; + BBox box; + VisState vis_st; + ActiveState act_st; + + float vis, act; + + long vis_start_time, act_start_time; +}; + + +Widget::Widget() + : name_prefix("widget") +{ + static int widget_count; + + std::stringstream sstr; + sstr << name_prefix << widget_count++; + name = sstr.str(); + + box.bmin = Vec2(0, 0); + box.bmax = Vec2(1, 1); + + vis_st = VST_VISIBLE; + act_st = AST_ACTIVE; + + vis = act = 1.0; +} + +Widget::~Widget() +{ +} + +void Widget::show() +{ + if(vis_st == VST_EASEVISIBLE || vis_st == VST_EASEIN) { + return; + } + + vis_st = VST_EASEIN; + vis_start_time = get_cur_time(); +} + +void Widget::hide() +{ + if(vis_st == VST_EASEHIDDEN || vis_st == VST_EASEOUT) { + return; + } + + vis_st = VST_EASEOUT; + vis_start_time = get_cur_time(); +} + +float Widget::get_visibility() const +{ + switch(vis_st) { + case VST_EASEIN: + vis = (get_cur_time() - vis_start_time) / gameui::ease_time; + if(vis < 0.0) vis = 0.0; + if(vis > 1.0) vis = 1.0; + break; + + case VST_EASEOUT: + vis = 1.0 - (get_cur_time() - vis_start_time) / gameui::ease_time; + if(vis < 0.0) vis = 0.0; + if(vis > 1.0) vis = 1.0; + break; + + case VST_HIDDEN: + vis = 0.0; + break; + + case VST_VISIBLE: + vis = 1.0; + break; + } + + return vis; +} + +#ifdef WIN32 +long gameui::get_cur_time() +{ + return GetTickCount(); +} +#endif + +#if defined(__unix__) || defined(__APPLE__) +long gameui::get_cur_time() +{ + struct timeval tv; + static struct timeval tv0; + + gettimeofday(&tv, 0); + if(tv0.tv_sec == 0 && tv0.tv_msec == 0) { + tv0 = tv; + return 0; + } + return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000; +} +#endif diff -r 000000000000 -r 3aa12cdb9925 test.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test.cc Mon Feb 24 22:25:49 2014 +0200 @@ -0,0 +1,94 @@ +#include +#include +#include +#include + +static bool init(); +static void cleanup(); +static void disp(); +static void reshape(int x, int y); +static void keypress(unsigned char key, int x, int y); +static void keyrelease(unsigned char key, int x, int y); +static void skeypress(int key, int x, int y); +static void skeyrelease(int key, int x, int y); +static void mouse(int bn, int st, int x, int y); +static void motion(int x, int y); + +int main(int argc, char **argv) +{ + glutInitWindowSize(800, 600); + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + glutCreateWindow("gameui test"); + + glutDisplayFunc(disp); + glutReshapeFunc(reshape); + glutKeyboardFunc(keypress); + glutKeyboardUpFunc(keyrelease); + glutSpecialFunc(skeypress); + glutSpecialUpFunc(skeyrelease); + glutMouseFunc(mouse); + glutMotionFunc(motion); + glutPassiveMotionFunc(motion); + + if(!init()) { + return 1; + } + atexit(cleanup); + + glutMainLoop(); + return 0; +} + + +static bool init() +{ + return true; +} + +static void cleanup() +{ +} + +static void disp() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glutSwapBuffers(); + assert(glGetError() == GL_NO_ERROR); +} + +static void reshape(int x, int y) +{ + glViewport(0, 0, x, y); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, x, y, 0, -1, 1); +} + +static void keypress(unsigned char key, int x, int y) +{ + if(key == 27) { + exit(0); + } +} + +static void keyrelease(unsigned char key, int x, int y) +{ +} + +static void skeypress(int key, int x, int y) +{ +} + +static void skeyrelease(int key, int x, int y) +{ +} + +static void mouse(int bn, int st, int x, int y) +{ +} + +static void motion(int x, int y) +{ +}