Skip to content

Commit

Permalink
Refactor: Switched ui2_main.c to C++ plus minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 28, 2012
1 parent c88f9b9 commit 54ac97a
Show file tree
Hide file tree
Showing 5 changed files with 355 additions and 387 deletions.
130 changes: 67 additions & 63 deletions doomsday/engine/api/dd_ui.h
Expand Up @@ -30,10 +30,6 @@
#include "dd_fontrenderer.h"
#include "dd_vectorgraphic.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @defgroup gui GUI
*/
Expand Down Expand Up @@ -76,7 +72,7 @@ struct fi_page_s;
*/
#define FIOBJECT_BASE_ELEMENTS() \
fi_obtype_e type; /* Type of the object. */ \
struct fi_page_s* page; /* Owning page */ \
struct fi_page_s *page; /* Owning page */ \
int group; \
struct { \
char looping:1; /* Animation will loop. */ \
Expand All @@ -87,34 +83,40 @@ struct fi_page_s;
animatorvector3_t pos; \
animator_t angle; \
animatorvector3_t scale; \
void (*drawer) (struct fi_object_s*, const float offset[3]); \
void (*thinker) (struct fi_object_s* obj);
void (*drawer) (struct fi_object_s *, float const offset[3]); \
void (*thinker) (struct fi_object_s *obj);

#ifdef __cplusplus
extern "C" {
#endif

struct fi_object_s *FI_NewObject(fi_obtype_e type, char const *name);

struct fi_object_s* FI_NewObject(fi_obtype_e type, const char* name);
void FI_DeleteObject(struct fi_object_s* obj);
struct fi_object_s* FI_Object(fi_objectid_t id);

struct fi_object_s *FI_Object(fi_objectid_t id);

/**
* @return Page which presently owns this object. Can be @c NULL if the
* object is presently being moved from one page to another.
*/
struct fi_page_s* FIObject_Page(struct fi_object_s* obj);
struct fi_page_s *FIObject_Page(struct fi_object_s *obj);

/**
* Change/setup a reverse link between this object and it's owning page.
* \note Changing this relationship here does not complete the task of
* @note Changing this relationship here does not complete the task of
* linking an object with a page (not enough information). It is therefore
* the page's responsibility to call this when adding/removing objects.
*/
void FIObject_SetPage(struct fi_object_s* obj, struct fi_page_s* page);
void FIObject_SetPage(struct fi_object_s *obj, struct fi_page_s *page);

/**
* A page is an aggregate visual/visual container.
*
* @ingroup video
*/
typedef struct {
struct fi_object_s** vector;
struct fi_object_s **vector;
uint size;
} fi_object_collection_t;

Expand All @@ -132,20 +134,20 @@ typedef struct fi_page_s {
} flags;

/// Child visuals (objects) visible on this page.
/// \note Unlike de::Visual the children are not owned by the page.
/// @note Unlike de::Visual the children are not owned by the page.
fi_object_collection_t _objects;

/// Offset the world origin.
animatorvector3_t _offset;

void (*drawer) (struct fi_page_s* page);
void (*ticker) (struct fi_page_s* page, timespan_t ticLength);
void (*drawer) (struct fi_page_s *page);
void (*ticker) (struct fi_page_s *page, timespan_t ticLength);

/// Pointer to the previous page, if any.
struct fi_page_s* previous;
struct fi_page_s *previous;

struct fi_page_background_s {
struct material_s* material;
struct material_s *material;
animatorvector4_t topColor;
animatorvector4_t bottomColor;
} _bg;
Expand All @@ -157,71 +159,78 @@ typedef struct fi_page_s {
uint _timer;
} fi_page_t;

fi_page_t* FI_NewPage(fi_page_t* prevPage);
void FI_DeletePage(fi_page_t* page);
fi_page_t *FI_NewPage(fi_page_t *prevPage);
void FI_DeletePage(fi_page_t *page);

/// Draws the page if not hidden.
void FIPage_Drawer(fi_page_t* page);
void FIPage_Drawer(fi_page_t *page);

/// Tic the page if not paused.
void FIPage_Ticker(fi_page_t* page, timespan_t ticLength);
void FIPage_Ticker(fi_page_t *page, timespan_t ticLength);

/// Adds UI object to the page if not already present. Page takes ownership.
struct fi_object_s* FIPage_AddObject(fi_page_t* page, struct fi_object_s* obj);
struct fi_object_s *FIPage_AddObject(fi_page_t *page, struct fi_object_s *obj);

/// Removes UI object from the page if present. Page gives up ownership.
struct fi_object_s* FIPage_RemoveObject(fi_page_t* page, struct fi_object_s* obj);
struct fi_object_s *FIPage_RemoveObject(fi_page_t *page, struct fi_object_s *obj);

/// Is the UI object present on the page?
boolean FIPage_HasObject(fi_page_t* page, struct fi_object_s* obj);
boolean FIPage_HasObject(fi_page_t *page, struct fi_object_s *obj);

/// Current background Material.
struct material_s* FIPage_BackgroundMaterial(fi_page_t* page);
struct material_s *FIPage_BackgroundMaterial(fi_page_t *page);

/// Sets the 'is-visible' state.
void FIPage_MakeVisible(fi_page_t* page, boolean yes);
void FIPage_MakeVisible(fi_page_t *page, boolean yes);

/// Sets the 'is-paused' state.
void FIPage_Pause(fi_page_t* page, boolean yes);
void FIPage_Pause(fi_page_t *page, boolean yes);

/// Sets the background Material.
void FIPage_SetBackgroundMaterial(fi_page_t* page, struct material_s* mat);
void FIPage_SetBackgroundMaterial(fi_page_t *page, struct material_s *mat);

/// Sets the background top color.
void FIPage_SetBackgroundTopColor(fi_page_t* page, float red, float green, float blue, int steps);
void FIPage_SetBackgroundTopColor(fi_page_t *page, float red, float green, float blue, int steps);

/// Sets the background top color and alpha.
void FIPage_SetBackgroundTopColorAndAlpha(fi_page_t* page, float red, float green, float blue, float alpha, int steps);
void FIPage_SetBackgroundTopColorAndAlpha(fi_page_t *page, float red, float green, float blue, float alpha, int steps);

/// Sets the background bottom color.
void FIPage_SetBackgroundBottomColor(fi_page_t* page, float red, float green, float blue, int steps);
void FIPage_SetBackgroundBottomColor(fi_page_t *page, float red, float green, float blue, int steps);

/// Sets the background bottom color and alpha.
void FIPage_SetBackgroundBottomColorAndAlpha(fi_page_t* page, float red, float green, float blue, float alpha, int steps);
void FIPage_SetBackgroundBottomColorAndAlpha(fi_page_t *page, float red, float green, float blue, float alpha, int steps);

/// Sets the x-axis component of the world offset.
void FIPage_SetOffsetX(fi_page_t* page, float x, int steps);
void FIPage_SetOffsetX(fi_page_t *page, float x, int steps);

/// Sets the y-axis component of the world offset.
void FIPage_SetOffsetY(fi_page_t* page, float y, int steps);
void FIPage_SetOffsetY(fi_page_t *page, float y, int steps);

/// Sets the world offset.
void FIPage_SetOffsetXYZ(fi_page_t* page, float x, float y, float z, int steps);
void FIPage_SetOffsetXYZ(fi_page_t *page, float x, float y, float z, int steps);

/// Sets the filter color and alpha.
void FIPage_SetFilterColorAndAlpha(fi_page_t* page, float red, float green, float blue, float alpha, int steps);
void FIPage_SetFilterColorAndAlpha(fi_page_t *page, float red, float green, float blue, float alpha, int steps);

/// Sets a predefined color.
void FIPage_SetPredefinedColor(fi_page_t* page, uint idx, float red, float green, float blue, int steps);
void FIPage_SetPredefinedColor(fi_page_t *page, uint idx, float red, float green, float blue, int steps);

/// @return Animator which represents the identified predefined color.
const animatorvector3_t* FIPage_PredefinedColor(fi_page_t* page, uint idx);
animatorvector3_t const *FIPage_PredefinedColor(fi_page_t *page, uint idx);

/// Sets a predefined font.
void FIPage_SetPredefinedFont(fi_page_t* page, uint idx, fontid_t font);
void FIPage_SetPredefinedFont(fi_page_t *page, uint idx, fontid_t font);

/// @return Unique identifier of the predefined font.
fontid_t FIPage_PredefinedFont(fi_page_t* page, uint idx);
fontid_t FIPage_PredefinedFont(fi_page_t *page, uint idx);

typedef enum {
PFT_MATERIAL,
PFT_PATCH,
PFT_RAW, /// "Raw" graphic or PCX lump.
PFT_XIMAGE /// External graphics resource.
} fi_pic_type_t;

/**
* Rectangle/Image sequence object.
Expand All @@ -230,17 +239,12 @@ fontid_t FIPage_PredefinedFont(fi_page_t* page, uint idx);
*/
typedef struct fidata_pic_frame_s {
int tics;
enum {
PFT_MATERIAL,
PFT_PATCH,
PFT_RAW, /// "Raw" graphic or PCX lump.
PFT_XIMAGE /// External graphics resource.
} type;
fi_pic_type_t type;
struct fidata_pic_frame_flags_s {
char flip:1;
} flags;
union {
struct material_s* material;
struct material_s *material;
patchid_t patch;
lumpnum_t lumpNum;
DGLuint tex;
Expand All @@ -252,7 +256,7 @@ typedef struct fidata_pic_s {
FIOBJECT_BASE_ELEMENTS()
int tics;
uint curFrame;
fidata_pic_frame_t** frames;
fidata_pic_frame_t **frames;
uint numFrames;

animatorvector4_t color;
Expand All @@ -263,10 +267,10 @@ typedef struct fidata_pic_s {
animatorvector4_t otherEdgeColor;
} fidata_pic_t;

void FIData_PicThink(struct fi_object_s* pic);
void FIData_PicDraw(struct fi_object_s* pic, const float offset[3]);
uint FIData_PicAppendFrame(struct fi_object_s* pic, int type, int tics, void* texRef, short sound, boolean flagFlipH);
void FIData_PicClearAnimation(struct fi_object_s* pic);
void FIData_PicThink(struct fi_object_s *pic);
void FIData_PicDraw(struct fi_object_s *pic, float const offset[3]);
uint FIData_PicAppendFrame(struct fi_object_s *pic, fi_pic_type_t type, int tics, void *texRef, short sound, boolean flagFlipH);
void FIData_PicClearAnimation(struct fi_object_s *pic);

/**
* Text object.
Expand All @@ -284,23 +288,23 @@ typedef struct fidata_text_s {
int wait, timer;
float lineHeight;
fontid_t fontNum;
char* text;
char *text;
} fidata_text_t;

void FIData_TextThink(struct fi_object_s* text);
void FIData_TextDraw(struct fi_object_s* text, const float offset[3]);
void FIData_TextCopy(struct fi_object_s* text, const char* str);
void FIData_TextSetFont(struct fi_object_s* text, fontid_t fontNum);
void FIData_TextThink(struct fi_object_s *text);
void FIData_TextDraw(struct fi_object_s *text, float const offset[3]);
void FIData_TextCopy(struct fi_object_s *text, char const *str);
void FIData_TextSetFont(struct fi_object_s *text, fontid_t fontNum);
void FIData_TextSetPreColor(struct fi_object_s* text, uint id);
void FIData_TextSetColor(struct fi_object_s* text, float red, float green, float blue, int steps);
void FIData_TextSetAlpha(struct fi_object_s* text, float alpha, int steps);
void FIData_TextSetColorAndAlpha(struct fi_object_s* text, float red, float green, float blue, float alpha, int steps);
void FIData_TextAccelerate(struct fi_object_s* obj);
void FIData_TextSetColor(struct fi_object_s *text, float red, float green, float blue, int steps);
void FIData_TextSetAlpha(struct fi_object_s *text, float alpha, int steps);
void FIData_TextSetColorAndAlpha(struct fi_object_s *text, float red, float green, float blue, float alpha, int steps);
void FIData_TextAccelerate(struct fi_object_s *obj);

/**
* @return Length of the current text as a counter.
*/
size_t FIData_TextLength(struct fi_object_s* text);
size_t FIData_TextLength(struct fi_object_s *text);

///@}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/engine.pro
Expand Up @@ -618,7 +618,7 @@ SOURCES += \
src/ui/nativeui.cpp \
src/ui/p_control.c \
src/ui/sys_input.c \
src/ui/ui2_main.c \
src/ui/ui2_main.cpp \
src/ui/ui_main.c \
src/ui/ui_panel.c \
src/ui/window.cpp \
Expand Down
35 changes: 17 additions & 18 deletions doomsday/engine/include/ui/ui2_main.h
@@ -1,24 +1,23 @@
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
/**
* @file ui2_main.cpp UI Widgets
* @ingroup ui
*
*\author Copyright © 2010-2012 Daniel Swanson <danij@dengine.net>
* @author Copyright &copy; 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2005-2012 Daniel Swanson <danij@dengine.net>
*
* This program 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 2 of the License, or
* (at your option) any later version.
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
* <small>This program 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 2 of the License, or (at your
* option) any later version. This program 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 this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_UI2_MAIN_H
Expand Down

0 comments on commit 54ac97a

Please sign in to comment.