1
0
forked from 0ad/0ad

minimap: now use GUI event system instead of polling. fixes broken click feature.

textureentry: add performance note
list, text: fix mousewheel direction
input: was going to add a deque to allow registering handlers in back
and front. obviated by minimap fix, though. cleaned up a bit and renamed
stuff (again, sigh).
loaderthunks: fixed weird alignment/padding warning

This was SVN commit r2979.
This commit is contained in:
janwas 2005-10-20 15:27:39 +00:00
parent 1ff1045a7c
commit 32cfc6d807
30 changed files with 91 additions and 112 deletions

View File

@ -24,7 +24,7 @@
#include "ConfigDB.h"
#include "Loader.h"
#include "Profile.h"
#include "LoaderThunks.h"
#include "ps/LoaderThunks.h"
#include "Quaternion.h"
#include "Unit.h"
@ -579,7 +579,7 @@ void CGameView::PopCameraTarget()
m_CameraTargets.pop_back();
}
InEventReaction game_view_handler(const SDL_Event* ev)
InReaction game_view_handler(const SDL_Event* ev)
{
// put any events that must be processed even if inactive here
@ -591,7 +591,7 @@ InEventReaction game_view_handler(const SDL_Event* ev)
return pView->HandleEvent(ev);
}
InEventReaction CGameView::HandleEvent(const SDL_Event* ev)
InReaction CGameView::HandleEvent(const SDL_Event* ev)
{
switch(ev->type)
{

View File

@ -93,7 +93,7 @@ public:
// Render: Render the World
void Render();
InEventReaction HandleEvent(const SDL_Event* ev);
InReaction HandleEvent(const SDL_Event* ev);
//Keep the camera in between boundaries/smooth camera scrolling/translating
//Should call this whenever moving (translating) the camera
@ -116,6 +116,6 @@ public:
inline CCamera *GetCamera()
{ return &m_Camera; }
};
extern InEventReaction game_view_handler(const SDL_Event* ev);
extern InReaction game_view_handler(const SDL_Event* ev);
#endif

View File

@ -12,7 +12,6 @@
#include "TerrainProperties.h"
#include "Texture.h"
#include "Renderer.h"
#include "timer.h"
#define LOG_CATEGORY "graphics"
@ -77,15 +76,12 @@ void CTextureEntry::LoadTexture()
}
}
TIMER_ADD_CLIENT(tc_mipmap_basecolor);
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BuildBaseColor: calculate the root colour of the texture, used for coloring minimap, and store
// in m_BaseColor member
void CTextureEntry::BuildBaseColor()
{
TIMER_ACCRUE(tc_mipmap_basecolor);
if (m_pProperties && m_pProperties->HasBaseColor())
{
m_BaseColor=m_pProperties->GetBaseColor();
@ -102,7 +98,11 @@ TIMER_ACCRUE(tc_mipmap_basecolor);
// (or gives an incorrect colour) in some cases:
// - suspect bug on Radeon cards when SGIS_generate_mipmap is used
// - any textures without mipmaps
// we'll just take the basic approach here:
// we'll just take the basic approach here.
//
// jw: this is horribly inefficient (taking 750ms for 10 texture types),
// but it is no longer called, since terrain XML files are supposed to
// include a minimap color attribute. therefore, leave it as-is.
int width,height;
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH,&width);
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&height);

View File

