Adds blinking cursors with configurable rate, based on patch by kingadami. Fixes #876

This was SVN commit r13068.
This commit is contained in:
historic_bruno 2013-01-12 01:20:01 +00:00
parent 1f8d0cacdc
commit a074eb814a
6 changed files with 96 additions and 15 deletions

View File

@ -306,3 +306,6 @@ joystick.camera.rotate.x = 3
joystick.camera.rotate.y = 2
joystick.camera.zoom.in = 5
joystick.camera.zoom.out = 4
; GENERAL GUI SETTINGS
gui.cursorblinkrate = 0.5 ; Cursor blink rate in seconds (0.0 to disable blinking)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -28,7 +28,9 @@ CInput
#include "graphics/TextRenderer.h"
#include "lib/ogl.h"
#include "lib/sysdep/clipboard.h"
#include "lib/timer.h"
#include "ps/CLogger.h"
#include "ps/ConfigDB.h"
#include "ps/Font.h"
#include "ps/Globals.h"
#include "ps/Hotkey.h"
@ -41,7 +43,9 @@ extern int g_yres;
//-------------------------------------------------------------------
// Constructor / Destructor
//-------------------------------------------------------------------
CInput::CInput() : m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(false), m_HorizontalScroll(0.f)
CInput::CInput()
: m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(false), m_HorizontalScroll(0.f),
m_PrevTime(0.0), m_CursorVisState(true), m_CursorBlinkRate(0.5)
{
AddSetting(GUIST_float, "buffer_zone");
AddSetting(GUIST_CStrW, "caption");
@ -58,6 +62,8 @@ CInput::CInput() : m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(fals
AddSetting(GUIST_CStrW, "tooltip");
AddSetting(GUIST_CStr, "tooltip_style");
CFG_GET_VAL("gui.cursorblinkrate", Double, m_CursorBlinkRate);
// Add scroll-bar
CGUIScrollBarVertical * bar = new CGUIScrollBarVertical();
bar->SetRightAligned(true);
@ -955,6 +961,8 @@ void CInput::HandleMessage(SGUIMessage &Message)
case GUIM_GOT_FOCUS:
m_iBufferPos = 0;
m_PrevTime = 0.0;
m_CursorVisState = false;
break;
@ -990,6 +998,22 @@ void CInput::Draw()
{
float bz = GetBufferedZ();
if (m_CursorBlinkRate > 0.0)
{
// check if the cursor visibility state needs to be changed
double currTime = timer_Time();
if ((currTime - m_PrevTime) >= m_CursorBlinkRate)
{
m_CursorVisState = !m_CursorVisState;
m_PrevTime = currTime;
}
}
else
{
// should always be visible
m_CursorVisState = true;
}
// First call draw on ScrollBarOwner
bool scrollbar;
float buffer_zone;
@ -1299,7 +1323,8 @@ void CInput::Draw()
it->m_ListStart + i == m_iBufferPos)
{
// selecting only one, then we need only to draw a cursor.
textRenderer.Put(0.0f, 0.0f, L"_");
if (m_CursorVisState)
textRenderer.Put(0.0f, 0.0f, L"_");
}
// Drawing selected area
@ -1326,7 +1351,8 @@ void CInput::Draw()
if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos)
{
textRenderer.Color(color);
textRenderer.PutAdvance(L"_");
if (m_CursorVisState)
textRenderer.PutAdvance(L"_");
if (using_selected_color)
{

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -182,6 +182,15 @@ protected:
// *** Things for one-line input control *** //
float m_HorizontalScroll;
// Used to store the previous time for flashing the cursor.
double m_PrevTime;
// Cursor blink rate in seconds, if greater than 0.0.
double m_CursorBlinkRate;
// If the cursor should be drawn or not.
bool m_CursorVisState;
};
#endif

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -29,6 +29,7 @@
#include "gui/GUIutil.h"
#include "lib/ogl.h"
#include "lib/sysdep/clipboard.h"
#include "lib/timer.h"
#include "maths/MathUtil.h"
#include "network/NetClient.h"
#include "network/NetServer.h"
@ -56,7 +57,11 @@ CConsole::CConsole()
m_iMsgHistPos = 1;
m_charsPerPage = 0;
m_prevTime = 0.0;
m_bCursorVisState = true;
m_cursorBlinkRate = 0.5;
InsertMessage(L"[ 0 A.D. Console v0.14 ]");
InsertMessage(L"");
}
@ -93,6 +98,16 @@ void CConsole::SetVisible(bool visible)
if (visible != m_bVisible)
m_bToggle = true;
m_bVisible = visible;
if (visible)
{
m_prevTime = 0.0;
m_bCursorVisState = false;
}
}
void CConsole::SetCursorBlinkRate(double rate)
{
m_cursorBlinkRate = rate;
}
void CConsole::FlushBuffer()
@ -301,14 +316,33 @@ void CConsole::DrawBuffer(CTextRenderer& textRenderer)
void CConsole::DrawCursor(CTextRenderer& textRenderer)
{
// Slightly translucent yellow
textRenderer.Color(1.0f, 1.0f, 0.0f, 0.8f);
if (m_cursorBlinkRate > 0.0)
{
// check if the cursor visibility state needs to be changed
double currTime = timer_Time();
if ((currTime - m_prevTime) >= m_cursorBlinkRate)
{
m_bCursorVisState = !m_bCursorVisState;
m_prevTime = currTime;
}
}
else
{
// Should always be visible
m_bCursorVisState = true;
}
// Cursor character is chosen to be an underscore
textRenderer.Put(0.0f, 0.0f, L"_");
if(m_bCursorVisState)
{
// Slightly translucent yellow
textRenderer.Color(1.0f, 1.0f, 0.0f, 0.8f);
// Revert to the standard text colour
textRenderer.Color(1.0f, 1.0f, 1.0f);
// Cursor character is chosen to be an underscore
textRenderer.Put(0.0f, 0.0f, L"_");
// Revert to the standard text colour
textRenderer.Color(1.0f, 1.0f, 1.0f);
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -61,6 +61,8 @@ public:
void ToggleVisible();
void SetVisible(bool visible);
void SetCursorBlinkRate(double rate);
/**
* @param deltaRealTime Elapsed real time since the last frame.
*/
@ -117,6 +119,9 @@ private:
bool m_bFocus;
bool m_bVisible; // console is to be drawn
bool m_bToggle; // show/hide animation is currently active
double m_prevTime; // the previous time the cursor draw state changed (used for blinking cursor)
bool m_bCursorVisState; // if the cursor should be drawn or not
double m_cursorBlinkRate; // cursor blink rate in seconds, if greater than 0.0
void ToLower(wchar_t* szMessage, size_t iSize = 0);
void Trim(wchar_t* szMessage, const wchar_t cChar = 32, size_t iSize = 0);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -492,6 +492,10 @@ static void InitPs(bool setup_gui, const CStrW& gui_page, CScriptVal initData)
g_Console->m_charsPerPage = (size_t)(g_xres / g_Console->m_iFontWidth);
// Offset by an arbitrary amount, to make it fit more nicely
g_Console->m_iFontOffset = 7;
double blinkRate = 0.5;
CFG_GET_VAL("gui.cursorblinkrate", Double, blinkRate);
g_Console->SetCursorBlinkRate(blinkRate);
}
// hotkeys