mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 10:20:48 +00:00
Remove css library
The css library was used for the old skin::Style property/painting code.
This commit is contained in:
parent
be3c9c1bcc
commit
87f715ee6b
@ -87,7 +87,6 @@ set(UNDO_TESTS OFF CACHE BOOL "Compile undo tests")
|
||||
add_subdirectory(undo)
|
||||
|
||||
add_subdirectory(cfg)
|
||||
add_subdirectory(css)
|
||||
add_subdirectory(doc)
|
||||
add_subdirectory(filters)
|
||||
add_subdirectory(fixmath)
|
||||
@ -194,7 +193,6 @@ if(ENABLE_TESTS)
|
||||
find_tests(gfx gfx-lib)
|
||||
find_tests(doc doc-lib)
|
||||
find_tests(render render-lib)
|
||||
find_tests(css css-lib)
|
||||
find_tests(ui ui-lib)
|
||||
find_tests(app/cli app-lib)
|
||||
find_tests(app/file app-lib)
|
||||
|
@ -15,7 +15,6 @@ because they don't depend on any other component.
|
||||
|
||||
* [allegro](allegro/): Modified version of [Allegro](http://alleg.sourceforge.net/) library, used for keyboard/mouse input, and drawing 2D graphics on screen.
|
||||
* [clip](https://github.com/aseprite/clip): Clipboard library.
|
||||
* [css](css/): Pseudo-style sheet library.
|
||||
* [fixmath](fixmath/): Fixed point operations (original code from Allegro code by Shawn Hargreaves).
|
||||
* [flic](https://github.com/aseprite/flic): Library to load/save FLI/FLC files.
|
||||
* [gfx](gfx/): Abstract graphics structures like point, size, rectangle, region, color, etc.
|
||||
|
@ -520,7 +520,6 @@ target_link_libraries(app-lib
|
||||
laf-base
|
||||
cfg-lib
|
||||
clip
|
||||
css-lib
|
||||
doc-lib
|
||||
docio-lib
|
||||
filters-lib
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "base/fs.h"
|
||||
#include "base/shared_ptr.h"
|
||||
#include "base/string.h"
|
||||
#include "css/sheet.h"
|
||||
#include "gfx/border.h"
|
||||
#include "gfx/point.h"
|
||||
#include "gfx/rect.h"
|
||||
|
@ -1,13 +0,0 @@
|
||||
# Aseprite CSS Library
|
||||
# Copyright (C) 2013-2016 David Capello
|
||||
|
||||
add_library(css-lib
|
||||
compound_style.cpp
|
||||
query.cpp
|
||||
rule.cpp
|
||||
sheet.cpp
|
||||
style.cpp
|
||||
value.cpp)
|
||||
|
||||
target_link_libraries(css-lib
|
||||
laf-base)
|
@ -1,20 +0,0 @@
|
||||
Copyright (c) 2001-2013 David Capello
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@ -1,4 +0,0 @@
|
||||
# Aseprite CSS Library
|
||||
*Copyright (C) 2013 David Capello*
|
||||
|
||||
> Distributed under [MIT license](LICENSE.txt)
|
@ -1,69 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "css/compound_style.h"
|
||||
|
||||
#include "css/sheet.h"
|
||||
|
||||
namespace css {
|
||||
|
||||
CompoundStyle::CompoundStyle(Sheet* sheet, const std::string& name) :
|
||||
m_sheet(sheet),
|
||||
m_name(name)
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void CompoundStyle::update()
|
||||
{
|
||||
deleteQueries();
|
||||
|
||||
const Style* style = m_sheet->getStyle(m_name);
|
||||
if (style)
|
||||
m_normal = m_sheet->query(*style);
|
||||
}
|
||||
|
||||
CompoundStyle::~CompoundStyle()
|
||||
{
|
||||
deleteQueries();
|
||||
}
|
||||
|
||||
void CompoundStyle::deleteQueries()
|
||||
{
|
||||
for (QueriesMap::iterator it = m_queries.begin(), end = m_queries.end();
|
||||
it != end; ++it) {
|
||||
delete it->second;
|
||||
}
|
||||
m_queries.clear();
|
||||
}
|
||||
|
||||
const Value& CompoundStyle::operator[](const Rule& rule) const
|
||||
{
|
||||
return m_normal[rule];
|
||||
}
|
||||
|
||||
const Query& CompoundStyle::operator[](const States& states) const
|
||||
{
|
||||
QueriesMap::const_iterator it = m_queries.find(states);
|
||||
|
||||
if (it != m_queries.end())
|
||||
return *it->second;
|
||||
else {
|
||||
const Style* style = m_sheet->getStyle(m_name);
|
||||
if (style == NULL)
|
||||
return m_normal;
|
||||
|
||||
Query* newQuery = new Query(m_sheet->query(StatefulStyle(*style, states)));
|
||||
m_queries[states] = newQuery;
|
||||
return *newQuery;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace css
|
@ -1,43 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_COMPOUND_STYLE_H_INCLUDED
|
||||
#define CSS_COMPOUND_STYLE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "css/query.h"
|
||||
#include "css/rule.h"
|
||||
#include "css/state.h"
|
||||
#include "css/stateful_style.h"
|
||||
|
||||
namespace css {
|
||||
|
||||
class Sheet;
|
||||
|
||||
class CompoundStyle {
|
||||
public:
|
||||
CompoundStyle(Sheet* sheet, const std::string& name);
|
||||
~CompoundStyle();
|
||||
|
||||
void update();
|
||||
|
||||
const Value& operator[](const Rule& rule) const;
|
||||
const Query& operator[](const States& states) const;
|
||||
|
||||
private:
|
||||
typedef std::map<States, Query*> QueriesMap;
|
||||
|
||||
void deleteQueries();
|
||||
|
||||
Sheet* m_sheet;
|
||||
std::string m_name;
|
||||
Query m_normal;
|
||||
mutable QueriesMap m_queries;
|
||||
};
|
||||
|
||||
} // namespace css
|
||||
|
||||
#endif
|
@ -1,20 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_CSS_H_INCLUDED
|
||||
#define CSS_CSS_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "css/compound_style.h"
|
||||
#include "css/query.h"
|
||||
#include "css/rule.h"
|
||||
#include "css/sheet.h"
|
||||
#include "css/state.h"
|
||||
#include "css/stateful_style.h"
|
||||
#include "css/style.h"
|
||||
#include "css/value.h"
|
||||
|
||||
#endif
|
@ -1,253 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "css/css.h"
|
||||
|
||||
using namespace css;
|
||||
|
||||
namespace css {
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Value& value)
|
||||
{
|
||||
os << "(" << value.type();
|
||||
|
||||
if (value.type() == Value::Number)
|
||||
os << ", " << value.number() << " [" << value.unit() << "]";
|
||||
else if (value.type() == Value::String)
|
||||
os << ", " << value.string();
|
||||
|
||||
os << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
} // namespace css
|
||||
|
||||
TEST(Css, Style)
|
||||
{
|
||||
Rule background("background");
|
||||
Rule text("text");
|
||||
Rule border("border");
|
||||
Style style("style");
|
||||
|
||||
style[background] = Value("image.png");
|
||||
style[text] = Value("hi");
|
||||
style[border] = Value(12.0, "px");
|
||||
EXPECT_EQ(Value("image.png"), style[background]);
|
||||
EXPECT_EQ(Value("hi"), style[text]);
|
||||
EXPECT_EQ(Value(12.0, "px"), style[border]);
|
||||
|
||||
style[border].setNumber(13.0);
|
||||
EXPECT_EQ(Value(13.0, "px"), style[border]);
|
||||
|
||||
Style style2("style2", &style);
|
||||
EXPECT_EQ(&style, style2.base());
|
||||
EXPECT_EQ(Value(), style2[background]);
|
||||
EXPECT_EQ(Value(), style2[text]);
|
||||
EXPECT_EQ(Value(), style2[border]);
|
||||
}
|
||||
|
||||
TEST(Css, QueryIsInSyncWithStyleSheet)
|
||||
{
|
||||
Rule background("background");
|
||||
Sheet sheet;
|
||||
sheet.addRule(&background);
|
||||
|
||||
Style style("style");
|
||||
style[background] = Value("a.png");
|
||||
sheet.addStyle(&style);
|
||||
|
||||
Query query = sheet.query(style);
|
||||
EXPECT_EQ(Value("a.png"), query[background]);
|
||||
|
||||
style[background] = Value("b.png");
|
||||
EXPECT_EQ(Value("b.png"), query[background]);
|
||||
}
|
||||
|
||||
TEST(Css, StatefulStyles)
|
||||
{
|
||||
Rule background("background");
|
||||
Rule text("text");
|
||||
Rule border("border");
|
||||
State hover("hover");
|
||||
State focus("focus");
|
||||
State active("active");
|
||||
Style base("base");
|
||||
Style baseHover("base:hover");
|
||||
Style baseFocus("base:focus");
|
||||
Style baseActive("base:active");
|
||||
base[background] = Value("image.png");
|
||||
base[text] = Value("textnormal");
|
||||
baseHover[text] = Value("texthover");
|
||||
baseFocus[border] = Value(12.0);
|
||||
baseActive[border] = Value(24.0);
|
||||
|
||||
Sheet sheet;
|
||||
sheet.addRule(&background);
|
||||
sheet.addRule(&text);
|
||||
sheet.addRule(&border);
|
||||
sheet.addStyle(&base);
|
||||
sheet.addStyle(&baseHover);
|
||||
sheet.addStyle(&baseFocus);
|
||||
sheet.addStyle(&baseActive);
|
||||
|
||||
Query query = sheet.query(base);
|
||||
EXPECT_EQ(Value("image.png"), query[background]);
|
||||
EXPECT_EQ(Value("textnormal"), query[text]);
|
||||
|
||||
query = sheet.query(base + hover);
|
||||
EXPECT_EQ(Value("image.png"), query[background]);
|
||||
EXPECT_EQ(Value("texthover"), query[text]);
|
||||
|
||||
query = sheet.query(base + focus);
|
||||
EXPECT_EQ(Value("image.png"), query[background]);
|
||||
EXPECT_EQ(Value("textnormal"), query[text]);
|
||||
EXPECT_EQ(Value(12.0), query[border]);
|
||||
|
||||
query = sheet.query(base + focus + hover);
|
||||
EXPECT_EQ(Value("image.png"), query[background]);
|
||||
EXPECT_EQ(Value("texthover"), query[text]);
|
||||
EXPECT_EQ(Value(12.0), query[border]);
|
||||
|
||||
query = sheet.query(base + focus + hover + active);
|
||||
EXPECT_EQ(Value("image.png"), query[background]);
|
||||
EXPECT_EQ(Value("texthover"), query[text]);
|
||||
EXPECT_EQ(Value(24.0), query[border]);
|
||||
|
||||
query = sheet.query(base + active + focus + hover); // Different order
|
||||
EXPECT_EQ(Value("image.png"), query[background]);
|
||||
EXPECT_EQ(Value("texthover"), query[text]);
|
||||
EXPECT_EQ(Value(12.0), query[border]);
|
||||
}
|
||||
|
||||
TEST(Css, StyleHierarchy)
|
||||
{
|
||||
Rule bg("bg");
|
||||
Rule fg("fg");
|
||||
State hover("hover");
|
||||
State focus("focus");
|
||||
Style base("base");
|
||||
Style stylea("stylea", &base);
|
||||
Style styleb("styleb", &stylea);
|
||||
Style stylec("stylec", &styleb);
|
||||
base[bg] = Value(1);
|
||||
base[fg] = Value(2);
|
||||
stylea[bg] = Value(3);
|
||||
styleb[bg] = Value(4);
|
||||
styleb[fg] = Value(5);
|
||||
stylec[bg] = Value(6);
|
||||
|
||||
Sheet sheet;
|
||||
sheet.addRule(&bg);
|
||||
sheet.addRule(&fg);
|
||||
sheet.addStyle(&base);
|
||||
sheet.addStyle(&stylea);
|
||||
sheet.addStyle(&styleb);
|
||||
sheet.addStyle(&stylec);
|
||||
|
||||
Query query = sheet.query(base);
|
||||
EXPECT_EQ(Value(1), query[bg]);
|
||||
EXPECT_EQ(Value(2), query[fg]);
|
||||
|
||||
query = sheet.query(stylea);
|
||||
EXPECT_EQ(Value(3), query[bg]);
|
||||
EXPECT_EQ(Value(2), query[fg]);
|
||||
|
||||
query = sheet.query(styleb);
|
||||
EXPECT_EQ(Value(4), query[bg]);
|
||||
EXPECT_EQ(Value(5), query[fg]);
|
||||
|
||||
query = sheet.query(stylec);
|
||||
EXPECT_EQ(Value(6), query[bg]);
|
||||
EXPECT_EQ(Value(5), query[fg]);
|
||||
}
|
||||
|
||||
TEST(Css, CompoundStyles)
|
||||
{
|
||||
Rule bg("bg");
|
||||
Rule fg("fg");
|
||||
State hover("hover");
|
||||
State focus("focus");
|
||||
Style base("base");
|
||||
Style baseHover("base:hover");
|
||||
Style baseFocus("base:focus");
|
||||
Style sub("sub", &base);
|
||||
Style subFocus("sub:focus", &base);
|
||||
Style sub2("sub2", &sub);
|
||||
Style sub3("sub3", &sub2);
|
||||
Style sub3FocusHover("sub3:focus:hover", &sub2);
|
||||
|
||||
base[bg] = Value(1);
|
||||
base[fg] = Value(2);
|
||||
baseHover[fg] = Value(3);
|
||||
baseFocus[bg] = Value(4);
|
||||
|
||||
sub[bg] = Value(5);
|
||||
subFocus[fg] = Value(6);
|
||||
|
||||
sub3[bg] = Value(7);
|
||||
sub3FocusHover[fg] = Value(8);
|
||||
|
||||
Sheet sheet;
|
||||
sheet.addRule(&bg);
|
||||
sheet.addRule(&fg);
|
||||
sheet.addStyle(&base);
|
||||
sheet.addStyle(&baseHover);
|
||||
sheet.addStyle(&baseFocus);
|
||||
sheet.addStyle(&sub);
|
||||
sheet.addStyle(&subFocus);
|
||||
sheet.addStyle(&sub2);
|
||||
sheet.addStyle(&sub3);
|
||||
sheet.addStyle(&sub3FocusHover);
|
||||
|
||||
CompoundStyle compoundBase = sheet.compoundStyle("base");
|
||||
EXPECT_EQ(Value(1), compoundBase[bg]);
|
||||
EXPECT_EQ(Value(2), compoundBase[fg]);
|
||||
EXPECT_EQ(Value(1), compoundBase[hover][bg]);
|
||||
EXPECT_EQ(Value(3), compoundBase[hover][fg]);
|
||||
EXPECT_EQ(Value(4), compoundBase[focus][bg]);
|
||||
EXPECT_EQ(Value(2), compoundBase[focus][fg]);
|
||||
EXPECT_EQ(Value(4), compoundBase[hover+focus][bg]);
|
||||
EXPECT_EQ(Value(3), compoundBase[hover+focus][fg]);
|
||||
|
||||
CompoundStyle compoundSub = sheet.compoundStyle("sub");
|
||||
EXPECT_EQ(Value(5), compoundSub[bg]);
|
||||
EXPECT_EQ(Value(2), compoundSub[fg]);
|
||||
EXPECT_EQ(Value(5), compoundSub[hover][bg]);
|
||||
EXPECT_EQ(Value(3), compoundSub[hover][fg]);
|
||||
EXPECT_EQ(Value(4), compoundSub[focus][bg]);
|
||||
EXPECT_EQ(Value(6), compoundSub[focus][fg]);
|
||||
EXPECT_EQ(Value(4), compoundSub[hover+focus][bg]);
|
||||
EXPECT_EQ(Value(6), compoundSub[hover+focus][fg]);
|
||||
|
||||
CompoundStyle compoundSub2 = sheet.compoundStyle("sub2");
|
||||
EXPECT_EQ(Value(5), compoundSub2[bg]);
|
||||
EXPECT_EQ(Value(2), compoundSub2[fg]);
|
||||
EXPECT_EQ(Value(5), compoundSub2[hover][bg]);
|
||||
EXPECT_EQ(Value(3), compoundSub2[hover][fg]);
|
||||
EXPECT_EQ(Value(4), compoundSub2[focus][bg]);
|
||||
EXPECT_EQ(Value(6), compoundSub2[focus][fg]);
|
||||
EXPECT_EQ(Value(4), compoundSub2[hover+focus][bg]);
|
||||
EXPECT_EQ(Value(6), compoundSub2[hover+focus][fg]);
|
||||
|
||||
CompoundStyle compoundSub3 = sheet.compoundStyle("sub3");
|
||||
EXPECT_EQ(Value(7), compoundSub3[bg]);
|
||||
EXPECT_EQ(Value(2), compoundSub3[fg]);
|
||||
EXPECT_EQ(Value(7), compoundSub3[hover][bg]);
|
||||
EXPECT_EQ(Value(3), compoundSub3[hover][fg]);
|
||||
EXPECT_EQ(Value(4), compoundSub3[focus][bg]);
|
||||
EXPECT_EQ(Value(6), compoundSub3[focus][fg]);
|
||||
EXPECT_EQ(Value(4), compoundSub3[hover+focus][bg]);
|
||||
EXPECT_EQ(Value(6), compoundSub3[hover+focus][fg]);
|
||||
EXPECT_EQ(Value(8), compoundSub3[focus+hover][fg]);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_MAP_H_INCLUDED
|
||||
#define CSS_MAP_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace css {
|
||||
|
||||
template<typename T>
|
||||
class Map {
|
||||
public:
|
||||
typedef std::map<std::string, T> map;
|
||||
typedef typename map::iterator iterator;
|
||||
typedef typename map::const_iterator const_iterator;
|
||||
|
||||
Map() : m_default() { }
|
||||
|
||||
iterator begin() { return m_map.begin(); }
|
||||
iterator end() { return m_map.end(); }
|
||||
|
||||
const_iterator begin() const { return m_map.begin(); }
|
||||
const_iterator end() const { return m_map.end(); }
|
||||
|
||||
const T& operator[](const std::string& name) const {
|
||||
const_iterator it = m_map.find(name);
|
||||
if (it != m_map.end())
|
||||
return it->second;
|
||||
else
|
||||
return m_default;
|
||||
}
|
||||
|
||||
T& operator[](const std::string& name) {
|
||||
iterator it = m_map.find(name);
|
||||
if (it != m_map.end())
|
||||
return it->second;
|
||||
else
|
||||
return m_map[name] = T();
|
||||
}
|
||||
|
||||
void add(const std::string& name, T value) {
|
||||
m_map[name] = value;
|
||||
}
|
||||
|
||||
bool exists(const std::string& name) const {
|
||||
return (m_map.find(name) != m_map.end());
|
||||
}
|
||||
|
||||
private:
|
||||
map m_map;
|
||||
T m_default;
|
||||
};
|
||||
|
||||
} // namespace css
|
||||
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "css/query.h"
|
||||
|
||||
namespace css {
|
||||
|
||||
void Query::addFromStyle(const Style* style)
|
||||
{
|
||||
for (Style::const_iterator it = style->begin(), end = style->end();
|
||||
it != end; ++it) {
|
||||
addRuleValue(it->first, style);
|
||||
}
|
||||
}
|
||||
|
||||
void Query::addRuleValue(const std::string& ruleName, const Style* style)
|
||||
{
|
||||
if (!m_ruleValue.exists(ruleName))
|
||||
m_ruleValue.add(ruleName, style);
|
||||
}
|
||||
|
||||
} // namespace css
|
@ -1,44 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_QUERY_H_INCLUDED
|
||||
#define CSS_QUERY_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "css/rule.h"
|
||||
#include "css/style.h"
|
||||
#include "css/value.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace css {
|
||||
|
||||
class Query {
|
||||
public:
|
||||
Query() { }
|
||||
|
||||
// Adds more rules from the given style only if the query doesn't
|
||||
// contain those rules already.
|
||||
void addFromStyle(const Style* style);
|
||||
|
||||
const Value& operator[](const Rule& rule) const {
|
||||
const Style* style = m_ruleValue[rule.name()];
|
||||
if (style)
|
||||
return (*style)[rule.name()];
|
||||
else
|
||||
return m_none;
|
||||
}
|
||||
|
||||
private:
|
||||
void addRuleValue(const std::string& ruleName, const Style* style);
|
||||
|
||||
Styles m_ruleValue;
|
||||
Value m_none;
|
||||
};
|
||||
|
||||
} // namespace css
|
||||
|
||||
#endif
|
@ -1,20 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "css/rule.h"
|
||||
|
||||
namespace css {
|
||||
|
||||
Rule::Rule(const std::string& name) :
|
||||
m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace css
|
@ -1,33 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_RULE_H_INCLUDED
|
||||
#define CSS_RULE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "css/map.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace css {
|
||||
|
||||
class Rule {
|
||||
public:
|
||||
Rule() { }
|
||||
Rule(const std::string& name);
|
||||
|
||||
const std::string& name() const { return m_name; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
typedef Map<Rule*> Rules;
|
||||
|
||||
} // namespace css
|
||||
|
||||
#endif
|
@ -1,110 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "css/sheet.h"
|
||||
|
||||
#include "css/compound_style.h"
|
||||
#include "css/query.h"
|
||||
#include "css/stateful_style.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace css {
|
||||
|
||||
Sheet::Sheet()
|
||||
{
|
||||
}
|
||||
|
||||
void Sheet::addRule(Rule* rule)
|
||||
{
|
||||
m_rules.add(rule->name(), rule);
|
||||
}
|
||||
|
||||
void Sheet::addStyle(Style* style)
|
||||
{
|
||||
m_styles.add(style->name(), style);
|
||||
}
|
||||
|
||||
const Style* Sheet::getStyle(const std::string& name)
|
||||
{
|
||||
return m_styles[name];
|
||||
}
|
||||
|
||||
Query Sheet::query(const StatefulStyle& compound)
|
||||
{
|
||||
const Style* firstStyle = &compound.style();
|
||||
const Style* style;
|
||||
Query query;
|
||||
std::string name;
|
||||
|
||||
// We create a string with all states. This is the style with
|
||||
// highest priority.
|
||||
std::string states;
|
||||
for (States::const_iterator
|
||||
state_it = compound.states().begin(),
|
||||
state_end = compound.states().end(); state_it != state_end; ++state_it) {
|
||||
states += StatefulStyle::kSeparator;
|
||||
states += (*state_it)->name();
|
||||
}
|
||||
|
||||
// Query by priority for the following styles:
|
||||
// style:state1:state2:...
|
||||
// ...
|
||||
// base1:state1:state2:...
|
||||
// base0:state1:state2:...
|
||||
for (style=firstStyle; style != NULL; style=style->base()) {
|
||||
name = style->name();
|
||||
name += states;
|
||||
|
||||
const Style* style2 = m_styles[name];
|
||||
if (style2)
|
||||
query.addFromStyle(style2);
|
||||
}
|
||||
|
||||
// Query for:
|
||||
// style:state2
|
||||
// style:state1
|
||||
// ...
|
||||
// base1:state2
|
||||
// base1:state1
|
||||
// base0:state2
|
||||
// base0:state1
|
||||
for (States::const_reverse_iterator
|
||||
state_it = compound.states().rbegin(),
|
||||
state_end = compound.states().rend(); state_it != state_end; ++state_it) {
|
||||
for (style=firstStyle; style != NULL; style=style->base()) {
|
||||
name = style->name();
|
||||
name += StatefulStyle::kSeparator;
|
||||
name += (*state_it)->name();
|
||||
|
||||
const Style* style2 = m_styles[name];
|
||||
if (style2)
|
||||
query.addFromStyle(style2);
|
||||
}
|
||||
}
|
||||
|
||||
// Query for:
|
||||
// style
|
||||
// ...
|
||||
// base1
|
||||
// base0
|
||||
for (style=firstStyle; style != NULL; style=style->base()) {
|
||||
query.addFromStyle(style);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
CompoundStyle Sheet::compoundStyle(const std::string& name)
|
||||
{
|
||||
return CompoundStyle(this, name);
|
||||
}
|
||||
|
||||
} // namespace css
|
@ -1,43 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_SHEET_H_INCLUDED
|
||||
#define CSS_SHEET_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "css/rule.h"
|
||||
#include "css/style.h"
|
||||
#include "css/value.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace css {
|
||||
|
||||
class CompoundStyle;
|
||||
class Query;
|
||||
class StatefulStyle;
|
||||
|
||||
class Sheet {
|
||||
public:
|
||||
Sheet();
|
||||
|
||||
void addRule(Rule* rule);
|
||||
void addStyle(Style* style);
|
||||
|
||||
const Style* getStyle(const std::string& name);
|
||||
|
||||
Query query(const StatefulStyle& stateful);
|
||||
CompoundStyle compoundStyle(const std::string& name);
|
||||
|
||||
private:
|
||||
Rules m_rules;
|
||||
Styles m_styles;
|
||||
};
|
||||
|
||||
} // namespace css
|
||||
|
||||
#endif
|
@ -1,77 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_STATE_H_INCLUDED
|
||||
#define CSS_STATE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace css {
|
||||
|
||||
class State {
|
||||
public:
|
||||
State() { }
|
||||
State(const std::string& name) : m_name(name) { }
|
||||
|
||||
const std::string& name() const { return m_name; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
class States {
|
||||
public:
|
||||
typedef std::vector<const State*> List;
|
||||
typedef List::iterator iterator;
|
||||
typedef List::const_iterator const_iterator;
|
||||
typedef List::reverse_iterator reverse_iterator;
|
||||
typedef List::const_reverse_iterator const_reverse_iterator;
|
||||
|
||||
States() { }
|
||||
States(const State& state) {
|
||||
operator+=(state);
|
||||
}
|
||||
|
||||
iterator begin() { return m_list.begin(); }
|
||||
iterator end() { return m_list.end(); }
|
||||
const_iterator begin() const { return m_list.begin(); }
|
||||
const_iterator end() const { return m_list.end(); }
|
||||
reverse_iterator rbegin() { return m_list.rbegin(); }
|
||||
reverse_iterator rend() { return m_list.rend(); }
|
||||
const_reverse_iterator rbegin() const { return m_list.rbegin(); }
|
||||
const_reverse_iterator rend() const { return m_list.rend(); }
|
||||
|
||||
States& operator+=(const State& other) {
|
||||
m_list.push_back(&other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
States& operator+=(const States& others) {
|
||||
for (const_iterator it=others.begin(), end=others.end(); it != end; ++it)
|
||||
operator+=(*(*it));
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator<(const States& other) const {
|
||||
return m_list < other.m_list;
|
||||
}
|
||||
|
||||
private:
|
||||
List m_list;
|
||||
};
|
||||
|
||||
inline States operator+(const State& a, const State& b) {
|
||||
States states;
|
||||
states += a;
|
||||
states += b;
|
||||
return states;
|
||||
}
|
||||
|
||||
} // namespace css
|
||||
|
||||
#endif
|
@ -1,74 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_STATEFUL_STYLE_H_INCLUDED
|
||||
#define CSS_STATEFUL_STYLE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "css/rule.h"
|
||||
#include "css/state.h"
|
||||
#include "css/style.h"
|
||||
#include "css/value.h"
|
||||
|
||||
namespace css {
|
||||
|
||||
class StatefulStyle {
|
||||
public:
|
||||
static const char kSeparator = ':';
|
||||
|
||||
StatefulStyle() : m_style(NULL) { }
|
||||
StatefulStyle(const Style& style) : m_style(&style) { }
|
||||
StatefulStyle(const State& state) {
|
||||
operator+=(state);
|
||||
}
|
||||
StatefulStyle(const Style& style, const States& states) :
|
||||
m_style(&style) {
|
||||
operator+=(states);
|
||||
}
|
||||
|
||||
const Style& style() const { return *m_style; }
|
||||
const States& states() const { return m_states; }
|
||||
|
||||
StatefulStyle& setStyle(const Style& style) {
|
||||
m_style = &style;
|
||||
return *this;
|
||||
}
|
||||
StatefulStyle& operator+=(const State& state) {
|
||||
m_states += state;
|
||||
return *this;
|
||||
}
|
||||
StatefulStyle& operator+=(const States& states) {
|
||||
m_states += states;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
const Style* m_style;
|
||||
States m_states;
|
||||
};
|
||||
|
||||
inline StatefulStyle operator+(const Style& style, const State& state) {
|
||||
StatefulStyle styleState;
|
||||
styleState.setStyle(style);
|
||||
styleState += state;
|
||||
return styleState;
|
||||
}
|
||||
|
||||
inline StatefulStyle operator+(const StatefulStyle& styleState, const State& state) {
|
||||
StatefulStyle styleState2 = styleState;
|
||||
styleState2 += state;
|
||||
return styleState2;
|
||||
}
|
||||
|
||||
inline StatefulStyle operator+(const StatefulStyle& styleState, const States& states) {
|
||||
StatefulStyle styleState2 = styleState;
|
||||
styleState2 += states;
|
||||
return styleState2;
|
||||
}
|
||||
|
||||
} // namespace css
|
||||
|
||||
#endif
|
@ -1,20 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "css/style.h"
|
||||
|
||||
namespace css {
|
||||
|
||||
Style::Style(const std::string& name, const Style* base) :
|
||||
m_name(name),
|
||||
m_base(base) {
|
||||
}
|
||||
|
||||
} // namespace css
|
@ -1,54 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_STYLE_H_INCLUDED
|
||||
#define CSS_STYLE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "css/map.h"
|
||||
#include "css/rule.h"
|
||||
#include "css/value.h"
|
||||
|
||||
namespace css {
|
||||
|
||||
class Style {
|
||||
public:
|
||||
typedef Values::iterator iterator;
|
||||
typedef Values::const_iterator const_iterator;
|
||||
|
||||
Style() { }
|
||||
Style(const std::string& name, const Style* base = NULL);
|
||||
|
||||
const std::string& name() const { return m_name; }
|
||||
const Style* base() const { return m_base; }
|
||||
|
||||
const Value& operator[](const Rule& rule) const {
|
||||
return m_values[rule.name()];
|
||||
}
|
||||
|
||||
Value& operator[](const Rule& rule) {
|
||||
return m_values[rule.name()];
|
||||
}
|
||||
|
||||
iterator begin() { return m_values.begin(); }
|
||||
iterator end() { return m_values.end(); }
|
||||
const_iterator begin() const { return m_values.begin(); }
|
||||
const_iterator end() const { return m_values.end(); }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
const Style* m_base;
|
||||
Values m_values;
|
||||
};
|
||||
|
||||
typedef Map<const Style*> Styles;
|
||||
|
||||
} // namespace css
|
||||
|
||||
#endif
|
@ -1,98 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "css/value.h"
|
||||
|
||||
namespace css {
|
||||
|
||||
Value::Value() :
|
||||
m_type(None)
|
||||
{
|
||||
}
|
||||
|
||||
Value::Value(double value, const std::string& unit) :
|
||||
m_type(Number),
|
||||
m_number(value),
|
||||
m_string(unit)
|
||||
{
|
||||
}
|
||||
|
||||
Value::Value(const std::string& value) :
|
||||
m_type(String),
|
||||
m_string(value)
|
||||
{
|
||||
}
|
||||
|
||||
double Value::number() const
|
||||
{
|
||||
if (m_type == Number)
|
||||
return m_number;
|
||||
else
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
std::string Value::string() const
|
||||
{
|
||||
if (m_type == String)
|
||||
return m_string;
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string Value::unit() const
|
||||
{
|
||||
if (m_type == Number)
|
||||
return m_string;
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void Value::setNumber(double value)
|
||||
{
|
||||
if (m_type != Number) {
|
||||
m_type = Number;
|
||||
m_string = "";
|
||||
}
|
||||
m_number = value;
|
||||
}
|
||||
|
||||
void Value::setString(const std::string& value)
|
||||
{
|
||||
m_type = String;
|
||||
m_string = value;
|
||||
}
|
||||
|
||||
void Value::setUnit(const std::string& unit)
|
||||
{
|
||||
if (m_type != Number) {
|
||||
m_type = Number;
|
||||
m_number = 0.0;
|
||||
}
|
||||
m_string = unit;
|
||||
}
|
||||
|
||||
bool Value::operator==(const Value& other) const
|
||||
{
|
||||
if (m_type != other.m_type)
|
||||
return false;
|
||||
|
||||
switch (m_type) {
|
||||
case None:
|
||||
return true;
|
||||
case Number:
|
||||
return m_number == other.m_number && m_string == other.m_string;
|
||||
case String:
|
||||
return m_string == other.m_string;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace css
|
@ -1,54 +0,0 @@
|
||||
// Aseprite CSS Library
|
||||
// Copyright (C) 2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef CSS_VALUE_H_INCLUDED
|
||||
#define CSS_VALUE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "css/map.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace css {
|
||||
|
||||
class Value {
|
||||
public:
|
||||
enum Type {
|
||||
None,
|
||||
Number,
|
||||
String
|
||||
};
|
||||
|
||||
Value();
|
||||
explicit Value(double value, const std::string& unit = "");
|
||||
explicit Value(const std::string& value);
|
||||
|
||||
Type type() const { return m_type; }
|
||||
|
||||
double number() const;
|
||||
std::string string() const;
|
||||
std::string unit() const;
|
||||
|
||||
void setNumber(double value);
|
||||
void setString(const std::string& value);
|
||||
void setUnit(const std::string& unit = "");
|
||||
|
||||
bool operator==(const Value& other) const;
|
||||
bool operator!=(const Value& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
double m_number;
|
||||
std::string m_string;
|
||||
};
|
||||
|
||||
typedef Map<Value> Values;
|
||||
|
||||
} // namespace css
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user