@ -181,7 +181,7 @@ void CDropDown::HandleMessage(const SGUIMessage &Message)
CList::HandleMessage(Message);
}
InEventReaction CDropDown::ManuallyHandleEvent(const SDL_Event* ev)
InReaction CDropDown::ManuallyHandleEvent(const SDL_Event* ev)
{
int szChar = ev->key.keysym.sym;
bool update_highlight = false;

View File

@ -68,7 +68,7 @@ public:
/**
* Handle events manually to catch keyboard inputting.
*/
virtual InEventReaction ManuallyHandleEvent(const SDL_Event* ev);
virtual InReaction ManuallyHandleEvent(const SDL_Event* ev);
/**
* Draws the Button

View File

@ -60,14 +60,14 @@ JSClass GUIClass = {
// event is passed to other handlers if false is returned.
// trampoline: we don't want to make the implementation (in CGUI) static
//-------------------------------------------------------------------
InEventReaction gui_handler(const SDL_Event* ev)
InReaction gui_handler(const SDL_Event* ev)
{
return g_GUI.HandleEvent(ev);
}
InEventReaction CGUI::HandleEvent(const SDL_Event* ev)
InReaction CGUI::HandleEvent(const SDL_Event* ev)
{
InEventReaction ret = IN_PASS;
InReaction ret = IN_PASS;
if (ev->type == SDL_GUIHOTKEYPRESS)
{

View File

@ -32,7 +32,7 @@ ERROR_TYPE(GUI, JSOpenFailed);
#include "XML/Xeromyces.h"
extern InEventReaction gui_handler(const SDL_Event* ev);
extern InReaction gui_handler(const SDL_Event* ev);
//--------------------------------------------------------
// Macros
@ -146,7 +146,7 @@ public:
*
* @param ev SDL Event, like mouse/keyboard input
*/
InEventReaction HandleEvent(const SDL_Event* ev);
InReaction HandleEvent(const SDL_Event* ev);
/**
* Load a GUI XML file into the GUI.

View File

@ -54,7 +54,7 @@ CInput::~CInput()
{
}
InEventReaction CInput::ManuallyHandleEvent(const SDL_Event* ev)
InReaction CInput::ManuallyHandleEvent(const SDL_Event* ev)
{
debug_assert(m_iBufferPos != -1);

View File

@ -80,7 +80,7 @@ protected:
/**
* Handle events manually to catch keyboard inputting.
*/
virtual InEventReaction ManuallyHandleEvent(const SDL_Event* ev);
virtual InReaction ManuallyHandleEvent(const SDL_Event* ev);
// void InsertMessage(const wchar_t* szMessage, ...);
// void InsertChar(const int szChar, const wchar_t cooked);

View File

@ -217,14 +217,14 @@ void CList::HandleMessage(const SGUIMessage &Message)
} break;
case GUIM_MOUSE_WHEEL_DOWN:
GetScrollBar(0).ScrollMinus();
GetScrollBar(0).ScrollPlus();
// Since the scroll was changed, let's simulate a mouse movement
// to check if scrollbar now is hovered
HandleMessage(SGUIMessage(GUIM_MOUSE_MOTION));
break;
case GUIM_MOUSE_WHEEL_UP:
GetScrollBar(0).ScrollPlus();
GetScrollBar(0).ScrollMinus();
// Since the scroll was changed, let's simulate a mouse movement
// to check if scrollbar now is hovered
HandleMessage(SGUIMessage(GUIM_MOUSE_MOTION));
@ -251,7 +251,7 @@ void CList::HandleMessage(const SGUIMessage &Message)
IGUITextOwner::HandleMessage(Message);
}
InEventReaction CList::ManuallyHandleEvent(const SDL_Event* ev)
InReaction CList::ManuallyHandleEvent(const SDL_Event* ev)
{
int szChar = ev->key.keysym.sym;

View File

@ -84,7 +84,7 @@ protected:
/**
* Handle events manually to catch keyboard inputting.
*/
virtual InEventReaction ManuallyHandleEvent(const SDL_Event* ev);
virtual InReaction ManuallyHandleEvent(const SDL_Event* ev);
/**
* Draws the List box

View File

@ -133,14 +133,14 @@ void CText::HandleMessage(const SGUIMessage &Message)
break;
case GUIM_MOUSE_WHEEL_DOWN:
GetScrollBar(0).ScrollMinus();
GetScrollBar(0).ScrollPlus();
// Since the scroll was changed, let's simulate a mouse movement
// to check if scrollbar now is hovered
HandleMessage(SGUIMessage(GUIM_MOUSE_MOTION));
break;
case GUIM_MOUSE_WHEEL_UP:
GetScrollBar(0).ScrollPlus();
GetScrollBar(0).ScrollMinus();
// Since the scroll was changed, let's simulate a mouse movement
// to check if scrollbar now is hovered
HandleMessage(SGUIMessage(GUIM_MOUSE_MOTION));

View File

@ -340,7 +340,7 @@ protected:
* the key won't be passed on and processed by other handlers.
* This is used for keys that the GUI uses.
*/
virtual InEventReaction ManuallyHandleEvent(const SDL_Event* UNUSED(ev)) { return IN_PASS; }
virtual InReaction ManuallyHandleEvent(const SDL_Event* UNUSED(ev)) { return IN_PASS; }
/**
* Loads a style.

View File

@ -16,10 +16,10 @@
#include "Terrain.h"
#include "Profile.h"
#include "LOSManager.h"
#include "ps/Globals.h"
#include "graphics/GameView.h"
bool g_TerrainModified = false;
// used by GetMapSpaceCoords (precalculated as an optimization).
@ -51,26 +51,11 @@ CMiniMap::~CMiniMap()
Destroy();
}
void CMiniMap::ProcessUserInput()
void CMiniMap::HandleMessage(const SGUIMessage &Message)
{
//================================================================
//INTERACTIVE MINIMAP STARTS
//Have questions on ^. Send email to ajdecker1022@msn.com
static bool HasClicked=false; // HACK
//Check for a click
if(g_mouse_buttons[SDL_BUTTON_LEFT]==true)
{
HasClicked=true;
}
//Check to see if left button is false (meaning it's been lifted)
if (g_mouse_buttons[SDL_BUTTON_LEFT]==false && HasClicked==true)
switch(Message.type)
{
//Is cursor inside Minimap boundaries?
if(g_mouse_x > m_CachedActualSize.left && g_mouse_x < m_CachedActualSize.right
&& g_mouse_y > m_CachedActualSize.top && g_mouse_y < m_CachedActualSize.bottom)
case GUIM_MOUSE_PRESS_LEFT:
{
CTerrain *MMTerrain=g_Game->GetWorld()->GetTerrain();
CVector3D CamOrient=m_Camera->m_Orientation.GetTranslation();
@ -105,12 +90,12 @@ void CMiniMap::ProcessUserInput()
m_Camera->m_Orientation._24=Height;
}
m_Camera->UpdateFrustum();
}
HasClicked=false;
}
//END OF INTERACTIVE MINIMAP
//====================================================================
break;
default:
break;
} // switch
}
// render view rect : John M. Mena
@ -270,10 +255,6 @@ void CMiniMap::Draw()
}
glEnd();
// JW: this really doesn't belong here.. tying us to the real GUI
// input mechanism is pending.
ProcessUserInput();
DrawViewRect();
// Reset everything back to normal

View File

@ -19,6 +19,8 @@ public:
protected:
virtual void Draw();
virtual void HandleMessage(const SGUIMessage &Message);
// create the minimap textures
void CreateTextures();
@ -62,7 +64,6 @@ protected:
u32 m_TextureSize;
void DrawViewRect(); // split out of Draw
void ProcessUserInput();
};
#endif

View File

@ -1,22 +1,20 @@
/*
* input layer (dispatch events to multiple handlers; record/playback events)
*
* Copyright (c) 2002 Jan Wassenberg
*
* 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.
*
* Contact info:
* Jan.Wassenberg@stud.uni-karlsruhe.de
* http://www.stud.uni-karlsruhe.de/~urkt/
*/
// input layer (dispatch events to multiple handlers; record/playback events)
//
// Copyright (c) 2002 Jan Wassenberg
//
// 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.
//
// Contact info:
// Jan.Wassenberg@stud.uni-karlsruhe.de
// http://www.stud.uni-karlsruhe.de/~urkt/
#include "precompiled.h"
@ -27,32 +25,31 @@
#include <stdlib.h>
#define MAX_HANDLERS 8
const uint MAX_HANDLERS = 8;
static InHandler handler_stack[MAX_HANDLERS];
static uint handler_stack_top = 0;
static InEventHandler handler_stack[MAX_HANDLERS];
static int handler_stack_top = 0;
void in_add_handler(InEventHandler handler)
void in_add_handler(InHandler handler)
{
debug_assert(handler);
if(handler_stack_top >= MAX_HANDLERS)
{
debug_warn("increase MAX_HANDLERS");
// return -1;
return;
}
handler_stack[handler_stack_top++] = handler;
}
// send event to each handler (newest first) until one returns true
void dispatch_event(const SDL_Event* event)
// send event to each handler until one returns IN_HANDLED
static void dispatch_event(const SDL_Event* event)
{
for(int i = handler_stack_top-1; i >= 0; i--)
for(int i = (int)handler_stack_top-1; i >= 0; i--)
{
int ret = handler_stack[i](event);
debug_assert(handler_stack[i] && event);
InReaction ret = handler_stack[i](event);
// .. done, return
if(ret == IN_HANDLED)
return;
@ -66,6 +63,7 @@ void dispatch_event(const SDL_Event* event)
}
//-----------------------------------------------------------------------------
static enum
{

View File

@ -27,8 +27,8 @@ extern "C" {
#endif
// event handler return values.
enum InEventReaction
// input handler return values.
enum InReaction
{
// (the handlers' return values are checked and these
// 'strange' values might bring errors to light)
@ -40,21 +40,11 @@ enum InEventReaction
IN_HANDLED = 2
};
typedef InEventReaction (*InEventHandler)(const SDL_Event*);
enum InEventOrder
{
// this handler will be added to the front of the queue -
// it'll be called first (unless another IN_FIRST is registered).
IN_FIRST,
IN_LAST
};
typedef InReaction (*InHandler)(const SDL_Event*);
// register an input handler, which will receive all subsequent events first.
// events are passed to other handlers if handler returns IN_PASS.
extern void in_add_handler(InEventHandler handler);
extern void in_add_handler(InHandler handler);
// send event to each handler (newest first) until one returns true
extern void in_dispatch_event(const SDL_Event* event);

View File

@ -45,7 +45,7 @@ void kill_mainloop();
// main app message handler
static InEventReaction MainInputHandler(const SDL_Event* ev)
static InReaction MainInputHandler(const SDL_Event* ev)
{
switch(ev->type)
{

View File

@ -630,7 +630,7 @@ extern CConsole* g_Console;
extern void Die(int err, const wchar_t* fmt, ...);
InEventReaction conInputHandler(const SDL_Event* ev)
InReaction conInputHandler(const SDL_Event* ev)
{
if( ev->type == SDL_HOTKEYDOWN )
{

View File

@ -118,6 +118,6 @@ public:
extern CConsole* g_Console;
extern InEventReaction conInputHandler(const SDL_Event* ev);
extern InReaction conInputHandler(const SDL_Event* ev);
#endif

View File

@ -28,6 +28,7 @@
#include "ps/Overlay.h"
#include "ps/StringConvert.h"
#include "ps/Globals.h"
#include "ps/Util.h"
#include "graphics/MapReader.h"
#include "graphics/Terrain.h"
@ -74,8 +75,6 @@
#include "Network/Client.h"
#include "Atlas.h"
#include "Config.h"
#include "ps/Util.h"
ERROR_GROUP(System);
ERROR_TYPE(System, SDLInitFailed);

View File

@ -15,7 +15,7 @@ bool g_mouse_buttons[5];
// updates the state of the above; never swallows messages.
InEventReaction GlobalsInputHandler(const SDL_Event* ev)
InReaction GlobalsInputHandler(const SDL_Event* ev)
{
int c;

View File

@ -7,4 +7,4 @@ extern int g_mouse_x, g_mouse_y;
// (order is given by SDL_BUTTON_* constants).
extern bool g_mouse_buttons[5];
extern InEventReaction GlobalsInputHandler(const SDL_Event* ev);
extern InReaction GlobalsInputHandler(const SDL_Event* ev);

View File

@ -309,7 +309,7 @@ void hotkeyRegisterGUIObject( const CStr& objName, const CStr& hotkeyName )
boundTo.push_back( objName );
}
InEventReaction hotkeyInputHandler( const SDL_Event* ev )
InReaction hotkeyInputHandler( const SDL_Event* ev )
{
int keycode;

View File

@ -103,7 +103,7 @@ enum
};
void loadHotkeys();
InEventReaction hotkeyInputHandler( const SDL_Event* ev );
InReaction hotkeyInputHandler( const SDL_Event* ev );
void hotkeyRegisterGUIObject( const CStr& objName, const CStr& hotkeyName );
void initKeyNameMap();

View File

@ -825,7 +825,7 @@ void MouseButtonUpHandler(const SDL_Event *ev, int clicks)
}
}
InEventReaction interactInputHandler( const SDL_Event* ev )
InReaction interactInputHandler( const SDL_Event* ev )
{
if (!g_active || !g_Game)
return IN_PASS;

View File

@ -150,7 +150,7 @@ bool isOnScreen( CEntity* ev, void* userdata );
void StartCustomSelection();
void ResetInteraction();
InEventReaction interactInputHandler( const SDL_Event* ev );
InReaction interactInputHandler( const SDL_Event* ev );
#define g_Selection CSelectedEntities::GetSingleton()
#define g_Mouseover CMouseoverEntities::GetSingleton()

View File

@ -7,6 +7,16 @@
// the thunked function's return value (because we mustn't free MemFun_t
// if the function times out), but is simpler.
// VC7 warns if T::*func is not aligned to its size (4..16 bytes on IA-32).
// this is a bug, since sizeof(void*) would be enough. MS says it won't
// be fixed: see http://www.dotnet247.com/247reference/msgs/1/7782.aspx
// we don't make sure alignment is acceptable because both 12 and 16 bytes
// may be required and padding to LCM(12,16) bytes would be wasteful;
// therefore, just disable the warning.
#if MSC_VERSION
#pragma warning(disable: 4121)
#endif
template<class T> struct MemFun_t
{
T* const this_;

View File

@ -164,7 +164,7 @@ void RenderProfile()
glPopMatrix();
}
InEventReaction profilehandler( const SDL_Event* ev )
InReaction profilehandler( const SDL_Event* ev )
{
switch( ev->type )
{

View File

@ -9,6 +9,6 @@
void ResetProfileViewer();
void RenderProfile();
InEventReaction profilehandler( const SDL_Event* ev );
InReaction profilehandler( const SDL_Event* ev );
#endif