Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Shalnev <c.shalnev@corp.mail.ru>2015-03-20 14:01:00 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:41:24 +0300
commitf7203eb9b75a01270d63e74e8eccebdf531c5742 (patch)
tree7b7a8ad4e92f21f9feee06548f2d134c5df93465
parentc427ac965987265c62761de2f822fd90be606e1a (diff)
implemented ChangeColorScheme functionality and its test for supported platforms
-rw-r--r--android/jni/com/mapswithme/maps/Framework.cpp57
-rw-r--r--android/jni/com/mapswithme/maps/Framework.hpp10
-rw-r--r--android/jni/nv_event/nv_event.hpp1
-rw-r--r--android/src/com/mapswithme/maps/Framework.java5
-rw-r--r--android/src/com/mapswithme/maps/MWMActivity.java15
-rw-r--r--android/src/com/mapswithme/maps/search/SearchFragment.java27
-rw-r--r--defines.hpp3
-rw-r--r--indexer/classificator_loader.cpp15
-rw-r--r--indexer/drawing_rules.cpp98
-rw-r--r--indexer/drawing_rules.hpp12
-rw-r--r--indexer/indexer.pro1
-rw-r--r--indexer/map_style.hpp8
-rw-r--r--iphone/Maps/Classes/EAGLView.h2
-rw-r--r--iphone/Maps/Classes/EAGLView.mm46
-rw-r--r--iphone/Maps/Classes/MapViewController.h4
-rw-r--r--iphone/Maps/Classes/MapViewController.mm6
-rw-r--r--iphone/Maps/Classes/MapsAppDelegate.h4
-rw-r--r--iphone/Maps/Classes/MapsAppDelegate.mm6
-rw-r--r--iphone/Maps/Classes/SearchView.mm24
-rw-r--r--iphone/Maps/Maps.xcodeproj/project.pbxproj4
-rw-r--r--map/framework.cpp12
-rw-r--r--map/framework.hpp5
-rw-r--r--map/proto_to_styles.cpp10
-rw-r--r--map/proto_to_styles.hpp2
-rw-r--r--map/render_policy.cpp3
-rw-r--r--qt/draw_widget.cpp85
-rw-r--r--qt/draw_widget.hpp4
-rw-r--r--qt/search_panel.cpp25
-rw-r--r--qt/search_panel.hpp2
29 files changed, 429 insertions, 67 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp
index bad02da3a8..324299aab0 100644
--- a/android/jni/com/mapswithme/maps/Framework.cpp
+++ b/android/jni/com/mapswithme/maps/Framework.cpp
@@ -18,8 +18,6 @@
#include "../../../../../graphics/opengl/framebuffer.hpp"
#include "../../../../../graphics/opengl/opengl.hpp"
-#include "../../../../../indexer/drawing_rules.hpp"
-
#include "../../../../../coding/file_container.hpp"
#include "../../../../../coding/file_name_utils.hpp"
@@ -69,7 +67,10 @@ namespace android
m_isCleanSingleClick(false),
m_doLoadState(true),
m_lastCompass(0.0),
- m_wasLongClick(false)
+ m_wasLongClick(false),
+ m_densityDpi(0),
+ m_screenWidth(0),
+ m_screenHeight(0)
{
ASSERT_EQUAL ( g_framework, 0, () );
g_framework = this;
@@ -116,7 +117,7 @@ namespace android
{
m_work.SaveState();
LOG(LINFO, ("Clearing current render policy."));
- m_work.SetRenderPolicy(0);
+ m_work.SetRenderPolicy(nullptr);
m_work.EnterBackground();
}
@@ -149,7 +150,7 @@ namespace android
params.m_density = dens[bestRangeIndex].second;
}
- bool Framework::InitRenderPolicy(int densityDpi, int screenWidth, int screenHeight)
+ bool Framework::InitRenderPolicyImpl(int densityDpi, int screenWidth, int screenHeight)
{
graphics::ResourceManager::Params rmParams;
@@ -163,7 +164,6 @@ namespace android
rpParams.m_rmParams = rmParams;
rpParams.m_primaryRC = make_shared<android::RenderContext>();
- char const * suffix = 0;
SetBestDensity(densityDpi, rpParams);
rpParams.m_skinName = "basic.skn";
@@ -176,10 +176,6 @@ namespace android
{
m_work.SetRenderPolicy(CreateRenderPolicy(rpParams));
m_work.InitGuiSubsystem();
- if (m_doLoadState)
- LoadState();
- else
- m_doLoadState = true;
}
catch (graphics::gl::platform_unsupported const & e)
{
@@ -187,12 +183,46 @@ namespace android
return false;
}
+ return true;
+ }
+
+ bool Framework::InitRenderPolicy(int densityDpi, int screenWidth, int screenHeight)
+ {
+ if (!InitRenderPolicyImpl(densityDpi, screenWidth, screenHeight))
+ return false;
+
+ if (m_doLoadState)
+ LoadState();
+ else
+ m_doLoadState = true;
+
m_work.SetUpdatesEnabled(true);
m_work.EnterForeground();
+ m_densityDpi = densityDpi;
+ m_screenWidth = screenWidth;
+ m_screenHeight = screenHeight;
+
return true;
}
+ void Framework::SetMapStyle(MapStyle mapStyle)
+ {
+ if (m_work.GetMapStyle() == mapStyle)
+ return;
+
+ // drop old render policy
+ m_work.SetRenderPolicy(nullptr);
+
+ m_work.SetMapStyle(mapStyle);
+
+ // construct new render policy
+ if (!InitRenderPolicyImpl(m_densityDpi, m_screenWidth, m_screenHeight))
+ return;
+
+ m_work.SetUpdatesEnabled(true);
+ }
+
Storage & Framework::Storage()
{
return m_work.Storage();
@@ -1395,4 +1425,11 @@ extern "C"
return jLatLon;
}
+
+ JNIEXPORT void JNICALL
+ Java_com_mapswithme_maps_Framework_setMapStyle(JNIEnv * env, jclass thiz, jint mapStyle)
+ {
+ MapStyle const val = static_cast<MapStyle>(mapStyle);
+ android::Platform::RunOnGuiThreadImpl(bind(&android::Framework::SetMapStyle, g_framework, val));
+ }
} // extern "C"
diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp
index a9664d3e2e..37152c474d 100644
--- a/android/jni/com/mapswithme/maps/Framework.hpp
+++ b/android/jni/com/mapswithme/maps/Framework.hpp
@@ -12,6 +12,8 @@
#include "../../../../../base/scheduled_task.hpp"
#include "../../../../../base/strings_bundle.hpp"
+#include "../../../../../indexer/map_style.hpp"
+
#include "../../../../../std/shared_ptr.hpp"
#include "../../../../../std/map.hpp"
@@ -62,6 +64,10 @@ namespace android
unique_ptr<ScheduledTask> m_scheduledTask;
bool m_wasLongClick;
+ int m_densityDpi;
+ int m_screenWidth;
+ int m_screenHeight;
+
void StartTouchTask(double x, double y, unsigned ms);
bool KillTouchTask();
void OnProcessTouchTask(double x, double y, unsigned ms);
@@ -70,6 +76,8 @@ namespace android
void SetBestDensity(int densityDpi, RenderPolicy::Params & params);
+ bool InitRenderPolicyImpl(int densityDpi, int screenWidth, int screenHeight);
+
public:
Framework();
~Framework();
@@ -92,6 +100,8 @@ namespace android
bool InitRenderPolicy(int densityDpi, int screenWidth, int screenHeight);
void DeleteRenderPolicy();
+ void SetMapStyle(MapStyle mapStyle);
+
void Resize(int w, int h);
void DrawFrame();
diff --git a/android/jni/nv_event/nv_event.hpp b/android/jni/nv_event/nv_event.hpp
index 8d5e132c4f..eea19d3bc1 100644
--- a/android/jni/nv_event/nv_event.hpp
+++ b/android/jni/nv_event/nv_event.hpp
@@ -535,7 +535,6 @@ void NVEventReportUnsupported();
void NVEventOnRenderingInitialized();
-
/** Returns the platform-specific handle to the application instance, if supported. This
function is, by definition platform-specific.
@return A platform-specific handle to the application. */
diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java
index bcd749f567..78c7d800de 100644
--- a/android/src/com/mapswithme/maps/Framework.java
+++ b/android/src/com/mapswithme/maps/Framework.java
@@ -12,6 +12,9 @@ import com.mapswithme.util.Constants;
*/
public class Framework
{
+ public static final int MAP_STYLE_LIGHT = 0;
+ public static final int MAP_STYLE_DARK = 1;
+
@SuppressWarnings("unused")
public interface OnBalloonListener
{
@@ -130,4 +133,6 @@ public class Framework
public native static void downloadCountry(Index idx);
public native static double[] predictLocation(double lat, double lon, double accuracy, double bearing, double speed, double elapsedSeconds);
+
+ public native static void setMapStyle(int mapStyle);
}
diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java
index 9ad88945a0..5533b7461b 100644
--- a/android/src/com/mapswithme/maps/MWMActivity.java
+++ b/android/src/com/mapswithme/maps/MWMActivity.java
@@ -100,6 +100,8 @@ public class MWMActivity extends BaseMwmFragmentActivity
private final static String EXTRA_COUNTRY_INDEX = "country_index";
// Need it for search
private static final String EXTRA_SEARCH_RES_SINGLE = "search_res_index";
+ // Need it for change map style
+ private static final String EXTRA_SET_MAP_STYLE = "set_map_style";
// Instance state
private static final String STATE_ROUTE_FOLLOWED = "RouteFollowed";
private static final String STATE_PP_OPENED = "PpOpened";
@@ -169,6 +171,14 @@ public class MWMActivity extends BaseMwmFragmentActivity
// Next we need to handle intent
}
+ public static void setMapStyle(Context context, int mapStyle)
+ {
+ final Intent mapIntent = new Intent(context, MWMActivity.class);
+ mapIntent.putExtra(EXTRA_SET_MAP_STYLE, mapStyle);
+ context.startActivity(mapIntent);
+ // Next we need to handle intent
+ }
+
public static void startSearch(Context context, String query)
{
final MWMActivity activity = (MWMActivity) context;
@@ -778,6 +788,11 @@ public class MWMActivity extends BaseMwmFragmentActivity
else
onDismiss();
}
+ else if (intent.hasExtra(EXTRA_SET_MAP_STYLE))
+ {
+ final int mapStyle = intent.getIntExtra(EXTRA_SET_MAP_STYLE, Framework.MAP_STYLE_LIGHT);
+ Framework.setMapStyle(mapStyle);
+ }
}
}
diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java
index d98e7a85b9..3c0f04c86c 100644
--- a/android/src/com/mapswithme/maps/search/SearchFragment.java
+++ b/android/src/com/mapswithme/maps/search/SearchFragment.java
@@ -19,6 +19,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import com.mapswithme.maps.MWMActivity;
+import com.mapswithme.maps.Framework;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmListFragment;
import com.mapswithme.maps.base.OnBackPressListener;
@@ -130,6 +131,28 @@ public class SearchFragment extends BaseMwmListFragment implements View.OnClickL
return mSearchEt.getText().toString();
}
+ // TODO: This code only for demonstration purposes and will be removed soon
+ private boolean tryChangeMapStyleCmd(String str)
+ {
+ // Hook for shell command on change map style
+ final boolean isDark = str.equals("mapstyle:dark");
+ final boolean isLight = isDark ? false : str.equals("mapstyle:light");
+
+ if (!isDark && !isLight)
+ return false;
+
+ // close Search panel
+ mSearchEt.setText(null);
+ InputUtils.hideKeyboard(mSearchEt);
+ getActivity().onBackPressed();
+
+ // change map style for the Map activity
+ final int mapStyle = isDark ? Framework.MAP_STYLE_DARK : Framework.MAP_STYLE_LIGHT;
+ MWMActivity.setMapStyle(getActivity(), mapStyle);
+
+ return true;
+ }
+
private void setUpView(ViewGroup root)
{
mVoiceInput = root.findViewById(R.id.search_voice_input);
@@ -144,6 +167,10 @@ public class SearchFragment extends BaseMwmListFragment implements View.OnClickL
@Override
public void afterTextChanged(Editable s)
{
+ // TODO: This code only for demonstration purposes and will be removed soon
+ if (tryChangeMapStyleCmd(s.toString()))
+ return;
+
if (runSearch() == QUERY_EMPTY)
showCategories();
diff --git a/defines.hpp b/defines.hpp
index 69957e1a6d..765fc73c52 100644
--- a/defines.hpp
+++ b/defines.hpp
@@ -58,7 +58,8 @@
#define EXTERNAL_RESOURCES_FILE "external_resources.txt"
-#define DRAWING_RULES_BIN_FILE "drules_proto.bin"
+#define DRAWING_RULES_LIGHT_BIN_FILE "drules_proto.bin"
+#define DRAWING_RULES_DARK_BIN_FILE "drules_proto_dark.bin"
/// How many langs we're supporting on indexing stage
#define MAX_SUPPORTED_LANGUAGES 64
diff --git a/indexer/classificator_loader.cpp b/indexer/classificator_loader.cpp
index 9015a63552..2b4e1cb333 100644
--- a/indexer/classificator_loader.cpp
+++ b/indexer/classificator_loader.cpp
@@ -2,8 +2,6 @@
#include "classificator.hpp"
#include "drawing_rules.hpp"
-#include "../defines.hpp"
-
#include "../platform/platform.hpp"
#include "../coding/reader_streambuf.hpp"
@@ -13,7 +11,7 @@
#include "../std/iostream.hpp"
-namespace classificator
+namespace
{
void ReadCommon(Reader * classificator,
Reader * types)
@@ -37,7 +35,10 @@ namespace classificator
c.ReadTypesMapping(s);
}
}
+}
+namespace classificator
+{
void Load()
{
LOG(LDEBUG, ("Reading of classificator started"));
@@ -47,13 +48,7 @@ namespace classificator
ReadCommon(p.GetReader("classificator.txt"),
p.GetReader("types.txt"));
- //LOG(LINFO, ("Reading of drawing rules"));
- drule::RulesHolder & rules = drule::rules();
-
- // Load from proto buffer binary file.
- string buffer;
- ModelReaderPtr(p.GetReader(DRAWING_RULES_BIN_FILE)).ReadAsString(buffer);
- rules.LoadFromBinaryProto(buffer);
+ drule::LoadRules();
LOG(LDEBUG, ("Reading of classificator finished"));
}
diff --git a/indexer/drawing_rules.cpp b/indexer/drawing_rules.cpp
index cf6f167d60..7ff88ae18e 100644
--- a/indexer/drawing_rules.cpp
+++ b/indexer/drawing_rules.cpp
@@ -5,11 +5,24 @@
#include "classificator.hpp"
#include "drules_include.hpp"
+#include "../defines.hpp"
+
#include "../std/bind.hpp"
#include "../std/iterator_facade.hpp"
+#include "../platform/platform.hpp"
+#include "../platform/settings.hpp"
+
+#include "../base/logging.hpp"
+
#include <google/protobuf/text_format.h>
+namespace
+{
+ uint32_t const DEFAULT_BG_COLOR = 0xEEEEDD;
+
+ char const * const MAP_STYLE_KEY = "MapStyleKey";
+}
namespace drule {
@@ -74,6 +87,10 @@ CircleRuleProto const * BaseRule::GetCircle() const
return 0;
}
+RulesHolder::RulesHolder()
+ : m_bgColor(DEFAULT_BG_COLOR)
+{}
+
RulesHolder::~RulesHolder()
{
Clean();
@@ -122,6 +139,11 @@ BaseRule const * RulesHolder::Find(Key const & k) const
return 0;
}
+uint32_t RulesHolder::GetBgColor() const
+{
+ return m_bgColor;
+}
+
void RulesHolder::ClearCaches()
{
ForEachRule(bind(static_cast<void (BaseRule::*)()>(&BaseRule::MakeEmptyID), _4));
@@ -337,6 +359,57 @@ namespace
m_names.pop_back();
}
};
+
+ uint32_t GetBackgroundColor(ContainerProto const & cont)
+ {
+ // WARNING!
+ // Background color is not specified in current format.
+ // Therefore, we use color of "natural-land" area element as background color.
+ // If such element is not present or if the element is not area then we use default background color
+
+ uint32_t backgroundColor = DEFAULT_BG_COLOR;
+
+ // Find the "natural-land" classification element
+ for (int i = 0; i < cont.cont_size(); ++i)
+ {
+ ClassifElementProto const & ce = cont.cont(i);
+ if (ce.name() == "natural-land")
+ {
+ // Take any area draw element
+ for (int j = 0; j < ce.element_size(); ++j)
+ {
+ DrawElementProto const & de = ce.element(j);
+ if (de.has_area())
+ {
+ // Take the color of the draw element
+ AreaRuleProto const & rule = de.area();
+ if (rule.has_color())
+ {
+ backgroundColor = rule.color();
+ break;
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ return backgroundColor;
+ }
+
+ string GetRulesFile(MapStyle mapStyle)
+ {
+ switch (mapStyle)
+ {
+ case MapStyleLight:
+ return DRAWING_RULES_LIGHT_BIN_FILE;
+ case MapStyleDark:
+ return DRAWING_RULES_DARK_BIN_FILE;
+ default:
+ LOG(LWARNING, ("Unknown map style, use light instead"));
+ return DRAWING_RULES_LIGHT_BIN_FILE;
+ }
+ }
}
void RulesHolder::LoadFromBinaryProto(string const & s)
@@ -348,6 +421,31 @@ void RulesHolder::LoadFromBinaryProto(string const & s)
CHECK ( doSet.m_cont.ParseFromString(s), ("Error in proto loading!") );
classif().GetMutableRoot()->ForEachObject(bind<void>(ref(doSet), _1));
+
+ m_bgColor = GetBackgroundColor(doSet.m_cont);
+}
+
+void LoadRules()
+{
+ string const rulesFile = GetRulesFile(GetCurrentMapStyle());
+
+ string buffer;
+ ModelReaderPtr(GetPlatform().GetReader(rulesFile)).ReadAsString(buffer);
+
+ rules().LoadFromBinaryProto(buffer);
+}
+
+MapStyle GetCurrentMapStyle()
+{
+ int mapStyle;
+ if (!Settings::Get(MAP_STYLE_KEY, mapStyle))
+ mapStyle = MapStyleLight;
+ return static_cast<MapStyle>(mapStyle);
+}
+
+void SetCurrentMapStyle(MapStyle mapStyle)
+{
+ Settings::Set(MAP_STYLE_KEY, static_cast<int>(mapStyle));
}
}
diff --git a/indexer/drawing_rules.hpp b/indexer/drawing_rules.hpp
index ed1dabf037..06d06a56c4 100644
--- a/indexer/drawing_rules.hpp
+++ b/indexer/drawing_rules.hpp
@@ -1,6 +1,8 @@
#pragma once
#include "drawing_rule_def.hpp"
+#include "map_style.hpp"
+
#include "../base/base.hpp"
#include "../base/buffer_vector.hpp"
@@ -60,7 +62,10 @@ namespace drule
typedef map<int32_t, array<vector<uint32_t>, count_of_rules> > rules_map_t;
rules_map_t m_rules;
+ uint32_t m_bgColor;
+
public:
+ RulesHolder();
~RulesHolder();
Key AddRule(int scale, rule_type_t type, BaseRule * p);
@@ -72,6 +77,8 @@ namespace drule
BaseRule const * Find(Key const & k) const;
+ uint32_t GetBgColor() const;
+
#ifdef OMIM_OS_DESKTOP
void LoadFromTextProto(string const & buffer);
static void SaveToBinaryProto(string const & buffer, ostream & s);
@@ -97,4 +104,9 @@ namespace drule
};
RulesHolder & rules();
+
+ void LoadRules();
+
+ MapStyle GetCurrentMapStyle();
+ void SetCurrentMapStyle(MapStyle mapStyle);
}
diff --git a/indexer/indexer.pro b/indexer/indexer.pro
index b227e74d31..89bc9468b5 100644
--- a/indexer/indexer.pro
+++ b/indexer/indexer.pro
@@ -79,6 +79,7 @@ HEADERS += \
interval_index.hpp \
interval_index_builder.hpp \
interval_index_iface.hpp \
+ map_style.hpp \
mercator.hpp \
mwm_set.hpp \
mwm_version.hpp \
diff --git a/indexer/map_style.hpp b/indexer/map_style.hpp
new file mode 100644
index 0000000000..fb3ecd821b
--- /dev/null
+++ b/indexer/map_style.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+enum MapStyle
+{
+ MapStyleLight = 0,
+ MapStyleDark = 1
+ // Add new map style here
+};
diff --git a/iphone/Maps/Classes/EAGLView.h b/iphone/Maps/Classes/EAGLView.h
index 76859df5a3..f82517196e 100644
--- a/iphone/Maps/Classes/EAGLView.h
+++ b/iphone/Maps/Classes/EAGLView.h
@@ -2,6 +2,7 @@
#include "../../std/shared_ptr.hpp"
+#include "../../indexer/map_style.hpp"
#ifndef USE_DRAPE
@@ -52,6 +53,7 @@ namespace dp
}
- (void)initRenderPolicy;
+- (void)setMapStyle:(MapStyle)mapStyle;
- (CGPoint)viewPoint2GlobalPoint:(CGPoint)pt;
- (CGPoint)globalPoint2ViewPoint:(CGPoint)pt;
diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm
index 60a5045836..361f26c117 100644
--- a/iphone/Maps/Classes/EAGLView.mm
+++ b/iphone/Maps/Classes/EAGLView.mm
@@ -13,6 +13,7 @@
#include "../../graphics/resource_manager.hpp"
#include "../../graphics/opengl/opengl.hpp"
#include "../../graphics/data_formats.hpp"
+ #include "../../indexer/classificator_loader.hpp"
#else
#import "../Platform/opengl/iosOGLContextFactory.h"
#endif
@@ -62,6 +63,12 @@
}
renderContext->makeCurrent();
+
+ typedef void (*drawFrameFn)(id, SEL);
+ SEL drawFrameSel = @selector(drawFrame);
+ drawFrameFn drawFrameImpl = (drawFrameFn)[self methodForSelector:drawFrameSel];
+
+ videoTimer = CreateIOSVideoTimer(bind(drawFrameImpl, self, drawFrameSel));
#else
dp::ThreadSafeFactory * factory = new dp::ThreadSafeFactory(new iosOGLContextFactory(eaglLayer));
m_factory.Reset(factory);
@@ -77,12 +84,6 @@
NSLog(@"EAGLView initRenderPolicy Started");
#ifndef USE_DRAPE
- typedef void (*drawFrameFn)(id, SEL);
- SEL drawFrameSel = @selector(drawFrame);
- drawFrameFn drawFrameImpl = (drawFrameFn)[self methodForSelector:drawFrameSel];
-
- videoTimer = CreateIOSVideoTimer(bind(drawFrameImpl, self, drawFrameSel));
-
graphics::ResourceManager::Params rmParams;
rmParams.m_videoMemoryLimit = GetPlatform().VideoMemoryLimit();
rmParams.m_texFormat = graphics::Data4Bpp;
@@ -90,7 +91,6 @@
RenderPolicy::Params rpParams;
UIScreen * screen = [UIScreen mainScreen];
- CGRect frameRect = screen.applicationFrame;
CGRect screenRect = screen.bounds;
double vs = self.contentScaleFactor;
@@ -124,7 +124,6 @@
frameBuffer = renderPolicy->GetDrawer()->screen()->frameBuffer();
Framework & f = GetFramework();
- f.OnSize(frameRect.size.width * vs, frameRect.size.height * vs);
f.SetRenderPolicy(renderPolicy);
f.InitGuiSubsystem();
#else
@@ -135,6 +134,37 @@
NSLog(@"EAGLView initRenderPolicy Ended");
}
+- (void)setMapStyle:(MapStyle)mapStyle
+{
+ Framework & f = GetFramework();
+
+ if (f.GetMapStyle() == mapStyle)
+ return;
+
+ NSLog(@"EAGLView setMapStyle Started");
+
+ renderContext->makeCurrent();
+
+ /// drop old render policy
+ f.SetRenderPolicy(nullptr);
+ frameBuffer.reset();
+
+ f.SetMapStyle(mapStyle);
+
+ /// init new render policy
+ [self initRenderPolicy];
+
+ /// restore render policy screen
+ CGFloat const scale = self.contentScaleFactor;
+ CGSize const s = self.bounds.size;
+ [self onSize:s.width * scale withHeight:s.height * scale];
+
+ /// update framework
+ f.SetUpdatesEnabled(true);
+
+ NSLog(@"EAGLView setMapStyle Ended");
+}
+
- (void)onSize:(int)width withHeight:(int)height
{
#ifndef USE_DRAPE
diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h
index de8f4cb0d4..a1f74bd112 100644
--- a/iphone/Maps/Classes/MapViewController.h
+++ b/iphone/Maps/Classes/MapViewController.h
@@ -9,7 +9,7 @@
#include "../../geometry/point2d.hpp"
#include "../../geometry/rect2d.hpp"
-
+#include "../../indexer/map_style.hpp"
namespace search { struct AddressInfo; }
@@ -45,6 +45,8 @@ namespace search { struct AddressInfo; }
- (void)dismissPopover;
+- (void)setMapStyle:(MapStyle)mapStyle;
+
@property (nonatomic) UIView * zoomButtonsView;
@property (nonatomic, strong) UIPopoverController * popoverVC;
@property (nonatomic) BottomMenu * bottomMenu;
diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm
index 632fcad0d6..dba70ff340 100644
--- a/iphone/Maps/Classes/MapViewController.mm
+++ b/iphone/Maps/Classes/MapViewController.mm
@@ -561,6 +561,12 @@ extern NSString * const kAlohalyticsTapEventKey = @"$onClick";
f.EnterBackground();
}
+- (void)setMapStyle:(MapStyle)mapStyle
+{
+ EAGLView * v = (EAGLView *)self.view;
+ [v setMapStyle: mapStyle];
+}
+
- (void)onEnterForeground
{
// Notify about entering foreground (should be called on the first launch too).
diff --git a/iphone/Maps/Classes/MapsAppDelegate.h b/iphone/Maps/Classes/MapsAppDelegate.h
index 3f28ae0c2b..37930eb2ab 100644
--- a/iphone/Maps/Classes/MapsAppDelegate.h
+++ b/iphone/Maps/Classes/MapsAppDelegate.h
@@ -3,6 +3,8 @@
#import "NavigationController.h"
#import "MapsObservers.h"
+#include "../../indexer/map_style.hpp"
+
@class MapViewController;
@class LocationManager;
@@ -31,4 +33,6 @@ extern NSString * const MapsStatusChangedNotification;
- (void)showMap;
+- (void)setMapStyle:(MapStyle)mapStyle;
+
@end
diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm
index 7d02ac0570..a42e6191f3 100644
--- a/iphone/Maps/Classes/MapsAppDelegate.mm
+++ b/iphone/Maps/Classes/MapsAppDelegate.mm
@@ -318,6 +318,12 @@ void InitLocalizedStrings()
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
+
+- (void)setMapStyle:(MapStyle)mapStyle
+{
+ [self.m_mapViewController setMapStyle: mapStyle];
+}
+
- (void)customizeAppearance
{
NSMutableDictionary * attributes = [[NSMutableDictionary alloc] init];
diff --git a/iphone/Maps/Classes/SearchView.mm b/iphone/Maps/Classes/SearchView.mm
index 1a475c5bb5..89231c093b 100644
--- a/iphone/Maps/Classes/SearchView.mm
+++ b/iphone/Maps/Classes/SearchView.mm
@@ -393,9 +393,33 @@ static void onSearchResultCallback(search::Results const & results)
[self setState:SearchViewStateHidden animated:YES withCallback:YES];
}
+// TODO: This code only for demonstration purposes and will be removed soon
+- (bool)tryChangeMapStyleCmd:(NSString*)str
+{
+ // Hook for shell command on change map style
+ bool const isDark = [str isEqualToString: @"mapstyle:dark"];
+ bool const isLight = isDark ? false : [str isEqualToString: @"mapstyle:light"];
+
+ if (!isDark && !isLight)
+ return false;
+
+ // close Search panel
+ [self searchBarDidPressCancelButton:nil];
+
+ // change map style
+ MapStyle const mapStyle = isDark ? MapStyleDark : MapStyleLight;
+ [[MapsAppDelegate theApp] setMapStyle: mapStyle];
+
+ return true;
+}
+
- (void)textFieldTextChanged:(id)sender
{
NSString * newText = self.searchBar.textField.text;
+
+ // TODO: This code only for demonstration purposes and will be removed soon
+ if ([self tryChangeMapStyleCmd: newText])
+ return;
if ([newText length])
{
diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj
index 3cf9843f89..5556fa8e0d 100644
--- a/iphone/Maps/Maps.xcodeproj/project.pbxproj
+++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj
@@ -16,6 +16,7 @@
46F26C7310F61FD600ECCA39 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46F26C7210F61FD600ECCA39 /* OpenGLES.framework */; };
46F26CD810F623BA00ECCA39 /* EAGLView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46F26CD710F623BA00ECCA39 /* EAGLView.mm */; };
46F26D1F10F626CB00ECCA39 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46F26D1E10F626CB00ECCA39 /* QuartzCore.framework */; };
+ 4A00DBDF1AB704C400113624 /* drules_proto_dark.bin in Resources */ = {isa = PBXBuildFile; fileRef = 4A00DBDE1AB704C400113624 /* drules_proto_dark.bin */; };
6BBD66B41A695722005FF58D /* MRGService.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6BBD66B21A695722005FF58D /* MRGService.framework */; };
6BDCBF491AA758FE004DAE48 /* libFlurry_6.0.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6BDCBF481AA758FE004DAE48 /* libFlurry_6.0.0.a */; };
974386DD19373EA400FD5659 /* ToastView.m in Sources */ = {isa = PBXBuildFile; fileRef = 974386DC19373EA400FD5659 /* ToastView.m */; };
@@ -210,6 +211,7 @@
46F26CD710F623BA00ECCA39 /* EAGLView.mm */ = {isa = PBXFileReference; fileEncoding = 11; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = EAGLView.mm; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
46F26D1E10F626CB00ECCA39 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
46F8A2EB10EB63040045521A /* MapViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = MapViewController.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
+ 4A00DBDE1AB704C400113624 /* drules_proto_dark.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = drules_proto_dark.bin; path = ../../data/drules_proto_dark.bin; sourceTree = "<group>"; };
6B948E1B1A25533C00229BD5 /* libAppsFlyerLib.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libAppsFlyerLib.a; path = Statistics/MRGService/ExternalLibs/AppsFlyer/libAppsFlyerLib.a; sourceTree = "<group>"; };
6BBD66B21A695722005FF58D /* MRGService.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MRGService.framework; path = Statistics/MRGService/MRGService.framework; sourceTree = "<group>"; };
6BDCBF481AA758FE004DAE48 /* libFlurry_6.0.0.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libFlurry_6.0.0.a; path = Statistics/libFlurry_6.0.0.a; sourceTree = "<group>"; };
@@ -950,6 +952,7 @@
FA065FC61286143F00FEA989 /* External Resources */ = {
isa = PBXGroup;
children = (
+ 4A00DBDE1AB704C400113624 /* drules_proto_dark.bin */,
97A5967E19B9CD47007A963F /* copyright.html */,
978D4A30199A11E600D72CA7 /* faq.html */,
FAAEA7D0161BD26600CCD661 /* synonyms.txt */,
@@ -1219,6 +1222,7 @@
FA99CB73147089B100689A9A /* Localizable.strings in Resources */,
F7FDD823147F30CC005900FA /* drules_proto.bin in Resources */,
FAAEA7D1161BD26600CCD661 /* synonyms.txt in Resources */,
+ 4A00DBDF1AB704C400113624 /* drules_proto_dark.bin in Resources */,
FA140651162A6288002BC1ED /* empty@2x.png in Resources */,
F61579361AC2CEB60032D8E9 /* MWMRateAlert.xib in Resources */,
F67BBB581AC54A7800D162C7 /* MWMFeedbackAlert.xib in Resources */,
diff --git a/map/framework.cpp b/map/framework.cpp
index ade83d627a..21351013a8 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -23,6 +23,7 @@
#include "../indexer/categories_holder.hpp"
#include "../indexer/feature.hpp"
#include "../indexer/scales.hpp"
+#include "../indexer/classificator_loader.hpp"
/// @todo Probably it's better to join this functionality.
//@{
@@ -1525,6 +1526,17 @@ void Framework::CreateDrapeEngine(dp::RefPointer<dp::OGLContextFactory> contextF
}
#endif // USE_DRAPE
+void Framework::SetMapStyle(MapStyle mapStyle)
+{
+ drule::SetCurrentMapStyle(mapStyle);
+ drule::LoadRules();
+}
+
+MapStyle Framework::GetMapStyle() const
+{
+ return drule::GetCurrentMapStyle();
+}
+
void Framework::SetupMeasurementSystem()
{
m_informationDisplay.measurementSystemChanged();
diff --git a/map/framework.hpp b/map/framework.hpp
index f55bc8adfd..d75d17b98f 100644
--- a/map/framework.hpp
+++ b/map/framework.hpp
@@ -40,6 +40,8 @@
#include "../geometry/rect2d.hpp"
#include "../geometry/screenbase.hpp"
+#include "../indexer/map_style.hpp"
+
#include "../base/strings_bundle.hpp"
#include "../std/vector.hpp"
@@ -235,6 +237,9 @@ public:
void CreateDrapeEngine(dp::RefPointer<dp::OGLContextFactory> contextFactory, float vs, int w, int h);
#endif // USE_DRAPE
+ void SetMapStyle(MapStyle mapStyle);
+ MapStyle GetMapStyle() const;
+
InformationDisplay & GetInformationDisplay();
CountryStatusDisplay * GetCountryStatusDisplay() const;
diff --git a/map/proto_to_styles.cpp b/map/proto_to_styles.cpp
index ebc32fdf00..f6532669ac 100644
--- a/map/proto_to_styles.cpp
+++ b/map/proto_to_styles.cpp
@@ -7,17 +7,17 @@
namespace
{
- graphics::Color ConvertColor(int c)
- {
- return graphics::Color::fromXRGB(c, 255 - (c >> 24));
- }
-
double ConvertWidth(double w, double scale)
{
return max(w * scale, 1.0);
}
}
+graphics::Color ConvertColor(uint32_t c)
+{
+ return graphics::Color::fromXRGB(c, 255 - (c >> 24));
+}
+
void ConvertStyle(LineDefProto const * pSrc, double scale, graphics::Pen::Info & dest)
{
double offset = 0.0;
diff --git a/map/proto_to_styles.hpp b/map/proto_to_styles.hpp
index ae6541fa0e..6f69352aee 100644
--- a/map/proto_to_styles.hpp
+++ b/map/proto_to_styles.hpp
@@ -12,6 +12,8 @@ class SymbolRuleProto;
class CaptionDefProto;
class CircleRuleProto;
+graphics::Color ConvertColor(uint32_t c);
+
void ConvertStyle(LineDefProto const * pSrc, double scale, graphics::Pen::Info & dest);
void ConvertStyle(AreaRuleProto const * pSrc, graphics::Brush::Info & dest);
void ConvertStyle(SymbolRuleProto const * pSrc, graphics::Icon::Info & dest);
diff --git a/map/render_policy.cpp b/map/render_policy.cpp
index a22b4790fb..7194b0c267 100644
--- a/map/render_policy.cpp
+++ b/map/render_policy.cpp
@@ -4,6 +4,7 @@
#include "window_handle.hpp"
#include "tiling_render_policy_st.hpp"
#include "tiling_render_policy_mt.hpp"
+#include "proto_to_styles.hpp"
#include "../anim/controller.hpp"
#include "../anim/task.hpp"
@@ -28,7 +29,7 @@ RenderPolicy::~RenderPolicy()
RenderPolicy::RenderPolicy(Params const & p,
size_t idCacheSize)
- : m_bgColor(0xEE, 0xEE, 0xDD, 0xFF),
+ : m_bgColor(ConvertColor(drule::rules().GetBgColor())),
m_primaryRC(p.m_primaryRC),
m_doForceUpdate(false),
m_density(p.m_density),
diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp
index 3518dad4bb..7962f46ef3 100644
--- a/qt/draw_widget.cpp
+++ b/qt/draw_widget.cpp
@@ -246,45 +246,51 @@ namespace qt
#ifndef USE_DRAPE
m_videoTimer.reset(CreateVideoTimer());
- shared_ptr<qt::gl::RenderContext> primaryRC(new qt::gl::RenderContext(this));
+ InitRenderPolicy();
+#endif
- graphics::ResourceManager::Params rmParams;
- rmParams.m_texFormat = graphics::Data8Bpp;
- rmParams.m_texRtFormat = graphics::Data4Bpp;
- rmParams.m_videoMemoryLimit = GetPlatform().VideoMemoryLimit();
+ m_isInitialized = true;
+ }
+ }
- RenderPolicy::Params rpParams;
+ void DrawWidget::InitRenderPolicy()
+ {
+#ifndef USE_DRAPE
+ shared_ptr<qt::gl::RenderContext> primaryRC(new qt::gl::RenderContext(this));
+ graphics::ResourceManager::Params rmParams;
+ rmParams.m_texFormat = graphics::Data8Bpp;
+ rmParams.m_texRtFormat = graphics::Data4Bpp;
+ rmParams.m_videoMemoryLimit = GetPlatform().VideoMemoryLimit();
- QRect const & geometry = QApplication::desktop()->geometry();
- rpParams.m_screenWidth = L2D(geometry.width());
- rpParams.m_screenHeight = L2D(geometry.height());
+ RenderPolicy::Params rpParams;
- if (m_ratio >= 1.5 || QApplication::desktop()->physicalDpiX() >= 180)
- rpParams.m_density = graphics::EDensityXHDPI;
- else
- rpParams.m_density = graphics::EDensityMDPI;
+ QRect const & geometry = QApplication::desktop()->geometry();
+ rpParams.m_screenWidth = L2D(geometry.width());
+ rpParams.m_screenHeight = L2D(geometry.height());
- rpParams.m_videoTimer = m_videoTimer.get();
- rpParams.m_useDefaultFB = true;
- rpParams.m_rmParams = rmParams;
- rpParams.m_primaryRC = primaryRC;
- rpParams.m_skinName = "basic.skn";
+ if (m_ratio >= 1.5 || QApplication::desktop()->physicalDpiX() >= 180)
+ rpParams.m_density = graphics::EDensityXHDPI;
+ else
+ rpParams.m_density = graphics::EDensityMDPI;
- try
- {
- m_framework->SetRenderPolicy(CreateRenderPolicy(rpParams));
- m_framework->InitGuiSubsystem();
- }
- catch (graphics::gl::platform_unsupported const & e)
- {
- LOG(LERROR, ("OpenGL platform is unsupported, reason: ", e.what()));
- /// @todo Show "Please Update Drivers" dialog and close the program.
- }
-#endif // USE_DRAPE
+ rpParams.m_videoTimer = m_videoTimer.get();
+ rpParams.m_useDefaultFB = true;
+ rpParams.m_rmParams = rmParams;
+ rpParams.m_primaryRC = primaryRC;
+ rpParams.m_skinName = "basic.skn";
- m_isInitialized = true;
+ try
+ {
+ m_framework->SetRenderPolicy(CreateRenderPolicy(rpParams));
+ m_framework->InitGuiSubsystem();
}
+ catch (graphics::gl::platform_unsupported const & e)
+ {
+ LOG(LERROR, ("OpenGL platform is unsupported, reason: ", e.what()));
+ /// @todo Show "Please Update Drivers" dialog and close the program.
+ }
+#endif // USE_DRAPE
}
void DrawWidget::resizeGL(int w, int h)
@@ -664,4 +670,23 @@ namespace qt
{
m_framework->XorQueryMaxScaleMode();
}
+
+ void DrawWidget::SetMapStyle(MapStyle mapStyle)
+ {
+#ifndef USE_DRAPE
+ if (m_framework->GetMapStyle() == mapStyle)
+ return;
+
+ makeCurrent();
+
+ m_framework->SetRenderPolicy(nullptr);
+
+ m_framework->SetMapStyle(mapStyle);
+
+ // init new render policy
+ InitRenderPolicy();
+
+ m_framework->SetUpdatesEnabled(true);
+#endif
+ }
}
diff --git a/qt/draw_widget.hpp b/qt/draw_widget.hpp
index c4f1b49f7c..563a66416a 100644
--- a/qt/draw_widget.hpp
+++ b/qt/draw_widget.hpp
@@ -105,6 +105,8 @@ namespace qt
Framework & GetFramework() { return *m_framework.get(); }
+ void SetMapStyle(MapStyle mapStyle);
+
protected:
VideoTimer * CreateVideoTimer();
@@ -149,5 +151,7 @@ namespace qt
bool m_emulatingLocation;
PinClickManager & GetBalloonManager() { return m_framework->GetBalloonManager(); }
+
+ void InitRenderPolicy();
};
}
diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp
index 6e34d5eb06..48e186e2dc 100644
--- a/qt/search_panel.cpp
+++ b/qt/search_panel.cpp
@@ -150,10 +150,35 @@ void SearchPanel::OnSearchResult(ResultsT * res)
}
}
+// TODO: This code only for demonstration purposes and will be removed soon
+bool SearchPanel::TryChangeMapStyleCmd(QString const & str)
+{
+ // Hook for shell command on change map style
+ bool const isDark = (str == "mapstyle:dark");
+ bool const isLight = isDark ? false : (str == "mapstyle:light");
+
+ if (!isDark && !isLight)
+ return false;
+
+ // close Search panel
+ m_pEditor->setText("");
+ parentWidget()->hide();
+
+ // change color scheme for the Map activity
+ MapStyle const mapStyle = isDark ? MapStyleDark : MapStyleLight;
+ m_pDrawWidget->SetMapStyle(mapStyle);
+
+ return true;
+}
+
void SearchPanel::OnSearchTextChanged(QString const & str)
{
QString const normalized = str.normalized(QString::NormalizationForm_KC);
+ // TODO: This code only for demonstration purposes and will be removed soon
+ if (TryChangeMapStyleCmd(normalized))
+ return;
+
// search even with empty query
if (!normalized.isEmpty())
{
diff --git a/qt/search_panel.hpp b/qt/search_panel.hpp
index 12dee36f18..13ab5a15ac 100644
--- a/qt/search_panel.hpp
+++ b/qt/search_panel.hpp
@@ -63,6 +63,8 @@ private slots:
void OnAnimationTimer();
void OnClearButton();
+
+ bool TryChangeMapStyleCmd(QString const & str);
};
}