From: <wrt...@us...> - 2008-02-17 08:51:51
|
Revision: 7972 http://armagetronad.svn.sourceforge.net/armagetronad/?rev=7972&view=rev Author: wrtlprnft Date: 2008-02-17 00:51:57 -0800 (Sun, 17 Feb 2008) Log Message: ----------- Added support for widgets with arbitrary start and end angles and included a small analog clock in the default cockpit to show how it can be used. Hi there Self_Destructo. Modified Paths: -------------- armagetronad/trunk/armagetronad/resource/proto/Anonymous/original/original.cockpit.xml armagetronad/trunk/armagetronad/resource/proto/cockpit.dtd armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.cpp armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.h armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.cpp armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.h Modified: armagetronad/trunk/armagetronad/resource/proto/Anonymous/original/original.cockpit.xml =================================================================== --- armagetronad/trunk/armagetronad/resource/proto/Anonymous/original/original.cockpit.xml 2008-02-17 07:36:10 UTC (rev 7971) +++ armagetronad/trunk/armagetronad/resource/proto/Anonymous/original/original.cockpit.xml 2008-02-17 08:51:57 UTC (rev 7972) @@ -10,6 +10,7 @@ <AtomicData field="minimum" source="0" /> <AtomicData field="maximum" source="max_speed" /> </DataSet> + <Angles min="85" max="95" /> <Position x="-0.165" y="-0.9" /> <Size height="0.15" width="0.15" /> <ShowCurrent value="true" /> @@ -201,6 +202,77 @@ </Table> </Face> </Label> + <NeedleGauge viewport="top"> + <DataSet> + <AtomicData field="source" source="current_seconds" /> + <AtomicData field="minimum" source="0" /> + <AtomicData field="maximum" source="60" /> + </DataSet> + <Angles min="-270" max="90" /> + <Position x=".85" y=".2" /> + <Size height="0.075" width="0.075" /> + <ShowCurrent value="false" /> + <ShowMaximum value="false" /> + <ShowMinimum value="false" /> + <Caption location="off"> + <Text value="Time" /> + </Caption> + <Foreground> + <Solid> + <Color r="1." g="0." b="0." alpha="1." /> + </Solid> + </Foreground> + </NeedleGauge> + <NeedleGauge viewport="top"> + <DataSet> + <Math lvalue="current_minutes" type="sum" field="source"> + <RValue> + <Math rvalue="0.01666666" type="product" lvalue="current_seconds" /> + </RValue> + </Math> + <AtomicData field="minimum" source="0" /> + <AtomicData field="maximum" source="60" /> + </DataSet> + <Angles min="-270" max="90" /> + <Position x=".85" y=".2" /> + <Size height="0.075" width="0.075" /> + <ShowCurrent value="false" /> + <ShowMaximum value="false" /> + <ShowMinimum value="false" /> + <Caption location="off"> + <Text value="Time" /> + </Caption> + <Foreground> + <Solid> + <Color r="0." g="1." b="0." alpha="1." /> + </Solid> + </Foreground> + </NeedleGauge> + <NeedleGauge viewport="top"> + <DataSet> + <Math lvalue="current_hours12h" type="sum" field="source"> + <RValue> + <Math rvalue="0.01666666" type="product" lvalue="current_minutes" /> + </RValue> + </Math> + <AtomicData field="minimum" source="0" /> + <AtomicData field="maximum" source="12" /> + </DataSet> + <Angles min="-270" max="90" /> + <Position x=".85" y=".2" /> + <Size height="0.05" width="0.05" /> + <ShowCurrent value="false" /> + <ShowMaximum value="false" /> + <ShowMinimum value="false" /> + <Caption location="off"> + <Text value="Time" /> + </Caption> + <Foreground> + <Solid> + <Color r="0." g="0." b="1." alpha="1." /> + </Solid> + </Foreground> + </NeedleGauge> <Label camera="^in" viewport="top"> <DataSet id="hours"> <AtomicData source="current_hours12h" minwidth="2" fill="0" /> Modified: armagetronad/trunk/armagetronad/resource/proto/cockpit.dtd =================================================================== --- armagetronad/trunk/armagetronad/resource/proto/cockpit.dtd 2008-02-17 07:36:10 UTC (rev 7971) +++ armagetronad/trunk/armagetronad/resource/proto/cockpit.dtd 2008-02-17 08:51:57 UTC (rev 7972) @@ -28,6 +28,7 @@ ShowMaximum | ShowMinimum | Reverse | + Angles | Caption | Background | Foreground | @@ -77,6 +78,7 @@ ShowMaximum | ShowMinimum | Reverse | + Angles | Caption | Background | Foreground @@ -154,6 +156,10 @@ <!ELEMENT Reverse EMPTY> <!ATTLIST Reverse value (true | false) "true"> +<!ELEMENT Angles EMPTY> +<!ATTLIST Angles min CDATA "0"> +<!ATTLIST Angles max CDATA "180"> + <!ELEMENT Caption (Text?) > <!ATTLIST Caption location (top | bottom | off) "bottom"> Modified: armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.cpp 2008-02-17 07:36:10 UTC (rev 7971) +++ armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.cpp 2008-02-17 08:51:57 UTC (rev 7972) @@ -36,6 +36,7 @@ bool BarGauge::Process(tXmlParser::node cur) { if ( + WithAngles ::Process(cur) || WithSingleData ::Process(cur) || WithBackground ::Process(cur) || WithForeground ::Process(cur) || @@ -178,9 +179,11 @@ void NeedleGauge::RenderGraph(float min, float max, float val, float factor, tValue::Base const &val_s) { - float x, y=0.0; - x= (m_reverse?-1:1) * cos(M_PI*val/max); - y= sin(M_PI*val/max); + float x, y; + float t = m_reverse ? (val - max) / (min - max) : (val - min) / (max - min); + float a = m_angle_min * (1 - t) + m_angle_max * t; + x= cos(a); + y= sin(a); /* Draws an ugly background on the gauge BeginQuads(); Modified: armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.h =================================================================== --- armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.h 2008-02-17 07:36:10 UTC (rev 7971) +++ armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.h 2008-02-17 08:51:57 UTC (rev 7972) @@ -40,7 +40,7 @@ namespace cWidget { //! Processes and renders a bar gauge -class BarGauge : public WithSingleData, public WithBackground, public WithForeground, public WithCoordinates, public WithShowSettings, public WithCaption, public WithReverse { +class BarGauge : public WithSingleData, public WithBackground, public WithForeground, public WithCoordinates, public WithShowSettings, public WithCaption, public WithReverse, public WithAngles { public: virtual ~BarGauge() { }; //!< Do- nothing destructor void Render(); //!< Renders the gauge Modified: armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.cpp 2008-02-17 07:36:10 UTC (rev 7971) +++ armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.cpp 2008-02-17 08:51:57 UTC (rev 7972) @@ -508,6 +508,17 @@ return Base::Process(cur); } +bool WithAngles::Process(tXmlParser::node cur) { + if(cur.IsOfType("Angles")) { + cur.GetProp("min", m_angle_min); + cur.GetProp("max", m_angle_max); + m_angle_min *= M_PI / 180.; + m_angle_max *= M_PI / 180.; + return true; + } + return Base::Process(cur); +} + bool WithShowSettings::Process(tXmlParser::node cur) { if(cur.IsOfType("ShowMinimum")) { m_showmin = cur.GetPropBool("value"); Modified: armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.h =================================================================== --- armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.h 2008-02-17 07:36:10 UTC (rev 7971) +++ armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.h 2008-02-17 08:51:57 UTC (rev 7972) @@ -204,6 +204,16 @@ bool Process(tXmlParser::node cur); //!< Processes a Reverse node or passes on to Base::Process }; +//! Able to parse and store an Angles node +class WithAngles : virtual public Base{ +protected: + float m_angle_min; //!< Stores the angle at the minimum value + float m_angle_max; //!< Stores the angle at the minimum value + WithAngles() : m_angle_min(0), m_angle_max(M_PI){}; //!< Default constructor +public: + bool Process(tXmlParser::node cur); //!< Processes an Angles node or passes on to Base::Process +}; + //! Able to parse and store ShowMinimum, ShowMaximum or ShowValue nodes class WithShowSettings : virtual public Base{ protected: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |