Commit 81463916 authored by sm's avatar sm

New version 0.6

- Add ProgressWidget
- Fix Event handling bugs
- Improve CircularBuffer template class
- Fix bug (discovered with clang++)
- Add man page to source build
- Improve build scripts
parent 5432fe72
stmm-games (0.6) unstable; urgency=low
* Add ProgressWidget
* Fix Event handling bugs
* Improve CircularBuffer template class
* Fix bug (discovered with clang++)
* Add man page to source build
* Improve build scripts
* Increase minor version
-- Stefano Marsili <efanomars@gmx.ch> Mon, 25 Mar 2019 19:29:39 +0100
stmm-games (0.5) unstable; urgency=low
* Make GameDiskFiles more testable
......
......@@ -138,7 +138,7 @@ bool DumbBlockEvent::move(Direction::VALUE eDir, bool bDoMove
, int32_t nClipX, int32_t nClipY, int32_t nClipW, int32_t nClipH)
{
Level& oLevel = level();
assert((eDir >= 0) && (eDir < 4));
assert((static_cast<int32_t>(eDir) >= 0) && (static_cast<int32_t>(eDir) < 4));
const int32_t nPosX = LevelBlock::blockPosX();
const int32_t nPosY = LevelBlock::blockPosY();
const std::vector< Block::Contact >& aContacts = blockContacts(eDir);
......
......@@ -20,12 +20,12 @@
# MINOR is REVISION (implementation of interface)
# AGE is always 0
set(STMM_GAMES_FAKE_MAJOR_VERSION 0)
set(STMM_GAMES_FAKE_MINOR_VERSION 5)
set(STMM_GAMES_FAKE_MINOR_VERSION 6)
set(STMM_GAMES_FAKE_VERSION "${STMM_GAMES_FAKE_MAJOR_VERSION}.${STMM_GAMES_FAKE_MINOR_VERSION}.0")
# required stmm-games version
set(STMM_GAMES_FAKE_REQ_STMM_GAMES_MAJOR_VERSION 0)
set(STMM_GAMES_FAKE_REQ_STMM_GAMES_MINOR_VERSION 5)
set(STMM_GAMES_FAKE_REQ_STMM_GAMES_MINOR_VERSION 6)
set(STMM_GAMES_FAKE_REQ_STMM_GAMES_VERSION "${STMM_GAMES_FAKE_REQ_STMM_GAMES_MAJOR_VERSION}.${STMM_GAMES_FAKE_REQ_STMM_GAMES_MINOR_VERSION}")
include("${PROJECT_SOURCE_DIR}/../libstmm-games/stmm-games-defs.cmake")
......
......@@ -70,6 +70,7 @@ set(STMMI_HEADERS_WIDGETS
${STMMI_HEADERS_DIR}/widgets/inputboxthwidgetfactory.h
${STMMI_HEADERS_DIR}/widgets/levelshowthwidgetfactory.h
${STMMI_HEADERS_DIR}/widgets/previewthwidgetfactory.h
${STMMI_HEADERS_DIR}/widgets/progressthwidgetfactory.h
${STMMI_HEADERS_DIR}/widgets/transparentthwidgetfactory.h
${STMMI_HEADERS_DIR}/widgets/varthwidgetfactory.h
)
......@@ -185,6 +186,7 @@ set(STMMI_SOURCES
${STMMI_SOURCES_DIR}/widgets/inputboxthwidgetfactory.cc
${STMMI_SOURCES_DIR}/widgets/levelshowthwidgetfactory.cc
${STMMI_SOURCES_DIR}/widgets/previewthwidgetfactory.cc
${STMMI_SOURCES_DIR}/widgets/progressthwidgetfactory.cc
${STMMI_SOURCES_DIR}/widgets/transparentthwidgetfactory.cc
${STMMI_SOURCES_DIR}/widgets/varthwidgetfactory.cc
)
......
/*
* File: progressthwidgetfactory.h
*
* Copyright © 2019 Stefano Marsili, <stemars@gmx.ch>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>
*/
#ifndef STMG_PROGRESS_TH_WIDGET_FACTORY_H
#define STMG_PROGRESS_TH_WIDGET_FACTORY_H
#include "stdthemewidgetfactory.h"
#include "image.h"
#include "frame.h"
#include <stmm-games/gamewidgets.h>
namespace stmg
{
class ProgressThWidgetFactory : public StdThemeWidgetFactory
{
public:
ProgressThWidgetFactory(StdTheme* p1Owner
, const TileColor& oNormalColor, const TileColor& oDangerColor
, const Frame& oFrame);
shared_ptr<ThemeWidget> create(const shared_ptr<GameWidget>& refGameWidget
, double fTileWHRatio, const Glib::RefPtr<Pango::Layout>& refFontLayout) override;
private:
class ProgressTWidget : public ThemeWidget
{
public:
ProgressTWidget(ProgressThWidgetFactory* p1Owner
, const shared_ptr<GameWidget>& refGameWidget, ProgressWidget* p0ProgressWidget
, double fTileWHRatio);
void reInit(ProgressThWidgetFactory* p1Owner
, const shared_ptr<GameWidget>& refGameWidget, ProgressWidget* p0ProgressWidget
, double fTileWHRatio);
bool canChange() const override { return true; }
NSize getSize() const override { return m_oSizedTW.getSize(); }
NPoint getPos() const override { return m_oSizedTW.getPos(); }
bool drawIfChanged(const Cairo::RefPtr<Cairo::Context>& refCc) override { return m_oSizedTW.drawIfChanged(refCc); }
void draw(const Cairo::RefPtr<Cairo::Context>& refCc) override { m_oSizedTW.draw(refCc); }
const std::pair<SegmentedFunction, SegmentedFunction>& getSizeFunctions(int32_t nLayoutConfig) const override;
void placeAndMaybeResizeIn(const NRect& oRect) override;
inline ThemeContainerWidget* getParent() const { return ThemeWidget::getParent(); }
void dump(int32_t nIndentSpaces, bool bHeader) const override;
protected:
void onAssignedToLayout() override { m_oSizedTW.onAssignedToLayout(); }
void onRecalcSizeFunctions(ThemeWidget* p0ReferenceThemeWidget) override { m_oSizedTW.onRecalcSizeFunctions(p0ReferenceThemeWidget); }
void sizeAndConfig(int32_t nTileSize, int32_t nLayoutConfig) override;
private:
void reInitCommon(double fTileWHRatio);
void drawBase(const Cairo::RefPtr<Cairo::Context>& refCc);
void drawVariable(const Cairo::RefPtr<Cairo::Context>& refCc);
bool isChanged() const { return m_p0ProgressWidget->isChanged(); }
NSize getMinSize(int32_t nLayoutConfig) const;
private:
void calcCanvas();
private:
friend class ProgressThWidgetFactory;
friend class StdLeafThemeWidget<ProgressTWidget>;
friend class StdRelSizedThemeWidget<ProgressTWidget>;
ProgressThWidgetFactory* m_p1Owner;
ProgressWidget* m_p0ProgressWidget;
//
StdRelSizedThemeWidget<ProgressTWidget> m_oSizedTW;
int32_t m_nPixCanvasX;
int32_t m_nPixCanvasY;
int32_t m_nPixCanvasW;
int32_t m_nPixCanvasH;
int32_t m_nPixMinCanvasWidth;
int32_t m_nPixMinCanvasHeight;
int32_t m_nMinValue;
int32_t m_nMaxValue;
int32_t m_nThresholdValue;
bool m_bThresholdValid;
bool m_bDangerBelow;
};
private:
Recycler<ProgressTWidget> m_oProgressTWidgets;
const TileColor m_oNormalColor;
const TileColor m_oDangerColor;
const Frame m_oFrame;
};
} // namespace stmg
#endif /* STMG_PROGRESS_TH_WIDGET_FACTORY_H */
......@@ -30,12 +30,12 @@
namespace stmg
{
GameGtkDrawingArea::GameGtkDrawingArea(shared_ptr<StdView>& refGameView, Glib::Timer& oTimer)
GameGtkDrawingArea::GameGtkDrawingArea(shared_ptr<StdView>& refGameView, Glib::Timer& /*oTimer*/)
: m_refGameView(refGameView)
, m_bIsRealized(false)
, m_nDelayedAllocW(-777)
, m_nDelayedAllocH(-777)
, m_oTimer(oTimer)
//, m_oTimer(oTimer)
{
signal_draw().connect(sigc::mem_fun(*this, &GameGtkDrawingArea::onCustomDraw));
}
......
......@@ -56,7 +56,7 @@ private:
Cairo::RefPtr<Cairo::Region> m_refCurrentDrawingRegion;
Glib::Timer& m_oTimer;
//Glib::Timer& m_oTimer;
};
} // namespace stmg
......
/*
* File: progressthwidgetfactory.cc
*
* Copyright © 2019 Stefano Marsili, <stemars@gmx.ch>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>
*/
#include "widgets/progressthwidgetfactory.h"
#include "stdtheme.h"
#include "stdthemecontext.h"
#include <stmm-games/variable.h>
namespace stmg
{
ProgressThWidgetFactory::ProgressThWidgetFactory(StdTheme* p1Owner
, const TileColor& oNormalColor, const TileColor& oDangerColor
, const Frame& oFrame)
: StdThemeWidgetFactory(p1Owner)
, m_oNormalColor(oNormalColor)
, m_oDangerColor(oDangerColor)
, m_oFrame(oFrame)
{
assert(p1Owner != nullptr);
}
shared_ptr<ThemeWidget> ProgressThWidgetFactory::create(const shared_ptr<GameWidget>& refGameWidget
, double fTileWHRatio
, const Glib::RefPtr<Pango::Layout>& /*refFontLayout*/)
{
//std::cout << "ProgressThWidgetFactory::create" << '\n';
assert(refGameWidget);
assert(fTileWHRatio > 0);
GameWidget* p0GameWidget = refGameWidget.get();
assert(p0GameWidget != nullptr);
ProgressWidget* p0ProgressWidget = dynamic_cast<ProgressWidget*>(p0GameWidget);
if (p0ProgressWidget == nullptr) {
return shared_ptr<ThemeWidget>{};
}
shared_ptr<ProgressTWidget> refWidget;
m_oProgressTWidgets.create(refWidget, this, refGameWidget, p0ProgressWidget, fTileWHRatio);
return refWidget;
}
ProgressThWidgetFactory::ProgressTWidget::ProgressTWidget(ProgressThWidgetFactory* p1Owner
, const shared_ptr<GameWidget>& refGameWidget, ProgressWidget* p0ProgressWidget
, double fTileWHRatio)
: ThemeWidget(refGameWidget)
, m_p1Owner(p1Owner)
, m_p0ProgressWidget(p0ProgressWidget)
, m_oSizedTW(this)
, m_nPixCanvasX(0)
, m_nPixCanvasY(0)
, m_nPixCanvasW(0)
, m_nPixCanvasH(0)
{
reInitCommon(fTileWHRatio);
}
void ProgressThWidgetFactory::ProgressTWidget::reInit(ProgressThWidgetFactory* p1Owner
, const shared_ptr<GameWidget>& refGameWidget, ProgressWidget* p0ProgressWidget
, double fTileWHRatio)
{
//std::cout << " ProgressThWidgetFactory::ProgressTWidget::reInit() p0ProgressWidget=" << reinterpret_cast<int64_t>(p0ProgressWidget) << '\n';
ThemeWidget::reInit(refGameWidget);
m_p1Owner = p1Owner;
m_p0ProgressWidget = p0ProgressWidget;
m_nPixCanvasX = 0;
m_nPixCanvasY = 0;
m_nPixCanvasW = 0;
m_nPixCanvasH = 0;
//
reInitCommon(fTileWHRatio);
}
void ProgressThWidgetFactory::ProgressTWidget::reInitCommon(double fTileWHRatio)
{
assert(m_p1Owner != nullptr);
assert(m_p0ProgressWidget != nullptr);
//
m_nPixMinCanvasWidth = 20;
m_nPixMinCanvasHeight = 20;
m_oSizedTW.reInit(m_p0ProgressWidget, fTileWHRatio);
m_nMinValue = m_p0ProgressWidget->getMinValue();
m_nMaxValue = m_p0ProgressWidget->getMaxValue();
m_nThresholdValue = m_p0ProgressWidget->getThresholdValue();
m_bThresholdValid = ((m_nThresholdValue >= m_nMinValue) && (m_nThresholdValue <= m_nMaxValue));
m_bDangerBelow = m_p0ProgressWidget->getDangerBelow();
}
void ProgressThWidgetFactory::ProgressTWidget::dump(int32_t
#ifndef NDEBUG
nIndentSpaces
#endif //NDEBUG
, bool
#ifndef NDEBUG
bHeader
#endif //NDEBUG
) const
{
#ifndef NDEBUG
auto sIndent = std::string(nIndentSpaces, ' ');
if (bHeader) {
std::cout << sIndent << "ProgressThWidgetFactory::ProgressTWidget adr:" << reinterpret_cast<int64_t>(this) << '\n';
}
m_oSizedTW.dump(nIndentSpaces);
ThemeWidget::dump(nIndentSpaces, false);
if (m_nPixCanvasW > 0) {
std::cout << sIndent << " " << "m_nPixCanvas: (" << m_nPixCanvasX << ", " << m_nPixCanvasY << ", " << m_nPixCanvasW << ", " << m_nPixCanvasH << ")" << '\n';
//std::cout << sIndent << " " << "m_fTitleAlign: " << m_fTitleAlign << '\n';
}
#endif //NDEBUG
}
NSize ProgressThWidgetFactory::ProgressTWidget::getMinSize(int32_t /*nLayoutConfig*/) const
{
ProgressThWidgetFactory* const & p0Factory = m_p1Owner;
if (p0Factory == nullptr) {
return NSize{0,0};
}
const Frame& oFrame = p0Factory->m_oFrame;
const int32_t nPixW = m_nPixMinCanvasWidth + oFrame.m_nPixMinLeft + oFrame.m_nPixMinRight;
const int32_t nPixH = m_nPixMinCanvasHeight + oFrame.m_nPixMinTop + oFrame.m_nPixMinBottom;
return NSize{nPixW, nPixH};
}
void ProgressThWidgetFactory::ProgressTWidget::calcCanvas()
{
ProgressThWidgetFactory*& p0Factory = m_p1Owner;
if (p0Factory == nullptr) {
return;
}
const Frame& oFrame = p0Factory->m_oFrame;
m_nPixCanvasX = oFrame.m_nPixMinLeft;
m_nPixCanvasY = oFrame.m_nPixMinTop;
m_nPixCanvasW = std::max(0, m_oSizedTW.getPixW() - oFrame.m_nPixMinLeft - oFrame.m_nPixMinRight);
m_nPixCanvasH = std::max(0, m_oSizedTW.getPixH() - oFrame.m_nPixMinTop - oFrame.m_nPixMinBottom);
//std::cout << "ProgressThWidgetFactory::ProgressTWidget::calcCanvas() m_nPixCanvasW=" << m_nPixCanvasW << " m_nPixCanvasH=" << m_nPixCanvasH << '\n';
}
void ProgressThWidgetFactory::ProgressTWidget::sizeAndConfig(int32_t nTileSize, int32_t nLayoutConfig)
{
m_oSizedTW.sizeAndConfig(nTileSize, nLayoutConfig);
calcCanvas();
}
void ProgressThWidgetFactory::ProgressTWidget::placeAndMaybeResizeIn(const NRect& oRect)
{
//std::cout << "ProgressThWidgetFactory::ProgressTWidget::placeAndMaybeResizeIn() nX=" << nX << " nY=" << nY << " nW=" << nW << " nH=" << nH << '\n';
m_oSizedTW.placeAndMaybeResizeIn(oRect);
calcCanvas();
//std::cout << "ProgressThWidgetFactory::ProgressTWidget::placeAndMaybeResizeIn() nResX=" << m_oSizedTW.getPixX() << " nResY=" << m_oSizedTW.getPixY()
//<< " nResW=" << m_oSizedTW.getPixW() << " nResH=" << m_oSizedTW.getPixH() << '\n';
}
const std::pair<SegmentedFunction, SegmentedFunction>& ProgressThWidgetFactory::ProgressTWidget::getSizeFunctions(int32_t nLayoutConfig) const
{
//std::cout << "ProgressThWidgetFactory::ProgressTWidget::getSizeFunctions this=" << reinterpret_cast<int64_t>(this) << '\n';
return m_oSizedTW.getSizeFunctions(nLayoutConfig);
}
void ProgressThWidgetFactory::ProgressTWidget::drawBase(const Cairo::RefPtr<Cairo::Context>& refCc)
{
ProgressThWidgetFactory*& p0Factory = m_p1Owner;
if (p0Factory == nullptr) {
return;
}
StdTheme* p0StdTheme = p0Factory->owner();
if (p0StdTheme == nullptr) {
return;
}
if ((m_nPixCanvasW <= 0) || (m_nPixCanvasH <= 0)) {
return; //--------------------------------------------------------------
}
const Frame& oFrame = p0Factory->m_oFrame;
oFrame.draw(refCc, 0, 0, m_oSizedTW.getPixW(), m_oSizedTW.getPixH());
}
void ProgressThWidgetFactory::ProgressTWidget::drawVariable(const Cairo::RefPtr<Cairo::Context>& refCc)
{
ProgressThWidgetFactory*& p0Factory = m_p1Owner;
if (p0Factory == nullptr) {
return;
}
StdTheme* p0StdTheme = p0Factory->owner();
if (p0StdTheme == nullptr) {
return;
}
const Variable& oVar = m_p0ProgressWidget->variable();
const int32_t nValue = [&](int32_t nVal)
{
if (nVal < m_nMinValue) {
return m_nMinValue;
} else if (nVal > m_nMaxValue) {
return m_nMaxValue;
}
return nVal;
}(oVar.get());
bool bDanger = false;
if (m_bThresholdValid) {
if (m_bDangerBelow) {
bDanger = (nValue <= m_nThresholdValue);
} else {
bDanger = (nValue >= m_nThresholdValue);
}
}
const TileColor& oColor = (bDanger ? p0Factory->m_oDangerColor : p0Factory->m_oNormalColor);
double fR1, fG1, fB1;
uint8_t nR, nG, nB;
p0StdTheme->getColorRgb(oColor, nR, nG, nB);
fR1 = TileColor::colorUint8ToDouble1(nR);
fG1 = TileColor::colorUint8ToDouble1(nG);
fB1 = TileColor::colorUint8ToDouble1(nB);
int32_t nX = m_nPixCanvasX;
int32_t nY = m_nPixCanvasY;
int32_t nW;
int32_t nH;
double fPixPerUnit;
const int32_t nDiff = m_nMaxValue - m_nMinValue + 1;
const bool bHoriz = (m_nPixCanvasW > m_nPixCanvasH);
if (bHoriz) {
fPixPerUnit = (1.0 * m_nPixCanvasW / nDiff);
nW = fPixPerUnit * (nValue - m_nMinValue);
nH = m_nPixCanvasH;
} else {
fPixPerUnit = (1.0 * m_nPixCanvasH / nDiff);
nW = m_nPixCanvasW;
nH = fPixPerUnit * (nValue - m_nMinValue);
nY += m_nPixCanvasH - nH;
}
refCc->save();
refCc->set_source_rgb(fR1,fG1,fB1);
refCc->rectangle(nX, nY, nW, nH);
refCc->fill();
const int32_t s_nMarkPixSize = 2;
const IntSet& oMarks = m_p0ProgressWidget->getMarks();
const int32_t nTotValues = oMarks.size();
if (nTotValues > 0) {
refCc->set_source_rgb(0.0,0.0,0.0);
if (bHoriz) {
for (int32_t nIdx = 0; nIdx < nTotValues; ++nIdx) {
const int32_t nMarkValue = oMarks.getValueByIndex(nIdx);
const int32_t nMarkPixX = nX + fPixPerUnit * (nMarkValue - m_nMinValue);
const int32_t nMarkPixY = nY;
const int32_t nMarkPixW = s_nMarkPixSize;
const int32_t nMarkPixH = nH;
refCc->rectangle(nMarkPixX, nMarkPixY, nMarkPixW, nMarkPixH);
refCc->fill();
}
} else {
for (int32_t nIdx = 0; nIdx < nTotValues; ++nIdx) {
const int32_t nMarkValue = oMarks.getValueByIndex(nIdx);
const int32_t nMarkPixX = nX;
const int32_t nMarkPixY = (nY + nH) - fPixPerUnit * (nMarkValue - m_nMinValue);
const int32_t nMarkPixW = nW;
const int32_t nMarkPixH = s_nMarkPixSize;
refCc->rectangle(nMarkPixX, nMarkPixY, nMarkPixW, nMarkPixH);
refCc->fill();
}
}
}
refCc->restore();
}
} // namespace stmg
......@@ -20,11 +20,11 @@
# MINOR is REVISION (implementation of interface)
# AGE is always 0
set(STMM_GAMES_GTK_MAJOR_VERSION 0)
set(STMM_GAMES_GTK_MINOR_VERSION 5)
set(STMM_GAMES_GTK_MINOR_VERSION 6)
set(STMM_GAMES_GTK_VERSION "${STMM_GAMES_GTK_MAJOR_VERSION}.${STMM_GAMES_GTK_MINOR_VERSION}.0")
set(STMM_GAMES_GTK_REQ_STMM_GAMES_MAJOR_VERSION 0)
set(STMM_GAMES_GTK_REQ_STMM_GAMES_MINOR_VERSION 5)
set(STMM_GAMES_GTK_REQ_STMM_GAMES_MINOR_VERSION 6)
set(STMM_GAMES_GTK_REQ_STMM_GAMES_VERSION "${STMM_GAMES_GTK_REQ_STMM_GAMES_MAJOR_VERSION}.${STMM_GAMES_GTK_REQ_STMM_GAMES_MINOR_VERSION}")
set(STMM_GAMES_GTK_REQ_STMM_INPUT_GTK_MAJOR_VERSION 0)
......
......@@ -109,6 +109,8 @@ set(STMMI_SOURCES
${STMMI_SOURCES_DIR}/gamewidgets/xmllevelshowwidget.cc
${STMMI_SOURCES_DIR}/gamewidgets/xmlpreviewwidget.h
${STMMI_SOURCES_DIR}/gamewidgets/xmlpreviewwidget.cc
${STMMI_SOURCES_DIR}/gamewidgets/xmlprogresswidget.h
${STMMI_SOURCES_DIR}/gamewidgets/xmlprogresswidget.cc
${STMMI_SOURCES_DIR}/gamewidgets/xmltransparentwidget.h
${STMMI_SOURCES_DIR}/gamewidgets/xmltransparentwidget.cc
${STMMI_SOURCES_DIR}/gamewidgets/xmlvarwidget.h
......@@ -170,6 +172,8 @@ set(STMMI_SOURCES
${STMMI_SOURCES_DIR}/themewidgets/xmllevelshowthwidgetfactory.cc
${STMMI_SOURCES_DIR}/themewidgets/xmlpreviewthwidgetfactory.h
${STMMI_SOURCES_DIR}/themewidgets/xmlpreviewthwidgetfactory.cc
${STMMI_SOURCES_DIR}/themewidgets/xmlprogressthwidgetfactory.h
${STMMI_SOURCES_DIR}/themewidgets/xmlprogressthwidgetfactory.cc
${STMMI_SOURCES_DIR}/themewidgets/xmltransparentthwidgetfactory.h
${STMMI_SOURCES_DIR}/themewidgets/xmltransparentthwidgetfactory.cc
${STMMI_SOURCES_DIR}/themewidgets/xmlvarthwidgetfactory.h
......
......@@ -98,6 +98,20 @@
</Frame>
</ActionFactory>
<TransparentFactory name="Simple:Transparent"/>
<ProgressFactory name="Simple:Progress">
<Normal colorName="green"/>
<Danger colorName="red"/>
<Frame left="3" right="3" top="3" bottom="3">
<TopLeftImg imgFile="cmdframe-tl.svg"/>
<TopImg imgFile="cmdframe-t.svg"/>
<TopRightImg imgFile="cmdframe-tr.svg"/>
<RightImg imgFile="cmdframe-r.svg"/>
<BottomRightImg imgFile="cmdframe-br.svg"/>
<BottomImg imgFile="cmdframe-b.svg"/>
<BottomLeftImg imgFile="cmdframe-bl.svg"/>
<LeftImg imgFile="cmdframe-l.svg"/>
</Frame>
</ProgressFactory>
</WidgetFactories>
<Assigns>
<Assign idAss="squareP" arrayId="squareP" imgFromIdx="0">
......
......@@ -97,9 +97,24 @@ public:
static std::pair<bool, std::string> getAttributeValue(ParserCtx& oCtx, const xmlpp::Element* p0Element, const std::string& sAttr0);
static std::pair<bool, std::string> getAttributeValue(ParserCtx& oCtx, const xmlpp::Element* p0Element, const std::string& sAttr0, const std::string& sAttr1);
static std::string parseSeparator(ParserCtx& oCtx, const xmlpp::Element* p0Element, const std::string& sSeparatorAttr);
/** Parse IntSet attributes.
* @param oCtx The context.
* @param p0Element The element. Cannot be null.
* @param sSingleAttr The single attribute name.
* @param sFromAttr The 'from' range attribute name.
* @param sToAttr The 'to' range attribute name.
* @param sStepAttr The 'step' attribute name.
* @param sMultiAttr The attribute name containing (usually) comma separated values.
* @param sSeparatorAttr The separator string. Cannot contain spaces. If empty comma is used.
* @param bMin Whether the range has a minimum.
* @param nMin The minimum value, if bMin is true.
* @param bMax Whether the range has a maximum.
* @param nMax The maximum value, if bMax is true.
* @return Whether one of the attributes was defined and the resulting IntSet.
*/
static std::pair<bool, IntSet> parseIntSetAttrs(ParserCtx& oCtx, const xmlpp::Element* p0Element
, const std::string& sSingleAttr, const std::string& sFromAttr, const std::string& sToAttr
, const std::string& sSingleAttr
, const std::string& sFromAttr, const std::string& sToAttr, const std::string& sStepAttr
, const std::string& sMultiAttr, const std::string& sSeparatorAttr
, bool bMin, int32_t nMin, bool bMax, int32_t nMax);
......
/*
* File: xmlprogresswidget.cc
*
* Copyright © 2019 Stefano Marsili, <stemars@gmx.ch>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>
*/
#include "xmlprogresswidget.h"
namespace stmg
{
static const std::string s_sGameProgressWidgetNodeName = "ProgressWidget";
static const std::string s_sGameProgressWidgetMinValueAttr = "minValue";
static const std::string s_sGameProgressWidgetMaxValueAttr = "maxValue";
static const std::string s_sGameProgressWidgetThresholdValueAttr = "thresholdValue";
static const std::string s_sGameProgressWidgetDangerBelowAttr = "dangerBelow";
static const std::string s_sGameProgressWidgetVariableAttr = "variable";
static const std::string s_sGameProgressWidgetMarkAttr = "mark";
static const std::string s_sGameProgressWidgetMarksAttr = "marks";
static const std::string s_sGameProgressWidgetMarksFromAttr = "marksFrom";
static const std::string s_sGameProgressWidgetMarksToAttr = "marksTo";
static const std::string s_sGameProgressWidgetMarksStepAttr = "marksStep";
XmlProgressWidgetParser::XmlProgressWidgetParser()
: XmlGameWidgetParser(s_sGameProgressWidgetNodeName)
{
}
shared_ptr<GameWidget> XmlProgressWidgetParser::parseGameWidget(LayoutCtx& oCtx, const xmlpp::Element* p0WidgetElement)
{
oCtx.addChecker(p0WidgetElement);
ProgressWidget::Init oInit;
parseRelSizedGameWidget(oInit, oCtx, p0WidgetElement);
//
const auto oPairMinValue = getXmlConditionalParser().getAttributeValue(oCtx, p0WidgetElement, s_sGameProgressWidgetMinValueAttr);
if (oPairMinValue.first) {
const std::string& sMinValue = oPairMinValue.second;
oInit.m_nMinValue = XmlCommonParser::strToNumber<int32_t>(oCtx, p0WidgetElement, s_sGameProgressWidgetMinValueAttr, sMinValue
, false, false, -1, false, -1);
}
const auto oPairMaxValue = getXmlConditionalParser().getAttributeValue(oCtx, p0WidgetElement, s_sGameProgressWidgetMaxValueAttr);
if (oPairMaxValue.first) {
const std::string& sMaxValue = oPairMaxValue.second;
oInit.m_nMaxValue = XmlCommonParser::strToNumber<int32_t>(oCtx, p0WidgetElement, s_sGameProgressWidgetMaxValueAttr, sMaxValue
, false, false, -1, false, -1);
}
const auto oPairThresholdValue = getXmlConditionalParser().getAttributeValue(oCtx, p0WidgetElement, s_sGameProgressWidgetThresholdValueAttr);
if (oPairThresholdValue.first) {
const std::string& sThresholdValue = oPairThresholdValue.second;
oInit.m_nThresholdValue = XmlCommonParser::strToNumber<int32_t>(oCtx, p0WidgetElement, s_sGameProgressWidgetThresholdValueAttr, sThresholdValue
, false, false, -1, false, -1);
}
const auto oPairDangerBelow = getXmlConditionalParser().getAttributeValue(oCtx, p0WidgetElement, s_sGameProgressWidgetDangerBelowAttr);
if (oPairDangerBelow.first) {
const std::string& sDangerBelow = oPairDangerBelow.second;
oInit.m_bDangerBelow = XmlCommonParser::strToBool(oCtx, p0WidgetElement, s_sGameProgressWidgetDangerBelowAttr, sDangerBelow);
}
//
const auto oPairVariableName = getXmlConditionalParser().getAttributeValue(oCtx, p0WidgetElement, s_sGameProgressWidgetVariableAttr);
if (oPairVariableName.first) {
const std::string& sVariableName = oPairVariableName.second;
std::string sVarType;
if (oInit.m_nTeam < 0) {
assert(oInit.m_nMate < 0);
oInit.m_nVariableId = oCtx.getGameVariableTypes().getIndex(sVariableName);
sVarType = "Game";
} else if (oInit.m_nMate < 0) {
oInit.m_nVariableId = oCtx.getTeamVariableTypes().getIndex(sVariableName);
sVarType = "Team";
} else {
oInit.m_nVariableId = oCtx.getMateVariableTypes().getIndex(sVariableName);
sVarType = "Mate";
}
//std::cout << "XmlProgressWidgetParser::parseGameWidget sVariableName=" << sVariableName << " sVarType=" << sVarType << " oInit.m_nVarId=" << oInit.m_nVarId << '\n';
if (oInit.m_nVariableId < 0) {
throw XmlCommonErrors::error(oCtx, p0WidgetElement, s_sGameProgressWidgetVariableAttr
, Util::stringCompose("%1 variable named '%2' not found", sVarType, sVariableName));
}
} else {
throw XmlCommonErrors::errorAttrNotFound(oCtx, p0WidgetElement, s_sGameProgressWidgetVariableAttr);
}
auto oMarksPair = XmlCommonParser::parseIntSetAttrs(oCtx, p0WidgetElement, s_sGameProgressWidgetMarkAttr
, s_sGameProgressWidgetMarksFromAttr, s_sGameProgressWidgetMarksToAttr, s_sGameProgressWidgetMarksStepAttr
, s_sGameProgressWidgetMarksAttr, ""
, true, oInit.m_nMinValue, true, oInit.m_nMaxValue);
if (oMarksPair.first) {
oInit.m_oMarks = std::move(oMarksPair.second);
}
//std::cout << "XmlProgressWidgetParser::parseGameWidget oInit.m_nTeam=" << oInit.m_nTeam << " oInit.m_nMate=" << oInit.m_nMate << '\n';
oCtx.removeChecker(p0WidgetElement, true);
return std::make_shared<ProgressWidget>(std::move(oInit));
}
} // namespace stmg
/*
* File: xmlprogresswidget.h
*
* Copyright © 2019 Stefano Marsili, <stemars@gmx.ch>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of