Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Rationalize naming for style-related code
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Apr 29, 2016
1 parent 142f356 commit 00c9500
Show file tree
Hide file tree
Showing 147 changed files with 1,099 additions and 887 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/annotation/shape_annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define MBGL_ANNOTATION_SHAPE_ANNOTATION

#include <mbgl/annotation/annotation.hpp>
#include <mbgl/style/types.hpp>

#include <mbgl/util/geo.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/variant.hpp>

namespace mbgl {
Expand Down
15 changes: 9 additions & 6 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/style/property_transition.hpp>
#include <mbgl/style/transition_options.hpp>

#include <cstdint>
#include <string>
Expand All @@ -24,10 +24,13 @@ class View;
class SpriteImage;
class PointAnnotation;
class ShapeAnnotation;
class Layer;
struct CameraOptions;
struct AnimationOptions;

namespace style {
class Layer;
}

class Map : private util::noncopyable {
public:
explicit Map(View&, FileSource&,
Expand All @@ -48,9 +51,9 @@ class Map : private util::noncopyable {
void update(Update update);

// Styling
void addClass(const std::string&, const PropertyTransition& = {});
void removeClass(const std::string&, const PropertyTransition& = {});
void setClasses(const std::vector<std::string>&, const PropertyTransition& = {});
void addClass(const std::string&, const style::TransitionOptions& = {});
void removeClass(const std::string&, const style::TransitionOptions& = {});
void setClasses(const std::vector<std::string>&, const style::TransitionOptions& = {});

bool hasClass(const std::string&) const;
std::vector<std::string> getClasses() const;
Expand Down Expand Up @@ -150,7 +153,7 @@ class Map : private util::noncopyable {

AnnotationIDs getPointAnnotationsInBounds(const LatLngBounds&);

void addLayer(std::unique_ptr<Layer>, const optional<std::string>& beforeLayerID = {});
void addLayer(std::unique_ptr<style::Layer>, const optional<std::string>& beforeLayerID = {});
void removeLayer(const std::string& layerID);

// Feature queries
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/storage/offline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace mbgl {

class TileID;
class SourceInfo;
class Tileset;

/*
* An offline region defined by a style URL, geographic bounding box, zoom range, and
Expand All @@ -30,7 +30,7 @@ class OfflineTilePyramidRegionDefinition {
OfflineTilePyramidRegionDefinition(const std::string&, const LatLngBounds&, double, double, float);

/* Private */
std::vector<TileID> tileCover(SourceType, uint16_t tileSize, const SourceInfo&) const;
std::vector<TileID> tileCover(SourceType, uint16_t tileSize, const Tileset&) const;

const std::string styleURL;
const LatLngBounds bounds;
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/storage/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <mbgl/storage/response.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/util/font_stack.hpp>

#include <string>

Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/style/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>

namespace mbgl {
namespace style {

typedef variant<
class NullFilter,
Expand Down Expand Up @@ -88,4 +89,5 @@ class NoneFilter {
std::vector<Filter> filters;
};

} // namespace style
} // namespace mbgl
27 changes: 27 additions & 0 deletions include/mbgl/style/function.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <vector>
#include <utility>

namespace mbgl {
namespace style {

template <typename T>
class Function {
public:
using Stop = std::pair<float, T>;
using Stops = std::vector<Stop>;

explicit Function(const Stops& stops_, float base_)
: base(base_), stops(stops_) {}

float getBase() const { return base; }
const std::vector<std::pair<float, T>>& getStops() const { return stops; }

private:
float base = 1;
std::vector<std::pair<float, T>> stops;
};

} // namespace style
} // namespace mbgl
7 changes: 3 additions & 4 deletions include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef MBGL_LAYER
#define MBGL_LAYER
#pragma once

#include <mbgl/util/noncopyable.hpp>
#include <mbgl/style/types.hpp>

#include <memory>

namespace mbgl {
namespace style {

/**
* The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style
Expand Down Expand Up @@ -79,6 +79,5 @@ class Layer : public mbgl::util::noncopyable {
Layer(Type, std::unique_ptr<Impl>);
};

} // namespace style
} // namespace mbgl

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>

#include <mbgl/util/color.hpp>

namespace mbgl {
namespace style {

class BackgroundLayer : public Layer {
public:
Expand Down Expand Up @@ -38,4 +41,5 @@ inline bool Layer::is<BackgroundLayer>() const {
return type == Type::Background;
}

} // namespace style
} // namespace mbgl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>

#include <mbgl/util/color.hpp>

namespace mbgl {
namespace style {

class CircleLayer : public Layer {
public:
Expand Down Expand Up @@ -56,4 +59,5 @@ inline bool Layer::is<CircleLayer>() const {
return type == Type::Circle;
}

} // namespace style
} // namespace mbgl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <mbgl/style/layer.hpp>

namespace mbgl {
namespace style {

/**
* Initialize any GL state needed by the custom layer. This method is called once, from the
Expand Down Expand Up @@ -66,4 +67,5 @@ inline bool Layer::is<CustomLayer>() const {
return type == Type::Custom;
}

} // namespace style
} // namespace mbgl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>

#include <mbgl/util/color.hpp>

namespace mbgl {
namespace style {

class FillLayer : public Layer {
public:
Expand Down Expand Up @@ -59,4 +62,5 @@ inline bool Layer::is<FillLayer>() const {
return type == Type::Fill;
}

} // namespace style
} // namespace mbgl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>

#include <mbgl/util/color.hpp>

#include <vector>

namespace mbgl {
namespace style {

class LineLayer : public Layer {
public:
Expand Down Expand Up @@ -84,4 +87,5 @@ inline bool Layer::is<LineLayer>() const {
return type == Type::Line;
}

} // namespace style
} // namespace mbgl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>

#include <mbgl/util/color.hpp>

namespace mbgl {
namespace style {

class RasterLayer : public Layer {
public:
Expand Down Expand Up @@ -55,4 +58,5 @@ inline bool Layer::is<RasterLayer>() const {
return type == Type::Raster;
}

} // namespace style
} // namespace mbgl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>

#include <mbgl/util/color.hpp>

#include <vector>

namespace mbgl {
namespace style {

class SymbolLayer : public Layer {
public:
Expand Down Expand Up @@ -177,4 +180,5 @@ inline bool Layer::is<SymbolLayer>() const {
return type == Type::Symbol;
}

} // namespace style
} // namespace mbgl
20 changes: 0 additions & 20 deletions include/mbgl/style/property_transition.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once

#include <mbgl/util/variant.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/function.hpp>

namespace mbgl {
namespace style {

class Undefined {};

Expand Down Expand Up @@ -33,4 +34,5 @@ class PropertyValue {
}
};

}
} // namespace style
} // namespace mbgl
19 changes: 19 additions & 0 deletions include/mbgl/style/transition_options.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <mbgl/util/chrono.hpp>
#include <mbgl/util/optional.hpp>

namespace mbgl {
namespace style {

class TransitionOptions {
public:
TransitionOptions(const optional<Duration>& duration_ = {}, const optional<Duration>& delay_ = {})
: duration(duration_), delay(delay_) {}

optional<Duration> duration;
optional<Duration> delay;
};

} // namespace style
} // namespace mbgl
46 changes: 4 additions & 42 deletions include/mbgl/style/types.hpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,10 @@
#ifndef MBGL_STYLE_TYPES
#define MBGL_STYLE_TYPES
#pragma once

#include <mbgl/util/enum.hpp>

#include <string>
#include <array>
#include <vector>
#include <utility>

namespace mbgl {

// Stores a premultiplied color, with all four channels ranging from 0..1
using Color = std::array<float, 4>;

// An array of font names
using FontStack = std::vector<std::string>;

std::string fontStackToString(const FontStack&);

struct FontStackHash {
std::size_t operator()(const FontStack&) const;
};

template <typename T>
class Function {
public:
using Stop = std::pair<float, T>;
using Stops = std::vector<Stop>;

explicit Function(const Stops& stops_, float base_)
: base(base_), stops(stops_) {}

float getBase() const { return base; }
const std::vector<std::pair<float, T>>& getStops() const { return stops; }

private:
float base = 1;
std::vector<std::pair<float, T>> stops;
};

// -------------------------------------------------------------------------------------------------

// TODO: should be in public source.hpp header and style namespace
enum class SourceType : uint8_t {
Vector,
Raster,
Expand All @@ -57,7 +21,7 @@ MBGL_DEFINE_ENUM_CLASS(SourceTypeClass, SourceType, {
{ SourceType::Annotations, "annotations" },
});

// -------------------------------------------------------------------------------------------------
namespace style {

enum class VisibilityType : bool {
Visible,
Expand Down Expand Up @@ -123,7 +87,5 @@ enum class TextTransformType : uint8_t {
Lowercase,
};

} // namespace style
} // namespace mbgl

#endif

Loading

0 comments on commit 00c9500

Please sign in to comment.