mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
MapRender: First release (FormEditorCommon, FormEditorProperties, Map, MapBG, MapCommon, MapEditor, MapRenderTest.
git-svn-id: svn://ultimatepp.org/upp/trunk@4180 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
5531a704ba
commit
9959d8888c
92 changed files with 7485 additions and 0 deletions
9
bazaar/FormEditorCommon/FormEditorCommon.h
Normal file
9
bazaar/FormEditorCommon/FormEditorCommon.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef FORM_EDITOR_COMMON__FORM_EDITOR_COMMON_H
|
||||
#define FORM_EDITOR_COMMON__FORM_EDITOR_COMMON_H
|
||||
|
||||
#include "Logger.h"
|
||||
#include "IHistory.h"
|
||||
#include "IPartBase.h"
|
||||
#include "MenuBarEx.h"
|
||||
|
||||
#endif
|
||||
18
bazaar/FormEditorCommon/FormEditorCommon.upp
Normal file
18
bazaar/FormEditorCommon/FormEditorCommon.upp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
"Hypercall Library" readonly separator,
|
||||
hypercall.h,
|
||||
Main readonly separator,
|
||||
Utils.h,
|
||||
Logger.h,
|
||||
IHistory.h,
|
||||
IPartBase.h,
|
||||
MenuBarEx.h,
|
||||
MenuBarEx.cpp,
|
||||
FormEditorCommon.h;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI SSE2";
|
||||
|
||||
51
bazaar/FormEditorCommon/IHistory.h
Normal file
51
bazaar/FormEditorCommon/IHistory.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef FORM_EDITOR_COMMON__I_HISTORY_H
|
||||
#define FORM_EDITOR_COMMON__I_HISTORY_H
|
||||
|
||||
#include <Core/Core.h>
|
||||
using namespace Upp;
|
||||
|
||||
class IHistoryItem
|
||||
{
|
||||
public:
|
||||
virtual ~IHistoryItem() {}
|
||||
|
||||
virtual String SetDesc(const char* desc) { return String(); }
|
||||
virtual String GetDesc() const = 0;
|
||||
virtual void Undo() = 0;
|
||||
virtual void Do() = 0;
|
||||
};
|
||||
|
||||
// Group action
|
||||
class HBatchAction : public IHistoryItem
|
||||
{
|
||||
Array<IHistoryItem*> _Actions;
|
||||
String _Desc;
|
||||
|
||||
public:
|
||||
virtual HBatchAction& Add(IHistoryItem* item) { _Actions.Add(item); return *this; }
|
||||
virtual ~HBatchAction()
|
||||
{
|
||||
for (int i = 0; i < _Actions.GetCount(); ++i)
|
||||
if (_Actions[i])
|
||||
delete _Actions[i];
|
||||
}
|
||||
|
||||
virtual String SetDesc(const char* desc) { return _Desc = String(desc); }
|
||||
virtual String GetDesc() const { return _Desc; }
|
||||
|
||||
virtual void Undo()
|
||||
{
|
||||
for (int i = _Actions.GetCount() - 1; i >= 0; --i)
|
||||
if (_Actions[i])
|
||||
_Actions[i]->Undo();
|
||||
}
|
||||
|
||||
virtual void Do()
|
||||
{
|
||||
for (int i = 0; i < _Actions.GetCount(); ++i)
|
||||
if (_Actions[i])
|
||||
_Actions[i]->Do();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
17
bazaar/FormEditorCommon/IPartBase.h
Normal file
17
bazaar/FormEditorCommon/IPartBase.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef FORM_EDITOR_COMMON__I_PART_BASE_H
|
||||
#define FORM_EDITOR_COMMON__I_PART_BASE_H
|
||||
|
||||
#include "IHistory.h"
|
||||
|
||||
class IPartBase
|
||||
{
|
||||
public:
|
||||
virtual ~IPartBase() {}
|
||||
|
||||
virtual String GetObjectClass() const { return String(); }
|
||||
virtual String GetObjectWidgetClass() const { return String(); }
|
||||
|
||||
virtual void AddToHistory(IHistoryItem* item) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
54
bazaar/FormEditorCommon/Logger.h
Normal file
54
bazaar/FormEditorCommon/Logger.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#ifndef FORM_EDITOR_COMMON__LOGGER_H
|
||||
#define FORM_EDITOR_COMMON__LOGGER_H
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
#define LLOG(text) ToLog(text)
|
||||
#define LLOGF(text) ToLog(text, __FILE__, __LINE__, __FUNCTION__)
|
||||
#define LDUMP(text) ToLog(String(#text) + " = " + AsString(text))
|
||||
#define LERROR(text) ToLog(String(t_("ERROR: ")) + text, __FILE__, __LINE__, __FUNCTION__)
|
||||
#define LWARNING(text) ToLog(String(t_("WARNING: ")) + text, __FILE__, __LINE__, __FUNCTION__)
|
||||
|
||||
static StaticMutex __LogMutex;
|
||||
static bool __Created = false;
|
||||
inline bool CreateLogFile()
|
||||
{
|
||||
Mutex::Lock __(__LogMutex);
|
||||
if (__Created) return true;
|
||||
FileOut f;
|
||||
if (!f.Open(ConfigFileEx(GetFileTitle(GetExeFilePath()) + "Log.txt")))
|
||||
{
|
||||
LOG(t_("ERROR: LOG-file \"FormEditorLog.txt\" not created!"));
|
||||
return false;
|
||||
}
|
||||
f.PutLine(t_("LOG created."));
|
||||
f.Close();
|
||||
return __Created = true;
|
||||
}
|
||||
|
||||
inline String ToLog(const char *text)
|
||||
{
|
||||
Mutex::Lock __(__LogMutex);
|
||||
CreateLogFile();
|
||||
FileAppend f;
|
||||
if (!f.Open(ConfigFileEx(GetFileTitle(GetExeFilePath()) + "Log.txt")))
|
||||
return String(text);
|
||||
f.PutLine(FormatTime(GetSysTime(), "DD.MM.YYYY hh:mm:ss ") + text);
|
||||
f.Close();
|
||||
return String(text);
|
||||
}
|
||||
|
||||
inline String ToLog(const char *text, const char* file, int line, const char* method)
|
||||
{
|
||||
Mutex::Lock __(__LogMutex);
|
||||
CreateLogFile();
|
||||
FileAppend f;
|
||||
if (!f.Open(ConfigFileEx(GetFileTitle(GetExeFilePath()) + "Log.txt")))
|
||||
return String(text);
|
||||
f.PutLine(FormatTime(GetSysTime(), "DD.MM.YYYY hh:mm:ss ") + text
|
||||
+ NFormat(t_(" (file \"%s\", line %d: \"%s\")"), file, line, method));
|
||||
f.Close();
|
||||
return String(text) + " (доп. информация в лог-файле)";
|
||||
}
|
||||
|
||||
#endif
|
||||
17
bazaar/FormEditorCommon/MenuBarEx.cpp
Normal file
17
bazaar/FormEditorCommon/MenuBarEx.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include "MenuBarEx.h"
|
||||
|
||||
MenuBarEx& MenuBarEx::AddMenuHeader(const char* title)
|
||||
{
|
||||
MenuHeader& r = _Headers.Add().Title(title).CY(16);
|
||||
if (_Headers.GetCount() == 1)
|
||||
{
|
||||
AddMenu(r, 100, 20);
|
||||
r.TopPos(0, 20).HSizePos();
|
||||
}
|
||||
else
|
||||
{
|
||||
AddMenu(r, 100, 30);
|
||||
r.TopPos(5, 25).HSizePos();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
33
bazaar/FormEditorCommon/MenuBarEx.h
Normal file
33
bazaar/FormEditorCommon/MenuBarEx.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef FORM_EDITOR_COMMON__MENU_BAR_EX_H
|
||||
#define FORM_EDITOR_COMMON__MENU_BAR_EX_H
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
using namespace Upp;
|
||||
|
||||
class MenuBarEx : public MenuBar
|
||||
{
|
||||
class MenuHeader : public Ctrl
|
||||
{
|
||||
String _Title;
|
||||
int _CY;
|
||||
|
||||
public:
|
||||
MenuHeader() : _CY(0) {}
|
||||
MenuHeader& Title(const char* title) { _Title = String(title); return *this; }
|
||||
MenuHeader& CY(int cy) { _CY = cy; return *this; }
|
||||
virtual void Paint(Draw& w)
|
||||
{
|
||||
Rect r = GetRect();
|
||||
w.DrawRect(r, LtGray());
|
||||
w.DrawText(5, r.top + _CY / 2 - StdFont().GetHeight() / 2, _Title,
|
||||
StdFont(), Blue());
|
||||
}
|
||||
};
|
||||
|
||||
Array<MenuHeader> _Headers;
|
||||
|
||||
public:
|
||||
MenuBarEx& AddMenuHeader(const char* title);
|
||||
};
|
||||
|
||||
#endif
|
||||
48
bazaar/FormEditorCommon/Utils.h
Normal file
48
bazaar/FormEditorCommon/Utils.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef FORM_EDITOR_COMMON__UTILS_H
|
||||
#define FORM_EDITOR_COMMON__UTILS_H
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
using namespace Upp;
|
||||
|
||||
// Returns fullpath to the file in the exe-file directory
|
||||
inline String ConfigFileEx(const char* fp)
|
||||
{
|
||||
return AppendFileName( GetFileDirectory(GetExeFilePath()), String(fp) );
|
||||
}
|
||||
|
||||
// Converts const char* text to String
|
||||
inline String AsString(const char* s) { return String(s); }
|
||||
|
||||
// Saves Image to String
|
||||
inline String AsString(Image mIcon)
|
||||
{
|
||||
return StoreAsString(mIcon);
|
||||
}
|
||||
|
||||
// Loads Image from String
|
||||
inline Image ToImage(const String& icon)
|
||||
{
|
||||
Image r;
|
||||
return LoadFromString(r, icon) ? r : Image();
|
||||
}
|
||||
|
||||
// Returns the bool-value from any type of value
|
||||
inline bool ToBool(const Value& v)
|
||||
{
|
||||
if (v.GetType() == BOOL_V) return (bool)v;
|
||||
else return v.ToString() == "true" || ScanInt(v.ToString()) == 1;
|
||||
}
|
||||
|
||||
// Extended VectorMap, supports adding elements in one line
|
||||
template <class U, class T> class VectorMapEx : public VectorMap<U, T>
|
||||
{
|
||||
public:
|
||||
virtual ~VectorMapEx() {}
|
||||
VectorMapEx<U, T>& Add(const U& u, const T& t)
|
||||
{
|
||||
VectorMap<U, T>::Add(u, t);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
250
bazaar/FormEditorCommon/hypercall.h
Normal file
250
bazaar/FormEditorCommon/hypercall.h
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
// Created by ReC (rev.4) 19 april 2011
|
||||
|
||||
//============================================================================
|
||||
// Check template generation settings
|
||||
//============================================================================
|
||||
|
||||
// Name of the template class
|
||||
#ifndef HC_TEMPLATE_NAME
|
||||
#error "Please define HC_TEMPLATE_NAME"
|
||||
#endif
|
||||
|
||||
// Caller prototype for non-void functions
|
||||
#ifndef HC_NORMAL_CALLER
|
||||
#error "Please define HC_NORMAL_CALLER"
|
||||
#endif
|
||||
|
||||
// Caller prototype for void functions
|
||||
#ifndef HC_VOID_CALLER
|
||||
#error "Please define HC_VOID_CALLER"
|
||||
#endif
|
||||
|
||||
// How to extract and convert argument to required type
|
||||
#ifndef HC_ARGUMENT
|
||||
#error "Please define HC_ARGUMENT"
|
||||
#endif
|
||||
|
||||
#ifndef HC_BASE_CLASS
|
||||
#error "Please define HC_BASE_CLASS"
|
||||
#endif
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Some helpers to simplify shitty-coding
|
||||
//============================================================================
|
||||
|
||||
// EXPANDS2(A, B) -> A1 B, A2 B
|
||||
#define EXPANDS1(Prefix,Suffix) Prefix##1 Suffix
|
||||
#define EXPANDS2(Prefix,Suffix) EXPANDS1(Prefix,Suffix), Prefix##2 Suffix
|
||||
#define EXPANDS3(Prefix,Suffix) EXPANDS2(Prefix,Suffix), Prefix##3 Suffix
|
||||
#define EXPANDS4(Prefix,Suffix) EXPANDS3(Prefix,Suffix), Prefix##4 Suffix
|
||||
#define EXPANDS5(Prefix,Suffix) EXPANDS4(Prefix,Suffix), Prefix##5 Suffix
|
||||
#define EXPANDS6(Prefix,Suffix) EXPANDS5(Prefix,Suffix), Prefix##6 Suffix
|
||||
#define EXPANDS7(Prefix,Suffix) EXPANDS6(Prefix,Suffix), Prefix##7 Suffix
|
||||
#define EXPANDS8(Prefix,Suffix) EXPANDS7(Prefix,Suffix), Prefix##8 Suffix
|
||||
#define EXPANDS9(Prefix,Suffix) EXPANDS8(Prefix,Suffix), Prefix##9 Suffix
|
||||
#define EXPANDS10(Prefix,Suffix) EXPANDS9(Prefix,Suffix), Prefix##10 Suffix
|
||||
|
||||
// EXPAND2(A) -> A1, A2
|
||||
#define EXPAND1(Prefix) Prefix##1
|
||||
#define EXPAND2(Prefix) EXPAND1(Prefix), Prefix##2
|
||||
#define EXPAND3(Prefix) EXPAND2(Prefix), Prefix##3
|
||||
#define EXPAND4(Prefix) EXPAND3(Prefix), Prefix##4
|
||||
#define EXPAND5(Prefix) EXPAND4(Prefix), Prefix##5
|
||||
#define EXPAND6(Prefix) EXPAND5(Prefix), Prefix##6
|
||||
#define EXPAND7(Prefix) EXPAND6(Prefix), Prefix##7
|
||||
#define EXPAND8(Prefix) EXPAND7(Prefix), Prefix##8
|
||||
#define EXPAND9(Prefix) EXPAND8(Prefix), Prefix##9
|
||||
#define EXPAND10(Prefix) EXPAND9(Prefix), Prefix##10
|
||||
|
||||
// COPY2(A) -> A, A
|
||||
#define COPY1(Prefix) Prefix
|
||||
#define COPY2(Prefix) COPY1(Prefix), Prefix
|
||||
#define COPY3(Prefix) COPY2(Prefix), Prefix
|
||||
#define COPY4(Prefix) COPY3(Prefix), Prefix
|
||||
#define COPY5(Prefix) COPY4(Prefix), Prefix
|
||||
#define COPY6(Prefix) COPY5(Prefix), Prefix
|
||||
#define COPY7(Prefix) COPY6(Prefix), Prefix
|
||||
#define COPY8(Prefix) COPY7(Prefix), Prefix
|
||||
#define COPY9(Prefix) COPY8(Prefix), Prefix
|
||||
#define COPY10(Prefix) COPY9(Prefix), Prefix
|
||||
|
||||
#define ARG1(Prefix) HC_ARGUMENT(1, P##1)
|
||||
#define ARG2(Prefix) ARG1(Prefix), HC_ARGUMENT(2, Prefix##2)
|
||||
#define ARG3(Prefix) ARG2(Prefix), HC_ARGUMENT(3, Prefix##3)
|
||||
#define ARG4(Prefix) ARG3(Prefix), HC_ARGUMENT(4, Prefix##4)
|
||||
#define ARG5(Prefix) ARG4(Prefix), HC_ARGUMENT(5, Prefix##5)
|
||||
#define ARG6(Prefix) ARG5(Prefix), HC_ARGUMENT(6, Prefix##6)
|
||||
#define ARG7(Prefix) ARG6(Prefix), HC_ARGUMENT(7, Prefix##7)
|
||||
#define ARG8(Prefix) ARG7(Prefix), HC_ARGUMENT(8, Prefix##8)
|
||||
#define ARG9(Prefix) ARG8(Prefix), HC_ARGUMENT(9, Prefix##9)
|
||||
#define ARG10(Prefix) ARG9(Prefix), HC_ARGUMENT(10, Prefix##10)
|
||||
|
||||
//============================================================================
|
||||
// And now bunch of templates ...
|
||||
//============================================================================
|
||||
|
||||
// Templates for functions with return value
|
||||
template <class C, class R, EXPANDS10(typename P, =void)>
|
||||
struct HC_TEMPLATE_NAME HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND10(P)), (ARG10(P)))
|
||||
};
|
||||
|
||||
template <class C, class R, EXPAND9(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, R, EXPAND9(P), COPY1(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND9(P)), (ARG9(P)))
|
||||
};
|
||||
|
||||
template <class C, class R, EXPAND8(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, R, EXPAND8(P), COPY2(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND8(P)), (ARG8(P)))
|
||||
};
|
||||
|
||||
template <class C, class R, EXPAND7(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, R, EXPAND7(P), COPY3(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND7(P)), (ARG7(P)))
|
||||
};
|
||||
|
||||
template <class C, class R, EXPAND6(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, R, EXPAND6(P), COPY4(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND6(P)), (ARG6(P)))
|
||||
};
|
||||
|
||||
template <class C, class R, EXPAND5(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, R, EXPAND5(P), COPY5(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND5(P)), (ARG5(P)))
|
||||
};
|
||||
|
||||
template <class C, class R, EXPAND4(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, R, EXPAND4(P), COPY6(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND4(P)), (ARG4(P)))
|
||||
};
|
||||
|
||||
template <class C, class R, EXPAND3(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, R, EXPAND3(P), COPY7(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND3(P)), (ARG3(P)))
|
||||
};
|
||||
|
||||
template <class C, class R, EXPAND2(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, R, EXPAND2(P), COPY8(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND2(P)), (ARG2(P)))
|
||||
};
|
||||
|
||||
template <class C, class R, EXPAND1(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, R, EXPAND1(P), COPY9(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (EXPAND1(P)), (ARG1(P)))
|
||||
};
|
||||
|
||||
template <class C, class R>
|
||||
struct HC_TEMPLATE_NAME <C, R, COPY10(void)> HC_BASE_CLASS {
|
||||
HC_NORMAL_CALLER(C, R, (), ())
|
||||
};
|
||||
|
||||
// Templates for functions without return value
|
||||
template <class C, EXPAND10(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND10(P)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND10(P)), (ARG10(P)))
|
||||
};
|
||||
|
||||
template <class C, EXPAND9(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND9(P), COPY1(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND9(P)), (ARG9(P)))
|
||||
};
|
||||
|
||||
template <class C, EXPAND8(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND8(P), COPY2(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND8(P)), (ARG8(P)))
|
||||
};
|
||||
|
||||
template <class C, EXPAND7(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND7(P), COPY3(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND7(P)), (ARG7(P)))
|
||||
};
|
||||
|
||||
template <class C, EXPAND6(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND6(P), COPY4(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND6(P)), (ARG6(P)))
|
||||
};
|
||||
|
||||
template <class C, EXPAND5(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND5(P), COPY5(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND5(P)), (ARG5(P)))
|
||||
};
|
||||
|
||||
template <class C, EXPAND4(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND4(P), COPY6(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND4(P)), (ARG4(P)))
|
||||
};
|
||||
|
||||
template <class C, EXPAND3(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND3(P), COPY7(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND3(P)), (ARG3(P)))
|
||||
};
|
||||
|
||||
template <class C, EXPAND2(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND2(P), COPY8(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND2(P)), (ARG2(P)))
|
||||
};
|
||||
|
||||
template <class C, EXPAND1(typename P)>
|
||||
struct HC_TEMPLATE_NAME <C, void, EXPAND1(P), COPY9(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (EXPAND1(P)), (ARG1(P)))
|
||||
};
|
||||
|
||||
template <class C>
|
||||
struct HC_TEMPLATE_NAME <C, void, COPY10(void)> HC_BASE_CLASS {
|
||||
HC_VOID_CALLER(C, (), ())
|
||||
};
|
||||
|
||||
//============================================================================
|
||||
// Undefine all macroshit
|
||||
//============================================================================
|
||||
#undef EXPAND1
|
||||
#undef EXPAND2
|
||||
#undef EXPAND3
|
||||
#undef EXPAND4
|
||||
#undef EXPAND5
|
||||
#undef EXPAND6
|
||||
#undef EXPAND7
|
||||
#undef EXPAND8
|
||||
#undef EXPAND9
|
||||
#undef EXPAND10
|
||||
|
||||
#undef EXPANDS1
|
||||
#undef EXPANDS2
|
||||
#undef EXPANDS3
|
||||
#undef EXPANDS4
|
||||
#undef EXPANDS5
|
||||
#undef EXPANDS6
|
||||
#undef EXPANDS7
|
||||
#undef EXPANDS8
|
||||
#undef EXPANDS9
|
||||
#undef EXPANDS10
|
||||
|
||||
#undef COPY1
|
||||
#undef COPY2
|
||||
#undef COPY3
|
||||
#undef COPY4
|
||||
#undef COPY5
|
||||
#undef COPY6
|
||||
#undef COPY7
|
||||
#undef COPY8
|
||||
#undef COPY9
|
||||
#undef COPY10
|
||||
|
||||
#undef ARG1
|
||||
#undef ARG2
|
||||
#undef ARG3
|
||||
#undef ARG4
|
||||
#undef ARG5
|
||||
#undef ARG6
|
||||
#undef ARG7
|
||||
#undef ARG8
|
||||
#undef ARG9
|
||||
#undef ARG10
|
||||
|
||||
#undef HC_TEMPLATE_NAME
|
||||
#undef HC_NORMAL_CALLER
|
||||
#undef HC_VOID_CALLER
|
||||
#undef HC_ARGUMENT
|
||||
#undef HC_BASE_CLASS
|
||||
4
bazaar/FormEditorCommon/init
Normal file
4
bazaar/FormEditorCommon/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _FormEditorCommon_icpp_init_stub
|
||||
#define _FormEditorCommon_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#endif
|
||||
74
bazaar/FormEditorProperties/Common.h
Normal file
74
bazaar/FormEditorProperties/Common.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#ifndef FORM_EDITOR_PROPERTIES__COMMON_H
|
||||
#define FORM_EDITOR_PROPERTIES__COMMON_H
|
||||
|
||||
#include <FormEditorCommon/FormEditorCommon.h>
|
||||
#include <Esc/Esc.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// For PropertyCaller automatic argument conversion
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SProperty
|
||||
{
|
||||
public:
|
||||
SProperty(const Vector<Value>& args) { _args <<= args; }
|
||||
SProperty& operator=(const Value& v) { Return = v; return *this; }
|
||||
Value GetArg(int i) { if (i < 0 || i >= _args.GetCount()) return Value(); return _args[i]; }
|
||||
Value Return;
|
||||
private:
|
||||
Vector<Value> _args;
|
||||
};
|
||||
|
||||
template<typename P> void PropReturn(P p, SProperty& e) { }
|
||||
template<> inline void PropReturn<EscValue>(EscValue p, SProperty& e) { e = p.ToString(); }
|
||||
template<> inline void PropReturn<WString>(WString p, SProperty& e) { e = p.ToString(); }
|
||||
template<> inline void PropReturn<String>(String p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<double>(double p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<dword>(dword p, SProperty& e) { e = (int)p; }
|
||||
template<> inline void PropReturn<char*>(char* p, SProperty& e) { e = String(p); }
|
||||
template<> inline void PropReturn<bool>(bool p, SProperty& e) { e = (int)p; }
|
||||
template<> inline void PropReturn<long>(long p, SProperty& e) { e = (int)p; }
|
||||
template<> inline void PropReturn<int>(int p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<Size>(Size p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<Rect>(Rect p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<Point>(Point p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<Color>(Color p, SProperty& e) { e = p; }
|
||||
|
||||
template<> inline void PropReturn<const EscValue&>(const EscValue& p, SProperty& e){ e = p.ToString();}
|
||||
template<> inline void PropReturn<const WString&>(const WString& p, SProperty& e) { e = p.ToString(); }
|
||||
template<> inline void PropReturn<const String&>(const String& p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<const double&>(const double& p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<const dword&>(const dword& p, SProperty& e) { e = (int)p; }
|
||||
template<> inline void PropReturn<const char*>(const char* p, SProperty& e) { e = String(p); }
|
||||
template<> inline void PropReturn<const bool&>(const bool& p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<const long&>(const long& p, SProperty& e) { e = (int)p; }
|
||||
template<> inline void PropReturn<const int&>(const int& p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<const Size&>(const Size& p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<const Rect&>(const Rect& p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<const Point&>(const Point& p, SProperty& e) { e = p; }
|
||||
template<> inline void PropReturn<const Color&>(const Color& p, SProperty& e) { e = p; }
|
||||
|
||||
class ValueConvert
|
||||
{
|
||||
private:
|
||||
String _Str;
|
||||
Value _Val;
|
||||
|
||||
public:
|
||||
virtual ~ValueConvert() {}
|
||||
ValueConvert(const Value& v) { if (IsString(v)) _Str = v.ToString(); else _Val = v; }
|
||||
operator const char*() const { return (const char*)_Str; }
|
||||
String ToString() const { return _Str; }
|
||||
operator String() const { return _Str; }
|
||||
operator Value() const { return _Val; }
|
||||
operator dword() const { return ScanInt(_Val.ToString()); }
|
||||
operator Color() const { if (_Val.GetType() == COLOR_V) return _Val; return Color(); }
|
||||
operator Point() const { if (_Val.GetType() == POINT_V) return _Val; return Point(); }
|
||||
operator Rect() const { if (_Val.GetType() == RECT_V) return _Val; return Rect(); }
|
||||
operator Size() const { if (_Val.GetType() == SIZE_V) return _Val; return Size(); }
|
||||
operator bool() const { return ToBool(_Val); }
|
||||
operator int () const { return ScanInt(_Val.ToString()); }
|
||||
operator double() const { return ScanDouble(_Val.ToString()); }
|
||||
};
|
||||
|
||||
#endif
|
||||
8
bazaar/FormEditorProperties/FormEditorProperties.h
Normal file
8
bazaar/FormEditorProperties/FormEditorProperties.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef FORM_EDITOR_PROPERTIES__FORM_EDITOR_PROPERTIES_H
|
||||
#define FORM_EDITOR_PROPERTIES__FORM_EDITOR_PROPERTIES_H
|
||||
|
||||
#include "PropertiesEditor.h"
|
||||
#include "PropertiesMacro.h"
|
||||
#include "Properties.h"
|
||||
|
||||
#endif
|
||||
4
bazaar/FormEditorProperties/FormEditorProperties.icpp
Normal file
4
bazaar/FormEditorProperties/FormEditorProperties.icpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#include "Common.h"
|
||||
|
||||
#define TFILE <FormEditorProperties/FormEditorProperties.t>
|
||||
#include <Core/t.h>
|
||||
6
bazaar/FormEditorProperties/FormEditorProperties.lay
Normal file
6
bazaar/FormEditorProperties/FormEditorProperties.lay
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
LAYOUT(PropertiesLayout, 296, 460)
|
||||
ITEM(ExpanderCtrl, propGroups, HSizePosZ(8, 8).VSizePosZ(8, 44))
|
||||
ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 80).BottomPosZ(8, 28))
|
||||
ITEM(Button, ok, SetLabel(t_("Save")).RightPosZ(92, 80).BottomPosZ(8, 28))
|
||||
END_LAYOUT
|
||||
|
||||
34
bazaar/FormEditorProperties/FormEditorProperties.t
Normal file
34
bazaar/FormEditorProperties/FormEditorProperties.t
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifdef _MSC_VER
|
||||
#pragma setlocale("C")
|
||||
#endif
|
||||
// FormEditorProperties.lay
|
||||
|
||||
T_("Cancel")
|
||||
ruRU("\320\236\321\202\320\274\320\265\320\275\320\260")
|
||||
|
||||
T_("Save")
|
||||
ruRU("\320\241\320\276\321\205\321\200\320\260\320\275\320\270\321\202\321\214")
|
||||
|
||||
|
||||
// PropertiesEditor.h
|
||||
|
||||
T_("Properties")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\260")
|
||||
|
||||
T_("No properties for object!")
|
||||
ruRU("\320\235\320\265\321\202 \321\201\320\262\320\276\320\271\321\201\321\202\320\262 "
|
||||
"\320\264\320\273\321\217 \320\276\320\261\321\212\320\265\320\272\321\202\320\260!")
|
||||
|
||||
T_("Others")
|
||||
ruRU("\320\237\321\200\320\276\321\207\320\270\320\265")
|
||||
|
||||
T_("Unable to change the property: NULL-pointer.")
|
||||
ruRU("\320\235\320\265\320\262\320\276\320\267\320\274\320\276\320\266\320\275\320\276 "
|
||||
"\320\270\320\267\320\274\320\265\320\275\320\270\321\202\321\214 \321\201\320\262\320\276\320\271\321\201\321\202\320\262\320\276: "
|
||||
"NULL-\321\203\320\272\320\260\320\267\320\260\321\202\320\265\320\273\321\214.")
|
||||
|
||||
T_("Property of the object (type \"%s\"), named \"%s\", changed to: \"%s\"")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\276 \320\276\320\261\321\212\320\265\320\272\321\202\320\260 "
|
||||
"(\321\202\320\270\320\277 \"%s\") \321\201 \320\270\320\274\320\265\320\275\320\265\320\274 "
|
||||
"\"%s\", \320\270\320\267\320\274\320\265\320\275\320\270\320\273\320\276\321\201\321\214 "
|
||||
"\320\275\320\260: \"%s\"")
|
||||
25
bazaar/FormEditorProperties/FormEditorProperties.upp
Normal file
25
bazaar/FormEditorProperties/FormEditorProperties.upp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
FormEditorCommon,
|
||||
ExpandFrame;
|
||||
|
||||
file
|
||||
Basis readonly separator,
|
||||
Common.h,
|
||||
PropertyCaller.h,
|
||||
Properties readonly separator,
|
||||
FormEditorProperties.lay,
|
||||
FormEditorProperties.h,
|
||||
FormEditorProperties.t,
|
||||
FormEditorProperties.icpp,
|
||||
PropertiesMacro.h,
|
||||
PropertiesEditor.h,
|
||||
Properties.h,
|
||||
Property.h,
|
||||
Property.cpp,
|
||||
PropertyEdits.h,
|
||||
PropertyEdits.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
81
bazaar/FormEditorProperties/Properties.h
Normal file
81
bazaar/FormEditorProperties/Properties.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#ifndef FORM_EDITOR_PROPERTIES__PROPERTIES_H
|
||||
#define FORM_EDITOR_PROPERTIES__PROPERTIES_H
|
||||
|
||||
#include "PropertiesEditor.h"
|
||||
|
||||
template <class T>
|
||||
class PropertiesBase : public IPartBase
|
||||
{
|
||||
public:
|
||||
PropertiesBase(T* c) : _This(c) {}
|
||||
virtual ~PropertiesBase() {}
|
||||
|
||||
virtual void InitProperties() {}
|
||||
virtual int OpenProperties();
|
||||
virtual void ClearProperties() { GetProperties().Clear(); }
|
||||
virtual int ExecuteProperties(const Size& wndSize = Null);
|
||||
|
||||
Array<Property>& GetProperties() { return _Properties; }
|
||||
const Array<Property>& GetProperties() const { return _Properties; }
|
||||
|
||||
int GetPropertyGroupCount() const { return GetPropertiesGroups().GetCount(); }
|
||||
Vector<String> GetPropertiesGroups() const;
|
||||
Array<Property*> GetPropertiesByGroup(const String& group);
|
||||
|
||||
T* GetObject() { return _This; }
|
||||
|
||||
private:
|
||||
T* _This;
|
||||
Array<Property> _Properties;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
Vector<String> PropertiesBase<T>::GetPropertiesGroups() const
|
||||
{
|
||||
const Array<Property>& props = GetProperties();
|
||||
Vector<String> result;
|
||||
for (int i = 0; i < props.GetCount(); ++i)
|
||||
{
|
||||
bool found = false;
|
||||
for (int j = 0; j < result.GetCount(); ++j)
|
||||
if (props[i].MetaString("Group") == result[j])
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
result << props[i].MetaString("Group");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Array<Property*> PropertiesBase<T>::GetPropertiesByGroup(const String& group)
|
||||
{
|
||||
Array<Property>& props = GetProperties();
|
||||
Array<Property*> result;
|
||||
for (int i = 0; i < props.GetCount(); ++i)
|
||||
{
|
||||
if (props[i].MetaString("Group") == group)
|
||||
result.Add(&props[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int PropertiesBase<T>::OpenProperties()
|
||||
{
|
||||
return PropertiesWindow<PropertiesBase<T> >(this).Execute();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int PropertiesBase<T>::ExecuteProperties(const Size& wndSize)
|
||||
{
|
||||
PropertiesWindow<PropertiesBase<T> > wnd(this);
|
||||
if (!IsNull(wndSize))
|
||||
wnd.GetWorkArea().CenterRect(wndSize);
|
||||
int r = wnd.Execute();
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
204
bazaar/FormEditorProperties/PropertiesEditor.h
Normal file
204
bazaar/FormEditorProperties/PropertiesEditor.h
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
#ifndef FORM_EDITOR_PROPERTIES__PROPERTIES_EDITOR_H
|
||||
#define FORM_EDITOR_PROPERTIES__PROPERTIES_EDITOR_H
|
||||
|
||||
#include "Property.h"
|
||||
#include "PropertyCaller.h"
|
||||
#include <ExpandFrame/ExpandFrame.h>
|
||||
#include <FormEditorCommon/FormEditorCommon.h>
|
||||
|
||||
#define LAYOUTFILE <FormEditorProperties/FormEditorProperties.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
template <class T>
|
||||
class PropertiesWindowBase : public WithPropertiesLayout<TopWindow>
|
||||
{
|
||||
typedef PropertiesWindowBase CLASSNAME;
|
||||
|
||||
protected:
|
||||
T* GetProperties() { return _Properties; }
|
||||
virtual void Cancel();
|
||||
virtual void Load();
|
||||
virtual void Save();
|
||||
|
||||
public:
|
||||
PropertiesWindowBase(T* p);
|
||||
virtual ~PropertiesWindowBase();
|
||||
virtual String GetObjectWidgetClass() const { return String(); }
|
||||
virtual int Execute();
|
||||
|
||||
private:
|
||||
T* _Properties;
|
||||
Array<StaticRect> _Panes;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
PropertiesWindowBase<T>::PropertiesWindowBase(T* p)
|
||||
{
|
||||
CtrlLayoutOKCancel(*this, t_("Properties"));
|
||||
ToolWindow().Sizeable();
|
||||
_Properties = p;
|
||||
_Properties->InitProperties();
|
||||
Load();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PropertiesWindowBase<T>::~PropertiesWindowBase()
|
||||
{
|
||||
_Properties->ClearProperties();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int PropertiesWindowBase<T>::Execute()
|
||||
{
|
||||
if (!_Properties->GetProperties().GetCount())
|
||||
{
|
||||
PromptOK(t_("No properties for object!"));
|
||||
return IDCANCEL;
|
||||
}
|
||||
int r = WithPropertiesLayout<TopWindow>::Execute();
|
||||
r == IDOK ? Save() : Cancel();
|
||||
return r;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void PropertiesWindowBase<T>::Load()
|
||||
{
|
||||
Vector<String> groups = _Properties->GetPropertiesGroups();
|
||||
propGroups.Clear();
|
||||
_Panes.Clear();
|
||||
|
||||
for (int i = 0; i < groups.GetCount(); ++i)
|
||||
{
|
||||
if (groups[i].IsEmpty())
|
||||
groups[i] = t_("Others");
|
||||
Array<Property*> gProps = _Properties->GetPropertiesByGroup(groups[i]);
|
||||
StaticRect& pane = _Panes.Add();
|
||||
int paneCY = 10;
|
||||
for (int j = 0; j < gProps.GetCount(); ++j)
|
||||
{
|
||||
gProps[j]->ToPane(pane, paneCY, 5);
|
||||
}
|
||||
paneCY += 15;
|
||||
propGroups.AddExpander(pane, true, paneCY).SetTitle(groups[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void PropertiesWindowBase<T>::Save()
|
||||
{
|
||||
Array<Property>& props = _Properties->GetProperties();
|
||||
for (int i = 0; i < props.GetCount(); ++i)
|
||||
if (props[i].IsChanged())
|
||||
props[i].Apply();
|
||||
Break();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void PropertiesWindowBase<T>::Cancel()
|
||||
{
|
||||
Array<Property>& props = _Properties->GetProperties();
|
||||
for (int i = 0; i < props.GetCount(); ++i)
|
||||
if (props[i].IsChanged())
|
||||
props[i].Restore();
|
||||
Break();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class PropertiesWindowHistory
|
||||
{
|
||||
class HChangeProperty : public IHistoryItem
|
||||
{
|
||||
String _Name;
|
||||
Value _Last;
|
||||
Value _Next;
|
||||
int _Prop;
|
||||
T* _Ptr;
|
||||
|
||||
public:
|
||||
HChangeProperty(T* obj, String name, int prop, Value last, Value v)
|
||||
: _Ptr(obj), _Name(name), _Prop(prop), _Last(last), _Next(v) {}
|
||||
virtual ~HChangeProperty() {}
|
||||
|
||||
virtual String GetDesc() const;
|
||||
virtual void Undo();
|
||||
virtual void Do();
|
||||
};
|
||||
|
||||
public:
|
||||
PropertiesWindowHistory(T* p) : _Properties(p) {}
|
||||
|
||||
private:
|
||||
T* _Properties;
|
||||
|
||||
protected:
|
||||
virtual void Save();
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void PropertiesWindowHistory<T>::Save()
|
||||
{
|
||||
Array<Property>& props = _Properties->GetProperties();
|
||||
for (int i = 0; i < props.GetCount(); ++i)
|
||||
if (props[i].IsChanged())
|
||||
{
|
||||
T* c = _Properties->GetObject();
|
||||
if (!c) continue;
|
||||
Value v;
|
||||
props[i].Get(v, Vector<Value>());
|
||||
c->AddToHistory(new HChangeProperty(c, props[i].MetaString("Name"),
|
||||
i, props[i].GetLast(), v));
|
||||
}
|
||||
}
|
||||
|
||||
// History: Property changes
|
||||
template <class T>
|
||||
void PropertiesWindowHistory<T>::HChangeProperty::Do()
|
||||
{
|
||||
if (!_Ptr) return;
|
||||
_Ptr->InitProperties();
|
||||
Property& prop = _Ptr->GetProperties()[_Prop];
|
||||
prop.Set(Vector<Value>() << _Next);
|
||||
_Ptr->ClearProperties();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void PropertiesWindowHistory<T>::HChangeProperty::Undo()
|
||||
{
|
||||
if (!_Ptr) return;
|
||||
_Ptr->InitProperties();
|
||||
Property& prop = _Ptr->GetProperties()[_Prop];
|
||||
prop.Set(Vector<Value>() << _Last);
|
||||
_Ptr->ClearProperties();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
String PropertiesWindowHistory<T>::HChangeProperty::GetDesc() const
|
||||
{
|
||||
if (!_Ptr) return String(t_("Unable to change the property: NULL-pointer."));
|
||||
return NFormat(t_("Property of the object (type \"%s\"), named \"%s\", changed to: \"%s\""),
|
||||
_Ptr->GetObjectWidgetClass(), _Name, _Next.ToString());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class PropertiesWindow : public PropertiesWindowBase<T>, public PropertiesWindowHistory<T>
|
||||
{
|
||||
public:
|
||||
PropertiesWindow(T* p) : PropertiesWindowBase<T>(p), PropertiesWindowHistory<T>(p)
|
||||
{ _useHistory = false; }
|
||||
virtual ~PropertiesWindow() {}
|
||||
|
||||
virtual void Save()
|
||||
{
|
||||
PropertiesWindowBase<T>::Save();
|
||||
|
||||
if (_useHistory)
|
||||
PropertiesWindowHistory<T>::Save();
|
||||
}
|
||||
|
||||
bool UseHistory(bool flag = true) { _useHistory = flag; }
|
||||
|
||||
private:
|
||||
bool _useHistory;
|
||||
};
|
||||
|
||||
#endif
|
||||
65
bazaar/FormEditorProperties/PropertiesMacro.h
Normal file
65
bazaar/FormEditorProperties/PropertiesMacro.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#ifndef FORM_EDITOR_PROPERTIES__PROPERTIES_MACRO_H
|
||||
#define FORM_EDITOR_PROPERTIES__PROPERTIES_MACRO_H
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Properties declaration macros
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define PROPS_INIT_PROPERTIES virtual void InitProperties() \
|
||||
{
|
||||
|
||||
#define PROPS_INIT_PROPERTIES_END \
|
||||
}
|
||||
|
||||
#define PROPS_DEFINE_PROPERTY(MethodSet, MethodGet) \
|
||||
GetProperties().Add().SetCalls(THISBACK(PropSet##MethodSet), THISBACK(PropGet##MethodGet)) \
|
||||
PROPS_SET_NAME(#MethodSet)PROPS_GET_NAME(#MethodGet)
|
||||
|
||||
// Meta info for property
|
||||
#define PROPS_SET_NAME(Name) .AddMetaInfo("SetMethodName", Name)
|
||||
#define PROPS_GET_NAME(Name) .AddMetaInfo("GetMethodName", Name)
|
||||
#define PROPS_GROUP(Group) .AddMetaInfo("Group", Group)
|
||||
#define PROPS_NAME(Name) .AddMetaInfo("Name", Name)
|
||||
#define PROPS_HINT(Hint) .AddMetaInfo("Hint", Hint)
|
||||
#define PROPS_DEFAULT(Default) .SetDefault(Default)
|
||||
#define PROPS_TYPE(EditType, Notify) .SetEdit(new EditType, Notify)
|
||||
|
||||
// Ends property description
|
||||
#define PROPS_PROPERTY_END \
|
||||
;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Properties implementation macros
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define PROPS_METHOD_SET(MethodName, ...) \
|
||||
void PropSet##MethodName(const Vector<Value>& args) \
|
||||
{ \
|
||||
SProperty c(args); \
|
||||
PropertyCaller<CLASSNAME, __VA_ARGS__>::call(*this, &CLASSNAME::MethodName, c); \
|
||||
}
|
||||
|
||||
#define PROPS_METHOD_GET(MethodName, ...) \
|
||||
void PropGet##MethodName(Value& v, const Vector<Value>& args) \
|
||||
{ \
|
||||
SProperty c(args); \
|
||||
PropertyCaller<CLASSNAME, __VA_ARGS__>::call(*this, &CLASSNAME::MethodName, c); \
|
||||
v = c.Return; \
|
||||
}
|
||||
|
||||
#define PROPS_CLASS_METHOD_SET(ClassName, MethodName, ...) \
|
||||
void PropSet##MethodName(const Vector<Value>& args) \
|
||||
{ \
|
||||
SProperty c(args); \
|
||||
PropertyCaller<ClassName, __VA_ARGS__>::call(GetCtrl(), &ClassName::MethodName, c); \
|
||||
}
|
||||
|
||||
#define PROPS_CLASS_METHOD_GET(ClassName, MethodName, ...) \
|
||||
void PropGet##MethodName(Value& v, const Vector<Value>& args) \
|
||||
{ \
|
||||
SProperty c(args); \
|
||||
PropertyCaller<ClassName, __VA_ARGS__>::call(GetCtrl(), &ClassName::MethodName, c); \
|
||||
v = c.Return; \
|
||||
}
|
||||
|
||||
#endif
|
||||
57
bazaar/FormEditorProperties/Property.cpp
Normal file
57
bazaar/FormEditorProperties/Property.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#include "Property.h"
|
||||
|
||||
Property& Property::SetCalls(Callback1<const Vector<Value>&> set,
|
||||
Callback2<Value&, const Vector<Value>&> get)
|
||||
{
|
||||
Set = set;
|
||||
Get = get;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Property& Property::SetEdit(IEditCtrl* edit, bool notify)
|
||||
{
|
||||
if (_Edit) _Edit->Release();
|
||||
if (!edit) return *this;
|
||||
_Edit = edit;
|
||||
_Edit->Retain();
|
||||
_Edit->SetNotify(notify);
|
||||
_Edit->AttachObserver(this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Property& Property::ToPane(Ctrl& c, int& cy, int space)
|
||||
{
|
||||
Value v;
|
||||
Get(v, Vector<Value>());
|
||||
_Last = v;
|
||||
if (!_Edit) { _Edit = new CEditField(); _Edit->Retain(); }
|
||||
_Edit->SetLabel(MetaString("Name"));
|
||||
_Edit->SetData(v);
|
||||
_Edit->Set(c, cy);
|
||||
cy += space;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Property::IsDefault() const
|
||||
{
|
||||
Value v;
|
||||
Get(v, Vector<Value>());
|
||||
if ((v.GetType() == BOOL_V || v.GetType() == INT_V) &&
|
||||
(_Default.GetType() == BOOL_V || _Default.GetType() == INT_V))
|
||||
return _Default == v;
|
||||
return _Default.ToString() == v.ToString();
|
||||
}
|
||||
|
||||
bool Property::IsChanged() const
|
||||
{
|
||||
Value v;
|
||||
Get(v, Vector<Value>());
|
||||
|
||||
bool changed = ((v.GetType() == BOOL_V || v.GetType() == INT_V) &&
|
||||
(_Last.GetType() == BOOL_V || _Last.GetType() == INT_V))
|
||||
? (_Last != v)
|
||||
: (_Last.ToString() != v.ToString());
|
||||
if (!changed && _Edit)
|
||||
return v != _Edit->GetData();
|
||||
return changed;
|
||||
}
|
||||
44
bazaar/FormEditorProperties/Property.h
Normal file
44
bazaar/FormEditorProperties/Property.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef FORM_EDITOR_PROPERTIES__PROPERTY_H
|
||||
#define FORM_EDITOR_PROPERTIES__PROPERTY_H
|
||||
|
||||
#include <FormEditorCommon/FormEditorCommon.h>
|
||||
#include "PropertyEdits.h"
|
||||
|
||||
class Property : public IObserver
|
||||
{
|
||||
public:
|
||||
Property() : _Edit(NULL), _Default(String()) {}
|
||||
virtual ~Property() { if (_Edit) _Edit->Release(); }
|
||||
virtual void OnUpdate(ISubject* s) { Set(Vector<Value>() << _Edit->GetData()); }
|
||||
|
||||
Property& SetCalls(Callback1<const Vector<Value>&> set,
|
||||
Callback2<Value&, const Vector<Value>&> get);
|
||||
|
||||
Property& AddMetaInfo(const String& s, const Value& v){ _Meta.Add(s, v); return *this; }
|
||||
Property& SetDefault(const Value& val) { _Default = val; return *this; }
|
||||
Property& SetEdit(IEditCtrl* edit, bool notify);
|
||||
Property& ToPane(Ctrl& c, int& cy, int space);
|
||||
|
||||
void RestoreDefault() { Set(Vector<Value>() << _Default); }
|
||||
void Restore() { Set(Vector<Value>() << _Last); }
|
||||
void Apply() { Set(Vector<Value>() << _Edit->GetData()); }
|
||||
bool IsDefault() const;
|
||||
bool IsChanged() const;
|
||||
void Serialize(Stream& s) { s % _Last; }
|
||||
|
||||
Value GetLast() const { return _Last; }
|
||||
Value GetDefault() const { return _Default; }
|
||||
Value GetMetaInfo(const char* s) const { return _Meta.Get(String(s), Value()); }
|
||||
String MetaString(const char* s) const { return _Meta.Get(String(s), Value()).ToString(); }
|
||||
|
||||
Callback1<const Vector<Value>&> Set;
|
||||
Callback2<Value&, const Vector<Value>&> Get;
|
||||
|
||||
private:
|
||||
Value _Last;
|
||||
Value _Default;
|
||||
IEditCtrl* _Edit;
|
||||
VectorMap<String, Value> _Meta;
|
||||
};
|
||||
|
||||
#endif
|
||||
35
bazaar/FormEditorProperties/PropertyCaller.h
Normal file
35
bazaar/FormEditorProperties/PropertyCaller.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef FORM_EDITOR_PROPERTIES__PROPERTY_CALLER_H
|
||||
#define FORM_EDITOR_PROPERTIES__PROPERTY_CALLER_H
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#define HC_TEMPLATE_NAME PropertyCaller
|
||||
|
||||
// Prototype for non-void functions
|
||||
#define HC_NORMAL_CALLER(Class, Return, ArgList, Args) \
|
||||
static void call(Class &object, Return (Class::*method)ArgList, SProperty& c) { \
|
||||
PropReturn<Return>((object.*method)Args, c); \
|
||||
} \
|
||||
static void call(const Class &object, Return (Class::*method)ArgList const, SProperty& c) { \
|
||||
PropReturn<Return>((object.*method)Args, c); \
|
||||
}
|
||||
|
||||
// Prototype for void functions
|
||||
#define HC_VOID_CALLER(Class, ArgList, Args) \
|
||||
static void call(Class &object, void (Class::*method)ArgList, SProperty& c) { \
|
||||
(object.*method)Args; \
|
||||
} \
|
||||
static void call(const Class &object, void (Class::*method)ArgList const, SProperty& c) { \
|
||||
(object.*method)Args; \
|
||||
}
|
||||
|
||||
// Argument conversion
|
||||
#define HC_ARGUMENT(Pos, Type) (Type)ValueConvert(c.GetArg(Pos-1))
|
||||
|
||||
// No base class
|
||||
#define HC_BASE_CLASS
|
||||
|
||||
// Generate now!
|
||||
#include <FormEditorCommon/hypercall.h>
|
||||
|
||||
#endif
|
||||
230
bazaar/FormEditorProperties/PropertyEdits.cpp
Normal file
230
bazaar/FormEditorProperties/PropertyEdits.cpp
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
#include "PropertyEdits.h"
|
||||
|
||||
#define TEXT_DEFAULT_LEFT 5
|
||||
#define TEXT_DEFAULT_RIGHT 120
|
||||
#define EDIT_DEFAULT_LEFT 120
|
||||
#define EDIT_DEFAULT_RIGHT 5
|
||||
|
||||
// Edit field for text
|
||||
CEditField::CEditField()
|
||||
{
|
||||
_Label.HSizePosZ(TEXT_DEFAULT_LEFT, TEXT_DEFAULT_RIGHT);
|
||||
_Edit.HSizePosZ(EDIT_DEFAULT_LEFT, EDIT_DEFAULT_RIGHT);
|
||||
_Edit.WhenAction = THISBACK(Notify);
|
||||
}
|
||||
|
||||
CEditField::CEditField(int (*filter)(int))
|
||||
{
|
||||
_Label.HSizePosZ(TEXT_DEFAULT_LEFT, TEXT_DEFAULT_RIGHT);
|
||||
_Edit.HSizePosZ(EDIT_DEFAULT_LEFT, EDIT_DEFAULT_RIGHT);
|
||||
_Edit.WhenAction = THISBACK(Notify);
|
||||
_Edit.SetFilter(filter);
|
||||
}
|
||||
|
||||
void CEditField::Set(Ctrl& c, int& cy)
|
||||
{
|
||||
_Label.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
_Edit.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
cy += _Edit.GetStdSize().cy;
|
||||
c.Add(_Label);
|
||||
c.Add(_Edit);
|
||||
}
|
||||
|
||||
// Button
|
||||
CButton::CButton(const char* label, const Callback& call)
|
||||
{
|
||||
_Label.HSizePosZ(TEXT_DEFAULT_LEFT, TEXT_DEFAULT_RIGHT);
|
||||
_Edit.HSizePosZ(EDIT_DEFAULT_LEFT, EDIT_DEFAULT_RIGHT);
|
||||
|
||||
_Edit.SetLabel(label);
|
||||
_Edit.WhenPush = call;
|
||||
}
|
||||
|
||||
void CButton::Set(Ctrl& c, int& cy)
|
||||
{
|
||||
_Label.TopPosZ(cy, EditField().GetStdSize().cy);
|
||||
_Edit.TopPosZ(cy, EditField().GetStdSize().cy);
|
||||
cy += _Edit.GetStdSize().cy;
|
||||
c.Add(_Label);
|
||||
c.Add(_Edit);
|
||||
}
|
||||
|
||||
// Edit field for numbers
|
||||
CEditIntSpin::CEditIntSpin(int min, int max)
|
||||
{
|
||||
_Label.HSizePosZ(TEXT_DEFAULT_LEFT, TEXT_DEFAULT_RIGHT);
|
||||
_Edit.HSizePosZ(EDIT_DEFAULT_LEFT, EDIT_DEFAULT_RIGHT);
|
||||
_Edit.Min(min).Max(max);
|
||||
_Edit.WhenAction = THISBACK(Notify);
|
||||
}
|
||||
|
||||
void CEditIntSpin::Set(Ctrl& c, int& cy)
|
||||
{
|
||||
_Label.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
_Edit.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
cy += _Edit.GetStdSize().cy;
|
||||
c.Add(_Label);
|
||||
c.Add(_Edit);
|
||||
}
|
||||
|
||||
void CEditIntSpin::SetData(const Value& data)
|
||||
{
|
||||
if (data.GetType() == INT_V)
|
||||
_Edit.SetData(data);
|
||||
else
|
||||
_Edit.SetData(10);
|
||||
}
|
||||
|
||||
// Edit field for double-type
|
||||
CEditDouble::CEditDouble(double min, double max)
|
||||
{
|
||||
_Label.HSizePosZ(TEXT_DEFAULT_LEFT, TEXT_DEFAULT_RIGHT);
|
||||
_Edit.HSizePosZ(EDIT_DEFAULT_LEFT, EDIT_DEFAULT_RIGHT);
|
||||
_Edit.Min(min).Max(max);
|
||||
_Edit.WhenAction = THISBACK(Notify);
|
||||
}
|
||||
|
||||
void CEditDouble::Set(Ctrl& c, int& cy)
|
||||
{
|
||||
_Label.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
_Edit.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
cy += _Edit.GetStdSize().cy;
|
||||
c.Add(_Label);
|
||||
c.Add(_Edit);
|
||||
}
|
||||
|
||||
void CEditDouble::SetData(const Value& data)
|
||||
{
|
||||
_Edit.SetData(ScanDouble(data.ToString()));
|
||||
}
|
||||
|
||||
// Edit field for boolean
|
||||
CEditBool::CEditBool()
|
||||
{
|
||||
_Edit.HSizePosZ(10, 10);
|
||||
_Edit.WhenAction = THISBACK(Notify);
|
||||
}
|
||||
|
||||
void CEditBool::Set(Ctrl& c, int& cy)
|
||||
{
|
||||
_Edit.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
cy += _Edit.GetStdSize().cy;
|
||||
c.Add(_Edit);
|
||||
}
|
||||
|
||||
void CEditBool::SetData(const Value& data)
|
||||
{
|
||||
if (data.GetType() == BOOL_V || data.GetType() == INT_V)
|
||||
_Edit.Set(data);
|
||||
}
|
||||
|
||||
// Dropping list
|
||||
CDropList::CDropList(const VectorMapEx<String, Value>& list, int defaultIndex)
|
||||
{
|
||||
_Label.HSizePosZ(TEXT_DEFAULT_LEFT, TEXT_DEFAULT_RIGHT);
|
||||
_Edit .HSizePosZ(EDIT_DEFAULT_LEFT, EDIT_DEFAULT_RIGHT);
|
||||
_Edit .WhenAction = THISBACK(Notify);
|
||||
|
||||
for (int i = 0; i < list.GetCount(); ++i)
|
||||
_Edit.Add(list.GetKey(i), list[i]);
|
||||
if (_Edit.GetCount()) _Edit.SetIndex(defaultIndex);
|
||||
}
|
||||
|
||||
void CDropList::Set(Ctrl& c, int& cy)
|
||||
{
|
||||
_Label.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
_Edit.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
cy += _Edit.GetStdSize().cy;
|
||||
c.Add(_Label);
|
||||
c.Add(_Edit);
|
||||
}
|
||||
|
||||
void CDropList::SetData(const Value& data)
|
||||
{
|
||||
bool found = false;
|
||||
for (int i = 0; i < _Edit.GetCount(); ++i)
|
||||
if (_Edit.GetValue(i) == data)
|
||||
{
|
||||
_Edit.SetIndex(i);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
_Edit.SetData(data);
|
||||
}
|
||||
|
||||
// Edit field for text
|
||||
CEditColor::CEditColor()
|
||||
{
|
||||
_Label.HSizePosZ(TEXT_DEFAULT_LEFT, TEXT_DEFAULT_RIGHT);
|
||||
_Edit.HSizePosZ(EDIT_DEFAULT_LEFT, EDIT_DEFAULT_RIGHT);
|
||||
_Edit.WhenAction = THISBACK(Notify);
|
||||
}
|
||||
|
||||
void CEditColor::Set(Ctrl& c, int& cy)
|
||||
{
|
||||
_Label.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
_Edit.TopPosZ(cy, _Edit.GetStdSize().cy);
|
||||
cy += _Edit.GetStdSize().cy;
|
||||
c.Add(_Label);
|
||||
c.Add(_Edit);
|
||||
}
|
||||
|
||||
// Edit field for simple doc
|
||||
CDocEdit::CDocEdit()
|
||||
{
|
||||
_Label.HSizePosZ(TEXT_DEFAULT_LEFT, TEXT_DEFAULT_RIGHT);
|
||||
_Edit.HSizePosZ(EDIT_DEFAULT_LEFT, EDIT_DEFAULT_RIGHT);
|
||||
_Edit.WhenAction = THISBACK(Notify);
|
||||
}
|
||||
|
||||
void CDocEdit::Set(Ctrl& c, int& cy)
|
||||
{
|
||||
_Label.TopPosZ(cy, _Label.GetStdSize().cy);
|
||||
_Edit.TopPosZ(cy, 100);
|
||||
cy += 100;
|
||||
c.Add(_Label);
|
||||
c.Add(_Edit);
|
||||
}
|
||||
|
||||
// Edit field for size
|
||||
CEditSize::CEditSize(int min, int max)
|
||||
{
|
||||
_CX.Min(min).Max(max);
|
||||
_CY.Min(min).Max(max);
|
||||
_CX.WhenAction = THISBACK(Notify);
|
||||
_CY.WhenAction = THISBACK(Notify);
|
||||
_Label.HSizePosZ(TEXT_DEFAULT_LEFT, TEXT_DEFAULT_RIGHT);
|
||||
_Size.HSizePosZ(EDIT_DEFAULT_LEFT, EDIT_DEFAULT_RIGHT);
|
||||
_Size.Add(_CX.SizePos());
|
||||
_Size.Add(_CY.SizePos());
|
||||
}
|
||||
|
||||
void CEditSize::Set(Ctrl& c, int& cy)
|
||||
{
|
||||
c.Add(_Label.TopPosZ(cy, _CY.GetStdSize().cy));
|
||||
c.Add(_Size.TopPosZ(cy, _CY.GetStdSize().cy));
|
||||
|
||||
cy += _CY.GetStdSize().cy;
|
||||
}
|
||||
|
||||
void CEditSize::SetData(const Value& data)
|
||||
{
|
||||
if (data.GetType() == SIZE_V)
|
||||
{
|
||||
Size sz = data;
|
||||
_CX.SetData(sz.cx);
|
||||
_CY.SetData(sz.cy);
|
||||
}
|
||||
}
|
||||
|
||||
// Edit field for point
|
||||
void CEditPoint::SetData(const Value& data)
|
||||
{
|
||||
if (data.GetType() == POINT_V)
|
||||
{
|
||||
Point p = data;
|
||||
_CX.SetData(p.x);
|
||||
_CY.SetData(p.y);
|
||||
}
|
||||
}
|
||||
205
bazaar/FormEditorProperties/PropertyEdits.h
Normal file
205
bazaar/FormEditorProperties/PropertyEdits.h
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
#ifndef FORM_EDITOR_PROPERTIES__PROPERTY_EDITS_H
|
||||
#define FORM_EDITOR_PROPERTIES__PROPERTY_EDITS_H
|
||||
|
||||
#include <FormEditorCommon/FormEditorCommon.h>
|
||||
|
||||
class ISubject;
|
||||
class IObserver : public Pte<IObserver>
|
||||
{
|
||||
public:
|
||||
virtual void OnUpdate(ISubject* s) = 0;
|
||||
};
|
||||
|
||||
class ISubject
|
||||
{
|
||||
Vector<Ptr<IObserver> > _Observers;
|
||||
Atomic _Refcount;
|
||||
bool _Notify;
|
||||
|
||||
public:
|
||||
ISubject() { _Notify = false; AtomicWrite(_Refcount, 0); }
|
||||
void Retain() { AtomicInc(_Refcount); }
|
||||
void Release() { if (AtomicDec(_Refcount) == 0) delete this; }
|
||||
virtual ~ISubject() {}
|
||||
|
||||
virtual void AttachObserver(Ptr<IObserver> p) { if (p) _Observers.Add(p); }
|
||||
virtual void SetNotify(bool flag) { _Notify = flag; }
|
||||
virtual void Notify()
|
||||
{
|
||||
if (_Notify)
|
||||
for (int i = 0; i < _Observers.GetCount(); ++i)
|
||||
if (_Observers[i]) _Observers[i]->OnUpdate(this);
|
||||
}
|
||||
};
|
||||
|
||||
class IEditCtrl : public ISubject
|
||||
{
|
||||
public:
|
||||
virtual ~IEditCtrl() {}
|
||||
virtual void Set(Ctrl& c, int& cy) = 0;
|
||||
virtual void SetData(const Value& data) = 0;
|
||||
virtual void SetLabel(const String& label) = 0;
|
||||
virtual Value GetData() const = 0;
|
||||
};
|
||||
|
||||
// Edit field for text
|
||||
class CEditField : public IEditCtrl
|
||||
{
|
||||
typedef CEditField CLASSNAME;
|
||||
EditField _Edit;
|
||||
Label _Label;
|
||||
|
||||
public:
|
||||
CEditField();
|
||||
CEditField(int (*filter)(int));
|
||||
virtual ~CEditField() {}
|
||||
virtual void Set(Ctrl& c, int& cy);
|
||||
virtual void SetData(const Value& data) { _Edit.SetData(data); }
|
||||
virtual void SetLabel(const String& label) { _Label.SetLabel(label + ":"); }
|
||||
virtual Value GetData() const { return _Edit.GetData(); }
|
||||
};
|
||||
|
||||
// Button
|
||||
class CButton : public IEditCtrl
|
||||
{
|
||||
typedef CButton CLASSNAME;
|
||||
Button _Edit;
|
||||
Label _Label;
|
||||
|
||||
public:
|
||||
CButton(const char* label, const Callback& call);
|
||||
virtual ~CButton() {}
|
||||
virtual void Set(Ctrl& c, int& cy);
|
||||
virtual void SetData(const Value& data) {}
|
||||
virtual void SetLabel(const String& label) { _Label.SetLabel(label + ":"); }
|
||||
virtual Value GetData() const { return Value(); }
|
||||
};
|
||||
|
||||
// Edit field for numbers
|
||||
class CEditIntSpin : public IEditCtrl
|
||||
{
|
||||
typedef CEditIntSpin CLASSNAME;
|
||||
EditIntSpin _Edit;
|
||||
Label _Label;
|
||||
|
||||
public:
|
||||
CEditIntSpin(int min, int max);
|
||||
virtual ~CEditIntSpin() {}
|
||||
virtual void Set(Ctrl& c, int& cy);
|
||||
virtual void SetData(const Value& data);
|
||||
virtual void SetLabel(const String& label) { _Label.SetLabel(label + ":"); }
|
||||
virtual Value GetData() const { return _Edit.GetData(); }
|
||||
};
|
||||
|
||||
// Edit field for double-type
|
||||
class CEditDouble : public IEditCtrl
|
||||
{
|
||||
typedef CEditDouble CLASSNAME;
|
||||
EditDouble _Edit;
|
||||
Label _Label;
|
||||
|
||||
public:
|
||||
CEditDouble(double min, double max);
|
||||
virtual ~CEditDouble() {}
|
||||
virtual void Set(Ctrl& c, int& cy);
|
||||
virtual void SetData(const Value& data);
|
||||
virtual void SetLabel(const String& label) { _Label.SetLabel(label + ":"); }
|
||||
virtual Value GetData() const { return _Edit.GetData(); }
|
||||
};
|
||||
|
||||
// Edit field for boolean
|
||||
class CEditBool : public IEditCtrl
|
||||
{
|
||||
typedef CEditBool CLASSNAME;
|
||||
Option _Edit;
|
||||
|
||||
public:
|
||||
CEditBool();
|
||||
virtual ~CEditBool() {}
|
||||
virtual void Set(Ctrl& c, int& cy);
|
||||
virtual void SetData(const Value& data);
|
||||
virtual void SetLabel(const String& label) { _Edit.SetLabel(label); }
|
||||
virtual Value GetData() const { return _Edit.Get(); }
|
||||
};
|
||||
|
||||
// Dropping list
|
||||
class CDropList : public IEditCtrl
|
||||
{
|
||||
typedef CDropList CLASSNAME;
|
||||
DropList _Edit;
|
||||
Label _Label;
|
||||
|
||||
public:
|
||||
CDropList(const VectorMapEx<String, Value>& list, int defaultIndex = 0);
|
||||
virtual ~CDropList() {}
|
||||
virtual void Set(Ctrl& c, int& cy);
|
||||
virtual void SetData(const Value& data);
|
||||
virtual void SetLabel(const String& label) { _Label.SetLabel(label + ":"); }
|
||||
virtual Value GetData() const { return _Edit.GetValue(); }
|
||||
};
|
||||
|
||||
// Edit color
|
||||
class CEditColor : public IEditCtrl
|
||||
{
|
||||
typedef CEditColor CLASSNAME;
|
||||
ColorPusher _Edit;
|
||||
Label _Label;
|
||||
|
||||
public:
|
||||
CEditColor();
|
||||
virtual ~CEditColor() {}
|
||||
virtual void Set(Ctrl& c, int& cy);
|
||||
virtual void SetData(const Value& data) { _Edit.SetData(data); }
|
||||
virtual void SetLabel(const String& label) { _Label.SetLabel(label + ":"); }
|
||||
virtual Value GetData() const { return _Edit.GetData(); }
|
||||
};
|
||||
|
||||
// Edit doc
|
||||
class CDocEdit : public IEditCtrl
|
||||
{
|
||||
typedef CEditColor CLASSNAME;
|
||||
DocEdit _Edit;
|
||||
Label _Label;
|
||||
|
||||
public:
|
||||
CDocEdit();
|
||||
virtual ~CDocEdit() {}
|
||||
virtual void Set(Ctrl& c, int& cy);
|
||||
virtual void SetData(const Value& data) { _Edit.SetData(data); }
|
||||
virtual void SetLabel(const String& label) { _Label.SetLabel(label + ":"); }
|
||||
virtual Value GetData() const { return _Edit.GetData(); }
|
||||
};
|
||||
|
||||
// Edit field for size
|
||||
class CEditSize : public IEditCtrl
|
||||
{
|
||||
typedef CEditSize CLASSNAME;
|
||||
friend class CEditPoint;
|
||||
EditIntSpin _CX;
|
||||
EditIntSpin _CY;
|
||||
Splitter _Size;
|
||||
Label _Label;
|
||||
|
||||
public:
|
||||
CEditSize(int min, int max);
|
||||
virtual ~CEditSize() {}
|
||||
virtual void Set(Ctrl& c, int& cy);
|
||||
virtual void SetData(const Value& data);
|
||||
virtual void SetLabel(const String& label) { _Label.SetLabel(label + ":"); }
|
||||
virtual Value GetData() const { return Size( _CX.GetData(), _CY.GetData()); }
|
||||
};
|
||||
|
||||
// Edit field for point
|
||||
class CEditPoint : public CEditSize
|
||||
{
|
||||
typedef CEditPoint CLASSNAME;
|
||||
|
||||
public:
|
||||
CEditPoint(int min, int max) : CEditSize(min, max) {}
|
||||
virtual ~CEditPoint() {}
|
||||
virtual void SetData(const Value& data);
|
||||
virtual void SetLabel(const String& label) { _Label.SetLabel(label + ":"); }
|
||||
virtual Value GetData() const { return Point(_CX.GetData(), _CY.GetData()); }
|
||||
};
|
||||
|
||||
#endif
|
||||
9
bazaar/FormEditorProperties/init
Normal file
9
bazaar/FormEditorProperties/init
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _FormEditorProperties_icpp_init_stub
|
||||
#define _FormEditorProperties_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "FormEditorCommon/init"
|
||||
#include "ExpandFrame/init"
|
||||
#define BLITZ_INDEX__ FBF5B444DA4360EC5FCE19D15538383D2
|
||||
#include "FormEditorProperties.icpp"
|
||||
#undef BLITZ_INDEX__
|
||||
#endif
|
||||
7
bazaar/Map/Map.h
Normal file
7
bazaar/Map/Map.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef MAP__MAP_H
|
||||
#define MAP__MAP_H
|
||||
|
||||
#include "MapView.h"
|
||||
#include "MapSerialize.h"
|
||||
|
||||
#endif
|
||||
4
bazaar/Map/Map.icpp
Normal file
4
bazaar/Map/Map.icpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#include "Map.h"
|
||||
|
||||
#define TFILE <Map/Map.t>
|
||||
#include <Core/t.h>
|
||||
157
bazaar/Map/Map.t
Normal file
157
bazaar/Map/Map.t
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
#ifdef _MSC_VER
|
||||
#pragma setlocale("C")
|
||||
#endif
|
||||
// MapSerialize.h
|
||||
|
||||
T_("Room properties")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\260 \320\272\320\276\320\274\320\275\320\260\321\202\321\213")
|
||||
|
||||
T_("Name")
|
||||
ruRU("\320\235\320\260\320\267\320\262\320\260\320\275\320\270\320\265")
|
||||
|
||||
T_("Sets the name of the room")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\275\320\260\320\267\320\262\320\260\320\275\320\270\320\265 \320\264\320\273\321\217 "
|
||||
"\320\272\320\276\320\274\320\275\320\260\321\202\321\213")
|
||||
|
||||
T_("Description")
|
||||
ruRU("\320\236\320\277\320\270\321\201\320\260\320\275\320\270\320\265")
|
||||
|
||||
T_("Sets the description of the room")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\276\320\277\320\270\321\201\320\260\320\275\320\270\320\265 \320\272\320\276\320\274\320\275\320\260\321\202\321\213")
|
||||
|
||||
T_("Tags")
|
||||
ruRU("\320\242\320\265\320\263\320\270")
|
||||
|
||||
T_("Sets the tags of the room")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 \321\202\320\265\320\263\320\270 \320\264\320\273\321\217 \320\277\320\276\320\270\321\201\320\272\320\260 \320\272\320\276\320\274\320\275\320\260\321\202\321\213")
|
||||
|
||||
T_("Room number")
|
||||
ruRU("\320\235\320\276\320\274\320\265\321\200 \320\272\320\276\320\274\320\275\320\260\321\202\321\213")
|
||||
|
||||
T_("Sets the number of the room")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\275\320\276\320\274\320\265\321\200 \320\272\320\276\320\274\320\275\320\260\321\202\321\213")
|
||||
|
||||
T_("Logo path")
|
||||
ruRU("\320\237\321\203\321\202\321\214 \320\272 \320\273\320\276\320\263\320\276\321\202\320\270\320\277\321\203")
|
||||
|
||||
T_("Sets the path to the room logo")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\277\321\203\321\202\321\214 \320\272 \321\204\320\260\320\271\320\273\321\203 "
|
||||
"\320\273\320\276\320\263\320\276\321\202\320\270\320\277\320\260")
|
||||
|
||||
T_("Discount properties")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\260 \321\201\320\272\320\270\320\264\320\276\320\272")
|
||||
|
||||
T_("Discount")
|
||||
ruRU("\320\241\320\272\320\270\320\264\320\272\320\270, \320\272\320\276\320\273-\320\262\320\276")
|
||||
|
||||
T_("Sets the number of the room discounts")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\272\320\276\320\273-\320\262\320\276 \321\201\320\272\320\270\320\264\320\276\320\272 "
|
||||
"\320\262 \321\215\321\202\320\276\320\274 \320\277\320\276\320\274\320\265\321\211\320\265\320\275\320\270\320\270")
|
||||
|
||||
T_("Layer properties")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\276 \321\201\320\273\320\276\321\217")
|
||||
|
||||
T_("Sets the name of the layer")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\275\320\260\320\267\320\262\320\260\320\275\320\270\320\265 \321\201\320\273\320\276\321\217")
|
||||
|
||||
T_("Level properties")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\260 \321\215\321\202\320\260\320\266\320\260/\321\203\321\200\320\276\320\262\320\275\321\217")
|
||||
|
||||
T_("Sets the name of the level")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\275\320\260\320\267\320\262\320\260\320\275\320\270\321\217 \320\264\320\273\321\217 "
|
||||
"\321\215\321\202\320\260\320\266\320\260/\321\203\321\200\320\276\320\262\320\275\321\217")
|
||||
|
||||
T_("Sets the description of the level")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\276\320\277\320\270\321\201\320\260\320\275\320\270\320\265 \320\264\320\273\321\217 "
|
||||
"\321\215\321\202\320\260\320\266\320\260/\321\203\321\200\320\276\320\262\320\275\321\217")
|
||||
|
||||
T_("BG properties")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\260 \320\272\320\260\321\200\321\202\321\213 "
|
||||
"(\320\276\321\201\320\275\320\276\320\262\321\213)")
|
||||
|
||||
T_("Source map image")
|
||||
ruRU("\320\230\321\201\321\205\320\276\320\264\320\275\320\260\321\217 \320\272\320\260\321\200\321\202\320\260")
|
||||
|
||||
T_("Sets the background map of the level")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\270\320\267\320\276\320\261\321\200\320\260\320\266\320\265\320\275\320\270\320\265 "
|
||||
"\320\272\320\260\321\200\321\202\321\213 \320\262 \321\204\320\276\320\275\320\265")
|
||||
|
||||
T_("None selected")
|
||||
ruRU("\320\235\320\265 \320\262\321\213\320\261\321\200\320\260\320\275\320\276")
|
||||
|
||||
T_("Start page size")
|
||||
ruRU("\320\235\320\260\321\207\320\260\320\273\321\214\320\275\321\213\320\271 "
|
||||
"\321\200\320\260\320\267\320\274\320\265\321\200")
|
||||
|
||||
T_("Sets the page size at the start of level calculation")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\275\320\260\321\207\320\260\320\273\321\214\320\275\321\213\320\271 "
|
||||
"\321\200\320\260\320\267\320\274\320\265\321\200 \320\272\320\260\321\200\321\202\321\213 "
|
||||
"\320\264\320\273\321\217 \321\200\320\260\321\201\321\207\320\265\321\202\320\276\320\262 "
|
||||
"(\320\277\321\200\320\270 \320\274\320\260\320\272\321\201\320\270\320\274\320\260\320\273\321\214\320\275\320\276\320\274 "
|
||||
"\320\276\321\202\320\264\320\260\320\273\320\265\320\275\320\270\320\270)")
|
||||
|
||||
T_("Mipmap size")
|
||||
ruRU("\320\240\320\260\320\267\320\274\320\265\321\200 \321\217\321\207\320\265\320\271\320\272\320\270")
|
||||
|
||||
T_("Sets the mipmap size")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\321\200\320\260\320\267\320\274\320\265\321\200 \321\217\321\207\320\265\320\271\320\272\320\270 "
|
||||
"\320\272\320\260\321\200\321\202\321\213 (\321\207\320\265\320\274 \320\274\320\265\320\275\321\214\321\210\320\265 "
|
||||
"\321\200\320\260\320\267\320\274\320\265\321\200, \321\202\320\265\320\274 "
|
||||
"\320\261\320\276\320\273\321\214\321\210\320\265 \321\204\320\260\320\271\320\273\320\276\320\262 "
|
||||
"\320\261\321\203\320\264\320\265\321\202 \321\201\320\276\320\267\320\264\320\260\320\275\320\276")
|
||||
|
||||
T_("Zoom step (dx)")
|
||||
ruRU("\320\232\320\276\321\215\321\204. \321\203\320\262\320\265\320\273\320\270\321\207\320\265\320\275\320\270\321\217")
|
||||
|
||||
T_("Sets the zoom value between two zoom levels")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\272\320\276\321\215\321\204\321\204\320\270\321\206\320\270\320\265\320\275\321\202 "
|
||||
"\321\203\320\262\320\265\320\273\320\270\321\207\320\265\320\275\320\270\321\217 "
|
||||
"\320\276\321\202 \321\202\320\265\320\272\321\203\321\211\320\265\320\263\320\276 "
|
||||
"\321\203\321\200\320\276\320\262\320\275\321\217 \320\267\321\203\320\274\320\260 "
|
||||
"\320\272 \321\201\320\273\320\265\320\264\321\203\321\216\321\211\320\265\320\274\321\203 "
|
||||
"(\321\207\320\265\320\274 \320\261\320\276\320\273\321\214\321\210\320\265 "
|
||||
"\320\267\320\275\320\260\321\207\320\265\320\275\320\270\320\265, \321\202\320\265\320\274 "
|
||||
"\321\201\320\270\320\273\321\214\320\275\320\265\320\265 \321\203\320\262\320\265\320\273\320\270\321\207\320\265\320\275\320\270\320\265 "
|
||||
"\320\277\320\276\321\201\320\273\320\265 \320\277\321\200\320\270\320\261\320\273\320\270\320\266\320\265\320\275\320\270\321\217)")
|
||||
|
||||
T_("Calculates mipmaps for the map background for zoom and translate")
|
||||
ruRU("\320\240\320\260\321\201\321\201\321\207\320\270\321\202\321\213\320\262\320\260\320\265\321\202 "
|
||||
"mipmap-\320\270\320\267\320\276\320\261\321\200\320\260\320\266\320\265\320\275\320\270\321\217 "
|
||||
"\320\264\320\273\321\217 \320\276\321\201\320\275\320\276\320\262\321\213 "
|
||||
"\320\272\320\260\321\200\321\202\321\213 \321\215\321\202\320\260\320\266\320\260 "
|
||||
"(\320\264\320\273\321\217 \320\277\321\200\320\270\320\261\320\273\320\270\320\266\320\265\320\275\320\270\321\217 "
|
||||
"\320\270 \321\201\320\274\320\265\321\211\320\265\320\275\320\270\321\217)")
|
||||
|
||||
T_("Calculate")
|
||||
ruRU("\320\240\320\260\321\201\321\201\321\207\320\270\321\202\320\260\321\202\321\214...")
|
||||
|
||||
T_("Map properties")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\260 \320\272\320\260\321\200\321\202\321\213")
|
||||
|
||||
T_("Sets the name of the map")
|
||||
ruRU("\320\243\321\201\321\202\320\260\320\275\320\260\320\262\320\273\320\270\320\262\320\260\320\265\321\202 "
|
||||
"\320\275\320\260\320\267\320\262\320\260\320\275\320\270\320\265 \320\272\320\260\321\200\321\202\321\213")
|
||||
|
||||
|
||||
// MapView.lay
|
||||
|
||||
T_("X")
|
||||
ruRU("")
|
||||
|
||||
|
||||
// MapView.cpp
|
||||
|
||||
T_("MapCtrl View")
|
||||
ruRU("\320\237\321\200\320\276\321\201\320\274\320\276\321\202\321\200 \320\272\320\260\321\200\321\202\321\213")
|
||||
29
bazaar/Map/Map.upp
Normal file
29
bazaar/Map/Map.upp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
MapBG,
|
||||
FormEditorProperties;
|
||||
|
||||
file
|
||||
Map.t,
|
||||
Map.h,
|
||||
Map.icpp,
|
||||
MapSerialize.h,
|
||||
Map readonly separator,
|
||||
MapLevel.iml,
|
||||
MapLevel.h,
|
||||
MapLevel.cpp,
|
||||
MapEvents.cpp,
|
||||
MapRender.cpp,
|
||||
MapRenderInfo.cpp,
|
||||
MapNavigation.cpp,
|
||||
Viewer readonly separator,
|
||||
MapView.lay,
|
||||
MapView.iml,
|
||||
MapView.h,
|
||||
MapView.cpp,
|
||||
MapViewEvents.cpp,
|
||||
MapViewSearch.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI SSE2";
|
||||
|
||||
9
bazaar/Map/MapCtrl.iml
Normal file
9
bazaar/Map/MapCtrl.iml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
PREMULTIPLIED
|
||||
IMAGE_ID(TestIcon)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,237,149,209,14,64,17,12,67,247,41,254,255,39,241,44,110,114,215,117,22,210,134,55,233,41,54,172,89,51,73)
|
||||
IMAGE_DATA(66,213,231,248,154,21,204,236,44,8,155,149,193,235,201,204,16,241,137,102,96,236,1,245,96,222,33,226,197,174,225,155)
|
||||
IMAGE_DATA(248,89,111,9,210,63,226,139,127,154,159,145,225,166,254,95,215,87,188,191,172,12,149,127,32,235,12,87,31,79,255,176)
|
||||
IMAGE_DATA(106,104,231,249,119,70,217,145,12,44,182,39,75,22,83,122,83,3,28,41,138,196,0,0,0,0,0,0,0,0,0,0)
|
||||
IMAGE_END_DATA(128, 1)
|
||||
253
bazaar/Map/MapEvents.cpp
Normal file
253
bazaar/Map/MapEvents.cpp
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
#include "MapLevel.h"
|
||||
|
||||
bool MapLevel::Zoom(int level)
|
||||
{
|
||||
_zoomLevel = level;
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i])
|
||||
{
|
||||
if (!_layers[i]->Zoom(level))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessLeftDouble(Point p, dword keyflags)
|
||||
{
|
||||
p = SceneToView(p);
|
||||
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessLeftDouble(p, keyflags))
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessLeftDouble(p, keyflags);
|
||||
if (r) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessLeftDown(Point p, dword keyflags)
|
||||
{
|
||||
p = SceneToView(p);
|
||||
|
||||
DUMP(IsEditMode());
|
||||
if (IsEditMode())
|
||||
_currPoint = GetEditPointIndex(p);
|
||||
|
||||
if (!_highQuality)
|
||||
NoAA();
|
||||
|
||||
// StatesOff(STATE_SELECTED);
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessLeftDown(p, keyflags))
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessLeftDown(p, keyflags);
|
||||
if (r) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessLeftDrag(Point p, dword keyflags)
|
||||
{
|
||||
p = SceneToView(p);
|
||||
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessLeftDrag(p, keyflags))
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessLeftDrag(p, keyflags);
|
||||
if (r) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessLeftUp(Point p, dword keyflags)
|
||||
{
|
||||
p = SceneToView(p);
|
||||
|
||||
if (IsEditMode())
|
||||
_currPoint = -1;
|
||||
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessLeftUp(p, keyflags))
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessLeftUp(p, keyflags);
|
||||
if (!_highQuality)
|
||||
Subpixel();
|
||||
if (r || !_highQuality) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessRightDouble(Point p, dword keyflags)
|
||||
{
|
||||
p = SceneToView(p);
|
||||
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessRightDouble(p, keyflags))
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessRightDouble(p, keyflags);
|
||||
if (r) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessRightDown(Point p, dword keyflags)
|
||||
{
|
||||
p = SceneToView(p);
|
||||
|
||||
if (IsEditMode())
|
||||
{
|
||||
AddEditPoint(p);
|
||||
WhenChangePoint();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessRightDown(p, keyflags))
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessRightDown(p, keyflags);
|
||||
if (r) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessRightDrag(Point p, dword keyflags)
|
||||
{
|
||||
p = SceneToView(p);
|
||||
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessRightDrag(p, keyflags))
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessRightDrag(p, keyflags);
|
||||
if (r) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessRightUp(Point p, dword keyflags)
|
||||
{
|
||||
p = SceneToView(p);
|
||||
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessRightUp(p, keyflags))
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessRightUp(p, keyflags);
|
||||
if (r) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessMouseMove(Point p, dword keyflags)
|
||||
{
|
||||
p = SceneToView(p);
|
||||
|
||||
if (IsEditMode())
|
||||
{
|
||||
_editModePos = p;
|
||||
|
||||
if (_currPoint != -1)
|
||||
{
|
||||
SetEditPoint(_currPoint, p);
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessMouseMove(p, keyflags))
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessMouseMove(p, keyflags);
|
||||
if (r) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessMouseEnter()
|
||||
{
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessMouseEnter())
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessMouseEnter();
|
||||
if (r) Refresh();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool MapLevel::ProcessMouseLeave()
|
||||
{
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
{
|
||||
if (_layers[i]->ProcessMouseLeave())
|
||||
{
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool r = IMapRender::ProcessMouseLeave();
|
||||
if (!_highQuality)
|
||||
Subpixel();
|
||||
if (r || !_highQuality) Refresh();
|
||||
return r;
|
||||
}
|
||||
9
bazaar/Map/MapLayer.iml
Normal file
9
bazaar/Map/MapLayer.iml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
PREMULTIPLIED
|
||||
IMAGE_ID(TestIcon)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,237,149,209,14,64,17,12,67,247,41,254,255,39,241,44,110,114,215,117,22,210,134,55,233,41,54,172,89,51,73)
|
||||
IMAGE_DATA(66,213,231,248,154,21,204,236,44,8,155,149,193,235,201,204,16,241,137,102,96,236,1,245,96,222,33,226,197,174,225,155)
|
||||
IMAGE_DATA(248,89,111,9,210,63,226,139,127,154,159,145,225,166,254,95,215,87,188,191,172,12,149,127,32,235,12,87,31,79,255,176)
|
||||
IMAGE_DATA(106,104,231,249,119,70,217,145,12,44,182,39,75,22,83,122,83,3,28,41,138,196,0,0,0,0,0,0,0,0,0,0)
|
||||
IMAGE_END_DATA(128, 1)
|
||||
54
bazaar/Map/MapLevel.cpp
Normal file
54
bazaar/Map/MapLevel.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include "MapLevel.h"
|
||||
|
||||
#define IMAGECLASS MapLevelImg
|
||||
#define IMAGEFILE <Map/MapLevel.iml>
|
||||
#include <Draw/iml_source.h>
|
||||
|
||||
MapLevel::MapLevel()
|
||||
: IMapRender(this), _highQuality(true), _editMode(false), _currPoint(-1),
|
||||
_pagePos(Point(0, 0)), _editModePos(Point(0, 0)), _zoomLevel(-1)
|
||||
{
|
||||
SetTopRender(this);
|
||||
BackPaint();
|
||||
}
|
||||
|
||||
void MapLevel::ClearBG()
|
||||
{
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i])
|
||||
delete _layers[i];
|
||||
_layers.Clear();
|
||||
}
|
||||
|
||||
bool MapLevel::LoadMap(const char* fp)
|
||||
{
|
||||
_zoomLevel = -1;
|
||||
if (!AddLayer<MapBG>(0)->Load(fp))
|
||||
{
|
||||
LOG("MapLevel: Error while creating MapBG-layer!");
|
||||
return false;
|
||||
}
|
||||
if (!LoadFromXMLFile(_zoomLevels,
|
||||
AppendFileName( GetFileDirectory(fp), AppendExt(GetFileTitle(fp), ".zoom") )))
|
||||
{
|
||||
LOG(NFormat("MapLevel: Error while loading zoom-levels from file %s", fp));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_zoomLevels.GetCount())
|
||||
_zoomLevel = 0;
|
||||
|
||||
Subpixel();
|
||||
Zoom(_zoomLevel);
|
||||
MoveTo(Point(0, 0));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MapLevel::UpdateMap()
|
||||
{
|
||||
if (_layers.GetCount())
|
||||
if (_layers[0])
|
||||
_layers[0]->PerformState(PERFORM_INIT);
|
||||
Refresh();
|
||||
}
|
||||
199
bazaar/Map/MapLevel.h
Normal file
199
bazaar/Map/MapLevel.h
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
#ifndef MAP_RENDER__MAP_RENDER_H
|
||||
#define MAP_RENDER__MAP_RENDER_H
|
||||
|
||||
#include <MapCommon/MapCommon.h>
|
||||
#include <MapBG/MapBG.h>
|
||||
|
||||
#define IMAGECLASS MapLevelImg
|
||||
#define IMAGEFILE <Map/MapLevel.iml>
|
||||
#include <Draw/iml_header.h>
|
||||
|
||||
class MapLevel : public Ctrl, public IMapRender
|
||||
{
|
||||
public:
|
||||
MapLevel();
|
||||
virtual ~MapLevel() { ClearBG(); }
|
||||
|
||||
// render
|
||||
public:
|
||||
virtual void Render(Draw* w);
|
||||
virtual void RenderInfo(Draw* w);
|
||||
|
||||
virtual Rect GetRenderRect();
|
||||
virtual Point GetPageOffset();
|
||||
virtual Rect GetPageRect();
|
||||
|
||||
virtual void Layout() { PagePos(GetPagePos()); UpdateMap(); }
|
||||
virtual void Paint(Draw& w);
|
||||
virtual void ClearBG();
|
||||
virtual bool Zoom(int level);
|
||||
virtual Rect GetRect();
|
||||
|
||||
virtual double GetZoom(int i) { return _zoomLevels[i].GetZoom(); }
|
||||
virtual int GetZoomCount() { return _zoomLevels.GetCount(); }
|
||||
virtual int GetCurrentZoom() { return _zoomLevel; }
|
||||
|
||||
virtual void RefreshView();
|
||||
|
||||
// settings
|
||||
bool LoadMap(const char* fp);
|
||||
void UpdateMap();
|
||||
|
||||
template <class T>
|
||||
Ptr<IMapRender> AddLayer(int pos)
|
||||
{
|
||||
T* render = new T(this);
|
||||
_layers.Add(pos, render);
|
||||
Sort(_layers);
|
||||
Refresh();
|
||||
return render;
|
||||
}
|
||||
|
||||
int GetRenderCount() { return _layers.GetCount(); }
|
||||
Ptr<IMapRender> GetRender(int i) { return _layers[i]; }
|
||||
|
||||
MapLevel& HighQuality(bool flag = true) { _highQuality = flag; Refresh(); return *this; }
|
||||
MapLevel& EditMode(bool flag = true) { _editMode = flag; Refresh(); return *this; }
|
||||
MapLevel& NoEditMode() { EditMode(false); return *this; }
|
||||
|
||||
// navigation
|
||||
public:
|
||||
MapLevel& PagePos(const Point& p);
|
||||
|
||||
MapLevel& MoveTo(const Point& p);
|
||||
MapLevel& MoveBy(const Point& p);
|
||||
|
||||
MapLevel& ZoomTo(int zoom);
|
||||
MapLevel& ZoomIn();
|
||||
MapLevel& ZoomOut();
|
||||
|
||||
virtual Point SceneToView(const Point& p);
|
||||
virtual Size SceneToView(const Size& sz);
|
||||
virtual Rect SceneToView(const Rect& rt);
|
||||
virtual Point ViewToScene(const Point& p);
|
||||
virtual Size ViewToScene(const Size& sz);
|
||||
virtual Rect ViewToScene(const Rect& rt);
|
||||
|
||||
virtual Array<Point> SceneToView(const Array<Point>& p);
|
||||
virtual Vector<Point> SceneToView(const Vector<Point>& p);
|
||||
|
||||
virtual Array<Point> ViewToScene(const Array<Point>& p);
|
||||
virtual Vector<Point> ViewToScene(const Vector<Point>& p);
|
||||
|
||||
virtual Rect CurrentViewRect();
|
||||
virtual Rect CurrentSceneRect();
|
||||
|
||||
protected:
|
||||
Point PointZoomIn();
|
||||
Point PointZoomOut();
|
||||
|
||||
// events
|
||||
public:
|
||||
virtual void LeftDouble (Point p, dword keyflags) { ProcessLeftDown(p, keyflags); }
|
||||
virtual void LeftDown (Point p, dword keyflags) { ProcessLeftDown(p, keyflags); }
|
||||
virtual void LeftDrag (Point p, dword keyflags) { ProcessLeftDrag(p, keyflags); }
|
||||
virtual void LeftUp (Point p, dword keyflags) { ProcessLeftUp (p, keyflags); }
|
||||
|
||||
virtual void RightDouble(Point p, dword keyflags) { ProcessRightDown(p, keyflags); }
|
||||
virtual void RightDrag (Point p, dword keyflags) { ProcessRightDrag(p, keyflags); }
|
||||
virtual void RightUp (Point p, dword keyflags) { ProcessRightUp (p, keyflags); }
|
||||
|
||||
virtual void MouseMove (Point p, dword keyflags) { ProcessMouseMove(p, keyflags); }
|
||||
|
||||
virtual void MouseEnter() { ProcessMouseEnter(); Subpixel(); Refresh(); }
|
||||
virtual void MouseLeave() { ProcessMouseLeave(); Subpixel(); Refresh(); }
|
||||
|
||||
virtual bool ProcessLeftDouble (Point p, dword keyflags);
|
||||
virtual bool ProcessLeftDown (Point p, dword keyflags);
|
||||
virtual bool ProcessLeftDrag (Point p, dword keyflags);
|
||||
virtual bool ProcessLeftUp (Point p, dword keyflags);
|
||||
|
||||
virtual bool ProcessRightDouble(Point p, dword keyflags);
|
||||
virtual bool ProcessRightDown (Point p, dword keyflags);
|
||||
virtual bool ProcessRightDrag (Point p, dword keyflags);
|
||||
virtual bool ProcessRightUp (Point p, dword keyflags);
|
||||
|
||||
virtual bool ProcessMouseMove (Point p, dword keyflags);
|
||||
|
||||
virtual bool ProcessMouseEnter();
|
||||
virtual bool ProcessMouseLeave();
|
||||
|
||||
public:
|
||||
void SetLevelName(const char* name) { _levelName = name; }
|
||||
void SetLevelDesc(const char* desc) { _levelDesc = desc; }
|
||||
|
||||
String GetLevelName() const { return _levelName; }
|
||||
String GetLevelDesc() const { return _levelDesc; }
|
||||
|
||||
Point GetMousePos() const { return _editModePos; }
|
||||
bool IsEditMode() const { return _editMode; }
|
||||
|
||||
int GetEditPointIndex(const Point& p) const
|
||||
{
|
||||
Rect r(Point(p.x - 8, p.y - 8), Size(16, 16));
|
||||
for (int i = _editModePoints.GetCount() - 1; i >= 0; --i)
|
||||
{
|
||||
if (Rect(Point(_editModePoints[i].x - 8, _editModePoints[i].y - 8), Size(16, 16))
|
||||
.Intersects(r))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void SetEditPoint(int index, const Point& p)
|
||||
{
|
||||
if (index < 0 || index >= _editModePoints.GetCount())
|
||||
return;
|
||||
_editModePoints[index] = p;
|
||||
WhenChangePoint();
|
||||
}
|
||||
|
||||
void AddEditPoint(const Point& p)
|
||||
{
|
||||
if (p.x < 0 || p.y < 0)
|
||||
return;
|
||||
|
||||
Rect r(Point(p.x - 8, p.y - 8), Size(16, 16));
|
||||
bool found = false;
|
||||
|
||||
for (int i = _editModePoints.GetCount() - 1; i >= 0; --i)
|
||||
{
|
||||
Rect er(Point(_editModePoints[i].x - 8, _editModePoints[i].y - 8), Size(16, 16));
|
||||
if ( er.Intersects(r))
|
||||
{
|
||||
_editModePoints.Remove(i);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
_editModePoints << p;
|
||||
else
|
||||
_currPoint = -1;
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
Callback WhenChangePoint;
|
||||
void ClearEditPoints() { _editModePoints.Clear(); }
|
||||
Array<Point>& GetEditPoints() { return _editModePoints; }
|
||||
const Array<Point>& GetEditPoints() const { return _editModePoints; }
|
||||
|
||||
private:
|
||||
String _levelName;
|
||||
String _levelDesc;
|
||||
|
||||
int _currPoint;
|
||||
bool _editMode;
|
||||
Point _editModePos;
|
||||
Array<Point> _editModePoints;
|
||||
|
||||
bool _highQuality;
|
||||
int _zoomLevel;
|
||||
Point _pagePos;
|
||||
Vector<MapZoomLevel> _zoomLevels;
|
||||
VectorMap<int, Ptr<IMapRender> > _layers;
|
||||
};
|
||||
|
||||
#endif
|
||||
57
bazaar/Map/MapLevel.iml
Normal file
57
bazaar/Map/MapLevel.iml
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
PREMULTIPLIED
|
||||
IMAGE_ID(TestIcon)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,197,87,75,108,148,85,20,102,71,103,58,239,233,204,252,175,153,41,180,208,74,75,11,27,59,21,73,0,165,198)
|
||||
IMAGE_DATA(200,198,240,232,86,17,87,6,72,192,168,193,165,60,182,210,2,43,121,24,37,130,59,67,97,73,177,137,206,163,8,178)
|
||||
IMAGE_DATA(22,116,11,46,69,87,208,30,207,119,206,189,119,166,165,152,248,72,252,147,63,255,63,247,191,247,60,191,243,157,51,171)
|
||||
IMAGE_DATA(122,87,245,174,122,222,21,133,62,5,65,68,81,16,154,187,76,149,192,167,170,31,146,124,143,42,178,94,241,177,30,202)
|
||||
IMAGE_DATA(93,13,42,84,246,3,26,88,187,94,246,96,45,100,57,144,133,189,229,40,112,103,158,167,119,107,237,101,209,181,198,243)
|
||||
IMAGE_DATA(249,108,153,202,161,177,193,200,176,122,35,43,55,44,81,232,71,84,137,202,252,12,120,127,69,244,84,140,221,85,175,234)
|
||||
IMAGE_DATA(108,47,123,145,216,104,237,133,174,78,221,59,95,153,112,123,195,48,164,163,147,69,154,59,157,165,199,179,49,122,120,61)
|
||||
IMAGE_DATA(65,51,39,178,244,210,144,199,49,240,105,67,95,72,123,182,151,232,220,225,30,58,195,247,217,247,10,244,201,254,60,175)
|
||||
IMAGE_DATA(21,37,110,216,83,227,189,223,156,202,210,163,153,4,253,113,51,70,119,46,165,233,232,190,28,199,200,99,27,61,177,127)
|
||||
IMAGE_DATA(203,120,219,134,106,24,72,188,134,251,2,154,155,206,18,53,98,180,216,140,241,179,155,159,221,68,205,184,60,111,95,204)
|
||||
IMAGE_DATA(16,213,241,59,205,119,146,191,175,166,133,249,184,121,79,208,227,155,9,186,117,134,207,55,19,230,92,194,157,93,228,239)
|
||||
IMAGE_DATA(119,47,229,104,195,154,192,248,169,185,216,52,50,42,239,240,251,242,177,30,149,85,231,115,173,120,91,78,67,109,160,150)
|
||||
IMAGE_DATA(202,211,59,161,119,195,124,103,155,173,46,61,23,163,167,173,152,232,21,153,114,175,166,111,167,50,28,163,178,196,27,186)
|
||||
IMAGE_DATA(45,46,198,55,150,88,111,151,145,157,84,253,117,227,67,203,250,147,164,133,70,220,252,142,233,154,253,214,74,169,46,190)
|
||||
IMAGE_DATA(23,69,78,178,109,31,191,139,61,198,230,137,177,162,224,0,184,129,239,200,199,185,131,5,145,5,155,23,90,122,22,239)
|
||||
IMAGE_DATA(98,71,195,196,3,178,90,73,151,27,177,181,158,146,111,139,236,155,205,195,194,188,137,83,163,187,35,134,106,243,2,251)
|
||||
IMAGE_DATA(52,117,168,232,234,107,185,126,181,89,125,134,255,54,142,118,77,100,179,92,213,1,27,77,12,172,222,70,186,141,155,150)
|
||||
IMAGE_DATA(205,163,137,105,61,38,121,58,123,40,47,120,179,181,130,231,201,253,158,200,178,120,83,95,227,138,5,232,107,116,41,214)
|
||||
IMAGE_DATA(144,103,19,115,205,109,98,9,70,229,140,141,153,137,63,246,225,22,91,249,247,244,161,130,212,137,112,135,169,243,26,242)
|
||||
IMAGE_DATA(223,138,59,236,203,94,150,137,39,244,222,255,58,41,245,164,177,79,168,45,136,187,201,141,172,127,159,113,113,110,99,47)
|
||||
IMAGE_DATA(174,241,179,118,242,222,218,70,95,240,135,123,116,100,88,108,64,237,126,249,113,182,237,87,75,113,123,249,88,142,134,214)
|
||||
IMAGE_DATA(250,194,111,176,119,124,56,162,7,87,172,111,49,250,109,54,33,124,128,250,65,93,157,120,187,224,242,45,50,108,45,3)
|
||||
IMAGE_DATA(131,188,246,197,71,25,229,39,214,185,105,100,179,242,165,175,220,243,193,222,156,201,153,198,109,238,116,74,245,250,85,122)
|
||||
IMAGE_DATA(119,87,145,118,214,60,193,203,96,191,47,181,142,125,88,131,31,101,191,40,252,183,123,155,199,156,211,81,51,245,132,195)
|
||||
IMAGE_DATA(21,236,120,113,132,237,12,139,194,157,150,127,148,107,203,52,59,157,113,251,16,183,55,119,148,132,135,107,236,51,226,6)
|
||||
IMAGE_DATA(110,170,24,62,159,57,94,160,107,39,211,242,187,55,8,196,255,137,49,175,125,190,97,114,216,104,199,29,24,250,112,111)
|
||||
IMAGE_DATA(129,117,85,69,110,103,207,1,30,144,95,173,85,173,155,73,214,143,88,237,28,11,68,230,157,11,41,135,89,112,213,150)
|
||||
IMAGE_DATA(33,229,14,241,159,249,127,254,66,218,97,66,242,216,140,153,88,26,30,152,239,102,236,103,159,233,69,218,23,124,199,19)
|
||||
IMAGE_DATA(90,71,49,193,41,108,67,14,128,3,216,30,68,90,47,211,135,179,242,13,121,12,3,143,227,94,112,124,235,248,203,242)
|
||||
IMAGE_DATA(143,173,101,182,227,135,139,41,215,59,157,255,166,6,159,182,86,27,44,91,238,78,74,62,97,27,48,16,153,154,69,220)
|
||||
IMAGE_DATA(107,67,129,244,100,93,243,105,238,211,188,244,24,244,41,96,228,29,198,203,157,243,153,165,245,140,30,112,49,237,228,44)
|
||||
IMAGE_DATA(209,207,54,89,140,90,174,87,174,141,211,47,87,146,226,47,244,62,186,145,228,126,152,119,125,25,121,223,205,121,218,49)
|
||||
IMAGE_DATA(86,146,181,161,126,224,165,104,234,219,167,123,156,19,200,65,189,226,137,254,132,126,220,153,127,244,63,244,198,159,175,166)
|
||||
IMAGE_DATA(149,191,90,93,38,110,202,59,100,121,189,145,146,167,250,168,115,0,244,156,57,152,211,25,133,101,94,59,158,98,158,79)
|
||||
IMAGE_DATA(209,216,176,39,62,238,223,149,215,190,49,175,62,77,29,236,121,198,127,197,80,72,51,167,114,244,164,217,213,198,160,229)
|
||||
IMAGE_DATA(150,219,73,99,79,23,199,32,47,113,135,223,152,41,118,111,247,233,238,133,172,244,52,172,221,251,44,35,186,246,240,58)
|
||||
IMAGE_DATA(106,108,223,54,95,207,214,181,15,29,120,157,245,115,253,128,111,58,241,143,94,116,224,141,130,244,49,219,179,44,15,144)
|
||||
IMAGE_DATA(201,9,120,103,176,95,115,37,250,57,110,192,211,131,175,210,110,246,1,102,49,179,68,6,211,71,246,230,197,23,96,26)
|
||||
IMAGE_DATA(243,140,114,110,176,4,255,3,235,214,147,229,32,156,237,196,139,229,82,244,68,212,155,230,189,44,49,56,241,86,206,196)
|
||||
IMAGE_DATA(54,193,216,203,152,218,212,121,12,178,6,120,158,249,245,134,241,133,253,7,126,144,35,212,211,242,249,15,121,132,79,71)
|
||||
IMAGE_DATA(38,123,58,102,13,211,231,235,90,83,143,103,185,119,30,206,115,175,204,115,174,50,142,131,237,140,240,227,249,148,204,110)
|
||||
IMAGE_DATA(147,219,74,194,229,191,223,50,223,217,23,188,131,251,108,223,125,86,127,187,23,2,179,228,250,85,91,190,205,161,173,205)
|
||||
IMAGE_DATA(206,58,117,115,150,237,187,166,7,219,30,57,45,61,55,20,158,30,29,29,93,113,14,6,143,34,190,168,109,244,21,199)
|
||||
IMAGE_DATA(157,205,165,115,137,244,148,14,94,117,58,155,166,47,202,124,104,99,147,228,153,75,251,8,124,172,172,224,187,189,48,143)
|
||||
IMAGE_DATA(33,63,216,3,46,71,204,158,218,89,198,206,37,174,223,118,155,25,44,166,53,139,249,199,205,29,113,23,151,159,174,164)
|
||||
IMAGE_DATA(164,95,129,243,87,138,251,242,107,176,111,64,106,90,102,2,174,243,251,87,149,63,68,87,35,177,44,206,172,231,59,147)
|
||||
IMAGE_DATA(147,70,183,241,221,204,65,252,237,243,99,89,199,11,240,169,115,230,254,171,107,96,221,160,235,115,192,50,106,10,177,104)
|
||||
IMAGE_DATA(251,219,145,27,206,201,147,121,211,103,234,186,142,62,54,185,221,115,120,138,254,134,110,123,109,222,52,226,234,8,220,130)
|
||||
IMAGE_DATA(25,228,253,201,60,205,78,101,59,112,215,198,255,195,235,113,169,175,125,252,63,164,151,185,5,103,241,31,9,231,39,94)
|
||||
IMAGE_DATA(125,237,111,233,238,188,214,120,101,238,121,190,240,131,198,209,23,238,222,208,231,203,124,128,217,199,250,104,251,136,252,231)
|
||||
IMAGE_DATA(227,126,60,216,191,238,31,235,93,126,161,54,42,94,32,186,43,65,73,245,132,190,235,165,194,43,38,95,47,244,253,119)
|
||||
IMAGE_DATA(122,87,186,182,142,215,220,188,167,207,240,95,197,248,255,188,254,4,184,236,29,214,0,0,0,0,0,0,0,0,0,0)
|
||||
IMAGE_END_DATA(1664, 1)
|
||||
260
bazaar/Map/MapNavigation.cpp
Normal file
260
bazaar/Map/MapNavigation.cpp
Normal file
|
|
@ -0,0 +1,260 @@
|
|||
#include "MapLevel.h"
|
||||
|
||||
MapLevel& MapLevel::PagePos(const Point& p)
|
||||
{
|
||||
Size rsz = GetRenderSize();
|
||||
Size psz = GetPageSize();
|
||||
|
||||
if ( psz.cx < rsz.cx )
|
||||
{
|
||||
if (p.x < 0)
|
||||
_pagePos.x = 0;
|
||||
else if (p.x >= rsz.cx - psz.cx)
|
||||
_pagePos.x = rsz.cx - psz.cx - 1;
|
||||
else
|
||||
_pagePos.x = p.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pagePos.x = 0;
|
||||
}
|
||||
|
||||
if ( psz.cy < rsz.cy )
|
||||
{
|
||||
if (p.y < 0)
|
||||
_pagePos.y = 0;
|
||||
else if (p.y >= rsz.cy - psz.cy)
|
||||
_pagePos.y = rsz.cy - psz.cy - 1;
|
||||
else
|
||||
_pagePos.y = p.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pagePos.y = 0;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
MapLevel& MapLevel::MoveTo(const Point& p)
|
||||
{
|
||||
PagePos(p);
|
||||
UpdateMap();
|
||||
return *this;
|
||||
}
|
||||
|
||||
MapLevel& MapLevel::MoveBy(const Point& p)
|
||||
{
|
||||
PagePos(GetPagePos() + p);
|
||||
UpdateMap();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point MapLevel::PointZoomIn()
|
||||
{
|
||||
if (!_zoomLevels.GetCount())
|
||||
return Point(0, 0);
|
||||
|
||||
int newZoom = _zoomLevel + 1;
|
||||
if (newZoom >= _zoomLevels.GetCount())
|
||||
return Point(0, 0);
|
||||
|
||||
_zoomLevel = newZoom;
|
||||
|
||||
// before
|
||||
Point s = GetPagePos();
|
||||
Size ss = GetSize();
|
||||
|
||||
// after
|
||||
double x = (double)s.x * _zoomLevels[_zoomLevel].GetZoom();
|
||||
double y = (double)s.y * _zoomLevels[_zoomLevel].GetZoom();
|
||||
|
||||
double cx = (double)ss.cx * _zoomLevels[_zoomLevel].GetZoom();
|
||||
double cy = (double)ss.cy * _zoomLevels[_zoomLevel].GetZoom();
|
||||
|
||||
// calculating new pos
|
||||
x -= (ss.cx - cx) / 2;
|
||||
y -= (ss.cy - cy) / 2;
|
||||
Point pos = Point((int)x, (int)y);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
Point MapLevel::PointZoomOut()
|
||||
{
|
||||
if (!_zoomLevels.GetCount())
|
||||
return Point(0, 0);
|
||||
|
||||
int newZoom = _zoomLevel - 1;
|
||||
if (newZoom < 0)
|
||||
return Point(0, 0);
|
||||
|
||||
_zoomLevel = newZoom;
|
||||
|
||||
// before
|
||||
Point s = GetPagePos();
|
||||
Size ss = GetPageSize();
|
||||
|
||||
// after
|
||||
double x = (double)s.x / _zoomLevels[_zoomLevel].GetZoom();
|
||||
double y = (double)s.y / _zoomLevels[_zoomLevel].GetZoom();
|
||||
|
||||
double cx = (double)ss.cx / _zoomLevels[_zoomLevel].GetZoom();
|
||||
double cy = (double)ss.cy / _zoomLevels[_zoomLevel].GetZoom();
|
||||
|
||||
// calculating new pos
|
||||
x -= (ss.cx - cx) / 2;
|
||||
y -= (ss.cy - cy) / 2;
|
||||
Point pos = Point((int)x, (int)y);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
MapLevel& MapLevel::ZoomTo(int zoom)
|
||||
{
|
||||
if (zoom == _zoomLevel)
|
||||
return *this;
|
||||
|
||||
Point pos = Point(0, 0);
|
||||
|
||||
if (zoom > _zoomLevel)
|
||||
{
|
||||
for (int i = _zoomLevel; i < zoom; ++i)
|
||||
pos = PointZoomIn();
|
||||
}
|
||||
|
||||
if (zoom < _zoomLevel)
|
||||
{
|
||||
for (int i = _zoomLevel; i > zoom; --i)
|
||||
pos = PointZoomOut();
|
||||
}
|
||||
|
||||
Zoom(_zoomLevel);
|
||||
MoveTo(pos);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
MapLevel& MapLevel::ZoomIn()
|
||||
{
|
||||
Point pos = PointZoomIn();
|
||||
Zoom(_zoomLevel);
|
||||
MoveTo(pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MapLevel& MapLevel::ZoomOut()
|
||||
{
|
||||
Point pos = PointZoomOut();
|
||||
Zoom(_zoomLevel);
|
||||
MoveTo(pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point MapLevel::SceneToView(const Point& p)
|
||||
{
|
||||
if (!GetZoomCount())
|
||||
return p;
|
||||
|
||||
Point res = p - GetPageOffset() + GetPagePos();
|
||||
for (int i = GetCurrentZoom() + 1; i < GetZoomCount(); ++i)
|
||||
res = Point((double)res.x * GetZoom(i), (double)res.y * GetZoom(i));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Point MapLevel::ViewToScene(const Point& p)
|
||||
{
|
||||
if (!GetZoomCount())
|
||||
return p;
|
||||
|
||||
Point res = p;
|
||||
for (int i = GetZoomCount() - 1; i > GetCurrentZoom(); --i)
|
||||
res = Point((double)res.x / GetZoom(i), (double)res.y / GetZoom(i));
|
||||
|
||||
return res + GetPageOffset() - GetPagePos();
|
||||
}
|
||||
|
||||
Size MapLevel::SceneToView(const Size& p)
|
||||
{
|
||||
if (!GetZoomCount())
|
||||
return p;
|
||||
|
||||
Size res = p;
|
||||
for (int i = GetCurrentZoom() + 1; i < GetZoomCount(); ++i)
|
||||
res = Size((double)res.cx * GetZoom(i), (double)res.cy * GetZoom(i));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Size MapLevel::ViewToScene(const Size& p)
|
||||
{
|
||||
if (!GetZoomCount())
|
||||
return p;
|
||||
|
||||
Size res = p;
|
||||
for (int i = GetZoomCount() - 1; i > GetCurrentZoom(); --i)
|
||||
res = Size((double)res.cx / GetZoom(i), (double)res.cx / GetZoom(i));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Rect MapLevel::SceneToView(const Rect& rt)
|
||||
{
|
||||
return GetZoomCount() > 0 ? Rect(SceneToView(rt.TopLeft()), SceneToView(rt.GetSize())) : rt;
|
||||
}
|
||||
|
||||
Rect MapLevel::ViewToScene(const Rect& rt)
|
||||
{
|
||||
return GetZoomCount() > 0 ? Rect(ViewToScene(rt.TopLeft()), ViewToScene(rt.GetSize())) : rt;
|
||||
}
|
||||
|
||||
Array<Point> MapLevel::SceneToView(const Array<Point>& p)
|
||||
{
|
||||
if (!GetZoomCount())
|
||||
return p;
|
||||
Array<Point> res;
|
||||
for (int i = 0; i < p.GetCount(); ++i)
|
||||
res << SceneToView(p[i]);
|
||||
return res;
|
||||
}
|
||||
|
||||
Array<Point> MapLevel::ViewToScene(const Array<Point>& p)
|
||||
{
|
||||
if (!GetZoomCount())
|
||||
return p;
|
||||
Array<Point> res;
|
||||
for (int i = 0; i < p.GetCount(); ++i)
|
||||
res << ViewToScene(p[i]);
|
||||
return res;
|
||||
}
|
||||
|
||||
Vector<Point> MapLevel::SceneToView(const Vector<Point>& p)
|
||||
{
|
||||
if (!GetZoomCount())
|
||||
return p;
|
||||
Vector<Point> res;
|
||||
for (int i = 0; i < p.GetCount(); ++i)
|
||||
res << SceneToView(p[i]);
|
||||
return res;
|
||||
}
|
||||
|
||||
Vector<Point> MapLevel::ViewToScene(const Vector<Point>& p)
|
||||
{
|
||||
if (!GetZoomCount())
|
||||
return p;
|
||||
Vector<Point> res;
|
||||
for (int i = 0; i < p.GetCount(); ++i)
|
||||
res << ViewToScene(p[i]);
|
||||
return res;
|
||||
}
|
||||
|
||||
Rect MapLevel::CurrentViewRect()
|
||||
{
|
||||
return SceneToView(CurrentSceneRect());
|
||||
}
|
||||
|
||||
Rect MapLevel::CurrentSceneRect()
|
||||
{
|
||||
return GetPageRect() - GetPagePos();
|
||||
}
|
||||
51
bazaar/Map/MapRender.cpp
Normal file
51
bazaar/Map/MapRender.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include "MapLevel.h"
|
||||
|
||||
void MapLevel::Paint(Draw& w)
|
||||
{
|
||||
w.DrawRect(Ctrl::GetSize(), SColorPaper());
|
||||
Render(&w);
|
||||
}
|
||||
|
||||
void MapLevel::Render(Draw* w)
|
||||
{
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i] && _layers[i]->IsShown())
|
||||
_layers[i]->Render(w);
|
||||
IMapRender::Render(w);
|
||||
RenderInfo(w);
|
||||
|
||||
if (IsEditMode())
|
||||
for (int i = 0; i < _editModePoints.GetCount(); ++i)
|
||||
{
|
||||
Point p = ViewToScene(_editModePoints[i]);
|
||||
Rect r(Point(p.x - 4, p.y - 4), Size(8, 8));
|
||||
|
||||
w->DrawRect(r, Black());
|
||||
r.Deflate(1, 1);
|
||||
|
||||
w->DrawRect(r, LtRed());
|
||||
}
|
||||
}
|
||||
|
||||
void RenderText(Draw* w, Point pos, const char* text)
|
||||
{
|
||||
Size sz = GetTextSize(text, StdFont());
|
||||
Rect r(pos, sz + Size(8, 8));
|
||||
w->DrawRect(r, Black());
|
||||
r.Deflate(1, 1);
|
||||
w->DrawRect(r, White());
|
||||
w->DrawText(pos.x + 4, pos.y + 4, text);
|
||||
}
|
||||
|
||||
void MapLevel::RenderInfo(Draw* w)
|
||||
{
|
||||
if (!IsEditMode())
|
||||
return;
|
||||
|
||||
// RenderText(w, Point(100, 11), "Pos: " + GetMousePos().ToString());
|
||||
}
|
||||
|
||||
void MapLevel::RefreshView()
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
52
bazaar/Map/MapRenderInfo.cpp
Normal file
52
bazaar/Map/MapRenderInfo.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include "MapLevel.h"
|
||||
|
||||
Rect MapLevel::GetRect()
|
||||
{
|
||||
Point p1(INT_MAX, INT_MAX);
|
||||
Point p2(INT_MIN, INT_MIN);
|
||||
|
||||
bool found = false;
|
||||
for (int i = 0; i < _layers.GetCount(); ++i)
|
||||
if (_layers[i])
|
||||
{
|
||||
Rect r = _layers[i]->GetRenderRect();
|
||||
|
||||
if (r.BottomRight().x > p2.x)
|
||||
p2.x = r.BottomRight().x;
|
||||
|
||||
if (r.BottomRight().y > p2.y)
|
||||
p2.y = r.BottomRight().y;
|
||||
|
||||
if (r.TopLeft().x < p1.x)
|
||||
p1.x = r.TopLeft().x;
|
||||
|
||||
if (r.TopLeft().y < p1.y)
|
||||
p1.y = r.TopLeft().y;
|
||||
|
||||
found = true;
|
||||
}
|
||||
|
||||
return found ? Rect(p1, p2) : Rect(Point(0, 0), Size(0, 0));
|
||||
}
|
||||
|
||||
Point MapLevel::GetPageOffset()
|
||||
{
|
||||
Size rsz = GetRenderSize();
|
||||
Size psz = GetPageSize();
|
||||
Point r = Point(0, 0);
|
||||
|
||||
if (rsz.cx < psz.cx) r.x = (psz.cx - rsz.cx) / 2;
|
||||
if (rsz.cy < psz.cy) r.y = (psz.cy - rsz.cy) / 2;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
Rect MapLevel::GetRenderRect()
|
||||
{
|
||||
return GetRect();
|
||||
}
|
||||
|
||||
Rect MapLevel::GetPageRect()
|
||||
{
|
||||
return Rect(_pagePos, GetSize());
|
||||
}
|
||||
413
bazaar/Map/MapSerialize.h
Normal file
413
bazaar/Map/MapSerialize.h
Normal file
|
|
@ -0,0 +1,413 @@
|
|||
#ifndef MAP__MAP_SERIALIZE_H
|
||||
#define MAP__MAP_SERIALIZE_H
|
||||
|
||||
#include <Core/Core.h>
|
||||
using namespace Upp;
|
||||
|
||||
#include <FormEditorProperties/FormEditorProperties.h>
|
||||
|
||||
inline int CharFilterMapName(int c)
|
||||
{
|
||||
return c >= 32 && c < 128 && c != '\"' ? c : 0;
|
||||
}
|
||||
|
||||
class MapItemProp : public PropertiesBase<MapItemProp>
|
||||
{
|
||||
public:
|
||||
MapItemProp() : PropertiesBase<MapItemProp>(this) {}
|
||||
};
|
||||
|
||||
class Room : public MapItemProp
|
||||
{
|
||||
typedef Room CLASSNAME;
|
||||
|
||||
public:
|
||||
Room() : number(0), discount(0) {}
|
||||
virtual ~Room() {}
|
||||
|
||||
PROPS_INIT_PROPERTIES
|
||||
PROPS_DEFINE_PROPERTY(SetName, GetName)
|
||||
PROPS_GROUP(t_("Room properties"))
|
||||
PROPS_NAME(t_("Name"))
|
||||
PROPS_HINT(t_("Sets the name of the room"))
|
||||
PROPS_TYPE(CEditField(), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetDesc, GetDesc)
|
||||
PROPS_GROUP(t_("Room properties"))
|
||||
PROPS_NAME(t_("Description"))
|
||||
PROPS_HINT(t_("Sets the description of the room"))
|
||||
PROPS_TYPE(CDocEdit(), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetTags, GetTags)
|
||||
PROPS_GROUP(t_("Room properties"))
|
||||
PROPS_NAME(t_("Tags"))
|
||||
PROPS_HINT(t_("Sets the tags of the room"))
|
||||
PROPS_TYPE(CEditField(), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetNumber, GetNumber)
|
||||
PROPS_GROUP(t_("Room properties"))
|
||||
PROPS_NAME(t_("Room number"))
|
||||
PROPS_HINT(t_("Sets the number of the room"))
|
||||
PROPS_TYPE(CEditIntSpin(0, INT_MAX), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetLogoPath, GetLogoPath)
|
||||
PROPS_GROUP(t_("Room properties"))
|
||||
PROPS_NAME(t_("Logo path"))
|
||||
PROPS_HINT(t_("Sets the path to the room logo"))
|
||||
PROPS_TYPE(CEditField(), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetDiscount, GetDiscount)
|
||||
PROPS_GROUP(t_("Discount properties"))
|
||||
PROPS_NAME(t_("Discount"))
|
||||
PROPS_HINT(t_("Sets the number of the room discounts"))
|
||||
PROPS_TYPE(CEditIntSpin(0, INT_MAX), true)
|
||||
PROPS_PROPERTY_END
|
||||
PROPS_INIT_PROPERTIES_END
|
||||
|
||||
PROPS_METHOD_SET(SetName, void, const char*);
|
||||
PROPS_METHOD_GET(GetName, String);
|
||||
|
||||
PROPS_METHOD_SET(SetDesc, void, const char*);
|
||||
PROPS_METHOD_GET(GetDesc, String);
|
||||
|
||||
PROPS_METHOD_SET(SetTags, void, const char*);
|
||||
PROPS_METHOD_GET(GetTags, String);
|
||||
|
||||
PROPS_METHOD_SET(SetNumber, void, int);
|
||||
PROPS_METHOD_GET(GetNumber, int);
|
||||
|
||||
PROPS_METHOD_SET(SetDiscount, void, int);
|
||||
PROPS_METHOD_GET(GetDiscount, int);
|
||||
|
||||
PROPS_METHOD_SET(SetLogoPath, void, const char*);
|
||||
PROPS_METHOD_GET(GetLogoPath, String);
|
||||
|
||||
public:
|
||||
void SetName(const char* s) { name = s; }
|
||||
String GetName() const { return name; }
|
||||
|
||||
void SetDesc(const char* s) { desc = s; }
|
||||
String GetDesc() const { return desc; }
|
||||
|
||||
void SetTags(const char* s) { tags = s; }
|
||||
String GetTags() const { return tags; }
|
||||
|
||||
void SetNumber(int n) { number = n; }
|
||||
int GetNumber() const { return number; }
|
||||
|
||||
void SetDiscount(int n) { discount = n; }
|
||||
int GetDiscount() const { return discount; }
|
||||
|
||||
void SetLogoPath(const char* s) { logo = s; }
|
||||
String GetLogoPath() const { return logo; }
|
||||
|
||||
Room& AddVertice(const Point& p) { vertices.Add(p); return *this; }
|
||||
Room& AddVertice(int x, int y) { vertices.Add(Point(x, y)); return *this; }
|
||||
|
||||
Array<Point>& GetVertices() { return vertices; }
|
||||
const Array<Point>& GetVertices() const { return vertices; }
|
||||
|
||||
public:
|
||||
void Xmlize(XmlIO& xml)
|
||||
{
|
||||
xml ("polygon", "point", vertices)
|
||||
("number", number)
|
||||
("logo", logo)
|
||||
("name", name)
|
||||
("desc", desc)
|
||||
("tags", tags)
|
||||
("discount", discount);
|
||||
}
|
||||
|
||||
public:
|
||||
Room(const Room& other)
|
||||
{
|
||||
vertices <<= other.vertices;
|
||||
number = other.number;
|
||||
logo = other.logo;
|
||||
name = other.name;
|
||||
desc = other.desc;
|
||||
tags = other.tags;
|
||||
discount = other.discount;
|
||||
}
|
||||
|
||||
Room& operator=(const Room& other)
|
||||
{
|
||||
vertices <<= other.vertices;
|
||||
number = other.number;
|
||||
logo = other.logo;
|
||||
name = other.name;
|
||||
desc = other.desc;
|
||||
tags = other.tags;
|
||||
discount = other.discount;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void SetRoom(const Room& other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
protected:
|
||||
Array<Point> vertices;
|
||||
String logo;
|
||||
String name;
|
||||
String desc;
|
||||
String tags;
|
||||
int discount;
|
||||
int number;
|
||||
};
|
||||
|
||||
class Layer : public MapItemProp
|
||||
{
|
||||
typedef Layer CLASSNAME;
|
||||
|
||||
public:
|
||||
virtual ~Layer() {}
|
||||
|
||||
PROPS_INIT_PROPERTIES
|
||||
PROPS_DEFINE_PROPERTY(SetName, GetName)
|
||||
PROPS_GROUP(t_("Layer properties"))
|
||||
PROPS_NAME(t_("Name"))
|
||||
PROPS_HINT(t_("Sets the name of the layer"))
|
||||
PROPS_TYPE(CEditField(), true)
|
||||
PROPS_PROPERTY_END
|
||||
PROPS_INIT_PROPERTIES_END
|
||||
|
||||
PROPS_METHOD_SET(SetName, void, const char*);
|
||||
PROPS_METHOD_GET(GetName, String);
|
||||
|
||||
public:
|
||||
void SetName(const char* s) { name = s; }
|
||||
String GetName() const { return name; }
|
||||
|
||||
Array<Room>& GetRooms() { return rooms; }
|
||||
const Array<Room>& GetRooms() const { return rooms; }
|
||||
|
||||
public:
|
||||
void Xmlize(XmlIO& xml)
|
||||
{
|
||||
xml ("name", name)
|
||||
("rooms", "room", rooms);
|
||||
}
|
||||
|
||||
public:
|
||||
Layer() {}
|
||||
Layer(const Layer& other)
|
||||
{
|
||||
rooms <<= other.rooms;
|
||||
name = other.name;
|
||||
}
|
||||
|
||||
private:
|
||||
Array<Room> rooms;
|
||||
String name;
|
||||
};
|
||||
|
||||
class Level : public MapItemProp
|
||||
{
|
||||
typedef Level CLASSNAME;
|
||||
|
||||
public:
|
||||
Level()
|
||||
: zoomDX(1.2),
|
||||
pageSize(Size(736, 420)),
|
||||
cellSize(Size(128, 128))
|
||||
{}
|
||||
virtual ~Level() {}
|
||||
|
||||
PROPS_INIT_PROPERTIES
|
||||
// Level properties
|
||||
PROPS_DEFINE_PROPERTY(SetName, GetName)
|
||||
PROPS_GROUP(t_("Level properties"))
|
||||
PROPS_NAME(t_("Name"))
|
||||
PROPS_HINT(t_("Sets the name of the level"))
|
||||
PROPS_TYPE(CEditField(), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetDesc, GetDesc)
|
||||
PROPS_GROUP(t_("Level properties"))
|
||||
PROPS_NAME(t_("Description"))
|
||||
PROPS_HINT(t_("Sets the description of the level"))
|
||||
PROPS_TYPE(CDocEdit(), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
// BG properties
|
||||
PROPS_DEFINE_PROPERTY(SetMapBG, GetMapBG)
|
||||
PROPS_GROUP(t_("BG properties"))
|
||||
PROPS_DEFAULT("")
|
||||
PROPS_NAME(t_("Source map image"))
|
||||
PROPS_HINT(t_("Sets the background map of the level"))
|
||||
PROPS_TYPE(CDropList(FillMapList(VectorMapEx<String, Value>()
|
||||
.Add(t_("None selected"), ""))), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetPageSize, GetPageSize)
|
||||
PROPS_GROUP(t_("BG properties"))
|
||||
PROPS_NAME(t_("Start page size"))
|
||||
PROPS_HINT(t_("Sets the page size at the start of level calculation"))
|
||||
PROPS_TYPE(CEditSize(100, INT_MAX), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetCellSize, GetCellSize)
|
||||
PROPS_GROUP(t_("BG properties"))
|
||||
PROPS_NAME(t_("Mipmap size"))
|
||||
PROPS_HINT(t_("Sets the mipmap size"))
|
||||
PROPS_TYPE(CEditSize(100, INT_MAX), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetZoomDX, GetZoomDX)
|
||||
PROPS_GROUP(t_("BG properties"))
|
||||
PROPS_NAME(t_("Zoom step (dx)"))
|
||||
PROPS_HINT(t_("Sets the zoom value between two zoom levels"))
|
||||
PROPS_TYPE(CEditDouble(1.0, (double)INT_MAX), true)
|
||||
PROPS_PROPERTY_END
|
||||
|
||||
PROPS_DEFINE_PROPERTY(SetNull, GetNull)
|
||||
PROPS_GROUP(t_("BG properties"))
|
||||
PROPS_NAME("")
|
||||
PROPS_HINT(t_("Calculates mipmaps for the map background for zoom and translate"))
|
||||
PROPS_TYPE(CButton(t_("Calculate"), THISBACK(OnCalculate)), true)
|
||||
PROPS_PROPERTY_END
|
||||
PROPS_INIT_PROPERTIES_END
|
||||
|
||||
PROPS_METHOD_SET(SetName, void, const char*);
|
||||
PROPS_METHOD_GET(GetName, String);
|
||||
|
||||
PROPS_METHOD_SET(SetDesc, void, const char*);
|
||||
PROPS_METHOD_GET(GetDesc, String);
|
||||
|
||||
PROPS_METHOD_SET(SetMapBG, void, const char*);
|
||||
PROPS_METHOD_GET(GetMapBG, String);
|
||||
|
||||
PROPS_METHOD_SET(SetZoomDX, void, double);
|
||||
PROPS_METHOD_GET(GetZoomDX, double);
|
||||
|
||||
PROPS_METHOD_SET(SetPageSize, void, const Size&);
|
||||
PROPS_METHOD_GET(GetPageSize, Size);
|
||||
|
||||
PROPS_METHOD_SET(SetCellSize, void, const Size&);
|
||||
PROPS_METHOD_GET(GetCellSize, Size);
|
||||
|
||||
PROPS_METHOD_SET(SetNull, void, const char*);
|
||||
PROPS_METHOD_GET(GetNull, String);
|
||||
|
||||
public:
|
||||
void SetName(const char* s) { name = s; }
|
||||
String GetName() const { return name; }
|
||||
|
||||
void SetDesc(const char* s) { desc = s; }
|
||||
String GetDesc() const { return desc; }
|
||||
|
||||
void SetMapBG(const char* s) { mapPath = s; }
|
||||
String GetMapBG() const { return mapPath; }
|
||||
|
||||
void SetZoomDX(double n) { zoomDX = n; }
|
||||
double GetZoomDX() const { return zoomDX; }
|
||||
|
||||
void SetPageSize(const Size& sz) { pageSize = sz; }
|
||||
Size GetPageSize() { return pageSize; }
|
||||
|
||||
void SetCellSize(const Size& sz) { cellSize = sz; }
|
||||
Size GetCellSize() { return cellSize; }
|
||||
|
||||
void SetNull(const char* s) {}
|
||||
String GetNull() { return String(); }
|
||||
|
||||
Array<Layer>& GetLayers() { return layers; }
|
||||
const Array<Layer>& GetLayers() const { return layers; }
|
||||
|
||||
VectorMapEx<String, Value>& FillMapList(VectorMapEx<String, Value>& mapList)
|
||||
{
|
||||
WhenMapList(mapList);
|
||||
return mapList;
|
||||
}
|
||||
|
||||
void OnCalculate() { WhenCalculate(*this); }
|
||||
Callback1<Level&> WhenCalculate;
|
||||
Callback1<VectorMapEx<String, Value>&> WhenMapList;
|
||||
|
||||
public:
|
||||
void Xmlize(XmlIO& xml)
|
||||
{
|
||||
xml ("name", name)
|
||||
("desc", desc)
|
||||
("zoomDX", zoomDX)
|
||||
("mapPath", mapPath)
|
||||
("pageSize", pageSize)
|
||||
("cellSize", cellSize)
|
||||
("layers", "layer", layers);
|
||||
}
|
||||
|
||||
public:
|
||||
Level(const Level& other)
|
||||
{
|
||||
pageSize = other.pageSize;
|
||||
cellSize = other.cellSize;
|
||||
zoomDX = other.zoomDX;
|
||||
name = other.name;
|
||||
desc = other.desc;
|
||||
mapPath = other.mapPath;
|
||||
layers <<= other.layers;
|
||||
}
|
||||
|
||||
private:
|
||||
Size pageSize;
|
||||
Size cellSize;
|
||||
double zoomDX;
|
||||
String name;
|
||||
String desc;
|
||||
String mapPath;
|
||||
Array<Layer> layers;
|
||||
};
|
||||
|
||||
class Map : public MapItemProp
|
||||
{
|
||||
typedef Map CLASSNAME;
|
||||
|
||||
public:
|
||||
virtual ~Map() {}
|
||||
|
||||
PROPS_INIT_PROPERTIES
|
||||
PROPS_DEFINE_PROPERTY(SetName, GetName)
|
||||
PROPS_GROUP(t_("Map properties"))
|
||||
PROPS_NAME(t_("Name"))
|
||||
PROPS_HINT(t_("Sets the name of the map"))
|
||||
PROPS_TYPE(CEditField(CharFilterMapName), true)
|
||||
PROPS_PROPERTY_END
|
||||
PROPS_INIT_PROPERTIES_END
|
||||
|
||||
PROPS_METHOD_SET(SetName, void, const char*);
|
||||
PROPS_METHOD_GET(GetName, String);
|
||||
|
||||
public:
|
||||
void SetName(const char* s) { _name = s; }
|
||||
String GetName() const { return _name; }
|
||||
|
||||
Array<Level>& GetLevels() { return _levels; }
|
||||
const Array<Level>& GetLevels() const { return _levels; }
|
||||
|
||||
public:
|
||||
void Xmlize(XmlIO& xml)
|
||||
{
|
||||
xml ("_name", _name)
|
||||
("_levels", "level", _levels);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
_levels.Clear();
|
||||
_name .Clear();
|
||||
}
|
||||
|
||||
private:
|
||||
Array<Level> _levels;
|
||||
String _name;
|
||||
};
|
||||
|
||||
#endif
|
||||
316
bazaar/Map/MapView.cpp
Normal file
316
bazaar/Map/MapView.cpp
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
#include "MapView.h"
|
||||
|
||||
#define IMAGECLASS MapViewImg
|
||||
#define IMAGEFILE <Map/MapView.iml>
|
||||
#include <Draw/iml_source.h>
|
||||
|
||||
#define SetButtonStyle(but,im1,im2) \
|
||||
static Button::Style but##_style = Button::StyleNormal(); \
|
||||
but##_style.look[0] = MapViewImg::im1(); \
|
||||
but##_style.look[1] = MapViewImg::im1(); \
|
||||
but##_style.look[2] = MapViewImg::im2(); \
|
||||
but##_style.look[3] = MapViewImg::im2(); \
|
||||
but.SetStyle(but##_style);
|
||||
|
||||
MapView::MapView()
|
||||
{
|
||||
CtrlLayout(*this, t_("MapCtrl View"));
|
||||
MinimizeBox().MinimizeBox().Sizeable();
|
||||
|
||||
// init values
|
||||
_mousePos = Point(0, 0);
|
||||
_drag = false;
|
||||
_move = false;
|
||||
_level = -1;
|
||||
|
||||
HideZoomSlider();
|
||||
HideSearch();
|
||||
|
||||
// init layout
|
||||
ZoomInBtn .NoWantFocus();
|
||||
ZoomOutBtn .NoWantFocus();
|
||||
|
||||
MoveUpBtn .NoWantFocus();
|
||||
MoveDownBtn .NoWantFocus();
|
||||
MoveLeftBtn .NoWantFocus();
|
||||
MoveRightBtn.NoWantFocus();
|
||||
|
||||
LevelUpBtn .NoWantFocus();
|
||||
LevelDownBtn.NoWantFocus();
|
||||
|
||||
MoveUpBtn .WhenPush = MoveUpBtn .WhenRepeat = THISBACK(OnMoveUp);
|
||||
MoveDownBtn .WhenPush = MoveDownBtn .WhenRepeat = THISBACK(OnMoveDown);
|
||||
MoveLeftBtn .WhenPush = MoveLeftBtn .WhenRepeat = THISBACK(OnMoveLeft);
|
||||
MoveRightBtn.WhenPush = MoveRightBtn.WhenRepeat = THISBACK(OnMoveRight);
|
||||
|
||||
ZoomInBtn .WhenPush = ZoomInBtn .WhenRepeat = THISBACK(OnZoomIn);
|
||||
ZoomOutBtn.WhenPush = ZoomOutBtn.WhenRepeat = THISBACK(OnZoomOut);
|
||||
ZoomSlider.WhenAction = THISBACK(OnZoomSlide);
|
||||
|
||||
LevelUpBtn .WhenPush = THISBACK(OnLevelUp);
|
||||
LevelDownBtn.WhenPush = THISBACK(OnLevelDown);
|
||||
|
||||
Search.WhenAction = THISBACK(OnSearch);
|
||||
Search.WhenEnter = THISBACK(OnSearch);
|
||||
ClearSearchBtn <<= THISBACK(OnSearchClear);
|
||||
|
||||
SetButtonStyle(MoveUpBtn, map_button_up_1, map_button_up_2);
|
||||
SetButtonStyle(MoveDownBtn, map_button_down_1, map_button_down_2);
|
||||
SetButtonStyle(MoveLeftBtn, map_button_left_1, map_button_left_2);
|
||||
SetButtonStyle(MoveRightBtn, map_button_right_1, map_button_right_2);
|
||||
|
||||
SetButtonStyle(ZoomInBtn, map_button_zoom_in_1, map_button_zoom_in_2);
|
||||
SetButtonStyle(ZoomOutBtn, map_button_zoom_out_1, map_button_zoom_out_2);
|
||||
|
||||
SetButtonStyle(LevelUpBtn, map_button_zoom_in_1, map_button_zoom_in_2);
|
||||
SetButtonStyle(LevelDownBtn, map_button_zoom_out_1, map_button_zoom_out_2);
|
||||
}
|
||||
|
||||
void MapView::OnLevelUp()
|
||||
{
|
||||
_level++;
|
||||
SetCurrentLevel(_level);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
void MapView::OnLevelDown()
|
||||
{
|
||||
_level--;
|
||||
SetCurrentLevel(_level);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
void MapView::OnMoveUp()
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->MoveBy(Point(0, -100));
|
||||
}
|
||||
|
||||
void MapView::OnMoveDown()
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->MoveBy(Point(0, 100));
|
||||
}
|
||||
|
||||
void MapView::OnMoveLeft()
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->MoveBy(Point(-100, 0));
|
||||
}
|
||||
|
||||
void MapView::OnMoveRight()
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->MoveBy(Point( 100, 0));
|
||||
}
|
||||
|
||||
void MapView::OnZoomIn()
|
||||
{
|
||||
MapLevel* level = GetCurrentLevel();
|
||||
if (!level) return;
|
||||
|
||||
level->ZoomIn();
|
||||
UpdateButtons();
|
||||
ZoomSlider <<= level->GetCurrentZoom();
|
||||
}
|
||||
|
||||
void MapView::OnZoomOut()
|
||||
{
|
||||
MapLevel* level = GetCurrentLevel();
|
||||
if (!level) return;
|
||||
|
||||
level->ZoomOut();
|
||||
UpdateButtons();
|
||||
ZoomSlider <<= level->GetCurrentZoom();
|
||||
}
|
||||
|
||||
void MapView::OnZoomSlide()
|
||||
{
|
||||
MapLevel* level = GetCurrentLevel();
|
||||
if (!level) return;
|
||||
|
||||
int zoom = ~ZoomSlider;
|
||||
level->ZoomTo(zoom);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
void MapView::UpdateButtons()
|
||||
{
|
||||
MapLevel* level = GetCurrentLevel();
|
||||
if (!level)
|
||||
{
|
||||
ZoomInBtn .Disable();
|
||||
ZoomOutBtn .Disable();
|
||||
LevelUpBtn .Disable();
|
||||
LevelDownBtn.Disable();
|
||||
|
||||
MoveUpBtn .Disable();
|
||||
MoveDownBtn .Disable();
|
||||
MoveLeftBtn .Disable();
|
||||
MoveRightBtn.Disable();
|
||||
return;
|
||||
}
|
||||
|
||||
int total = level->GetZoomCount();
|
||||
int zoom = level->GetCurrentZoom();
|
||||
|
||||
ZoomInBtn .Enable(zoom >= 0 && zoom < total - 1);
|
||||
ZoomOutBtn.Enable(zoom >= 1 && zoom < total);
|
||||
|
||||
LevelUpBtn .Enable(_level < _levels.GetCount() - 1);
|
||||
LevelDownBtn.Enable(_level > 0);
|
||||
}
|
||||
|
||||
void MapView::ShowZoomSlider(bool flag)
|
||||
{
|
||||
ZoomSlider.Show(flag);
|
||||
}
|
||||
|
||||
void MapView::ShowNavButtons(bool flag)
|
||||
{
|
||||
MoveUpBtn .Show(flag);
|
||||
MoveDownBtn .Show(flag);
|
||||
MoveLeftBtn .Show(flag);
|
||||
MoveRightBtn.Show(flag);
|
||||
}
|
||||
|
||||
void MapView::ShowLevelsCtrl(bool flag)
|
||||
{
|
||||
LevelName .Show(flag);
|
||||
LevelUpBtn .Show(flag);
|
||||
LevelDownBtn.Show(flag);
|
||||
}
|
||||
|
||||
void MapView::ShowSearch(bool flag)
|
||||
{
|
||||
Search .Show(flag);
|
||||
ClearSearchBtn.Show(flag);
|
||||
}
|
||||
|
||||
void MapView::SetCurrentLevel(int level)
|
||||
{
|
||||
MapLevel* p = GetLevel(level);
|
||||
if (!p)
|
||||
{
|
||||
_level = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
_level = level;
|
||||
|
||||
for (int i = 0; i < _levels.GetCount(); ++i)
|
||||
_levels[i].Hide();
|
||||
|
||||
p->Show();
|
||||
ZoomSlider.Range(p->GetZoomCount() - 1).Step(1);
|
||||
ZoomSlider <<= p->GetCurrentZoom();
|
||||
LevelName.SetLabel(p->GetLevelName());
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
bool MapView::LoadMap(Map& map, bool editMode)
|
||||
{
|
||||
for (int i = 0; i < _levels.GetCount(); ++i)
|
||||
RemoveChild(&_levels[i]);
|
||||
_levels.Clear();
|
||||
|
||||
for (int i = 0; i < map.GetLevels().GetCount(); ++i)
|
||||
{
|
||||
MapLevel& level = _levels.Add();
|
||||
AddChildBefore(&level.SizePos(), GetFirstChild());
|
||||
level.IgnoreMouse();
|
||||
level.Hide();
|
||||
|
||||
String fp = AppendFileName(
|
||||
AppendFileName( GetFileDirectory(GetExeFilePath()), "Mipmaps"),
|
||||
NFormat("%s-%d.xml", map.GetName(), i + 1)
|
||||
);
|
||||
|
||||
level.SetLevelName(map.GetLevels()[i].GetName());
|
||||
level.SetLevelDesc(map.GetLevels()[i].GetDesc());
|
||||
level.LoadMap(fp);
|
||||
level.EditMode(editMode);
|
||||
|
||||
for (int j = 0; j < map.GetLevels()[i].GetLayers().GetCount(); ++j)
|
||||
{
|
||||
Ptr<IMapRender> layer = level.AddItem<IMapRender>();
|
||||
|
||||
/* Array<Room>& rooms = map.GetLevels()[i].GetLayers()[j].GetRooms();
|
||||
for (int r = 0; r < rooms.GetCount(); ++r)
|
||||
{
|
||||
Ptr<PolygonItem> room = layer->AddItem<PolygonItem>();
|
||||
for (int v = 0; v < rooms[r].GetVertices().GetCount(); ++v)
|
||||
room->AddVertice(rooms[r].GetVertices()[v]);
|
||||
room->SetRoom(rooms[r]);
|
||||
if (editMode)
|
||||
room->StateOn(STATE_EDIT);
|
||||
}*/
|
||||
|
||||
for (int rx = 0; rx < 10; ++rx)
|
||||
for (int ry = 0; ry < 10; ++ry)
|
||||
{
|
||||
Ptr<PolygonItem> room = layer->AddItem<PolygonItem>();
|
||||
room->AddVertice( 0 * rx, 0 * ry);
|
||||
room->AddVertice(40 * rx, 0 * ry);
|
||||
room->AddVertice(40 * rx, 40 * ry);
|
||||
room->AddVertice( 0 * rx, 40 * ry);
|
||||
room->SetRoom(rooms[r]);
|
||||
if (editMode)
|
||||
room->StateOn(STATE_EDIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetCurrentLevel(_levels.GetCount() ? 0 : -1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MapView::LoadMap(const char* fp, bool editMode)
|
||||
{
|
||||
Map map;
|
||||
if (!LoadFromXMLFile(map, fp))
|
||||
return false;
|
||||
|
||||
return LoadMap(map, editMode);
|
||||
}
|
||||
|
||||
bool MapView::UpdateLevel(Level& level, int pos, bool editMode)
|
||||
{
|
||||
if (pos < 0 || pos >= _levels.GetCount())
|
||||
return false;
|
||||
|
||||
MapLevel& mapLevel = _levels[pos];
|
||||
mapLevel.EditMode(editMode);
|
||||
|
||||
if (mapLevel.GetItems().GetCount() != level.GetLayers().GetCount())
|
||||
mapLevel.Clear();
|
||||
|
||||
Vector<Ptr<IMapItem> >& mapLayers = mapLevel.GetItems();
|
||||
|
||||
for (int j = 0; j < level.GetLayers().GetCount(); ++j)
|
||||
{
|
||||
IMapRender* mapLayer =
|
||||
(j < mapLayers.GetCount())
|
||||
? dynamic_cast<IMapRender*>(~mapLayers[j])
|
||||
: ~mapLevel.AddItem<IMapRender>();
|
||||
|
||||
Vector<Ptr<IMapItem> >& mapRooms = mapLayer->GetItems();
|
||||
Array<Room>& rooms = level.GetLayers()[j].GetRooms();
|
||||
mapLayer->Clear();
|
||||
|
||||
for (int r = 0; r < rooms.GetCount(); ++r)
|
||||
{
|
||||
Ptr<PolygonItem> mapRoom =
|
||||
mapLayer->AddItem<PolygonItem>();
|
||||
|
||||
mapRoom->GetVertices().Clear();
|
||||
for (int v = 0; v < rooms[r].GetVertices().GetCount(); ++v)
|
||||
mapRoom->AddVertice(rooms[r].GetVertices()[v]);
|
||||
mapRoom->SetRoom(rooms[r]);
|
||||
if (editMode)
|
||||
mapRoom->StateOn(STATE_EDIT);
|
||||
}
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
98
bazaar/Map/MapView.h
Normal file
98
bazaar/Map/MapView.h
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#ifndef MAP_VIEW__H
|
||||
#define MAP_VIEW__H
|
||||
|
||||
#include "MapLevel.h"
|
||||
#include "MapSerialize.h"
|
||||
|
||||
#define LAYOUTFILE <Map/MapView.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#define IMAGECLASS MapViewImg
|
||||
#define IMAGEFILE <Map/MapView.iml>
|
||||
#include <Draw/iml_header.h>
|
||||
|
||||
class MapView : public WithMapViewLayout<TopWindow>
|
||||
{
|
||||
typedef MapView CLASSNAME;
|
||||
|
||||
public:
|
||||
MapView();
|
||||
virtual ~MapView() {}
|
||||
virtual void Layout();
|
||||
|
||||
virtual void LeftDouble (Point p, dword keyflags);
|
||||
virtual void LeftDown (Point p, dword keyflags);
|
||||
virtual void LeftDrag (Point p, dword keyflags);
|
||||
virtual void LeftUp (Point p, dword keyflags);
|
||||
|
||||
virtual void RightDouble(Point p, dword keyflags);
|
||||
virtual void RightDown (Point p, dword keyflags);
|
||||
virtual void RightDrag (Point p, dword keyflags);
|
||||
virtual void RightUp (Point p, dword keyflags);
|
||||
|
||||
virtual void MouseMove (Point p, dword keyflags);
|
||||
|
||||
virtual void MouseEnter();
|
||||
virtual void MouseLeave();
|
||||
|
||||
void OnLevelUp();
|
||||
void OnLevelDown();
|
||||
|
||||
void OnMoveUp();
|
||||
void OnMoveDown();
|
||||
void OnMoveLeft();
|
||||
void OnMoveRight();
|
||||
|
||||
void OnZoomIn();
|
||||
void OnZoomOut();
|
||||
void OnZoomSlide();
|
||||
void UpdateButtons();
|
||||
|
||||
void DoSearch(const String& data);
|
||||
void OnSearch();
|
||||
void OnSearchClear();
|
||||
|
||||
void ShowNavButtons(bool flag = true);
|
||||
void HideNavButtons() { ShowNavButtons(false); }
|
||||
|
||||
void ShowZoomSlider(bool flag = true);
|
||||
void HideZoomSlider() { ShowZoomSlider(false); }
|
||||
|
||||
void ShowLevelsCtrl(bool flag = true);
|
||||
void HideLevelsCtrl() { ShowLevelsCtrl(false); }
|
||||
|
||||
void ShowSearch(bool flag = true);
|
||||
void HideSearch() { ShowSearch(false); }
|
||||
|
||||
bool UpdateLevel(Level& level, int pos, bool editMode = false);
|
||||
bool LoadMap(Map& map, bool editMode = false);
|
||||
bool LoadMap(const char* fp, bool editMode = false);
|
||||
|
||||
MapView& HighQuality(bool flag = true)
|
||||
{
|
||||
for (int i = 0; i < GetLevelCount(); ++i)
|
||||
GetLevel(i)->HighQuality(flag);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MapLevel* GetCurrentLevel() { return GetLevel(_level); }
|
||||
MapLevel* GetLevel(int i)
|
||||
{
|
||||
return (i < 0 || i >= GetLevelCount())
|
||||
? NULL
|
||||
: &_levels[i];
|
||||
}
|
||||
|
||||
int GetLevelCount() const { return _levels.GetCount(); }
|
||||
void SetCurrentLevel(int level);
|
||||
|
||||
private:
|
||||
int _level;
|
||||
bool _drag;
|
||||
bool _move;
|
||||
Point _mousePos;
|
||||
|
||||
Array<MapLevel> _levels;
|
||||
};
|
||||
|
||||
#endif
|
||||
1066
bazaar/Map/MapView.iml
Normal file
1066
bazaar/Map/MapView.iml
Normal file
File diff suppressed because it is too large
Load diff
15
bazaar/Map/MapView.lay
Normal file
15
bazaar/Map/MapView.lay
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
LAYOUT(MapViewLayout, 508, 356)
|
||||
ITEM(Button, LevelDownBtn, RightPosZ(80, 28).TopPosZ(4, 28))
|
||||
ITEM(Button, LevelUpBtn, RightPosZ(4, 28).TopPosZ(4, 28))
|
||||
ITEM(Button, ZoomInBtn, LeftPosZ(36, 28).TopPosZ(4, 28))
|
||||
ITEM(Button, ClearSearchBtn, SetLabel(t_("X")).RightPosZ(4, 28).BottomPosZ(4, 28))
|
||||
ITEM(Button, ZoomOutBtn, LeftPosZ(4, 28).TopPosZ(4, 28))
|
||||
ITEM(Button, MoveLeftBtn, LeftPosZ(4, 28).VCenterPosZ(112, 2))
|
||||
ITEM(Button, MoveRightBtn, RightPosZ(4, 28).VCenterPosZ(112, 2))
|
||||
ITEM(Button, MoveDownBtn, HCenterPosZ(112, -4).BottomPosZ(4, 28))
|
||||
ITEM(Button, MoveUpBtn, HCenterPosZ(112, -4).TopPosZ(4, 28))
|
||||
ITEM(Label, LevelName, SetAlign(ALIGN_CENTER).RightPosZ(32, 48).TopPosZ(4, 28))
|
||||
ITEM(SliderCtrl, ZoomSlider, LeftPosZ(68, 84).TopPosZ(4, 28))
|
||||
ITEM(EditField, Search, RightPosZ(36, 120).BottomPosZ(4, 28))
|
||||
END_LAYOUT
|
||||
|
||||
89
bazaar/Map/MapViewEvents.cpp
Normal file
89
bazaar/Map/MapViewEvents.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#include "MapView.h"
|
||||
|
||||
void MapView::Layout()
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->Refresh();
|
||||
TopWindow::Layout();
|
||||
}
|
||||
|
||||
void MapView::LeftDouble(Point p, dword keyflags)
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->ProcessLeftDouble(p, keyflags);
|
||||
}
|
||||
|
||||
void MapView::LeftDown(Point p, dword keyflags)
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->ProcessLeftDown(p, keyflags);
|
||||
|
||||
_mousePos = p;
|
||||
_move = true;
|
||||
}
|
||||
|
||||
void MapView::LeftDrag(Point p, dword keyflags)
|
||||
{
|
||||
if (GetCurrentLevel() && GetCurrentLevel()->ProcessLeftDrag(p, keyflags))
|
||||
return;
|
||||
_drag = true;
|
||||
}
|
||||
|
||||
void MapView::LeftUp(Point p, dword keyflags)
|
||||
{
|
||||
if (GetCurrentLevel() && GetCurrentLevel()->ProcessLeftUp(p, keyflags))
|
||||
return;
|
||||
_move = false;
|
||||
_drag = false;
|
||||
}
|
||||
|
||||
void MapView::RightDouble(Point p, dword keyflags)
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->ProcessRightDouble(p, keyflags);
|
||||
}
|
||||
|
||||
void MapView::RightDown(Point p, dword keyflags)
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->ProcessRightDown(p, keyflags);
|
||||
}
|
||||
|
||||
void MapView::RightDrag(Point p, dword keyflags)
|
||||
{
|
||||
if (GetCurrentLevel() && GetCurrentLevel()->ProcessRightDrag(p, keyflags))
|
||||
return;
|
||||
}
|
||||
|
||||
void MapView::RightUp(Point p, dword keyflags)
|
||||
{
|
||||
if (GetCurrentLevel() && GetCurrentLevel()->ProcessRightUp(p, keyflags))
|
||||
return;
|
||||
}
|
||||
|
||||
void MapView::MouseMove(Point p, dword keyflags)
|
||||
{
|
||||
MapLevel* level = GetCurrentLevel();
|
||||
if (!level) return;
|
||||
|
||||
if (level->ProcessMouseMove(p, keyflags))
|
||||
return;
|
||||
|
||||
if (_move)
|
||||
{
|
||||
level->MoveBy(_mousePos - p);
|
||||
_mousePos = p;
|
||||
}
|
||||
}
|
||||
|
||||
void MapView::MouseEnter()
|
||||
{
|
||||
_move = false;
|
||||
_drag = false;
|
||||
}
|
||||
|
||||
void MapView::MouseLeave()
|
||||
{
|
||||
_move = false;
|
||||
_drag = false;
|
||||
}
|
||||
27
bazaar/Map/MapViewSearch.cpp
Normal file
27
bazaar/Map/MapViewSearch.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "MapView.h"
|
||||
|
||||
void MapView::DoSearch(const String& data)
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->PerformStates(PERFORM_SEARCH, data);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void MapView::OnSearch()
|
||||
{
|
||||
if (GetCurrentLevel())
|
||||
GetCurrentLevel()->StatesOff(STATE_SELECTED);
|
||||
DoSearch((~Search).ToString());
|
||||
}
|
||||
|
||||
void MapView::OnSearchClear()
|
||||
{
|
||||
MapLevel* level = GetCurrentLevel();
|
||||
if (!level) return;
|
||||
|
||||
level->StatesOff(STATE_SELECTED);
|
||||
level->StatesOff(STATE_FOUND);
|
||||
Search.Clear();
|
||||
|
||||
Refresh();
|
||||
}
|
||||
9
bazaar/Map/init
Normal file
9
bazaar/Map/init
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _Map_icpp_init_stub
|
||||
#define _Map_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "MapBG/init"
|
||||
#include "FormEditorProperties/init"
|
||||
#define BLITZ_INDEX__ FDCB0E40879C2D486297E4287E58D5ECF
|
||||
#include "Map.icpp"
|
||||
#undef BLITZ_INDEX__
|
||||
#endif
|
||||
91
bazaar/MapBG/FileUtils.h
Normal file
91
bazaar/MapBG/FileUtils.h
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#ifndef MAP_BG__FILE_UTILS_H
|
||||
#define MAP_BG__FILE_UTILS_H
|
||||
|
||||
#include <Core/Core.h>
|
||||
using namespace Upp;
|
||||
|
||||
inline bool IsValidPath(const String& fp)
|
||||
{
|
||||
return fp.Left(1) != "." && fp.Left(2) != "..";
|
||||
}
|
||||
|
||||
inline bool IsFolder(const String& fp)
|
||||
{
|
||||
return fp.GetCount() ? fp[fp.GetCount() - 1] == '/' : false;
|
||||
}
|
||||
|
||||
static Vector<String> GetDirectoryFiles(const String& dir, const String& search = "*",
|
||||
String prefix = String())
|
||||
{
|
||||
FindFile ff(AppendFileName(dir, search));
|
||||
Vector<String> r;
|
||||
|
||||
while (ff)
|
||||
{
|
||||
if (ff.IsFolder())
|
||||
{
|
||||
prefix.IsEmpty()
|
||||
? r.Append( GetDirectoryFiles(AppendFileName(dir, ff.GetName()), ff.GetName()) )
|
||||
: r.Append( GetDirectoryFiles(AppendFileName(dir, ff.GetName()),
|
||||
AppendFileName(prefix, ff.GetName())) );
|
||||
}
|
||||
if (ff.IsFile())
|
||||
{
|
||||
prefix.IsEmpty()
|
||||
? r.Add(ff.GetName())
|
||||
: r.Add(AppendFileName(prefix, ff.GetName()));
|
||||
}
|
||||
ff.Next();
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static Vector<String> GetSubDirectories(const String& dir, String prefix = String())
|
||||
{
|
||||
FindFile ff(AppendFileName(dir, "*"));
|
||||
Vector<String> r;
|
||||
|
||||
while (ff)
|
||||
{
|
||||
if (ff.IsFolder())
|
||||
{
|
||||
Vector<String> files = GetSubDirectories(AppendFileName(dir, ff.GetName()),
|
||||
ff.GetName());
|
||||
|
||||
if (files.GetCount())
|
||||
r.Append(files);
|
||||
|
||||
prefix.IsEmpty()
|
||||
? r.Add(ff.GetName())
|
||||
: r.Add(AppendFileName(prefix, ff.GetName()));
|
||||
}
|
||||
ff.Next();
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static bool RemoveDirectory(const String& dir)
|
||||
{
|
||||
if (!DirectoryExists(dir))
|
||||
return true;
|
||||
|
||||
Vector<String> files = GetDirectoryFiles(dir);
|
||||
bool done = true;
|
||||
|
||||
for (int i = files.GetCount() - 1; i >= 0; --i)
|
||||
{
|
||||
done &= FileDelete( AppendFileName(dir, files[i]) );
|
||||
}
|
||||
|
||||
Vector<String> folders = GetSubDirectories(dir);
|
||||
for (int i = 0; i < folders.GetCount(); ++i)
|
||||
{
|
||||
done &= DirectoryDelete( AppendFileName(dir, folders[i]) );
|
||||
}
|
||||
|
||||
return done &= DirectoryDelete(dir);
|
||||
}
|
||||
|
||||
#endif
|
||||
119
bazaar/MapBG/MapBG.cpp
Normal file
119
bazaar/MapBG/MapBG.cpp
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
#include "MapBG.h"
|
||||
|
||||
MapBG::MapBG(IMapRender* render)
|
||||
: IMapRender(render), _recalc(true), _currLevel(-1), _virtPage(Size(0, 0)),
|
||||
_cachePageSize(CACHE_PAGE_SIZE), _cachePageInitSize(CACHE_PAGE_INIT_SIZE)
|
||||
{}
|
||||
|
||||
void MapBG::Render(Draw* w)
|
||||
{
|
||||
if (_currLevel < 0 || _currLevel >= _levels.GetCount() || !GetTopRender())
|
||||
return;
|
||||
|
||||
MipMapLevel& level = _levels[_currLevel];
|
||||
|
||||
Point offset = GetTopRender()->GetPageOffset();
|
||||
Rect page = GetTopRender()->GetPageRect();
|
||||
Point lt = GetTopRender()->GetPagePos();
|
||||
|
||||
for (int i = 0; i < level.GetMipMaps().GetCount(); ++i)
|
||||
{
|
||||
Rect itemRect(level.GetMipMaps().GetKey(i), level.GetBlockSize());
|
||||
|
||||
if (page.Intersects(itemRect))
|
||||
if (level.GetMipMaps()[i])
|
||||
{
|
||||
level.GetMipMaps()[i]
|
||||
->Render(w,
|
||||
itemRect
|
||||
.Offseted(-lt)
|
||||
.Offseted(offset));
|
||||
}
|
||||
}
|
||||
|
||||
IMapRender::Render(w);
|
||||
}
|
||||
|
||||
void MapBG::StatePerformed(dword state, const String& param)
|
||||
{
|
||||
if (_currLevel < 0 || _currLevel >= _levels.GetCount())
|
||||
return;
|
||||
|
||||
MipMapLevel& level = _levels[_currLevel];
|
||||
Rect pageRect = GetPageRect();
|
||||
|
||||
if (_recalc || !_virtPage.Contains(GetPageRect()))
|
||||
{
|
||||
_virtPage = pageRect.Inflated(level.GetBlockSize() * _cachePageInitSize);
|
||||
_recalc = true;
|
||||
}
|
||||
|
||||
Rect currVirtualPage = _virtPage.Inflated(level.GetBlockSize() * _cachePageSize);
|
||||
|
||||
if (!_recalc)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < level.GetMipMaps().GetCount(); ++i)
|
||||
{
|
||||
Point pi = level.GetMipMaps().GetKey(i);
|
||||
Rect itemRect(pi, level.GetBlockSize());
|
||||
|
||||
if (!level.GetMipMaps()[i])
|
||||
continue;
|
||||
|
||||
if (currVirtualPage.Intersects(itemRect))
|
||||
{
|
||||
level.GetMipMaps()[i]->Prepare(
|
||||
AppendFileName(_mapDir, NFormat("%d-%d-%d.png", _currLevel, pi.x, pi.y)),
|
||||
level.GetBlockSize()
|
||||
);
|
||||
}
|
||||
else
|
||||
level.GetMipMaps()[i]->Release();
|
||||
}
|
||||
|
||||
_recalc = false;
|
||||
}
|
||||
|
||||
bool MapBG::Load(const char* fp)
|
||||
{
|
||||
if (!FileExists(fp))
|
||||
{
|
||||
LOG(NFormat("MapBG: File not exists, \"%s\"", fp));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!LoadFromXMLFile(_levels, fp))
|
||||
{
|
||||
LOG("MapBG: Error while loading map from XML-file!");
|
||||
return false;
|
||||
}
|
||||
|
||||
_mapDir = AppendFileName(GetFileDirectory(fp), GetFileTitle(fp));
|
||||
_currLevel = _levels.GetCount() > 0 ? 0 : -1;
|
||||
if (_currLevel < 0)
|
||||
{
|
||||
LOG("MapBG: No zoom levels found in map!");
|
||||
return false;
|
||||
}
|
||||
_recalc = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MapBG::Zoom(int level)
|
||||
{
|
||||
if (level < 0 || level >= _levels.GetCount())
|
||||
return false;
|
||||
_currLevel = level;
|
||||
_recalc = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Rect MapBG::GetRect()
|
||||
{
|
||||
if (_currLevel < 0 || _currLevel >= _levels.GetCount())
|
||||
return Size(0, 0);
|
||||
|
||||
return Rect(Point(0, 0), _levels[_currLevel].GetTotalSize());
|
||||
}
|
||||
39
bazaar/MapBG/MapBG.h
Normal file
39
bazaar/MapBG/MapBG.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef MAP_BG__MAP_BG_H
|
||||
#define MAP_BG__MAP_BG_H
|
||||
|
||||
#include <MapCommon/MapCommon.h>
|
||||
#include "MipMapGen.h"
|
||||
#include "MipMap.h"
|
||||
|
||||
#define CACHE_PAGE_INIT_SIZE Size(2, 2)
|
||||
#define CACHE_PAGE_SIZE Size(4, 4)
|
||||
|
||||
class MapBG : public IMapRender
|
||||
{
|
||||
public:
|
||||
MapBG(IMapRender* render);
|
||||
virtual ~MapBG() {}
|
||||
|
||||
virtual void Render(Draw* w);
|
||||
virtual Rect GetRect();
|
||||
|
||||
virtual void StatePerformed(dword state, const String& param = String());
|
||||
virtual bool Load(const char* fp);
|
||||
virtual bool Zoom(int level);
|
||||
|
||||
virtual Rect GetRenderRect() { return GetRect(); }
|
||||
|
||||
virtual String GetItemType() { return "MapBG"; }
|
||||
|
||||
protected:
|
||||
Size _cachePageInitSize;
|
||||
Size _cachePageSize;
|
||||
int _currLevel;
|
||||
bool _recalc;
|
||||
Rect _virtPage;
|
||||
String _mapDir;
|
||||
|
||||
Vector<MipMapLevel> _levels;
|
||||
};
|
||||
|
||||
#endif
|
||||
15
bazaar/MapBG/MapBG.upp
Normal file
15
bazaar/MapBG/MapBG.upp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
uses
|
||||
Painter,
|
||||
CtrlLib,
|
||||
MapCommon,
|
||||
Painter;
|
||||
|
||||
file
|
||||
FileUtils.h,
|
||||
MipMapGen.h,
|
||||
MipMapGen.cpp,
|
||||
MipMap.h,
|
||||
MipMap.cpp,
|
||||
MapBG.h,
|
||||
MapBG.cpp;
|
||||
|
||||
37
bazaar/MapBG/MipMap.cpp
Normal file
37
bazaar/MapBG/MipMap.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "MipMap.h"
|
||||
#include <Painter/Painter.h>
|
||||
|
||||
void MipMapItem::Render(Draw* w, const Rect& r)
|
||||
{
|
||||
if (w)
|
||||
w->DrawImage(r, _mipMap);
|
||||
}
|
||||
|
||||
void MipMapItem::Prepare(const char* fp, const Size& sz)
|
||||
{
|
||||
if (_ready)
|
||||
return;
|
||||
_ready = true;
|
||||
|
||||
FileIn in(fp);
|
||||
One<StreamRaster> r = StreamRaster::OpenAny(in);
|
||||
if (!r)
|
||||
{
|
||||
LOG(NFormat("Ошибка при загрузке файла карты: %s", fp));
|
||||
ImageBuffer ib(sz);
|
||||
BufferPainter sw(ib);
|
||||
sw.DrawRect(sz, Yellow());
|
||||
_mipMap = ib;
|
||||
return;
|
||||
}
|
||||
|
||||
_mipMap = r->GetImage();
|
||||
}
|
||||
|
||||
void MipMapItem::Release()
|
||||
{
|
||||
if (!_ready)
|
||||
return;
|
||||
_mipMap.Clear();
|
||||
_ready = false;
|
||||
}
|
||||
161
bazaar/MapBG/MipMap.h
Normal file
161
bazaar/MapBG/MipMap.h
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
#ifndef MAP_BG__MAP_COMMON_H
|
||||
#define MAP_BG__MAP_COMMON_H
|
||||
|
||||
#include "FileUtils.h"
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
using namespace Upp;
|
||||
|
||||
class IMipMapItem : public Moveable<IMipMapItem>, public Pte<IMipMapItem>
|
||||
{
|
||||
public:
|
||||
virtual ~IMipMapItem() {}
|
||||
|
||||
virtual void Prepare(const char* fp, const Size& sz) = 0;
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual void Render(Draw* w, const Rect& r) = 0;
|
||||
virtual void Xmlize(XmlIO xml) {}
|
||||
};
|
||||
|
||||
class MipMapItem : public IMipMapItem
|
||||
{
|
||||
public:
|
||||
MipMapItem() : _ready(false) {}
|
||||
virtual ~MipMapItem() {}
|
||||
|
||||
virtual void Prepare(const char* fp, const Size& sz);
|
||||
virtual void Release();
|
||||
|
||||
virtual void Render(Draw* w, const Rect& r);
|
||||
|
||||
private:
|
||||
bool _ready;
|
||||
Image _mipMap;
|
||||
};
|
||||
|
||||
class MipMapLevel : public Moveable<MipMapLevel>
|
||||
{
|
||||
public:
|
||||
MipMapLevel() {}
|
||||
MipMapLevel(const MipMapLevel& other)
|
||||
{
|
||||
_blockX = other._blockX;
|
||||
_blockY = other._blockY;
|
||||
_totalX = other._totalX;
|
||||
_totalY = other._totalY;
|
||||
_zoomDX = other._zoomDX;
|
||||
_totalSizeX = other._totalSizeX;
|
||||
_totalSizeY = other._totalSizeY;
|
||||
_mipMaps <<= other._mipMaps;
|
||||
}
|
||||
|
||||
virtual ~MipMapLevel() { Clear(); }
|
||||
void Clear()
|
||||
{
|
||||
for (int i = 0; i < _mipMaps.GetCount(); ++i)
|
||||
if (_mipMaps[i])
|
||||
delete _mipMaps[i];
|
||||
_mipMaps.Clear();
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
for (int i = 0; i < _mipMaps.GetCount(); ++i)
|
||||
if (_mipMaps[i])
|
||||
_mipMaps[i]->Release();
|
||||
}
|
||||
|
||||
MipMapLevel& BlockCX (int i) { Mutex::Lock _(_mutex); _blockX = i; return *this; }
|
||||
MipMapLevel& BlockCY (int i) { Mutex::Lock _(_mutex); _blockY = i; return *this; }
|
||||
MipMapLevel& TotalCX (int i) { Mutex::Lock _(_mutex); _totalX = i; return *this; }
|
||||
MipMapLevel& TotalCY (int i) { Mutex::Lock _(_mutex); _totalY = i; return *this; }
|
||||
MipMapLevel& TotalSizeCX(int i) { Mutex::Lock _(_mutex); _totalSizeX = i; return *this; }
|
||||
MipMapLevel& TotalSizeCY(int i) { Mutex::Lock _(_mutex); _totalSizeY = i; return *this; }
|
||||
MipMapLevel& ZoomDX( double dx) { Mutex::Lock _(_mutex); _zoomDX = dx; return *this; }
|
||||
|
||||
int GetBlockCX() { Mutex::Lock _(_mutex); return _blockX; }
|
||||
int GetBlockCY() { Mutex::Lock _(_mutex); return _blockY; }
|
||||
int GetTotalCX() { Mutex::Lock _(_mutex); return _totalX; }
|
||||
int GetTotalCY() { Mutex::Lock _(_mutex); return _totalY; }
|
||||
int GetTotalSizeCX() { Mutex::Lock _(_mutex); return _totalSizeX; }
|
||||
int GetTotalSizeCY() { Mutex::Lock _(_mutex); return _totalSizeY; }
|
||||
double GetZoomDX() { Mutex::Lock _(_mutex); return _zoomDX; }
|
||||
|
||||
Size GetBlockSize() { Mutex::Lock _(_mutex); return Size(_blockX, _blockY); }
|
||||
Size GetTotalSize() { Mutex::Lock _(_mutex); return Size(_totalSizeX, _totalSizeY); }
|
||||
Size GetTotalBlockSize() { Mutex::Lock _(_mutex); return Size(_totalX, _totalY); }
|
||||
|
||||
MipMapLevel& AddMipMap(const Point& p, Ptr<IMipMapItem> item)
|
||||
{
|
||||
Mutex::Lock _(_mutex);
|
||||
_mipMaps.Add(p, item);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const VectorMap<Point, Ptr<IMipMapItem> >& GetMipMaps() const { return _mipMaps; }
|
||||
VectorMap<Point, Ptr<IMipMapItem> >& GetMipMaps() { return _mipMaps; }
|
||||
|
||||
void Xmlize(XmlIO xml)
|
||||
{
|
||||
Mutex::Lock _(_mutex);
|
||||
|
||||
xml ("blockX", _blockX)
|
||||
("blockY", _blockY)
|
||||
("totalX", _totalX)
|
||||
("totalY", _totalY)
|
||||
("zoomDX", _zoomDX)
|
||||
("totalSizeX", _totalSizeX)
|
||||
("totalSizeY", _totalSizeY);
|
||||
|
||||
if (xml.IsStoring())
|
||||
{
|
||||
Vector<Point> keys = _mipMaps.GetKeys();
|
||||
xml("mipmaps", keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector<Point> keys;
|
||||
xml("mipmaps", keys);
|
||||
|
||||
Clear();
|
||||
for (int i = 0; i < keys.GetCount(); ++i)
|
||||
AddMipMap(keys[i], new MipMapItem());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Mutex _mutex;
|
||||
int _blockX;
|
||||
int _blockY;
|
||||
int _totalX;
|
||||
int _totalY;
|
||||
int _totalSizeX;
|
||||
int _totalSizeY;
|
||||
double _zoomDX;
|
||||
VectorMap<Point, Ptr<IMipMapItem> > _mipMaps;
|
||||
};
|
||||
|
||||
class MapZoomLevel : public Moveable<MapZoomLevel>
|
||||
{
|
||||
public:
|
||||
MapZoomLevel() : _zoomDX(1.0) {}
|
||||
MapZoomLevel(double zx) : _zoomDX(zx) {}
|
||||
MapZoomLevel(const MapZoomLevel& other) { _zoomDX = other._zoomDX; }
|
||||
virtual ~MapZoomLevel() {}
|
||||
|
||||
MapZoomLevel& Zoom( double dx) { Mutex::Lock _(_mutex); _zoomDX = dx; return *this; }
|
||||
double GetZoom() { Mutex::Lock _(_mutex); return _zoomDX; }
|
||||
|
||||
void Xmlize(XmlIO xml)
|
||||
{
|
||||
Mutex::Lock _(_mutex);
|
||||
xml("zoomDX", _zoomDX);
|
||||
}
|
||||
|
||||
private:
|
||||
Mutex _mutex;
|
||||
double _zoomDX;
|
||||
};
|
||||
|
||||
#endif
|
||||
217
bazaar/MapBG/MipMapGen.cpp
Normal file
217
bazaar/MapBG/MipMapGen.cpp
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
#include "MipMapGen.h"
|
||||
#include "MipMap.h"
|
||||
#include <Painter/Painter.h>
|
||||
|
||||
static StaticMutex LevelsMutex;
|
||||
static Vector<MipMapLevel> Levels;
|
||||
static Vector<MapZoomLevel> ZoomLevels;
|
||||
|
||||
bool CalcLevel(Image& img, int& step, int blocks, int zoomLevel, const String& dir, Progress& p,
|
||||
const Size& totalSize, int cx, int cy, double zx);
|
||||
void CalcCount(Image& img, int cx, int cy, int& step);
|
||||
int GetScalesTotal(Image& img, const Size& sz, double zoom);
|
||||
int GetBlocksTotal(Image& img, const Size& sz, const Size& cellSize, double zoom);
|
||||
Size GetScaledSize(Image& img, const Size& sz, double zoom, int level);
|
||||
Image GetScaledMap(Image& img, const Size& sz);
|
||||
Image GetScaledMap(Image& img, const Size& sz, double zoom, int level);
|
||||
|
||||
bool Calculate(int cx, int cy, int px, int py, double zx, const String& name, Image& img)
|
||||
{
|
||||
Mutex::Lock __(LevelsMutex);
|
||||
|
||||
Levels.Clear();
|
||||
ZoomLevels.Clear();
|
||||
|
||||
// getting data
|
||||
Size sz = Size(cx, cy);
|
||||
Size ps = Size(px, py);
|
||||
|
||||
// preparing directory
|
||||
String dir = AppendFileName( AppendFileName(GetFileDirectory(GetExeFilePath()), "Mipmaps"),
|
||||
name);
|
||||
RemoveDirectory(dir);
|
||||
RealizeDirectory(dir);
|
||||
|
||||
String xmlFile = AppendFileName(
|
||||
AppendFileName(GetFileDirectory(GetExeFilePath()), "Mipmaps"),
|
||||
name + ".xml");
|
||||
|
||||
String zoomFile = AppendFileName(
|
||||
AppendFileName(GetFileDirectory(GetExeFilePath()), "Mipmaps"),
|
||||
name.ToString() + ".zoom");
|
||||
|
||||
FileDelete(xmlFile);
|
||||
FileDelete(zoomFile);
|
||||
|
||||
// generating first level
|
||||
Levels.Clear();
|
||||
|
||||
int blocks = GetBlocksTotal(img, ps, sz, zx);
|
||||
int total = GetScalesTotal(img, ps, zx);
|
||||
int count = 0;
|
||||
|
||||
Progress p;
|
||||
p.Create();
|
||||
|
||||
Size last = Null;
|
||||
for (int i = 0; i < total - 1; ++i)
|
||||
{
|
||||
Image scaledMap = GetScaledMap(img, ps, zx, i + 1);
|
||||
|
||||
if (i == total - 2)
|
||||
last = scaledMap.GetSize();
|
||||
if (!CalcLevel(scaledMap, count, blocks, i, dir, p, scaledMap.GetSize(), cx, cy,
|
||||
(i == total - 1) ? 1.0 : zx))
|
||||
break;
|
||||
}
|
||||
|
||||
if (!IsNull(last))
|
||||
CalcLevel(img, count, blocks, total - 1, dir, p, img.GetSize(), cx, cy,
|
||||
(double)img.GetSize().cx / last.cx);
|
||||
p.Close();
|
||||
|
||||
if (!StoreAsXMLFile(Levels, "levels", xmlFile))
|
||||
{
|
||||
Exclamation("Ошибка при сохранении XML-файла карты!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!StoreAsXMLFile(ZoomLevels, "zoomLevels", zoomFile))
|
||||
{
|
||||
Exclamation("Ошибка при сохранении XML-файла значений zoom!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CalcLevel(Image& img, int& step, int blocks, int zoomLevel, const String& dir, Progress& p,
|
||||
const Size& totalSize, int cx, int cy, double zx)
|
||||
{
|
||||
Size sz = Size(cx, cy);
|
||||
|
||||
double ratio = (double)img.GetSize().cx / img.GetSize().cy;
|
||||
int xt = img.GetSize().cx / cx + (img.GetSize().cx % cx ? 1 : 0);
|
||||
int yt = img.GetSize().cy / cy + (img.GetSize().cy % cy ? 1 : 0);
|
||||
|
||||
MipMapLevel level;
|
||||
level
|
||||
.TotalCX(xt).TotalCY(yt).BlockCX(cx).BlockCY(cy).ZoomDX(zx)
|
||||
.TotalSizeCX(totalSize.cx)
|
||||
.TotalSizeCY(totalSize.cy);
|
||||
|
||||
ZoomLevels.Add(MapZoomLevel(zx));
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < xt; ++i)
|
||||
for (int j = 0; j < yt; ++j)
|
||||
{
|
||||
p.Title(NFormat("Блок %d из %d [%d, %d]", step + 1, blocks, cx, cy));
|
||||
|
||||
ImageBuffer ib(cx, cy);
|
||||
BufferPainter sw(ib);
|
||||
sw.DrawRect(ib.GetSize(), White());
|
||||
sw.DrawImage(ib.GetSize(), img, Rect(Point(i * cx, j * cy), ib.GetSize()));
|
||||
|
||||
PNGEncoder en;
|
||||
if (!en.SaveFile(AppendFileName(dir, NFormat("%d-%d-%d.png", zoomLevel,
|
||||
i * cx, j * cy)), Rescale(ib, sz, ib.GetSize())))
|
||||
{
|
||||
Exclamation("Ошибка при сохранении MipMap-изображения!");
|
||||
return false;
|
||||
}
|
||||
|
||||
level.AddMipMap( Point(i * cx, j * cy), new MipMapItem() );
|
||||
p.Set(step++, blocks);
|
||||
}
|
||||
|
||||
// xml part
|
||||
Levels.Add(level);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CalcCount(Image& img, int cx, int cy, int& step)
|
||||
{
|
||||
Size sz = img.GetSize();
|
||||
int xt = sz.cx / cx + (sz.cx % cx ? 1 : 0);
|
||||
int yt = sz.cy / cy + (sz.cy % cy ? 1 : 0);
|
||||
|
||||
for (int i = 0; i < xt; ++i)
|
||||
for (int j = 0; j < yt; ++j)
|
||||
{
|
||||
step++;
|
||||
}
|
||||
}
|
||||
|
||||
Image GetScaledMap(Image& img, const Size& sz)
|
||||
{
|
||||
double scale = min((double)sz.cx / img.GetSize().cx, (double)sz.cy / img.GetSize().cy);
|
||||
return Rescale(img, img.GetSize() * scale, img.GetSize());
|
||||
}
|
||||
|
||||
Image GetScaledMap(Image& img, const Size& sz, double zoom, int level)
|
||||
{
|
||||
return Rescale(img, GetScaledSize(img, sz, zoom, level), img.GetSize());
|
||||
}
|
||||
|
||||
Size GetScaledSize(Image& img, const Size& sz, double zoom, int level)
|
||||
{
|
||||
if (!level) return sz;
|
||||
|
||||
double scale = min((double)sz.cx / img.GetSize().cx, (double)sz.cy / img.GetSize().cy);
|
||||
Size mapSize = img.GetSize() * scale;
|
||||
double ratio = (double)img.GetSize().cx / img.GetSize().cy;
|
||||
double w = (double)mapSize.cx;
|
||||
|
||||
for (int i = 1; i < level; ++i)
|
||||
w *= zoom;
|
||||
|
||||
if (w > img.GetSize().cx || w / ratio > img.GetSize().cy)
|
||||
return img.GetSize();
|
||||
|
||||
return Size(fabs(w), fabs(w / ratio));
|
||||
}
|
||||
|
||||
int GetScalesTotal(Image& img, const Size& sz, double zoom)
|
||||
{
|
||||
int totalCount = 0;
|
||||
Size check(0, 0);
|
||||
for(;;)
|
||||
{
|
||||
Size scaledSize = GetScaledSize(img, sz, zoom, totalCount + 1);
|
||||
|
||||
bool found = false;
|
||||
if (check == Size(0, 0))
|
||||
check = scaledSize;
|
||||
else
|
||||
{
|
||||
if (check == scaledSize)
|
||||
found = true;
|
||||
else
|
||||
check = scaledSize;
|
||||
}
|
||||
|
||||
if (found)
|
||||
break;
|
||||
|
||||
totalCount++;
|
||||
}
|
||||
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
int GetBlocksTotal(Image& img, const Size& sz, const Size& cellSize, double zoom)
|
||||
{
|
||||
int total = GetScalesTotal(img, sz, zoom);
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < total - 1; ++i)
|
||||
{
|
||||
Image scaledMap = GetScaledMap(img, sz, zoom, i + 1);
|
||||
if (i < total - 1)
|
||||
CalcCount(scaledMap, cellSize.cx, cellSize.cy, count);
|
||||
if (i == total - 1)
|
||||
CalcCount(img, cellSize.cx, cellSize.cy, count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
9
bazaar/MapBG/MipMapGen.h
Normal file
9
bazaar/MapBG/MipMapGen.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef MAP_BG__MIP_MAP_GEN_H
|
||||
#define MAP_BG__MIP_MAP_GEN_H
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
using namespace Upp;
|
||||
|
||||
bool Calculate(int cx, int cy, int px, int py, double zx, const String& name, Image& img);
|
||||
|
||||
#endif
|
||||
6
bazaar/MapBG/init
Normal file
6
bazaar/MapBG/init
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef _MapBG_icpp_init_stub
|
||||
#define _MapBG_icpp_init_stub
|
||||
#include "Painter/init"
|
||||
#include "CtrlLib/init"
|
||||
#include "MapCommon/init"
|
||||
#endif
|
||||
51
bazaar/MapCommon/ButtonItem.cpp
Normal file
51
bazaar/MapCommon/ButtonItem.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include "ButtonItem.h"
|
||||
#include "IMapRender.h"
|
||||
|
||||
ButtonItem::ButtonItem(IMapRender* render)
|
||||
: IMapItem(render), _pos(Null)
|
||||
{}
|
||||
|
||||
Rect ButtonItem::GetRect()
|
||||
{
|
||||
return Rect();
|
||||
}
|
||||
|
||||
Point ButtonItem::GetCenter()
|
||||
{
|
||||
return GetRect().CenterPoint();
|
||||
}
|
||||
|
||||
bool ButtonItem::Contains(const Point& p)
|
||||
{
|
||||
if (!GetParent() || !GetTopRender())
|
||||
return false;
|
||||
Point pos = GetTopRender()->ViewToScene(_pos == Null ? GetParent()->GetTopLeft() : _pos);
|
||||
Rect r = Rect(Point(pos.x - _icon.GetSize().cx / 2 - 5, pos.y - _icon.GetSize().cy / 2 - 5),
|
||||
_icon.GetSize() + Size(10, 10));
|
||||
return r.Contains(GetTopRender()->ViewToScene(p));
|
||||
}
|
||||
|
||||
void ButtonItem::Render(Draw* w)
|
||||
{
|
||||
if (!GetParent() || !GetTopRender())
|
||||
return;
|
||||
if (!GetParent()->IsState(STATE_SELECTED))
|
||||
return;
|
||||
LOG("Render");
|
||||
Point p = GetTopRender()->ViewToScene(_pos == Null ? GetParent()->GetTopLeft() : _pos);
|
||||
w->DrawImage(p.x - _icon.GetSize().cx / 2, p.y - _icon.GetSize().cy / 2, _icon);
|
||||
}
|
||||
|
||||
ButtonItem* ButtonItem::SetIcon(const Image& icon)
|
||||
{
|
||||
_icon = icon;
|
||||
GetTopRender()->RefreshView();
|
||||
return this;
|
||||
}
|
||||
|
||||
ButtonItem* ButtonItem::SetPos(const Point& pos)
|
||||
{
|
||||
_pos = pos;
|
||||
GetTopRender()->RefreshView();
|
||||
return this;
|
||||
}
|
||||
32
bazaar/MapCommon/ButtonItem.h
Normal file
32
bazaar/MapCommon/ButtonItem.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef MAP_COMMON__ICON_ITEM_H
|
||||
#define MAP_COMMON__ICON_ITEM_H
|
||||
|
||||
#include "IMapItem.h"
|
||||
|
||||
class ButtonItem : public IMapItem
|
||||
{
|
||||
public:
|
||||
ButtonItem(IMapRender* render);
|
||||
virtual ~ButtonItem() {}
|
||||
|
||||
virtual void Render(Draw* w);
|
||||
|
||||
virtual bool ProcessLeftDown(Point p, dword keyflags);
|
||||
|
||||
virtual void StatePerformed (dword state, const String& param = String());
|
||||
virtual bool Contains(const Point& p);
|
||||
virtual Point GetCenter();
|
||||
virtual Rect GetRect();
|
||||
|
||||
virtual String GetItemType() { return "ButtonItem"; }
|
||||
|
||||
public:
|
||||
virtual ButtonItem* SetIcon(const Image& icon);
|
||||
virtual ButtonItem* SetPos(const Point& pos);
|
||||
|
||||
private:
|
||||
Image _icon;
|
||||
Point _pos;
|
||||
};
|
||||
|
||||
#endif
|
||||
18
bazaar/MapCommon/ButtonItemEvents.cpp
Normal file
18
bazaar/MapCommon/ButtonItemEvents.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include "ButtonItem.h"
|
||||
#include "IMapRender.h"
|
||||
|
||||
void ButtonItem::StatePerformed(dword state, const String& param)
|
||||
{
|
||||
}
|
||||
|
||||
bool ButtonItem::ProcessLeftDown(Point p, dword keyflags)
|
||||
{
|
||||
if (Contains(p))
|
||||
{
|
||||
if (GetParent() && GetParent()->IsState(STATE_SELECTED))
|
||||
PromptOK("Getted!");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
28
bazaar/MapCommon/IMapEvent.h
Normal file
28
bazaar/MapCommon/IMapEvent.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef MAP_COMMON__I_MAP_EVENT_H
|
||||
#define MAP_COMMON__I_MAP_EVENT_H
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
using namespace Upp;
|
||||
|
||||
class IMapEvent
|
||||
{
|
||||
public:
|
||||
virtual ~IMapEvent() {}
|
||||
|
||||
virtual bool ProcessLeftDouble (Point p, dword keyflags) { return false; }
|
||||
virtual bool ProcessLeftDown (Point p, dword keyflags) { return false; }
|
||||
virtual bool ProcessLeftDrag (Point p, dword keyflags) { return false; }
|
||||
virtual bool ProcessLeftUp (Point p, dword keyflags) { return false; }
|
||||
|
||||
virtual bool ProcessRightDouble(Point p, dword keyflags) { return false; }
|
||||
virtual bool ProcessRightDown (Point p, dword keyflags) { return false; }
|
||||
virtual bool ProcessRightDrag (Point p, dword keyflags) { return false; }
|
||||
virtual bool ProcessRightUp (Point p, dword keyflags) { return false; }
|
||||
|
||||
virtual bool ProcessMouseMove (Point p, dword keyflags) { return false; }
|
||||
|
||||
virtual bool ProcessMouseEnter() { return false; }
|
||||
virtual bool ProcessMouseLeave() { return false; }
|
||||
};
|
||||
|
||||
#endif
|
||||
34
bazaar/MapCommon/IMapItem.cpp
Normal file
34
bazaar/MapCommon/IMapItem.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "IMapItem.h"
|
||||
#include "IMapRender.h"
|
||||
|
||||
Vector<Ptr<IMapItem> > IMapItem::_globalItemList;
|
||||
|
||||
IMapItem::IMapItem(IMapRender* parent)
|
||||
{
|
||||
IMapItem::RegisterInGlobalList(this);
|
||||
StateOn(STATE_SHOWN);
|
||||
|
||||
_topRender = NULL;
|
||||
_parent = parent;
|
||||
|
||||
if (_parent && _parent->GetTopRender())
|
||||
_topRender = _parent->GetTopRender();
|
||||
}
|
||||
|
||||
void IMapItem::RegisterInGlobalList(Ptr<IMapItem> item)
|
||||
{
|
||||
_globalItemList.Add(item);
|
||||
}
|
||||
|
||||
void IMapItem::UnregisterFromGlobalList(Ptr<IMapItem> item)
|
||||
{
|
||||
for (int i = _globalItemList.GetCount() - 1; i >= 0; --i)
|
||||
if (_globalItemList[i] == item)
|
||||
_globalItemList.Remove(i);
|
||||
}
|
||||
|
||||
double IMapItem::GetOpacity() { return GetParent()->GetOpacity(); }
|
||||
dword IMapItem::GetQuality() { return GetParent()->GetQuality(); }
|
||||
Color IMapItem::GetClearColor() { return GetParent()->GetClearColor(); }
|
||||
dword IMapItem::GetRenderType() { return GetParent()->GetRenderType(); }
|
||||
Rect IMapItem::GetRenderRect() { return GetParent()->GetRenderRect(); }
|
||||
84
bazaar/MapCommon/IMapItem.h
Normal file
84
bazaar/MapCommon/IMapItem.h
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#ifndef MAP_COMMON__I_MAP_ITEM_H
|
||||
#define MAP_COMMON__I_MAP_ITEM_H
|
||||
|
||||
#include "IMapEvent.h"
|
||||
#include <Painter/Painter.h>
|
||||
|
||||
enum
|
||||
{
|
||||
STATE_SHOWN,
|
||||
STATE_SELECTED,
|
||||
STATE_FOUND,
|
||||
STATE_EDIT,
|
||||
|
||||
PERFORM_INIT,
|
||||
PERFORM_UPDATE,
|
||||
PERFORM_RELEASE,
|
||||
PERFORM_SEARCH
|
||||
};
|
||||
|
||||
class IMapRender;
|
||||
class IMapItem : public Pte<IMapItem>, public IMapEvent
|
||||
{
|
||||
public:
|
||||
IMapItem(IMapRender* parent);
|
||||
virtual ~IMapItem() { Clear(); }
|
||||
|
||||
virtual void Render(Painter* w) { Render((Draw*)w); }
|
||||
virtual void Render(Draw* w) = 0;
|
||||
|
||||
virtual bool Contains(const Point& p) { return GetRect().Contains(p); }
|
||||
virtual Point GetTopLeft() { return GetRect().TopLeft(); }
|
||||
virtual Point GetCenter() { return GetRect().CenterPoint(); }
|
||||
virtual Rect GetRect() = 0;
|
||||
virtual void Clear() {}
|
||||
virtual Rect GetRenderRect();
|
||||
|
||||
virtual void StatePerformed (dword state, const String& param = String()) {}
|
||||
virtual void StateChanged (dword state) {}
|
||||
virtual void StateOff (dword state);
|
||||
virtual void StateOn (dword state);
|
||||
virtual bool IsState (dword state);
|
||||
virtual void PerformState (dword state, const String& param = String());
|
||||
|
||||
static void StatesPerformed(dword state, const String& param = String());
|
||||
static void StatesChanged (dword state);
|
||||
static void StatesOff (dword state);
|
||||
static void StatesOn (dword state);
|
||||
static bool IsAnyState (dword state);
|
||||
static void PerformStates (dword state, const String& param = String());
|
||||
|
||||
public:
|
||||
bool IsShown() { return IsState(STATE_SHOWN); }
|
||||
bool IsFound() { return IsState(STATE_FOUND); }
|
||||
bool IsSelected() { return IsState(STATE_SELECTED); }
|
||||
|
||||
void SetParent(Ptr<IMapRender> parent) { _parent = parent; }
|
||||
IMapRender* GetParent() { return _parent; }
|
||||
|
||||
void SetTopRender(Ptr<IMapRender> render) { _topRender = render; }
|
||||
IMapRender* GetTopRender() { return _topRender; }
|
||||
|
||||
virtual String GetItemType() = 0;
|
||||
|
||||
virtual double GetOpacity();
|
||||
virtual dword GetQuality();
|
||||
virtual Color GetClearColor();
|
||||
virtual dword GetRenderType();
|
||||
|
||||
virtual Vector<Ptr<IMapItem> >& GetItems() { return _globalItemList; }
|
||||
const virtual Vector<Ptr<IMapItem> >& GetItems() const { return _globalItemList; }
|
||||
|
||||
protected:
|
||||
static void RegisterInGlobalList(Ptr<IMapItem> item);
|
||||
static void UnregisterFromGlobalList(Ptr<IMapItem> item);
|
||||
|
||||
private:
|
||||
IMapRender* _topRender;
|
||||
IMapRender* _parent;
|
||||
|
||||
Vector<dword> _states;
|
||||
static Vector<Ptr<IMapItem> > _globalItemList;
|
||||
};
|
||||
|
||||
#endif
|
||||
81
bazaar/MapCommon/IMapItemState.cpp
Normal file
81
bazaar/MapCommon/IMapItemState.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include "IMapItem.h"
|
||||
#include "IMapRender.h"
|
||||
|
||||
void IMapItem::PerformState(dword state, const String& param)
|
||||
{
|
||||
StatesPerformed(state, param);
|
||||
}
|
||||
|
||||
void IMapItem::StateOff(dword state)
|
||||
{
|
||||
for (int i = 0; i < _states.GetCount(); ++i)
|
||||
if (_states[i] == state)
|
||||
{
|
||||
_states.Remove(i);
|
||||
StateChanged(state);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void IMapItem::StateOn(dword state)
|
||||
{
|
||||
for (int i = 0; i < _states.GetCount(); ++i)
|
||||
if (_states[i] == state)
|
||||
return;
|
||||
_states.Add(state);
|
||||
StateChanged(state);
|
||||
}
|
||||
|
||||
bool IMapItem::IsState(dword state)
|
||||
{
|
||||
for (int i = 0; i < _states.GetCount(); ++i)
|
||||
if (_states[i] == state)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void IMapItem::PerformStates(dword state, const String& param)
|
||||
{
|
||||
for (int i = 0; i < _globalItemList.GetCount(); ++i)
|
||||
if (_globalItemList[i])
|
||||
_globalItemList[i]->PerformState(state, param);
|
||||
}
|
||||
|
||||
void IMapItem::StatesOff(dword state)
|
||||
{
|
||||
for (int i = 0; i < _globalItemList.GetCount(); ++i)
|
||||
if (_globalItemList[i])
|
||||
_globalItemList[i]->StateOff(state);
|
||||
}
|
||||
|
||||
void IMapItem::StatesOn(dword state)
|
||||
{
|
||||
for (int i = 0; i < _globalItemList.GetCount(); ++i)
|
||||
if (_globalItemList[i])
|
||||
_globalItemList[i]->StateOn(state);
|
||||
}
|
||||
|
||||
bool IMapItem::IsAnyState(dword state)
|
||||
{
|
||||
for (int i = 0; i < _globalItemList.GetCount(); ++i)
|
||||
if (_globalItemList[i])
|
||||
{
|
||||
if (_globalItemList[i]->IsState(state))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void IMapItem::StatesChanged(dword state)
|
||||
{
|
||||
for (int i = 0; i < _globalItemList.GetCount(); ++i)
|
||||
if (_globalItemList[i])
|
||||
_globalItemList[i]->StateChanged(state);
|
||||
}
|
||||
|
||||
void IMapItem::StatesPerformed(dword state, const String& param)
|
||||
{
|
||||
for (int i = 0; i < _globalItemList.GetCount(); ++i)
|
||||
if (_globalItemList[i])
|
||||
_globalItemList[i]->StatePerformed(state, param);
|
||||
}
|
||||
121
bazaar/MapCommon/IMapRender.cpp
Normal file
121
bazaar/MapCommon/IMapRender.cpp
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
#include "IMapRender.h"
|
||||
|
||||
IMapRender::IMapRender(IMapRender* render)
|
||||
: IMapItem(render), _renderType(RENDER_DRAW), _quality(MODE_NOAA), _opacity(-1),
|
||||
_clearColor(RGBAZero())
|
||||
{}
|
||||
|
||||
void IMapRender::Clear()
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i])
|
||||
delete _items[i];
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
void IMapRender::Render(Draw* w)
|
||||
{
|
||||
if (!w || !IsShown())
|
||||
return;
|
||||
|
||||
/* Rect r = GetRenderRect();
|
||||
Size rsz = r.GetSize();
|
||||
Size vsz = CurrentSceneSize();
|
||||
int px = 0;
|
||||
int py = 0;
|
||||
|
||||
if (rsz.cx > vsz.cx)
|
||||
rsz.cx = vsz.cx;
|
||||
else
|
||||
px = r.TopLeft().x;
|
||||
|
||||
if (rsz.cy > vsz.cy)
|
||||
rsz.cy = vsz.cy;
|
||||
else
|
||||
py = r.TopLeft().y;*/
|
||||
|
||||
Size rsz = GetPageRect().GetSize();
|
||||
|
||||
if (_renderType == RENDER_PAINTER)
|
||||
{
|
||||
ImageBuffer ib(rsz);
|
||||
BufferPainter sw(ib, _quality);
|
||||
sw.Clear(_clearColor);
|
||||
// if (_opacity >= 0)
|
||||
// sw.Opacity(_opacity);
|
||||
sw.Opacity(0.5);
|
||||
|
||||
RenderItems(&sw);
|
||||
w->DrawImage(0, 0, ib);
|
||||
}
|
||||
else
|
||||
RenderItems(w);
|
||||
}
|
||||
|
||||
void IMapRender::RenderItems(Draw* w)
|
||||
{
|
||||
Rect view = CurrentViewRect();
|
||||
Vector<int> selected;
|
||||
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
{
|
||||
if (!_items[i] || !_items[i]->IsShown())
|
||||
continue;
|
||||
|
||||
if (!view.Intersects(_items[i]->GetRect()))
|
||||
continue;
|
||||
|
||||
if (_items[i]->IsSelected())
|
||||
{
|
||||
selected << i;
|
||||
continue;
|
||||
}
|
||||
|
||||
_items[i]->Render(w);
|
||||
}
|
||||
|
||||
for (int i = 0; i < selected.GetCount(); ++i)
|
||||
{
|
||||
_items[selected[i]]->Render(w);
|
||||
}
|
||||
}
|
||||
|
||||
IMapRender* IMapRender::Antialiased(bool use, bool subpixel)
|
||||
{
|
||||
_quality = use ? (use + subpixel) : 0;
|
||||
_renderType = RENDER_PAINTER;
|
||||
return this;
|
||||
}
|
||||
|
||||
IMapRender* IMapRender::Subpixel()
|
||||
{
|
||||
_renderType = RENDER_PAINTER;
|
||||
_quality = MODE_SUBPIXEL;
|
||||
return this;
|
||||
}
|
||||
|
||||
IMapRender* IMapRender::NoAA()
|
||||
{
|
||||
_renderType = RENDER_DRAW;
|
||||
_quality = MODE_NOAA;
|
||||
return this;
|
||||
}
|
||||
|
||||
Rect IMapRender::GetRect()
|
||||
{
|
||||
Point rb = Point(INT_MAX, INT_MAX);
|
||||
Point lt = Point(-1, -1);
|
||||
|
||||
for (int i = 0; i < _items.GetCount(); i++)
|
||||
{
|
||||
Rect r = _items[i]->GetRect();
|
||||
|
||||
lt.x = min(r.TopLeft().x, lt.x);
|
||||
lt.y = min(r.TopLeft().y, lt.y);
|
||||
|
||||
rb.x = max(r.BottomRight().x, rb.x);
|
||||
rb.y = max(r.BottomRight().y, rb.y);
|
||||
}
|
||||
|
||||
return Rect(lt, rb);
|
||||
}
|
||||
118
bazaar/MapCommon/IMapRender.h
Normal file
118
bazaar/MapCommon/IMapRender.h
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
#ifndef MAP_COMMON__I_MAP_RENDER_H
|
||||
#define MAP_COMMON__I_MAP_RENDER_H
|
||||
|
||||
#include "IMapItem.h"
|
||||
#include "IMapRenderInfo.h"
|
||||
|
||||
class IMapRender : public IMapItem, public IMapRenderInfo
|
||||
{
|
||||
public:
|
||||
IMapRender(IMapRender* render);
|
||||
virtual ~IMapRender() { Clear(); }
|
||||
|
||||
virtual void RenderItems(Draw* w);
|
||||
virtual void Render(Draw* w);
|
||||
|
||||
virtual Rect GetPageRect() { return GetTopRender() ? GetTopRender()->GetPageRect() : Null; }
|
||||
virtual Point GetPageOffset() { return GetTopRender() ? GetTopRender()->GetPageOffset() : Null; }
|
||||
virtual Rect GetRenderRect() { return GetTopRender() ? GetTopRender()->GetRenderRect() : Null; }
|
||||
|
||||
virtual void RefreshView() { if (GetTopRender()) GetTopRender()->RefreshView(); }
|
||||
|
||||
virtual bool Load(const char* fp) { return false; }
|
||||
virtual bool Zoom(int level) { return false; }
|
||||
virtual Rect GetRect();
|
||||
|
||||
virtual double GetZoom(int i) { return GetTopRender() ? GetTopRender()->GetZoom(i) : 1.0; }
|
||||
virtual int GetZoomCount() { return GetTopRender() ? GetTopRender()->GetZoomCount() : 0; }
|
||||
virtual int GetCurrentZoom() { return GetTopRender() ? GetTopRender()->GetCurrentZoom() : 0; }
|
||||
|
||||
virtual String GetItemType() { return "IMapRender"; }
|
||||
|
||||
IMapRender* Antialiased(bool use = true, bool subpixel = false);
|
||||
IMapRender* Subpixel();
|
||||
IMapRender* NoAA();
|
||||
|
||||
IMapRender* ClearColor(const Color& c) { _clearColor = c; return this; }
|
||||
IMapRender* Opacity(double value) { _opacity = value; return this; }
|
||||
virtual void Clear();
|
||||
|
||||
virtual double GetOpacity() { return _opacity; }
|
||||
virtual dword GetQuality() { return _quality; }
|
||||
virtual Color GetClearColor() { return _clearColor; }
|
||||
virtual dword GetRenderType() { return _renderType; }
|
||||
|
||||
virtual Point SceneToView(const Point& p) { return GetTopRender() ? GetTopRender()->SceneToView(p) : p; }
|
||||
virtual Size SceneToView(const Size& sz) { return GetTopRender() ? GetTopRender()->SceneToView(sz) : sz; }
|
||||
virtual Rect SceneToView(const Rect& rt) { return GetTopRender() ? GetTopRender()->SceneToView(rt) : rt; }
|
||||
virtual Array<Point> SceneToView(const Array<Point>& p) { return GetTopRender() ? GetTopRender()->SceneToView(p) : p; }
|
||||
virtual Vector<Point> SceneToView(const Vector<Point>& p) { return GetTopRender() ? GetTopRender()->SceneToView(p) : p; }
|
||||
|
||||
virtual Point ViewToScene(const Point& p) { return GetTopRender() ? GetTopRender()->ViewToScene(p) : p; }
|
||||
virtual Size ViewToScene(const Size& sz) { return GetTopRender() ? GetTopRender()->ViewToScene(sz) : sz; }
|
||||
virtual Rect ViewToScene(const Rect& rt) { return GetTopRender() ? GetTopRender()->ViewToScene(rt) : rt; }
|
||||
virtual Array<Point> ViewToScene(const Array<Point>& p) { return GetTopRender() ? GetTopRender()->ViewToScene(p) : p; }
|
||||
virtual Vector<Point> ViewToScene(const Vector<Point>& p) { return GetTopRender() ? GetTopRender()->ViewToScene(p) : p; }
|
||||
|
||||
virtual Rect CurrentViewRect() { return GetTopRender() ? GetTopRender()->CurrentViewRect() : GetRect(); }
|
||||
virtual Rect CurrentViewSize() { return CurrentViewRect().GetSize(); }
|
||||
virtual Rect CurrentSceneRect() { return GetTopRender() ? GetTopRender()->CurrentSceneRect() : GetRect(); }
|
||||
virtual Size CurrentSceneSize() { return CurrentSceneRect().GetSize(); }
|
||||
|
||||
template <class T>
|
||||
Ptr<T> AddItem() { T* t = new T(this); _items.Add(t); return t; }
|
||||
virtual Vector<Ptr<IMapItem> >& GetItems() { return _items; }
|
||||
const virtual Vector<Ptr<IMapItem> >& GetItems() const { return _items; }
|
||||
|
||||
public:
|
||||
virtual void StateOff(dword state);
|
||||
virtual void StateOn (dword state);
|
||||
virtual bool IsState (dword state);
|
||||
virtual void PerformState(dword state, const String& param = String());
|
||||
|
||||
public:
|
||||
virtual bool ProcessLeftDouble (Point p, dword keyflags);
|
||||
virtual bool ProcessLeftDown (Point p, dword keyflags);
|
||||
virtual bool ProcessLeftDrag (Point p, dword keyflags);
|
||||
virtual bool ProcessLeftUp (Point p, dword keyflags);
|
||||
|
||||
virtual bool ProcessRightDouble(Point p, dword keyflags);
|
||||
virtual bool ProcessRightDown (Point p, dword keyflags);
|
||||
virtual bool ProcessRightDrag (Point p, dword keyflags);
|
||||
virtual bool ProcessRightUp (Point p, dword keyflags);
|
||||
|
||||
virtual bool ProcessMouseMove (Point p, dword keyflags);
|
||||
|
||||
virtual bool ProcessMouseEnter();
|
||||
virtual bool ProcessMouseLeave();
|
||||
|
||||
protected:
|
||||
dword _renderType;
|
||||
dword _quality;
|
||||
double _opacity;
|
||||
Color _clearColor;
|
||||
Vector<Ptr<IMapItem> > _items;
|
||||
enum { RENDER_DRAW, RENDER_PAINTER };
|
||||
};
|
||||
|
||||
#define ZOOM_FUNCTIONS_DECLARE(Type) \
|
||||
inline Type ViewToScene(Ptr<IMapItem> item, const Type& p) \
|
||||
{ \
|
||||
if (!item) return p; \
|
||||
if ( item->GetTopRender() == NULL) return p; \
|
||||
return item->GetTopRender()->ViewToScene(p); \
|
||||
} \
|
||||
inline Type SceneToView(Ptr<IMapItem> item, const Type& p) \
|
||||
{ \
|
||||
if (!item) return p; \
|
||||
if ( item->GetTopRender() == NULL) return p; \
|
||||
return item->GetTopRender()->SceneToView(p); \
|
||||
}
|
||||
|
||||
ZOOM_FUNCTIONS_DECLARE(Point);
|
||||
ZOOM_FUNCTIONS_DECLARE(Size);
|
||||
ZOOM_FUNCTIONS_DECLARE(Rect);
|
||||
ZOOM_FUNCTIONS_DECLARE(Array<Point>);
|
||||
ZOOM_FUNCTIONS_DECLARE(Vector<Point>);
|
||||
|
||||
#endif
|
||||
133
bazaar/MapCommon/IMapRenderEvents.cpp
Normal file
133
bazaar/MapCommon/IMapRenderEvents.cpp
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
#include "IMapRender.h"
|
||||
|
||||
bool IMapRender::ProcessLeftDouble(Point p, dword keyflags)
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessLeftDouble(p, keyflags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessLeftDown(Point p, dword keyflags)
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessLeftDown(p, keyflags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessLeftDrag(Point p, dword keyflags)
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessLeftDrag(p, keyflags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessLeftUp(Point p, dword keyflags)
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessLeftUp(p, keyflags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessRightDouble(Point p, dword keyflags)
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessRightDouble(p, keyflags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessRightDown(Point p, dword keyflags)
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessRightDown(p, keyflags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessRightDrag(Point p, dword keyflags)
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessRightDrag(p, keyflags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessRightUp(Point p, dword keyflags)
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessRightUp(p, keyflags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessMouseMove(Point p, dword keyflags)
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessMouseMove(p, keyflags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessMouseEnter()
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessMouseEnter())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMapRender::ProcessMouseLeave()
|
||||
{
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i] && _items[i]->IsShown())
|
||||
{
|
||||
if (_items[i]->ProcessMouseLeave())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
27
bazaar/MapCommon/IMapRenderInfo.h
Normal file
27
bazaar/MapCommon/IMapRenderInfo.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef MAP_COMMON__I_MAP_RENDER_INFO_H
|
||||
#define MAP_COMMON__I_MAP_RENDER_INFO_H
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <Painter/Painter.h>
|
||||
using namespace Upp;
|
||||
|
||||
class IMapRenderInfo
|
||||
{
|
||||
public:
|
||||
virtual ~IMapRenderInfo() {}
|
||||
|
||||
virtual void RenderInfo(Painter* w) { RenderInfo((Draw*)w); }
|
||||
virtual void RenderInfo(Draw* w) {}
|
||||
|
||||
virtual Point GetRenderCenter() { return GetRenderRect().CenterPoint(); }
|
||||
virtual Size GetRenderSize() { return GetRenderRect().GetSize(); }
|
||||
virtual Rect GetRenderRect() = 0;
|
||||
|
||||
virtual Point GetPageCenter() { return GetPageRect().CenterPoint(); }
|
||||
virtual Point GetPageOffset() = 0;
|
||||
virtual Size GetPageSize() { return GetPageRect().GetSize(); }
|
||||
virtual Rect GetPageRect() = 0;
|
||||
virtual Point GetPagePos() { return GetPageRect().TopLeft(); }
|
||||
};
|
||||
|
||||
#endif
|
||||
30
bazaar/MapCommon/IMapRenderStates.cpp
Normal file
30
bazaar/MapCommon/IMapRenderStates.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include "IMapRender.h"
|
||||
|
||||
void IMapRender::StateOff(dword state)
|
||||
{
|
||||
IMapItem::StateOff(state);
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i])
|
||||
_items[i]->StateOff(state);
|
||||
}
|
||||
|
||||
void IMapRender::StateOn (dword state)
|
||||
{
|
||||
IMapItem::StateOn(state);
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i])
|
||||
_items[i]->StateOn(state);
|
||||
}
|
||||
|
||||
bool IMapRender::IsState (dword state)
|
||||
{
|
||||
return IMapItem::IsState(state);
|
||||
}
|
||||
|
||||
void IMapRender::PerformState(dword state, const String& param)
|
||||
{
|
||||
IMapItem::PerformState(state, param);
|
||||
for (int i = 0; i < _items.GetCount(); ++i)
|
||||
if (_items[i])
|
||||
_items[i]->PerformState(state, param);
|
||||
}
|
||||
9
bazaar/MapCommon/MapCommon.h
Normal file
9
bazaar/MapCommon/MapCommon.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef MAP_COMMON__MAP_COMMON_H
|
||||
#define MAP_COMMON__MAP_COMMON_H
|
||||
|
||||
#include "IMapRender.h"
|
||||
|
||||
#include "ButtonItem.h"
|
||||
#include "PolygonItem.h"
|
||||
|
||||
#endif
|
||||
25
bazaar/MapCommon/MapCommon.upp
Normal file
25
bazaar/MapCommon/MapCommon.upp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
Painter;
|
||||
|
||||
file
|
||||
MapCommon.h,
|
||||
Item readonly separator,
|
||||
IMapEvent.h,
|
||||
IMapItem.h,
|
||||
IMapItem.cpp,
|
||||
IMapItemState.cpp,
|
||||
Render readonly separator,
|
||||
IMapRenderInfo.h,
|
||||
IMapRender.h,
|
||||
IMapRender.cpp,
|
||||
IMapRenderStates.cpp,
|
||||
IMapRenderEvents.cpp,
|
||||
"Basic Entities" readonly separator,
|
||||
PolygonItem.h,
|
||||
PolygonItem.cpp,
|
||||
PolygonItemEvents.cpp,
|
||||
ButtonItem.h,
|
||||
ButtonItem.cpp,
|
||||
ButtonItemEvents.cpp;
|
||||
|
||||
126
bazaar/MapCommon/PolygonItem.cpp
Normal file
126
bazaar/MapCommon/PolygonItem.cpp
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
#include "PolygonItem.h"
|
||||
#include "IMapRender.h"
|
||||
|
||||
bool IsPointInsidePolygon(const Array<Point>& p, Point s)
|
||||
{
|
||||
int i, j;
|
||||
bool parity = false;
|
||||
for (i = 0, j = p.GetCount() - 1; i < p.GetCount(); j = i++)
|
||||
{
|
||||
if ( ( p[i].y < s.y && s.y <= p[j].y || p[j].y < s.y && s.y <= p[i].y )
|
||||
&& (s.x > (p[j].x - p[i].x) * (s.y - p[i].y) / (p[j].y - p[i].y) + p[i].x))
|
||||
parity = !parity;
|
||||
}
|
||||
return parity;
|
||||
}
|
||||
|
||||
Rect RectOfFigure(const Array<Point>& p)
|
||||
{
|
||||
if (!p.GetCount())
|
||||
return Null;
|
||||
|
||||
Point s = Point(INT_MAX, INT_MAX);
|
||||
Point e = Point(-1, -1);
|
||||
|
||||
for (int i = 0; i < p.GetCount(); i++)
|
||||
{
|
||||
s.x = min(p[i].x, s.x);
|
||||
s.y = min(p[i].y, s.y);
|
||||
|
||||
e.x = max(p[i].x, e.x);
|
||||
e.y = max(p[i].y, e.y);
|
||||
}
|
||||
|
||||
return Rect(s, e);
|
||||
}
|
||||
|
||||
Point CenterOfFigure(const Array<Point>& p)
|
||||
{
|
||||
return RectOfFigure(p).CenterPoint();
|
||||
}
|
||||
|
||||
Point TopLeftOfFigure(const Array<Point>& p)
|
||||
{
|
||||
if (!p.GetCount())
|
||||
return Null;
|
||||
|
||||
Point s = p[0];
|
||||
|
||||
for (int i = 1; i < p.GetCount(); i++)
|
||||
{
|
||||
if (s.x > p[i].x && s.y > p[i].y)
|
||||
s = p[i];
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
PolygonItem::PolygonItem(IMapRender* render)
|
||||
: IMapItem(render), _display(new PolygonItemDisplay()), _stdDisplay(true)
|
||||
{
|
||||
}
|
||||
|
||||
Callback1<Ptr<PolygonItem> > PolygonItem::WhenClick;
|
||||
|
||||
PolygonItem::~PolygonItem()
|
||||
{
|
||||
if (_stdDisplay && _display)
|
||||
delete _display;
|
||||
}
|
||||
|
||||
PolygonItem* PolygonItem::SetDisplay(PolygonItemDisplay* disp)
|
||||
{
|
||||
if (_stdDisplay && _display)
|
||||
delete _display;
|
||||
_display = disp;
|
||||
return this;
|
||||
}
|
||||
|
||||
Rect PolygonItem::GetRect()
|
||||
{
|
||||
return RectOfFigure(GetVertices());
|
||||
}
|
||||
|
||||
Point PolygonItem::GetCenter()
|
||||
{
|
||||
return CenterOfFigure(GetVertices());
|
||||
}
|
||||
|
||||
Point PolygonItem::GetTopLeft()
|
||||
{
|
||||
return TopLeftOfFigure(GetVertices());
|
||||
}
|
||||
|
||||
bool PolygonItem::Contains(const Point& p)
|
||||
{
|
||||
return IsPointInsidePolygon(GetVertices(), p);
|
||||
}
|
||||
|
||||
void PolygonItem::Render(Draw* w)
|
||||
{
|
||||
_display->Paint(w, this);
|
||||
}
|
||||
|
||||
void PolygonItemDisplay::Paint(Draw* w, PolygonItem* item) const
|
||||
{
|
||||
if (!item->GetTopRender())
|
||||
return;
|
||||
|
||||
Vector<Point> points;
|
||||
for (int i = 0; i < item->GetVertices().GetCount(); ++i)
|
||||
points << item->GetTopRender()->ViewToScene(item->GetVertices()[i]);
|
||||
|
||||
if (item->IsFound())
|
||||
{
|
||||
w->DrawPolygon(points,
|
||||
item->IsSelected()
|
||||
? Yellow()
|
||||
: LtRed(), 1, Black());
|
||||
}
|
||||
|
||||
else if (item->IsSelected() && !item->IsFound())
|
||||
w->DrawPolygon(points, Yellow(), 1, Black());
|
||||
|
||||
else if (item->IsState(STATE_EDIT))
|
||||
w->DrawPolygon(points, Green(), 1, Black());
|
||||
}
|
||||
45
bazaar/MapCommon/PolygonItem.h
Normal file
45
bazaar/MapCommon/PolygonItem.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef MAP_COMMON__POLYGON_ITEM_H
|
||||
#define MAP_COMMON__POLYGON_ITEM_H
|
||||
|
||||
#include "IMapRender.h"
|
||||
#include <Map/MapSerialize.h>
|
||||
|
||||
class PolygonItemDisplay;
|
||||
|
||||
class PolygonItem : public IMapItem, public Room
|
||||
{
|
||||
public:
|
||||
PolygonItem(IMapRender* render);
|
||||
virtual ~PolygonItem();
|
||||
|
||||
virtual void Render(Draw* w);
|
||||
|
||||
virtual bool ProcessLeftDown(Point p, dword keyflags);
|
||||
virtual bool ProcessLeftUp(Point p, dword keyflags);
|
||||
|
||||
virtual void StatePerformed (dword state, const String& param = String());
|
||||
virtual bool Contains(const Point& p);
|
||||
virtual Point GetTopLeft();
|
||||
virtual Point GetCenter();
|
||||
virtual Rect GetRect();
|
||||
|
||||
virtual String GetItemType() { return "PolygonItem"; }
|
||||
|
||||
public:
|
||||
static Callback1<Ptr<PolygonItem> > WhenClick;
|
||||
PolygonItem* SetDisplay(PolygonItemDisplay* disp);
|
||||
|
||||
private:
|
||||
Point _click;
|
||||
bool _stdDisplay;
|
||||
PolygonItemDisplay* _display;
|
||||
};
|
||||
|
||||
class PolygonItemDisplay
|
||||
{
|
||||
public:
|
||||
virtual ~PolygonItemDisplay() {}
|
||||
virtual void Paint(Draw* w, PolygonItem* item) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
43
bazaar/MapCommon/PolygonItemEvents.cpp
Normal file
43
bazaar/MapCommon/PolygonItemEvents.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "PolygonItem.h"
|
||||
#include "IMapRender.h"
|
||||
|
||||
void PolygonItem::StatePerformed(dword state, const String& param)
|
||||
{
|
||||
if (state == PERFORM_SEARCH)
|
||||
{
|
||||
if (param.IsEmpty() || ToLower(GetName() + GetTags()).Find(ToLower(param)) < 0)
|
||||
StateOff(STATE_FOUND);
|
||||
else
|
||||
StateOn (STATE_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
bool PolygonItem::ProcessLeftDown(Point p, dword keyflags)
|
||||
{
|
||||
bool sel = Contains(p);
|
||||
|
||||
if (sel)
|
||||
{
|
||||
_click = GetTopRender()->ViewToScene(p);
|
||||
StatesOff(STATE_SELECTED);
|
||||
StateOn(STATE_SELECTED);
|
||||
}
|
||||
|
||||
return sel || IMapItem::ProcessLeftDown(p, keyflags);
|
||||
}
|
||||
|
||||
bool PolygonItem::ProcessLeftUp(Point p, dword keyflags)
|
||||
{
|
||||
bool sel = Contains(p);
|
||||
|
||||
p = GetTopRender()->ViewToScene(p);
|
||||
|
||||
if (sel && !IsNull(_click))
|
||||
{
|
||||
if (abs(_click.x - p.x) < 5 && abs(_click.y - p.y) < 5)
|
||||
WhenClick(this);
|
||||
}
|
||||
|
||||
_click = Null;
|
||||
return IMapItem::ProcessLeftUp(p, keyflags);
|
||||
}
|
||||
5
bazaar/MapCommon/init
Normal file
5
bazaar/MapCommon/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _MapCommon_icpp_init_stub
|
||||
#define _MapCommon_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Painter/init"
|
||||
#endif
|
||||
142
bazaar/MapEditor/LevelEditor.cpp
Normal file
142
bazaar/MapEditor/LevelEditor.cpp
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
#include "LevelEditor.h"
|
||||
|
||||
LevelEditor::LevelEditor(Map& map, Level& level, int pos)
|
||||
{
|
||||
CtrlLayout(*this, "Редактор этажа");
|
||||
MaximizeBox().Sizeable();
|
||||
|
||||
_item = -1;
|
||||
_pos = pos;
|
||||
_map = ↦
|
||||
_level = &level;
|
||||
|
||||
EditView.HideLevelsCtrl();
|
||||
EditView.HideNavButtons();
|
||||
|
||||
LayerList.WhenToolBar = THISBACK(CreateLayerToolBar);
|
||||
LayerList.WhenChangeRow = THISBACK(UpdateItemList);
|
||||
LayerList.AddColumn(t_("#")).Min(HorzLayoutZoom(40)).Max(VertLayoutZoom(40))
|
||||
.HeaderAlignCenter().AlignCenter();
|
||||
LayerList.SetToolBar();
|
||||
|
||||
LayerList.AddColumn(t_("Layer Name"))
|
||||
.HeaderAlignCenter().AlignCenter();
|
||||
|
||||
ItemList.WhenToolBar = THISBACK(CreateItemToolBar);
|
||||
ItemList.WhenChangeRow = THISBACK(OnItemSelect);
|
||||
ItemList.WhenLeftDouble = THISBACK(OnItemProperties);
|
||||
ItemList.AddColumn(t_("#")).Min(HorzLayoutZoom(40)).Max(VertLayoutZoom(40))
|
||||
.HeaderAlignCenter().AlignCenter();
|
||||
ItemList.SetToolBar();
|
||||
|
||||
ItemList.AddColumn(t_("Item Name"))
|
||||
.HeaderAlignCenter().AlignCenter();
|
||||
|
||||
ItemTypeList.Add(t_("Rooms"));
|
||||
ItemTypeList.SetIndex(0);
|
||||
|
||||
LoadMap();
|
||||
UpdateLayerList();
|
||||
}
|
||||
|
||||
void LevelEditor::UpdateLayerList()
|
||||
{
|
||||
if (!_level)
|
||||
return;
|
||||
|
||||
int row = LayerList.GetCurrentRow();
|
||||
|
||||
LayerList.Clear();
|
||||
|
||||
for (int i = 0; i < _level->GetLayers().GetCount(); ++i)
|
||||
{
|
||||
LayerList.Add(i, _level->GetLayers()[i].GetName());
|
||||
}
|
||||
|
||||
if (row >= 0 && row < LayerList.GetRowCount())
|
||||
LayerList.SetCursor(row);
|
||||
|
||||
if (row < 0 && LayerList.GetRowCount())
|
||||
LayerList.SetCursor(0);
|
||||
|
||||
MapLevel* level = EditView.GetCurrentLevel();
|
||||
if (!level) return;
|
||||
else level->ClearEditPoints();
|
||||
|
||||
_item = -1;
|
||||
UpdateItemList();
|
||||
}
|
||||
|
||||
void LevelEditor::UpdateItemList()
|
||||
{
|
||||
ItemList.Clear();
|
||||
|
||||
int row = LayerList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
Layer& lay = _level->GetLayers()[row];
|
||||
|
||||
for (int i = 0; i < lay.GetRooms().GetCount(); ++i)
|
||||
{
|
||||
ItemList.Add(i, lay.GetRooms()[i].GetName());
|
||||
}
|
||||
|
||||
if (ItemList.GetRowCount())
|
||||
ItemList.SetCursor(0);
|
||||
|
||||
OnItemSelect();
|
||||
UpdateMap(ItemList.GetRowCount() > 0);
|
||||
}
|
||||
|
||||
void LevelEditor::LoadMap()
|
||||
{
|
||||
Map map;
|
||||
|
||||
for (int i = 0; i < _pos; ++i)
|
||||
map.GetLevels().Add(Level());
|
||||
|
||||
map.GetLevels().Add(Level(*_level));
|
||||
map.SetName(_map->GetName());
|
||||
|
||||
EditView.LoadMap(map, true);
|
||||
EditView.SetCurrentLevel(_pos);
|
||||
EditView.GetCurrentLevel()->WhenChangePoint = THISBACK(OnChangePoint);
|
||||
EditView.HighQuality(false);
|
||||
}
|
||||
|
||||
void LevelEditor::UpdateMap(bool editMode)
|
||||
{
|
||||
EditView.UpdateLevel(*_level, _pos, editMode);
|
||||
}
|
||||
|
||||
int LevelEditor::Execute()
|
||||
{
|
||||
int res = TopWindow::Execute();
|
||||
|
||||
int layer = LayerList.GetCurrentRow();
|
||||
if (layer < 0) return res;
|
||||
|
||||
Layer& lay = _level->GetLayers()[layer];
|
||||
|
||||
int row = ItemList.GetCurrentRow();
|
||||
if (row < 0) return res;
|
||||
|
||||
MapLevel* level = EditView.GetCurrentLevel();
|
||||
if (!level) return res;
|
||||
|
||||
if (_item != -1)
|
||||
{
|
||||
if (_item >= 0 && _item < lay.GetRooms().GetCount())
|
||||
{
|
||||
Room& room = lay.GetRooms()[_item];
|
||||
room.GetVertices().Clear();
|
||||
for (int i = 0; i < level->GetEditPoints().GetCount(); ++i)
|
||||
{
|
||||
room.GetVertices() << level->GetEditPoints()[i];
|
||||
}
|
||||
}
|
||||
_item = -1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
44
bazaar/MapEditor/LevelEditor.h
Normal file
44
bazaar/MapEditor/LevelEditor.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef MAP_EDITOR__LEVEL_EDITOR_H
|
||||
#define MAP_EDITOR__LEVEL_EDITOR_H
|
||||
|
||||
#include "MapEditor.h"
|
||||
|
||||
class LevelEditor : public WithLevelEditLayout<TopWindow>
|
||||
{
|
||||
typedef LevelEditor CLASSNAME;
|
||||
|
||||
public:
|
||||
LevelEditor(Map& map, Level& level, int pos);
|
||||
|
||||
virtual int Execute();
|
||||
|
||||
protected:
|
||||
void OnLayerAdd();
|
||||
void OnLayerEdit();
|
||||
void OnLayerRemove();
|
||||
void OnChangePoint();
|
||||
|
||||
void OnItemAdd();
|
||||
void OnItemEdit();
|
||||
void OnItemRemove();
|
||||
void OnItemSelect();
|
||||
void OnItemProperties();
|
||||
|
||||
void LoadMap();
|
||||
void UpdateMap(bool editMode);
|
||||
void UpdateItemList();
|
||||
void UpdateLayerList();
|
||||
|
||||
void CreateItemToolBar(Bar& bar);
|
||||
void CreateLayerToolBar(Bar& bar);
|
||||
|
||||
void OpenItemProperties();
|
||||
|
||||
private:
|
||||
int _item;
|
||||
Level* _level;
|
||||
Map* _map;
|
||||
int _pos;
|
||||
};
|
||||
|
||||
#endif
|
||||
110
bazaar/MapEditor/LevelEditorItem.cpp
Normal file
110
bazaar/MapEditor/LevelEditorItem.cpp
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#include "LevelEditor.h"
|
||||
|
||||
void LevelEditor::OnItemAdd()
|
||||
{
|
||||
int layer = LayerList.GetCurrentRow();
|
||||
if (layer < 0) return;
|
||||
|
||||
Layer& lay = _level->GetLayers()[layer];
|
||||
|
||||
Room room;
|
||||
room.SetName(NFormat(t_("Room #%d"), lay.GetRooms().GetCount() + 1));
|
||||
|
||||
if (room.OpenProperties() != IDOK)
|
||||
return;
|
||||
|
||||
lay.GetRooms().Add(room);
|
||||
|
||||
UpdateItemList();
|
||||
}
|
||||
|
||||
void LevelEditor::OnItemEdit()
|
||||
{
|
||||
int layer = LayerList.GetCurrentRow();
|
||||
if (layer < 0) return;
|
||||
|
||||
Layer& lay = _level->GetLayers()[layer];
|
||||
|
||||
int row = ItemList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
lay.GetRooms()[row].OpenProperties();
|
||||
|
||||
UpdateItemList();
|
||||
}
|
||||
|
||||
void LevelEditor::OnItemRemove()
|
||||
{
|
||||
int layer = LayerList.GetCurrentRow();
|
||||
if (layer < 0) return;
|
||||
|
||||
Layer& lay = _level->GetLayers()[layer];
|
||||
|
||||
int row = ItemList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
if (!PromptYesNo(t_("Remove the selected item from level?")))
|
||||
return;
|
||||
|
||||
lay.GetRooms().Remove(row);
|
||||
UpdateItemList();
|
||||
}
|
||||
|
||||
void LevelEditor::OnItemSelect()
|
||||
{
|
||||
int layer = LayerList.GetCurrentRow();
|
||||
if (layer < 0) return;
|
||||
|
||||
Layer& lay = _level->GetLayers()[layer];
|
||||
|
||||
int row = ItemList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
MapLevel* level = EditView.GetCurrentLevel();
|
||||
if (!level) return;
|
||||
|
||||
if (_item != -1)
|
||||
{
|
||||
if (_item >= 0 && _item < lay.GetRooms().GetCount())
|
||||
{
|
||||
Room& room = lay.GetRooms()[_item];
|
||||
room.GetVertices().Clear();
|
||||
for (int i = 0; i < level->GetEditPoints().GetCount(); ++i)
|
||||
{
|
||||
room.GetVertices() << level->GetEditPoints()[i];
|
||||
}
|
||||
}
|
||||
_item = -1;
|
||||
}
|
||||
|
||||
level->ClearEditPoints();
|
||||
|
||||
Room& room = lay.GetRooms()[row];
|
||||
for (int i = 0; i < room.GetVertices().GetCount(); ++i)
|
||||
{
|
||||
level->AddEditPoint(room.GetVertices()[i]);
|
||||
}
|
||||
|
||||
_item = row;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void LevelEditor::OnItemProperties()
|
||||
{
|
||||
int layer = LayerList.GetCurrentRow();
|
||||
if (layer < 0) return;
|
||||
|
||||
Layer& lay = _level->GetLayers()[layer];
|
||||
|
||||
int row = ItemList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
lay.GetRooms()[row].OpenProperties();
|
||||
UpdateItemList();
|
||||
}
|
||||
|
||||
void LevelEditor::OnChangePoint()
|
||||
{
|
||||
OnItemSelect();
|
||||
UpdateMap(true);
|
||||
}
|
||||
41
bazaar/MapEditor/LevelEditorLayer.cpp
Normal file
41
bazaar/MapEditor/LevelEditorLayer.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include "LevelEditor.h"
|
||||
|
||||
void LevelEditor::OnLayerAdd()
|
||||
{
|
||||
int row = LayerList.GetRowCount();
|
||||
|
||||
Layer layer;
|
||||
layer.SetName(NFormat(t_("Layer #%d"), _level->GetLayers().GetCount() + 1));
|
||||
|
||||
if (layer.OpenProperties() != IDOK)
|
||||
return;
|
||||
|
||||
_level->GetLayers().Add(layer);
|
||||
|
||||
UpdateLayerList();
|
||||
}
|
||||
|
||||
void LevelEditor::OnLayerEdit()
|
||||
{
|
||||
int row = LayerList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
_level->GetLayers()[row].OpenProperties();
|
||||
|
||||
UpdateLayerList();
|
||||
}
|
||||
|
||||
void LevelEditor::OnLayerRemove()
|
||||
{
|
||||
int row = LayerList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
if (!PromptYesNo(t_("Remove the selected layer from level?")))
|
||||
return;
|
||||
|
||||
if (!PromptYesNo(t_("No undo for this action. Are you sure?")))
|
||||
return;
|
||||
|
||||
_level->GetLayers().Remove(row);
|
||||
UpdateLayerList();
|
||||
}
|
||||
18
bazaar/MapEditor/LevelEditorTools.cpp
Normal file
18
bazaar/MapEditor/LevelEditorTools.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include "LevelEditor.h"
|
||||
|
||||
void LevelEditor::OpenItemProperties()
|
||||
{
|
||||
}
|
||||
|
||||
void LevelEditor::CreateItemToolBar(Bar& bar)
|
||||
{
|
||||
bar.Add("Add", CtrlImg::Add(), THISBACK(OnItemAdd));
|
||||
bar.Add("Remove", CtrlImg::Remove(), THISBACK(OnItemRemove));
|
||||
bar.Add("Properties", CtrlImg::smallcheck(), THISBACK(OnItemProperties));
|
||||
}
|
||||
|
||||
void LevelEditor::CreateLayerToolBar(Bar& bar)
|
||||
{
|
||||
bar.Add("Add", CtrlImg::Add(), THISBACK(OnLayerAdd));
|
||||
bar.Add("Remove", CtrlImg::Remove(), THISBACK(OnLayerRemove));
|
||||
}
|
||||
76
bazaar/MapEditor/MapEditor.cpp
Normal file
76
bazaar/MapEditor/MapEditor.cpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#include "MapEditor.h"
|
||||
|
||||
#define IMAGECLASS MapEditorImg
|
||||
#define IMAGEFILE <MapEditor/MapEditor.iml>
|
||||
#include <Draw/iml_source.h>
|
||||
|
||||
MapEditor::MapEditor()
|
||||
{
|
||||
CtrlLayout(*this, t_("Map Editor"));
|
||||
RealizeDirectories();
|
||||
UpdateEditorCtrls();
|
||||
|
||||
WhenClose = THISBACK(OnClose);
|
||||
PropsBtn <<= THISBACK(OnMapProperties);
|
||||
|
||||
NewMapBtn <<= THISBACK(OnNewMap);
|
||||
SaveMapBtn <<= THISBACK(OnSaveMap);
|
||||
LoadMapBtn <<= THISBACK(OnLoadMap);
|
||||
ViewMapBtn <<= THISBACK(OnViewMap);
|
||||
CalcMapBtn <<= THISBACK(CalculateAllPrompt);
|
||||
|
||||
AddLevelBtn <<= THISBACK(OnAddLevel);
|
||||
EditLevelBtn <<= THISBACK(OnEditLevel);
|
||||
ChangeLevelBtn <<= THISBACK(OnChangeLevel);
|
||||
RemoveLevelBtn <<= THISBACK(OnRemoveLevel);
|
||||
|
||||
LevelList.Moving();
|
||||
LevelList.AddColumn(t_("#")).Min(HorzLayoutZoom(40)).Max(VertLayoutZoom(40))
|
||||
.HeaderAlignCenter().AlignCenter();
|
||||
|
||||
LevelList.AddColumn(t_("Level Name"))
|
||||
.HeaderAlignCenter().AlignCenter();
|
||||
|
||||
LevelList.WhenChangeRow = THISBACK(UpdateEditorCtrls);
|
||||
LevelList.WhenLeftDouble = THISBACK(OnChangeLevel);
|
||||
LevelList.WhenMoveRow = THISBACK(OnMoveLevel);
|
||||
}
|
||||
|
||||
void MapEditor::OnClose()
|
||||
{
|
||||
if (!_map.GetName().IsEmpty() && _map.GetLevels().GetCount() > 0)
|
||||
{
|
||||
int r = PromptYesNoCancel(t_("Save current map before exit?"));
|
||||
|
||||
if (r == 1)
|
||||
OnSaveMap();
|
||||
|
||||
if (r == -1)
|
||||
return;
|
||||
}
|
||||
|
||||
Break();
|
||||
}
|
||||
|
||||
void MapEditor::UpdateEditorCtrls()
|
||||
{
|
||||
bool flag = _map.GetLevels().GetCount() > 0 && LevelList.GetCurrentRow() >= 0
|
||||
&& !_map.GetName().IsEmpty();
|
||||
|
||||
LevelList .Enable( _map.GetLevels().GetCount());
|
||||
SaveMapBtn .Enable( _map.GetLevels().GetCount());
|
||||
AddLevelBtn .Enable(!_map.GetName().IsEmpty());
|
||||
ChangeLevelBtn.Enable(flag);
|
||||
RemoveLevelBtn.Enable(flag);
|
||||
|
||||
EditLevelBtn .Enable(flag);
|
||||
|
||||
CalcMapBtn.Enable(_map.GetLevels().GetCount() > 0 && !_map.GetName().IsEmpty());
|
||||
ViewMapBtn.Enable(_map.GetLevels().GetCount() > 0 && !_map.GetName().IsEmpty());
|
||||
}
|
||||
|
||||
void MapEditor::RealizeDirectories()
|
||||
{
|
||||
RealizeDirectory(AppendFileName( GetFileDirectory(GetExeFilePath()), "Mipmaps"));
|
||||
RealizeDirectory(AppendFileName( GetFileDirectory(GetExeFilePath()), "Maps"));
|
||||
}
|
||||
48
bazaar/MapEditor/MapEditor.h
Normal file
48
bazaar/MapEditor/MapEditor.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef MAP_EDITOR__MAP_EDITOR_H
|
||||
#define MAP_EDITOR__MAP_EDITOR_H
|
||||
|
||||
#include <GridCtrl/GridCtrl.h>
|
||||
using namespace Upp;
|
||||
|
||||
#include <Map/Map.h>
|
||||
|
||||
#define LAYOUTFILE <MapEditor/MapEditor.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#define IMAGECLASS MapEditorImg
|
||||
#define IMAGEFILE <MapEditor/MapEditor.iml>
|
||||
#include <Draw/iml_header.h>
|
||||
|
||||
class MapEditor : public WithMapEditorLayout<TopWindow>
|
||||
{
|
||||
public:
|
||||
typedef MapEditor CLASSNAME;
|
||||
MapEditor();
|
||||
|
||||
void OnClose();
|
||||
void OnNewMap();
|
||||
void OnSaveMap();
|
||||
void OnLoadMap();
|
||||
void OnViewMap();
|
||||
void OnEditLevel();
|
||||
void OnMapProperties();
|
||||
|
||||
void OnAddLevel();
|
||||
void OnMoveLevel(int s, int e);
|
||||
void OnChangeLevel();
|
||||
void OnRemoveLevel();
|
||||
|
||||
void UpdateLevelList();
|
||||
void UpdateEditorCtrls();
|
||||
|
||||
protected:
|
||||
void RealizeDirectories();
|
||||
void CalculateAllPrompt();
|
||||
void OnLevelMapCalc(Level& level, int number);
|
||||
void OnLevelMapList(VectorMapEx<String, Value>& mapList);
|
||||
|
||||
private:
|
||||
Map _map;
|
||||
};
|
||||
|
||||
#endif
|
||||
9
bazaar/MapEditor/MapEditor.iml
Normal file
9
bazaar/MapEditor/MapEditor.iml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
PREMULTIPLIED
|
||||
IMAGE_ID(Reload)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,237,149,91,10,192,32,12,4,115,20,47,213,35,121,110,91,104,145,162,73,72,33,15,10,59,176,32,40,153,253)
|
||||
IMAGE_DATA(81,169,81,35,0,192,47,24,79,74,220,227,184,115,173,187,116,134,73,150,127,238,191,227,216,65,243,179,110,231,14,146)
|
||||
IMAGE_DATA(127,245,204,56,119,80,253,194,252,158,225,87,102,103,249,37,50,252,219,185,66,255,234,201,244,115,158,16,191,118,215,2)
|
||||
IMAGE_DATA(253,91,7,195,59,227,237,23,59,8,243,35,252,68,246,127,38,202,255,133,74,55,0,0,152,56,1,68,111,251,9,0)
|
||||
IMAGE_END_DATA(128, 1)
|
||||
34
bazaar/MapEditor/MapEditor.lay
Normal file
34
bazaar/MapEditor/MapEditor.lay
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
LAYOUT(MapEditorLayout, 240, 448)
|
||||
ITEM(GridCtrl, LevelList, HSizePosZ(8, 8).VSizePosZ(184, 44))
|
||||
ITEM(Button, NewMapBtn, SetLabel(t_("New map...")).LeftPosZ(8, 108).TopPosZ(8, 28))
|
||||
ITEM(Button, SaveMapBtn, SetLabel(t_("Save map...")).RightPosZ(8, 108).TopPosZ(8, 28))
|
||||
ITEM(Button, CalcMapBtn, SetLabel(t_("Calculate...")).LeftPosZ(124, 108).BottomPosZ(376, 28))
|
||||
ITEM(Button, ViewMapBtn, SetLabel(t_("Preview...")).LeftPosZ(124, 108).BottomPosZ(340, 28))
|
||||
ITEM(Button, LoadMapBtn, SetLabel(t_("Load map...")).LeftPosZ(8, 108).TopPosZ(116, 28))
|
||||
ITEM(Button, PropsBtn, SetLabel(t_("Properties...")).RightPosZ(8, 108).TopPosZ(116, 28))
|
||||
ITEM(Button, AddLevelBtn, SetLabel(t_("+")).LeftPosZ(8, 28).BottomPosZ(8, 28))
|
||||
ITEM(Button, ChangeLevelBtn, SetLabel(t_("Properties")).LeftPosZ(44, 72).BottomPosZ(8, 28))
|
||||
ITEM(Button, EditLevelBtn, SetLabel(t_("Edit level...")).RightPosZ(44, 72).VSizePosZ(412, 8))
|
||||
ITEM(Button, RemoveLevelBtn, SetLabel(t_("-")).RightPosZ(8, 28).BottomPosZ(8, 28))
|
||||
ITEM(Label, dv___11, SetFrame(TopSeparatorFrame()).HSizePosZ(0, 0).TopPosZ(156, 13))
|
||||
ITEM(Label, dv___12, SetLabel(t_("Levels:")).HSizePosZ(8, 8).TopPosZ(160, 23))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(MapLoadLayout, 264, 80)
|
||||
ITEM(DropList, MapList, HSizePosZ(8, 8).TopPosZ(8, 19))
|
||||
ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(92, 76).BottomPosZ(8, 28))
|
||||
ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 76).BottomPosZ(8, 28))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(PreviewLayout, 420, 332)
|
||||
ITEM(MapView, View, HSizePosZ(0, 0).VSizePosZ(0, 0))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(LevelEditLayout, 560, 452)
|
||||
ITEM(MapView, EditView, SetFrame(InsetFrame()).HSizePosZ(164, 4).VSizePosZ(4, 4))
|
||||
ITEM(GridCtrl, ItemList, LeftPosZ(4, 156).VSizePosZ(160, 4))
|
||||
ITEM(GridCtrl, LayerList, LeftPosZ(4, 156).TopPosZ(4, 116))
|
||||
ITEM(Label, dv___3, SetLabel(t_("Elements:")).LeftPosZ(4, 64).TopPosZ(132, 24))
|
||||
ITEM(DropList, ItemTypeList, LeftPosZ(68, 92).TopPosZ(132, 24))
|
||||
END_LAYOUT
|
||||
|
||||
167
bazaar/MapEditor/MapEditor.t
Normal file
167
bazaar/MapEditor/MapEditor.t
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
#ifdef _MSC_VER
|
||||
#pragma setlocale("C")
|
||||
#endif
|
||||
// MapEditor.lay
|
||||
|
||||
T_("New map...")
|
||||
ruRU("\320\235\320\276\320\262\320\260\321\217 \320\272\320\260\321\200\321\202\320\260...")
|
||||
|
||||
T_("Save map...")
|
||||
ruRU("\320\241\320\276\321\205\321\200\320\260\320\275\320\270\321\202\321\214...")
|
||||
|
||||
T_("Calculate...")
|
||||
ruRU("\320\237\321\200\320\276\321\201\321\207\320\270\321\202\320\260\321\202\321\214...")
|
||||
|
||||
T_("Preview...")
|
||||
ruRU("\320\237\321\200\320\276\321\201\320\274\320\276\321\202\321\200...")
|
||||
|
||||
T_("Load map...")
|
||||
ruRU("\320\236\321\202\320\272\321\200\321\213\321\202\321\214...")
|
||||
|
||||
T_("Properties...")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\260...")
|
||||
|
||||
T_("+")
|
||||
ruRU("")
|
||||
|
||||
T_("Properties")
|
||||
ruRU("\320\241\320\262\320\276\320\271\321\201\321\202\320\262\320\260")
|
||||
|
||||
T_("Edit level...")
|
||||
ruRU("\320\230\320\267\320\274\320\265\320\275\320\270\321\202\321\214")
|
||||
|
||||
T_("-")
|
||||
ruRU("")
|
||||
|
||||
T_("Levels:")
|
||||
ruRU("\320\255\321\202\320\260\320\266\320\270:")
|
||||
|
||||
T_("OK")
|
||||
ruRU("OK")
|
||||
|
||||
T_("Cancel")
|
||||
ruRU("\320\236\321\202\320\274\320\265\320\275\320\260")
|
||||
|
||||
T_("Elements:")
|
||||
ruRU("\320\255\320\273\320\265\320\274\320\265\320\275\321\202\321\213:")
|
||||
|
||||
|
||||
// MapEditor.cpp
|
||||
|
||||
T_("Map Editor")
|
||||
ruRU("\320\240\320\265\320\264\320\260\320\272\321\202\320\276\321\200 \320\272\320\260\321\200\321\202")
|
||||
|
||||
T_("#")
|
||||
ruRU("\342\204\226")
|
||||
|
||||
T_("Level Name")
|
||||
ruRU("\320\235\320\260\320\267\320\262\320\260\320\275\320\270\320\265 \321\215\321\202\320\260\320\266\320\260")
|
||||
|
||||
T_("Save current map before exit?")
|
||||
ruRU("\320\241\320\276\321\205\321\200\320\260\320\275\320\270\321\202\321\214 "
|
||||
"\321\202\320\265\320\272\321\203\321\211\321\203\321\216 \320\272\320\260\321\200\321\202\321\203 "
|
||||
"\320\277\320\265\321\200\320\265\320\264 \320\262\321\213\321\205\320\276\320\264\320\276\320\274?")
|
||||
|
||||
|
||||
// MapEditorMap.cpp
|
||||
|
||||
T_("Save current map before creating new map?")
|
||||
ruRU("\320\241\320\276\321\205\321\200\320\260\320\275\320\270\321\202\321\214 "
|
||||
"\321\202\320\265\320\272\321\203\321\211\321\203\321\216 \320\272\320\260\321\200\321\202\321\203 "
|
||||
"\320\277\320\265\321\200\320\265\320\264 \321\201\320\276\320\267\320\264\320\260\320\275\320\270\320\265\320\274 "
|
||||
"\320\275\320\276\320\262\320\276\320\271?")
|
||||
|
||||
T_("Error while saving map to file!")
|
||||
ruRU("\320\236\321\210\320\270\320\261\320\272\320\260 \320\277\321\200\320\270 "
|
||||
"\321\201\320\276\321\205\321\200\320\260\320\275\320\265\320\275\320\270\320\270 "
|
||||
"\320\272\320\260\321\200\321\202\321\213 \320\262 \321\204\320\260\320\271\320\273!")
|
||||
|
||||
T_("Load Map...")
|
||||
ruRU("\320\227\320\260\320\263\321\200\321\203\320\267\320\272\320\260 \320\272\320\260\321\200\321\202\321\213...")
|
||||
|
||||
T_("No any file to load!")
|
||||
ruRU("\320\235\320\265\321\202 \320\272\320\260\321\200\321\202 \320\264\320\273\321\217 "
|
||||
"\320\267\320\260\320\263\321\200\321\203\320\267\320\272\320\270!")
|
||||
|
||||
T_("File not found: %s")
|
||||
ruRU("\320\244\320\260\320\271\320\273 \320\275\320\265 \320\275\320\260\320\271\320\264\320\265\320\275: "
|
||||
"%s")
|
||||
|
||||
T_("Error while loading map from file: %s")
|
||||
ruRU("\320\236\321\210\320\270\320\261\320\272\320\260 \320\277\321\200\320\270 "
|
||||
"\320\267\320\260\320\263\321\200\321\203\320\267\320\272\320\265 \320\272\320\260\321\200\321\202\321\213 "
|
||||
"\320\270\320\267 \321\204\320\260\320\271\320\273\320\260: %s")
|
||||
|
||||
T_("Map Preview")
|
||||
ruRU("\320\237\321\200\320\276\321\201\320\274\320\276\321\202\321\200 \320\272\320\260\321\200\321\202\321\213")
|
||||
|
||||
T_("Error while loading preview!")
|
||||
ruRU("\320\236\321\210\320\270\320\261\320\272\320\260 \320\277\321\200\320\270 "
|
||||
"\320\267\320\260\320\263\321\200\321\203\320\267\320\272\320\265 \320\272\320\260\321\200\321\202\321\213 "
|
||||
"\320\264\320\273\321\217 \320\277\321\200\320\265\320\264\320\277\321\200\320\276\321\201\320\274\320\276\321\202\321\200\320\260!")
|
||||
|
||||
|
||||
// MapEditorLevel.cpp
|
||||
|
||||
T_("Level #%d")
|
||||
ruRU("%d \321\215\321\202\320\260\320\266")
|
||||
|
||||
T_("Error while loading editor!")
|
||||
ruRU("\320\236\321\210\320\270\320\261\320\272\320\260 \320\277\321\200\320\270 "
|
||||
"\320\267\320\260\320\263\321\200\321\203\320\267\320\272\320\265 \321\200\320\265\320\264\320\260\320\272\321\202\320\276\321\200\320\260 "
|
||||
"\321\215\321\202\320\260\320\266\320\260!")
|
||||
|
||||
T_("Remove the selected level from map?")
|
||||
ruRU("\320\243\320\264\320\260\320\273\320\270\321\202\321\214 \320\262\321\213\320\261\321\200\320\260\320\275\320\275\321\213\320\271 "
|
||||
"\321\215\321\202\320\260\320\266 \320\270\320\267 \320\272\320\260\321\200\321\202\321\213?")
|
||||
|
||||
T_("No undo for this action. Are you sure?")
|
||||
ruRU("\320\224\320\260\320\275\320\275\320\276\320\265 \320\264\320\265\320\271\321\201\321\202\320\262\320\270\320\265 "
|
||||
"\320\275\320\265 \320\276\321\202\320\274\320\265\320\275\320\270\321\202\321\214. "
|
||||
"\320\222\321\213 \321\203\320\262\320\265\321\200\320\265\320\275\321\213?")
|
||||
|
||||
T_("Recalculate mipmaps for moved levels now?")
|
||||
ruRU("\320\237\320\265\321\200\320\265\321\201\321\207\320\270\321\202\320\260\321\202\321\214 "
|
||||
"mipmap-\320\270\320\267\320\276\320\261\321\200\320\260\320\266\320\265\320\275\320\270\321\217 "
|
||||
"\320\264\320\273\321\217 \320\277\320\265\321\200\320\265\320\274\320\265\321\211\320\265\320\275\320\275\321\213\321\205 "
|
||||
"\321\203\321\200\320\276\320\262\320\275\320\265\320\271?")
|
||||
|
||||
T_("Please, select the image for level: %s")
|
||||
ruRU("\320\222\321\213 \320\264\320\276\320\273\320\266\320\275\321\213 \320\262\321\213\320\261\321\200\320\260\321\202\321\214 "
|
||||
"\320\270\320\267\320\276\320\261\321\200\320\260\320\266\320\265\320\275\320\270\320\265 "
|
||||
"\320\264\320\273\321\217 \320\272\320\260\321\200\321\202\321\213: %s")
|
||||
|
||||
T_("Image file not exist: %s")
|
||||
ruRU("\320\244\320\260\320\271\320\273 \321\201 \320\270\320\267\320\276\320\261\321\200\320\260\320\266\320\265\320\275\320\270\320\265\320\274 "
|
||||
"\320\275\320\265 \320\275\320\260\320\271\320\264\320\265\320\275: %s")
|
||||
|
||||
T_("Error while loading image file: %s")
|
||||
ruRU("\320\236\321\210\320\270\320\261\320\272\320\260 \320\277\321\200\320\270 "
|
||||
"\320\267\320\260\320\263\321\200\321\203\320\267\320\272\320\265 \320\270\320\267\320\276\320\261\321\200\320\260\320\266\320\265\320\275\320\270\321\217 "
|
||||
"\320\270\320\267 \321\204\320\260\320\271\320\273\320\260: %s")
|
||||
|
||||
T_("Recalculate all mipmaps for levels?")
|
||||
ruRU("\320\237\320\265\321\200\320\265\321\201\321\207\320\270\321\202\320\260\321\202\321\214 "
|
||||
"mipmap-\320\270\320\267\320\276\320\261\321\200\320\260\320\266\320\265\320\275\320\270\321\217 "
|
||||
"\320\264\320\273\321\217 \320\262\321\201\320\265\321\205 \321\203\321\200\320\276\320\262\320\275\320\265\320\271?")
|
||||
|
||||
|
||||
// LevelEditor.cpp
|
||||
|
||||
T_("Layer Name")
|
||||
ruRU("\320\241\320\273\320\276\320\271")
|
||||
|
||||
T_("Item Name")
|
||||
ruRU("\320\235\320\260\320\267\320\262\320\260\320\275\320\270\320\265")
|
||||
|
||||
T_("Rooms")
|
||||
ruRU("\320\237\320\276\320\274\320\265\321\211\320\265\320\275\320\270\320\265")
|
||||
|
||||
|
||||
// LevelEditorLayer.cpp
|
||||
|
||||
T_("Layer #%d")
|
||||
ruRU("\320\241\320\273\320\276\320\271 \342\204\226")
|
||||
|
||||
T_("Remove the selected layer from level?")
|
||||
ruRU("\320\243\320\264\320\260\320\273\320\270\321\202\321\214 \320\262\321\213\320\261\321\200\320\260\320\275\320\275\321\213\320\271 \321\201\320\273\320\276\320\271 \320\270\320\267 \321\215\321\202\320\260\320\266\320\260?")
|
||||
24
bazaar/MapEditor/MapEditor.upp
Normal file
24
bazaar/MapEditor/MapEditor.upp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
Map,
|
||||
GridCtrl;
|
||||
|
||||
file
|
||||
MapEditorLang.icpp,
|
||||
MapEditor.lay,
|
||||
MapEditor.iml,
|
||||
MapEditor.t,
|
||||
MapEditor.h,
|
||||
MapEditor.cpp,
|
||||
MapEditorMap.cpp,
|
||||
MapEditorLevel.cpp,
|
||||
LevelEditor.h,
|
||||
LevelEditor.cpp,
|
||||
LevelEditorLayer.cpp,
|
||||
LevelEditorItem.cpp,
|
||||
LevelEditorTools.cpp,
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI MT";
|
||||
|
||||
4
bazaar/MapEditor/MapEditorLang.icpp
Normal file
4
bazaar/MapEditor/MapEditorLang.icpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#include "MapEditor.h"
|
||||
|
||||
#define TFILE <MapEditor/MapEditor.t>
|
||||
#include <Core/t.h>
|
||||
138
bazaar/MapEditor/MapEditorLevel.cpp
Normal file
138
bazaar/MapEditor/MapEditorLevel.cpp
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
#include "MapEditor.h"
|
||||
#include "LevelEditor.h"
|
||||
|
||||
void MapEditor::OnAddLevel()
|
||||
{
|
||||
int row = LevelList.GetRowCount();
|
||||
|
||||
Level level;
|
||||
level.SetName(NFormat(t_("Level #%d"), _map.GetLevels().GetCount() + 1));
|
||||
|
||||
level.WhenMapList = THISBACK(OnLevelMapList);
|
||||
level.WhenCalculate = THISBACK1(OnLevelMapCalc, row);
|
||||
if (level.OpenProperties() != IDOK)
|
||||
return;
|
||||
|
||||
_map.GetLevels().Add(level);
|
||||
|
||||
UpdateLevelList();
|
||||
}
|
||||
|
||||
void MapEditor::OnEditLevel()
|
||||
{
|
||||
int row = LevelList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
LevelEditor edit(_map, _map.GetLevels()[row], row);
|
||||
edit.Execute();
|
||||
}
|
||||
|
||||
void MapEditor::OnChangeLevel()
|
||||
{
|
||||
int row = LevelList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
_map.GetLevels()[row].WhenCalculate = THISBACK1(OnLevelMapCalc, row);
|
||||
_map.GetLevels()[row].WhenMapList = THISBACK(OnLevelMapList);
|
||||
_map.GetLevels()[row].OpenProperties();
|
||||
|
||||
UpdateLevelList();
|
||||
}
|
||||
|
||||
void MapEditor::OnRemoveLevel()
|
||||
{
|
||||
int row = LevelList.GetCurrentRow();
|
||||
if (row < 0) return;
|
||||
|
||||
if (!PromptYesNo(t_("Remove the selected level from map?")))
|
||||
return;
|
||||
|
||||
if (!PromptYesNo(t_("No undo for this action. Are you sure?")))
|
||||
return;
|
||||
|
||||
_map.GetLevels().Remove(row);
|
||||
UpdateLevelList();
|
||||
}
|
||||
|
||||
void MapEditor::OnMoveLevel(int s, int e)
|
||||
{
|
||||
_map.GetLevels().Swap(s - 1, e - 1);
|
||||
|
||||
if (PromptOKCancel(t_("Recalculate mipmaps for moved levels now?")))
|
||||
{
|
||||
OnLevelMapCalc( _map.GetLevels()[s - 1], s - 1 );
|
||||
OnLevelMapCalc( _map.GetLevels()[e - 1], e - 1 );
|
||||
}
|
||||
|
||||
SetTimeCallback(1, THISBACK(UpdateLevelList));
|
||||
}
|
||||
|
||||
void MapEditor::OnLevelMapCalc(Level& level, int number)
|
||||
{
|
||||
if (level.GetMapBG().IsEmpty())
|
||||
{
|
||||
Exclamation(NFormat(t_("Please, select the image for level: %s"), level.GetName()));
|
||||
return;
|
||||
}
|
||||
|
||||
String fp = AppendFileName( AppendFileName( GetFileDirectory(GetExeFilePath()), "Maps"),
|
||||
level.GetMapBG());
|
||||
|
||||
if (!FileExists(fp))
|
||||
{
|
||||
Exclamation(NFormat(t_("Image file not exist: %s"), fp));
|
||||
return;
|
||||
}
|
||||
|
||||
String name = level.GetName();
|
||||
double zx = level.GetZoomDX();
|
||||
Size pz = level.GetPageSize();
|
||||
Size sz = level.GetCellSize();
|
||||
|
||||
FileIn in(fp);
|
||||
One<StreamRaster> r = StreamRaster::OpenAny(in);
|
||||
if (!r)
|
||||
{
|
||||
Exclamation(NFormat(t_("Error while loading image file: %s"), fp));
|
||||
return;
|
||||
}
|
||||
|
||||
Image img = r->GetImage();
|
||||
Calculate(sz.cx, sz.cy, pz.cx, pz.cy, zx,
|
||||
NFormat("%s-%d", _map.GetName(), number + 1), img);
|
||||
}
|
||||
|
||||
void MapEditor::OnLevelMapList(VectorMapEx<String, Value>& mapList)
|
||||
{
|
||||
Vector<String> files = GetDirectoryFiles(
|
||||
AppendFileName( GetFileDirectory(GetExeFilePath()), "Maps"));
|
||||
Sort(files);
|
||||
for (int i = 0; i < files.GetCount(); ++i)
|
||||
mapList.Add(files[i], files[i]);
|
||||
}
|
||||
|
||||
void MapEditor::CalculateAllPrompt()
|
||||
{
|
||||
if (PromptYesNo(t_("Recalculate all mipmaps for levels?")))
|
||||
for (int i = 0; i < _map.GetLevels().GetCount(); ++i)
|
||||
OnLevelMapCalc( _map.GetLevels()[i], i );
|
||||
}
|
||||
|
||||
void MapEditor::UpdateLevelList()
|
||||
{
|
||||
int row = LevelList.GetCurrentRow();
|
||||
|
||||
LevelList.Clear();
|
||||
for (int i = 0; i < _map.GetLevels().GetCount(); ++i)
|
||||
{
|
||||
LevelList.Add(i + 1, _map.GetLevels()[i].GetName());
|
||||
}
|
||||
|
||||
if (row >= 0 && row < LevelList.GetRowCount())
|
||||
LevelList.SetCursor(row);
|
||||
|
||||
if (row < 0 && LevelList.GetRowCount())
|
||||
LevelList.SetCursor(0);
|
||||
|
||||
UpdateEditorCtrls();
|
||||
}
|
||||
95
bazaar/MapEditor/MapEditorMap.cpp
Normal file
95
bazaar/MapEditor/MapEditorMap.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#include "MapEditor.h"
|
||||
|
||||
void MapEditor::OnNewMap()
|
||||
{
|
||||
int r = PromptYesNoCancel(t_("Save current map before creating new map?"));
|
||||
|
||||
if (r == IDYES)
|
||||
OnSaveMap();
|
||||
|
||||
if (r == IDCANCEL)
|
||||
return;
|
||||
|
||||
_map.Clear();
|
||||
|
||||
UpdateLevelList();
|
||||
UpdateEditorCtrls();
|
||||
}
|
||||
|
||||
void MapEditor::OnSaveMap()
|
||||
{
|
||||
CalculateAllPrompt();
|
||||
|
||||
if (!StoreAsXMLFile(_map, _map.GetName(),
|
||||
AppendFileName(
|
||||
AppendFileName(GetFileDirectory(GetExeFilePath()), "Mipmaps"),
|
||||
_map.GetName() + ".map"
|
||||
)))
|
||||
{
|
||||
Exclamation(t_("Error while saving map to file!"));
|
||||
}
|
||||
|
||||
UpdateEditorCtrls();
|
||||
}
|
||||
|
||||
void MapEditor::OnLoadMap()
|
||||
{
|
||||
WithMapLoadLayout<TopWindow> dlg;
|
||||
CtrlLayoutOKCancel(dlg, t_("Load Map..."));
|
||||
|
||||
String dir = AppendFileName( GetFileDirectory(GetExeFilePath()), "Mipmaps");
|
||||
Vector<String> files = GetDirectoryFiles(dir, "*.map");
|
||||
Sort(files);
|
||||
|
||||
if (files.GetCount() <= 0)
|
||||
{
|
||||
Exclamation(t_("No any file to load!"));
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < files.GetCount(); ++i)
|
||||
dlg.MapList.Add(files[i], files[i]);
|
||||
dlg.MapList.SetIndex(0);
|
||||
|
||||
if (dlg.Execute() != IDOK)
|
||||
return;
|
||||
|
||||
String fp = AppendFileName(dir, (~dlg.MapList).ToString());
|
||||
|
||||
if (!FileExists(fp))
|
||||
{
|
||||
Exclamation(NFormat(t_("File not found: %s"), fp));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!LoadFromXMLFile(_map, fp))
|
||||
{
|
||||
Exclamation(NFormat(t_("Error while loading map from file: %s"), fp));
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateLevelList();
|
||||
UpdateEditorCtrls();
|
||||
}
|
||||
|
||||
void MapEditor::OnViewMap()
|
||||
{
|
||||
WithPreviewLayout<TopWindow> dlg;
|
||||
CtrlLayout(dlg, t_("Map Preview"));
|
||||
dlg.Sizeable().MaximizeBox();
|
||||
dlg.View.HighQuality(true);
|
||||
|
||||
if (!dlg.View.LoadMap(_map))
|
||||
{
|
||||
Exclamation(t_("Error while loading preview!"));
|
||||
return;
|
||||
}
|
||||
|
||||
dlg.Execute();
|
||||
}
|
||||
|
||||
void MapEditor::OnMapProperties()
|
||||
{
|
||||
_map.OpenProperties();
|
||||
UpdateEditorCtrls();
|
||||
}
|
||||
9
bazaar/MapEditor/init
Normal file
9
bazaar/MapEditor/init
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _MapEditor_icpp_init_stub
|
||||
#define _MapEditor_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Map/init"
|
||||
#include "GridCtrl/init"
|
||||
#define BLITZ_INDEX__ F7451C483F16EAEF2B514EBA83339BB5F
|
||||
#include "MapEditorLang.icpp"
|
||||
#undef BLITZ_INDEX__
|
||||
#endif
|
||||
8
bazaar/MapEditor/main.cpp
Normal file
8
bazaar/MapEditor/main.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "MapEditor.h"
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
SetLanguage(LNGFromText("RU-RU"));
|
||||
Ctrl::SetAppName(" ");
|
||||
MapEditor().Run();
|
||||
}
|
||||
10
bazaar/MapRenderTest/MapRenderTest.upp
Normal file
10
bazaar/MapRenderTest/MapRenderTest.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
Map;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI MT";
|
||||
|
||||
5
bazaar/MapRenderTest/init
Normal file
5
bazaar/MapRenderTest/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _MapRenderTest_icpp_init_stub
|
||||
#define _MapRenderTest_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Map/init"
|
||||
#endif
|
||||
43
bazaar/MapRenderTest/main.cpp
Normal file
43
bazaar/MapRenderTest/main.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <Map/Map.h>
|
||||
|
||||
class TestWindow : public TopWindow
|
||||
{
|
||||
typedef TestWindow CLASSNAME;
|
||||
MapView View;
|
||||
|
||||
public:
|
||||
TestWindow()
|
||||
{
|
||||
Sizeable().MinimizeBox().MaximizeBox();
|
||||
Add(View.SizePos());
|
||||
|
||||
View.LoadMap(AppendFileName(AppendFileName(GetFileDirectory(GetExeFilePath()), "Mipmaps"),
|
||||
"marcos.map"));
|
||||
View.HighQuality(false);
|
||||
View.ShowSearch();
|
||||
|
||||
// here link to callback
|
||||
PolygonItem::WhenClick = THISBACK(OnRoomClick);
|
||||
}
|
||||
|
||||
// your method or function to react on clicks
|
||||
void OnRoomClick(Ptr<PolygonItem> room)
|
||||
{
|
||||
Point p = GetRect().TopLeft() + ViewToScene(~room, room->GetCenter());
|
||||
|
||||
TopWindow popup;
|
||||
popup.NoCenter();
|
||||
popup.SetRect(Rect(p, Size(150, 50)));
|
||||
|
||||
Label text;
|
||||
popup.Add(text.SizePos());
|
||||
text = "Name: " + room->GetName();
|
||||
|
||||
popup.Execute();
|
||||
}
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
TestWindow().Run();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue