mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-05 17:44:55 -06:00
Draw: Font, Drawing, Painting, Image now support Xmlize and Jsonize
git-svn-id: svn://ultimatepp.org/upp/trunk@4950 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
6a06a95b17
commit
9c66fcab3e
14 changed files with 2198 additions and 2143 deletions
|
|
@ -25,7 +25,7 @@ inline dword RGB(byte r, byte g, byte b) { return r | (g << 8) | (b << 1
|
|||
|
||||
const int COLOR_V = 39;
|
||||
|
||||
class Color : public AssignValueTypeNo<Color, COLOR_V, Moveable<Color> > {
|
||||
class Color : public ValueType<Color, COLOR_V, Moveable<Color> > {
|
||||
protected:
|
||||
dword color;
|
||||
|
||||
|
|
|
|||
|
|
@ -348,3 +348,36 @@ void Jsonize(JsonIO& io, ArrayIndex<T>& var)
|
|||
{
|
||||
JsonizeIndex<ArrayIndex<T>, T>(io, var);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void XmlizeBySerialize(XmlIO& xio, T& x)
|
||||
{
|
||||
String h;
|
||||
if(xio.IsStoring())
|
||||
h = HexString(StoreAsString(x));
|
||||
xio.Attr("data", h);
|
||||
if(xio.IsLoading())
|
||||
try {
|
||||
LoadFromString(x, ScanHexString(h));
|
||||
}
|
||||
catch(LoadingError) {
|
||||
throw XmlError("xmlize by serialize error");
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void JsonizeBySerialize(JsonIO& jio, T& x)
|
||||
{
|
||||
String h;
|
||||
if(jio.IsStoring())
|
||||
h = HexString(StoreAsString(x));
|
||||
jio("data", h);
|
||||
if(jio.IsLoading())
|
||||
try {
|
||||
LoadFromString(x, ScanHexString(h));
|
||||
}
|
||||
catch(LoadingError) {
|
||||
throw JsonizeError("jsonize by serialize error");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,6 +148,9 @@ public:
|
|||
|
||||
Value(Void *p) { ptr = p; }
|
||||
const Void *GetVoidPtr() const { return ptr; }
|
||||
|
||||
template <class T> // Forward compatibility
|
||||
static void Register(const char *name = NULL);
|
||||
};
|
||||
|
||||
#define VALUE_COMPARE(T) \
|
||||
|
|
@ -260,6 +263,11 @@ public:
|
|||
void operator=(const AssignValueTypeNo&) {} // MSC 6.0 empty base class bug fix
|
||||
};
|
||||
|
||||
template <class T, dword type, class B = EmptyClass> // Forward compatiblity
|
||||
class ValueType : public AssignValueTypeNo<T, type, B> {};
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
dword GetValueTypeNo() { return ValueTypeNo((T*)NULL); }
|
||||
|
||||
|
|
@ -474,6 +482,12 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void Value::Register(const char *)
|
||||
{
|
||||
RichValue<T>::Register();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline Value RichToValue(const T& data) { return RichValue<T>(data); }
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,9 @@ NAMESPACE_UPP
|
|||
|
||||
//#BLITZ_APPROVE
|
||||
|
||||
#ifdef SVO_VALUE
|
||||
INITBLOCK {
|
||||
Value::Register<Uuid>("Uuid");
|
||||
}
|
||||
#else
|
||||
INITBLOCK {
|
||||
RichValue<Uuid>::Register();
|
||||
}
|
||||
#endif
|
||||
|
||||
void Uuid::Serialize(Stream& s) {
|
||||
int version = 0;
|
||||
|
|
|
|||
|
|
@ -1,357 +1,357 @@
|
|||
#ifdef SVO_VALUE
|
||||
|
||||
Value Scan(dword stdtype, const String& text, const Value& def = Null);
|
||||
|
||||
inline const String& Nvl(const String& a, const String& b) { return IsNull(a) ? b : a; }
|
||||
inline int Nvl(int a, int b) { return IsNull(a) ? b : a; }
|
||||
inline int64 Nvl(int64 a, int64 b) { return IsNull(a) ? b : a; }
|
||||
inline double Nvl(double a, double b) { return IsNull(a) ? b : a; }
|
||||
inline Date Nvl(Date a, Date b) { return IsNull(a) ? b : a; }
|
||||
inline Time Nvl(Time a, Time b) { return IsNull(a) ? b : a; }
|
||||
|
||||
inline int Nvl(int a) { return Nvl(a, 0); }
|
||||
inline int64 Nvl(int64 a) { return Nvl(a, (int64)0); }
|
||||
inline double Nvl(double a) { return Nvl(a, 0.0); }
|
||||
|
||||
int StdValueCompare(const Value& a, const Value& b, int language);
|
||||
int StdValueCompare(const Value& a, const Value& b);
|
||||
|
||||
int StdValueCompareDesc(const Value& a, const Value& b, int language);
|
||||
int StdValueCompareDesc(const Value& a, const Value& b);
|
||||
|
||||
struct ValueOrder {
|
||||
virtual bool operator()(const Value& a, const Value& b) const = 0;
|
||||
virtual ~ValueOrder() {}
|
||||
};
|
||||
|
||||
struct StdValueOrder : ValueOrder {
|
||||
int language;
|
||||
|
||||
virtual bool operator()(const Value& a, const Value& b) const;
|
||||
|
||||
StdValueOrder(int l = -1);
|
||||
};
|
||||
|
||||
struct FnValueOrder : ValueOrder {
|
||||
int (*fn)(const Value& a, const Value& b);
|
||||
|
||||
virtual bool operator()(const Value& a, const Value& b) const;
|
||||
|
||||
FnValueOrder(int (*fn)(const Value& a, const Value& b)) : fn(fn) {}
|
||||
};
|
||||
|
||||
struct ValuePairOrder {
|
||||
virtual bool operator()(const Value& keya, const Value& valuea, const Value& keyb, const Value& valueb) const = 0;
|
||||
virtual ~ValuePairOrder() {}
|
||||
};
|
||||
|
||||
struct StdValuePairOrder : ValuePairOrder {
|
||||
int language;
|
||||
|
||||
virtual bool operator()(const Value& keya, const Value& valuea, const Value& keyb, const Value& valueb) const;
|
||||
|
||||
StdValuePairOrder(int l = -1);
|
||||
};
|
||||
|
||||
struct FnValuePairOrder : ValuePairOrder {
|
||||
int (*fn)(const Value& k1, const Value& v1, const Value& k2, const Value& v2);
|
||||
|
||||
virtual bool operator()(const Value& keya, const Value& valuea, const Value& keyb, const Value& valueb) const;
|
||||
|
||||
FnValuePairOrder(int (*fn)(const Value& k1, const Value& v1, const Value& k2, const Value& v2)) : fn(fn) {}
|
||||
};
|
||||
|
||||
class Id : Moveable<Id> {
|
||||
String id;
|
||||
|
||||
public:
|
||||
const String& ToString() const { return id; }
|
||||
dword GetHashValue() const { return UPP::GetHashValue(id); }
|
||||
bool IsNull() const { return UPP::IsNull(id); }
|
||||
|
||||
operator const String&() const { return ToString(); }
|
||||
const String& operator~() const { return ToString(); }
|
||||
bool operator==(const Id& b) const { return id == b.id; }
|
||||
bool operator!=(const Id& b) const { return id != b.id; }
|
||||
|
||||
operator bool() const { return id.GetCount(); }
|
||||
|
||||
Id() {}
|
||||
Id(const String& s) { id = s; }
|
||||
Id(const char *s) { id = s; }
|
||||
};
|
||||
|
||||
struct RefManager {
|
||||
virtual int GetType() = 0;
|
||||
virtual Value GetValue(const void *) { return Null; }
|
||||
virtual bool IsNull(const void *) { return false; }
|
||||
virtual void SetValue(void *, const Value& v) { NEVER(); }
|
||||
virtual void SetNull(void *) { NEVER(); }
|
||||
virtual ~RefManager() {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct StdRef : public RefManager {
|
||||
virtual void SetValue(void *p, const Value& v) { *(T *) p = (T)v; }
|
||||
virtual Value GetValue(const void *p) { return *(const T *) p; }
|
||||
virtual int GetType() { return GetValueTypeNo<T>(); }
|
||||
virtual bool IsNull(const void *p) { return UPP::IsNull(*(T *) p); }
|
||||
virtual void SetNull(void *p) { UPP::SetNull(*(T *)p); }
|
||||
virtual ~StdRef() {}
|
||||
};
|
||||
|
||||
class Ref : Moveable<Ref> {
|
||||
protected:
|
||||
RefManager *m;
|
||||
void *ptr;
|
||||
struct ValueRef;
|
||||
|
||||
public:
|
||||
dword GetType() const { return m ? m->GetType() : VOID_V; }
|
||||
bool IsNull() const { return m ? m->IsNull(ptr) : true; }
|
||||
|
||||
void *GetVoidPtr() const { return ptr; }
|
||||
|
||||
template <class T>
|
||||
bool Is() const { return GetType() == GetValueTypeNo<T>(); } // VALUE_V!!!
|
||||
template <class T>
|
||||
T& Get() const { ASSERT(GetValueTypeNo<T>() == GetType()); return *(T *)GetVoidPtr(); }
|
||||
|
||||
void SetNull() { if(m) m->SetNull(ptr); }
|
||||
Value GetValue() const { return m ? m->GetValue(ptr) : Value(); }
|
||||
void SetValue(const Value& v) { ASSERT(m); m->SetValue(ptr, v); }
|
||||
|
||||
operator Value() const { return GetValue(); }
|
||||
Value operator~() const { return GetValue(); }
|
||||
Ref& operator=(const Value& v) { SetValue(v); return *this; }
|
||||
|
||||
Ref(String& s);
|
||||
Ref(WString& s);
|
||||
Ref(int& i);
|
||||
Ref(int64& i);
|
||||
Ref(double& d);
|
||||
Ref(bool& b);
|
||||
Ref(Date& d);
|
||||
Ref(Time& t);
|
||||
Ref(Value& v);
|
||||
Ref(void *_ptr, RefManager *_m) { ptr = _ptr, m = _m; }
|
||||
Ref(const ValueTypeRef& r);
|
||||
Ref() { ptr = m = NULL; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
T& GetRef(Ref r, T *x = NULL) {
|
||||
ASSERT(GetValueTypeNo<T>() == r.GetType());
|
||||
return *(T *) r.GetVoidPtr();
|
||||
}
|
||||
|
||||
inline String& RefString(Ref f) { return GetRef<String>(f); }
|
||||
inline WString& RefWString(Ref f) { return GetRef<WString>(f); }
|
||||
inline int& RefInt(Ref f) { return GetRef<int>(f); }
|
||||
inline int64& RefInt64(Ref f) { return GetRef<int64>(f); }
|
||||
inline double& RefDouble(Ref f) { return GetRef<double>(f); }
|
||||
inline bool& RefBool(Ref f) { return GetRef<bool>(f); }
|
||||
inline Date& RefDate(Ref f) { return GetRef<Date>(f); }
|
||||
inline Time& RefTime(Ref f) { return GetRef<Time>(f); }
|
||||
inline Value& RefValue(Ref f) { ASSERT(f.GetType() == VALUE_V);
|
||||
return *(Value *)f.GetVoidPtr(); }
|
||||
|
||||
template <class T>
|
||||
Ref AsRef(T& x) {
|
||||
return Ref(&x, &Single< StdRef<T> >());
|
||||
}
|
||||
|
||||
struct ValueTypeRef {
|
||||
RefManager *m;
|
||||
void *ptr;
|
||||
};
|
||||
|
||||
inline
|
||||
Ref::Ref(const ValueTypeRef& r)
|
||||
{
|
||||
ptr = r.ptr;
|
||||
m = r.m;
|
||||
}
|
||||
|
||||
template <class T, dword type, class B>
|
||||
ValueType<T, type, B>::operator ValueTypeRef()
|
||||
{
|
||||
ValueTypeRef h;
|
||||
h.ptr = this;
|
||||
h.m = &Single< StdRef<T> >();
|
||||
return h;
|
||||
}
|
||||
|
||||
#define E__Value(I) Value p##I
|
||||
#define E__Ref(I) Ref p##I
|
||||
|
||||
// ---------------------- Value Array
|
||||
|
||||
class ValueArray : AssignValueTypeNo<ValueArray, VALUEARRAY_V, Moveable<ValueArray> > {
|
||||
struct Data : Value::Void {
|
||||
virtual dword GetType() const { return VALUEARRAY_V; }
|
||||
virtual bool IsNull() const;
|
||||
virtual void Serialize(Stream& s);
|
||||
virtual void Xmlize(XmlIO& xio);
|
||||
virtual void Jsonize(JsonIO& jio);
|
||||
virtual unsigned GetHashValue() const;
|
||||
virtual bool IsEqual(const Value::Void *p);
|
||||
virtual String AsString() const;
|
||||
|
||||
int GetRefCount() const { return AtomicRead(refcount); }
|
||||
|
||||
Vector<Value> data;
|
||||
};
|
||||
struct NullData : Data {};
|
||||
Data *data;
|
||||
|
||||
Vector<Value>& Create();
|
||||
Vector<Value>& Clone();
|
||||
void Init0();
|
||||
|
||||
friend Value::Void *ValueArrayDataCreate();
|
||||
friend class Value;
|
||||
|
||||
public:
|
||||
ValueArray() { Init0(); }
|
||||
ValueArray(const ValueArray& v);
|
||||
explicit ValueArray(pick_ Vector<Value>& values);
|
||||
explicit ValueArray(const Vector<Value>& values, int deep);
|
||||
~ValueArray();
|
||||
|
||||
ValueArray& operator=(const ValueArray& v);
|
||||
|
||||
operator Value() const;
|
||||
ValueArray(const Value& src);
|
||||
|
||||
ValueArray(const Nuller&) { Init0(); }
|
||||
bool IsNullInstance() const { return IsEmpty(); }
|
||||
|
||||
void Clear();
|
||||
void SetCount(int n);
|
||||
void SetCount(int n, const Value& v);
|
||||
int GetCount() const { return data->data.GetCount(); }
|
||||
bool IsEmpty() const { return data->data.IsEmpty(); }
|
||||
|
||||
void Add(const Value& v);
|
||||
ValueArray& operator<<(const Value& v) { Add(v); return *this; }
|
||||
void Set(int i, const Value& v);
|
||||
const Value& Get(int i) const;
|
||||
Value GetAndClear(int i);
|
||||
const Vector<Value>& Get() const { return data->data; }
|
||||
|
||||
void Remove(int i, int count = 1);
|
||||
void Insert(int i, const ValueArray& va);
|
||||
void Append(const ValueArray& va) { Insert(GetCount(), va); }
|
||||
|
||||
const Value& operator[](int i) const { return Get(i); }
|
||||
|
||||
unsigned GetHashValue() const { return data->GetHashValue(); }
|
||||
void Serialize(Stream& s);
|
||||
void Jsonize(JsonIO& jio);
|
||||
String ToString() const;
|
||||
|
||||
bool operator==(const ValueArray& v) const;
|
||||
bool operator!=(const ValueArray& v) const { return !operator==(v); }
|
||||
};
|
||||
|
||||
template<>
|
||||
String AsString(const ValueArray& v);
|
||||
|
||||
class ValueMap : AssignValueTypeNo<ValueMap, VALUEMAP_V, Moveable<ValueMap> >{
|
||||
struct Data : Value::Void {
|
||||
virtual dword GetType() const { return VALUEMAP_V; }
|
||||
virtual bool IsNull() const;
|
||||
virtual void Serialize(Stream& s);
|
||||
virtual void Xmlize(XmlIO& xio);
|
||||
virtual void Jsonize(JsonIO& jio);
|
||||
virtual unsigned GetHashValue() const;
|
||||
virtual bool IsEqual(const Value::Void *p);
|
||||
virtual String AsString() const;
|
||||
|
||||
const Value& Get(const Value& key) const;
|
||||
|
||||
Index<Value> key;
|
||||
ValueArray value;
|
||||
};
|
||||
|
||||
struct NullData : Data {};
|
||||
Data *data;
|
||||
|
||||
Data& Create();
|
||||
Data& Clone();
|
||||
void Init0();
|
||||
|
||||
friend Value::Void *ValueMapDataCreate();
|
||||
friend class Value;
|
||||
|
||||
public:
|
||||
ValueMap() { Init0(); }
|
||||
ValueMap(const ValueMap& v);
|
||||
ValueMap(pick_ Index<Value>& k, pick_ Vector<Value>& v);
|
||||
ValueMap(const Index<Value>& k, const Vector<Value>& v, int deep);
|
||||
~ValueMap();
|
||||
|
||||
ValueMap& operator=(const ValueMap& v);
|
||||
|
||||
operator Value() const;
|
||||
ValueMap(const Value& src);
|
||||
|
||||
ValueMap(const Nuller&) { Init0(); }
|
||||
bool IsNullInstance() const { return IsEmpty(); }
|
||||
|
||||
void Clear();
|
||||
int GetCount() const { return data->value.GetCount(); }
|
||||
bool IsEmpty() const { return data->value.IsEmpty(); }
|
||||
const Value& GetKey(int i) const { return data->key[i]; }
|
||||
const Value& GetValue(int i) const { return data->value[i]; }
|
||||
|
||||
void Add(const Value& key, const Value& value);
|
||||
void Add(const String& s, const Value& value) { Add(Value(s), value); }
|
||||
void Add(const char *s, const Value& value) { Add(Value(s), value); }
|
||||
void Add(Id id, const Value& value) { Add(Value(id.ToString()), value); }
|
||||
|
||||
void Set(const Value& key, const Value& value);
|
||||
void Set(const String& s, const Value& value) { Set(Value(s), value); }
|
||||
void Set(const char *s, const Value& value) { Set(Value(s), value); }
|
||||
void Set(Id id, const Value& value) { Set(Value(id.ToString()), value); }
|
||||
|
||||
void SetAt(int i, const Value& v);
|
||||
void SetKey(int i, const Value& k);
|
||||
void SetKey(int i, const String& s) { SetKey(i, Value(s)); }
|
||||
void SetKey(int i, const char* s) { SetKey(i, Value(s)); }
|
||||
void SetKey(int i, Id id) { SetKey(i, Value(id.ToString())); }
|
||||
void Remove(int i);
|
||||
|
||||
const Index<Value>& GetKeys() const { return data->key; }
|
||||
ValueArray GetValues() const { return data->value; }
|
||||
|
||||
operator ValueArray() const { return GetValues(); }
|
||||
|
||||
const Value& operator[](const Value& k) const;
|
||||
const Value& operator[](const String& s) const{ return operator[](Value(s)); }
|
||||
const Value& operator[](const char *s) const { return operator[](Value(s)); }
|
||||
const Value& operator[](const Id& k) const { return operator[](Value(k.ToString())); }
|
||||
|
||||
Value GetAndClear(const Value& key);
|
||||
|
||||
unsigned GetHashValue() const { return data->GetHashValue(); }
|
||||
void Serialize(Stream& s);
|
||||
void Jsonize(JsonIO& jio);
|
||||
String ToString() const { return data->AsString(); }
|
||||
|
||||
bool operator==(const ValueMap& v) const;
|
||||
bool operator!=(const ValueMap& v) const { return !operator==(v); }
|
||||
};
|
||||
|
||||
class ValueGen {
|
||||
public:
|
||||
virtual Value Get() = 0;
|
||||
Value operator++() { return Get(); }
|
||||
virtual ~ValueGen() {}
|
||||
};
|
||||
|
||||
|
||||
#include "Value.hpp"
|
||||
|
||||
#ifdef SVO_VALUE
|
||||
|
||||
Value Scan(dword stdtype, const String& text, const Value& def = Null);
|
||||
|
||||
inline const String& Nvl(const String& a, const String& b) { return IsNull(a) ? b : a; }
|
||||
inline int Nvl(int a, int b) { return IsNull(a) ? b : a; }
|
||||
inline int64 Nvl(int64 a, int64 b) { return IsNull(a) ? b : a; }
|
||||
inline double Nvl(double a, double b) { return IsNull(a) ? b : a; }
|
||||
inline Date Nvl(Date a, Date b) { return IsNull(a) ? b : a; }
|
||||
inline Time Nvl(Time a, Time b) { return IsNull(a) ? b : a; }
|
||||
|
||||
inline int Nvl(int a) { return Nvl(a, 0); }
|
||||
inline int64 Nvl(int64 a) { return Nvl(a, (int64)0); }
|
||||
inline double Nvl(double a) { return Nvl(a, 0.0); }
|
||||
|
||||
int StdValueCompare(const Value& a, const Value& b, int language);
|
||||
int StdValueCompare(const Value& a, const Value& b);
|
||||
|
||||
int StdValueCompareDesc(const Value& a, const Value& b, int language);
|
||||
int StdValueCompareDesc(const Value& a, const Value& b);
|
||||
|
||||
struct ValueOrder {
|
||||
virtual bool operator()(const Value& a, const Value& b) const = 0;
|
||||
virtual ~ValueOrder() {}
|
||||
};
|
||||
|
||||
struct StdValueOrder : ValueOrder {
|
||||
int language;
|
||||
|
||||
virtual bool operator()(const Value& a, const Value& b) const;
|
||||
|
||||
StdValueOrder(int l = -1);
|
||||
};
|
||||
|
||||
struct FnValueOrder : ValueOrder {
|
||||
int (*fn)(const Value& a, const Value& b);
|
||||
|
||||
virtual bool operator()(const Value& a, const Value& b) const;
|
||||
|
||||
FnValueOrder(int (*fn)(const Value& a, const Value& b)) : fn(fn) {}
|
||||
};
|
||||
|
||||
struct ValuePairOrder {
|
||||
virtual bool operator()(const Value& keya, const Value& valuea, const Value& keyb, const Value& valueb) const = 0;
|
||||
virtual ~ValuePairOrder() {}
|
||||
};
|
||||
|
||||
struct StdValuePairOrder : ValuePairOrder {
|
||||
int language;
|
||||
|
||||
virtual bool operator()(const Value& keya, const Value& valuea, const Value& keyb, const Value& valueb) const;
|
||||
|
||||
StdValuePairOrder(int l = -1);
|
||||
};
|
||||
|
||||
struct FnValuePairOrder : ValuePairOrder {
|
||||
int (*fn)(const Value& k1, const Value& v1, const Value& k2, const Value& v2);
|
||||
|
||||
virtual bool operator()(const Value& keya, const Value& valuea, const Value& keyb, const Value& valueb) const;
|
||||
|
||||
FnValuePairOrder(int (*fn)(const Value& k1, const Value& v1, const Value& k2, const Value& v2)) : fn(fn) {}
|
||||
};
|
||||
|
||||
class Id : Moveable<Id> {
|
||||
String id;
|
||||
|
||||
public:
|
||||
const String& ToString() const { return id; }
|
||||
dword GetHashValue() const { return UPP::GetHashValue(id); }
|
||||
bool IsNull() const { return UPP::IsNull(id); }
|
||||
|
||||
operator const String&() const { return ToString(); }
|
||||
const String& operator~() const { return ToString(); }
|
||||
bool operator==(const Id& b) const { return id == b.id; }
|
||||
bool operator!=(const Id& b) const { return id != b.id; }
|
||||
|
||||
operator bool() const { return id.GetCount(); }
|
||||
|
||||
Id() {}
|
||||
Id(const String& s) { id = s; }
|
||||
Id(const char *s) { id = s; }
|
||||
};
|
||||
|
||||
struct RefManager {
|
||||
virtual int GetType() = 0;
|
||||
virtual Value GetValue(const void *) { return Null; }
|
||||
virtual bool IsNull(const void *) { return false; }
|
||||
virtual void SetValue(void *, const Value& v) { NEVER(); }
|
||||
virtual void SetNull(void *) { NEVER(); }
|
||||
virtual ~RefManager() {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct StdRef : public RefManager {
|
||||
virtual void SetValue(void *p, const Value& v) { *(T *) p = (T)v; }
|
||||
virtual Value GetValue(const void *p) { return *(const T *) p; }
|
||||
virtual int GetType() { return GetValueTypeNo<T>(); }
|
||||
virtual bool IsNull(const void *p) { return UPP::IsNull(*(T *) p); }
|
||||
virtual void SetNull(void *p) { UPP::SetNull(*(T *)p); }
|
||||
virtual ~StdRef() {}
|
||||
};
|
||||
|
||||
class Ref : Moveable<Ref> {
|
||||
protected:
|
||||
RefManager *m;
|
||||
void *ptr;
|
||||
struct ValueRef;
|
||||
|
||||
public:
|
||||
dword GetType() const { return m ? m->GetType() : VOID_V; }
|
||||
bool IsNull() const { return m ? m->IsNull(ptr) : true; }
|
||||
|
||||
void *GetVoidPtr() const { return ptr; }
|
||||
|
||||
template <class T>
|
||||
bool Is() const { return GetType() == GetValueTypeNo<T>(); } // VALUE_V!!!
|
||||
template <class T>
|
||||
T& Get() const { ASSERT(GetValueTypeNo<T>() == GetType()); return *(T *)GetVoidPtr(); }
|
||||
|
||||
void SetNull() { if(m) m->SetNull(ptr); }
|
||||
Value GetValue() const { return m ? m->GetValue(ptr) : Value(); }
|
||||
void SetValue(const Value& v) { ASSERT(m); m->SetValue(ptr, v); }
|
||||
|
||||
operator Value() const { return GetValue(); }
|
||||
Value operator~() const { return GetValue(); }
|
||||
Ref& operator=(const Value& v) { SetValue(v); return *this; }
|
||||
|
||||
Ref(String& s);
|
||||
Ref(WString& s);
|
||||
Ref(int& i);
|
||||
Ref(int64& i);
|
||||
Ref(double& d);
|
||||
Ref(bool& b);
|
||||
Ref(Date& d);
|
||||
Ref(Time& t);
|
||||
Ref(Value& v);
|
||||
Ref(void *_ptr, RefManager *_m) { ptr = _ptr, m = _m; }
|
||||
Ref(const ValueTypeRef& r);
|
||||
Ref() { ptr = m = NULL; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
T& GetRef(Ref r, T *x = NULL) {
|
||||
ASSERT(GetValueTypeNo<T>() == r.GetType());
|
||||
return *(T *) r.GetVoidPtr();
|
||||
}
|
||||
|
||||
inline String& RefString(Ref f) { return GetRef<String>(f); }
|
||||
inline WString& RefWString(Ref f) { return GetRef<WString>(f); }
|
||||
inline int& RefInt(Ref f) { return GetRef<int>(f); }
|
||||
inline int64& RefInt64(Ref f) { return GetRef<int64>(f); }
|
||||
inline double& RefDouble(Ref f) { return GetRef<double>(f); }
|
||||
inline bool& RefBool(Ref f) { return GetRef<bool>(f); }
|
||||
inline Date& RefDate(Ref f) { return GetRef<Date>(f); }
|
||||
inline Time& RefTime(Ref f) { return GetRef<Time>(f); }
|
||||
inline Value& RefValue(Ref f) { ASSERT(f.GetType() == VALUE_V);
|
||||
return *(Value *)f.GetVoidPtr(); }
|
||||
|
||||
template <class T>
|
||||
Ref AsRef(T& x) {
|
||||
return Ref(&x, &Single< StdRef<T> >());
|
||||
}
|
||||
|
||||
struct ValueTypeRef {
|
||||
RefManager *m;
|
||||
void *ptr;
|
||||
};
|
||||
|
||||
inline
|
||||
Ref::Ref(const ValueTypeRef& r)
|
||||
{
|
||||
ptr = r.ptr;
|
||||
m = r.m;
|
||||
}
|
||||
|
||||
template <class T, dword type, class B>
|
||||
ValueType<T, type, B>::operator ValueTypeRef()
|
||||
{
|
||||
ValueTypeRef h;
|
||||
h.ptr = this;
|
||||
h.m = &Single< StdRef<T> >();
|
||||
return h;
|
||||
}
|
||||
|
||||
#define E__Value(I) Value p##I
|
||||
#define E__Ref(I) Ref p##I
|
||||
|
||||
// ---------------------- Value Array
|
||||
|
||||
class ValueArray : ValueType<ValueArray, VALUEARRAY_V, Moveable<ValueArray> > {
|
||||
struct Data : Value::Void {
|
||||
virtual dword GetType() const { return VALUEARRAY_V; }
|
||||
virtual bool IsNull() const;
|
||||
virtual void Serialize(Stream& s);
|
||||
virtual void Xmlize(XmlIO& xio);
|
||||
virtual void Jsonize(JsonIO& jio);
|
||||
virtual unsigned GetHashValue() const;
|
||||
virtual bool IsEqual(const Value::Void *p);
|
||||
virtual String AsString() const;
|
||||
|
||||
int GetRefCount() const { return AtomicRead(refcount); }
|
||||
|
||||
Vector<Value> data;
|
||||
};
|
||||
struct NullData : Data {};
|
||||
Data *data;
|
||||
|
||||
Vector<Value>& Create();
|
||||
Vector<Value>& Clone();
|
||||
void Init0();
|
||||
|
||||
friend Value::Void *ValueArrayDataCreate();
|
||||
friend class Value;
|
||||
|
||||
public:
|
||||
ValueArray() { Init0(); }
|
||||
ValueArray(const ValueArray& v);
|
||||
explicit ValueArray(pick_ Vector<Value>& values);
|
||||
explicit ValueArray(const Vector<Value>& values, int deep);
|
||||
~ValueArray();
|
||||
|
||||
ValueArray& operator=(const ValueArray& v);
|
||||
|
||||
operator Value() const;
|
||||
ValueArray(const Value& src);
|
||||
|
||||
ValueArray(const Nuller&) { Init0(); }
|
||||
bool IsNullInstance() const { return IsEmpty(); }
|
||||
|
||||
void Clear();
|
||||
void SetCount(int n);
|
||||
void SetCount(int n, const Value& v);
|
||||
int GetCount() const { return data->data.GetCount(); }
|
||||
bool IsEmpty() const { return data->data.IsEmpty(); }
|
||||
|
||||
void Add(const Value& v);
|
||||
ValueArray& operator<<(const Value& v) { Add(v); return *this; }
|
||||
void Set(int i, const Value& v);
|
||||
const Value& Get(int i) const;
|
||||
Value GetAndClear(int i);
|
||||
const Vector<Value>& Get() const { return data->data; }
|
||||
|
||||
void Remove(int i, int count = 1);
|
||||
void Insert(int i, const ValueArray& va);
|
||||
void Append(const ValueArray& va) { Insert(GetCount(), va); }
|
||||
|
||||
const Value& operator[](int i) const { return Get(i); }
|
||||
|
||||
unsigned GetHashValue() const { return data->GetHashValue(); }
|
||||
void Serialize(Stream& s);
|
||||
void Jsonize(JsonIO& jio);
|
||||
String ToString() const;
|
||||
|
||||
bool operator==(const ValueArray& v) const;
|
||||
bool operator!=(const ValueArray& v) const { return !operator==(v); }
|
||||
};
|
||||
|
||||
template<>
|
||||
String AsString(const ValueArray& v);
|
||||
|
||||
class ValueMap : ValueType<ValueMap, VALUEMAP_V, Moveable<ValueMap> >{
|
||||
struct Data : Value::Void {
|
||||
virtual dword GetType() const { return VALUEMAP_V; }
|
||||
virtual bool IsNull() const;
|
||||
virtual void Serialize(Stream& s);
|
||||
virtual void Xmlize(XmlIO& xio);
|
||||
virtual void Jsonize(JsonIO& jio);
|
||||
virtual unsigned GetHashValue() const;
|
||||
virtual bool IsEqual(const Value::Void *p);
|
||||
virtual String AsString() const;
|
||||
|
||||
const Value& Get(const Value& key) const;
|
||||
|
||||
Index<Value> key;
|
||||
ValueArray value;
|
||||
};
|
||||
|
||||
struct NullData : Data {};
|
||||
Data *data;
|
||||
|
||||
Data& Create();
|
||||
Data& Clone();
|
||||
void Init0();
|
||||
|
||||
friend Value::Void *ValueMapDataCreate();
|
||||
friend class Value;
|
||||
|
||||
public:
|
||||
ValueMap() { Init0(); }
|
||||
ValueMap(const ValueMap& v);
|
||||
ValueMap(pick_ Index<Value>& k, pick_ Vector<Value>& v);
|
||||
ValueMap(const Index<Value>& k, const Vector<Value>& v, int deep);
|
||||
~ValueMap();
|
||||
|
||||
ValueMap& operator=(const ValueMap& v);
|
||||
|
||||
operator Value() const;
|
||||
ValueMap(const Value& src);
|
||||
|
||||
ValueMap(const Nuller&) { Init0(); }
|
||||
bool IsNullInstance() const { return IsEmpty(); }
|
||||
|
||||
void Clear();
|
||||
int GetCount() const { return data->value.GetCount(); }
|
||||
bool IsEmpty() const { return data->value.IsEmpty(); }
|
||||
const Value& GetKey(int i) const { return data->key[i]; }
|
||||
const Value& GetValue(int i) const { return data->value[i]; }
|
||||
|
||||
void Add(const Value& key, const Value& value);
|
||||
void Add(const String& s, const Value& value) { Add(Value(s), value); }
|
||||
void Add(const char *s, const Value& value) { Add(Value(s), value); }
|
||||
void Add(Id id, const Value& value) { Add(Value(id.ToString()), value); }
|
||||
|
||||
void Set(const Value& key, const Value& value);
|
||||
void Set(const String& s, const Value& value) { Set(Value(s), value); }
|
||||
void Set(const char *s, const Value& value) { Set(Value(s), value); }
|
||||
void Set(Id id, const Value& value) { Set(Value(id.ToString()), value); }
|
||||
|
||||
void SetAt(int i, const Value& v);
|
||||
void SetKey(int i, const Value& k);
|
||||
void SetKey(int i, const String& s) { SetKey(i, Value(s)); }
|
||||
void SetKey(int i, const char* s) { SetKey(i, Value(s)); }
|
||||
void SetKey(int i, Id id) { SetKey(i, Value(id.ToString())); }
|
||||
void Remove(int i);
|
||||
|
||||
const Index<Value>& GetKeys() const { return data->key; }
|
||||
ValueArray GetValues() const { return data->value; }
|
||||
|
||||
operator ValueArray() const { return GetValues(); }
|
||||
|
||||
const Value& operator[](const Value& k) const;
|
||||
const Value& operator[](const String& s) const{ return operator[](Value(s)); }
|
||||
const Value& operator[](const char *s) const { return operator[](Value(s)); }
|
||||
const Value& operator[](const Id& k) const { return operator[](Value(k.ToString())); }
|
||||
|
||||
Value GetAndClear(const Value& key);
|
||||
|
||||
unsigned GetHashValue() const { return data->GetHashValue(); }
|
||||
void Serialize(Stream& s);
|
||||
void Jsonize(JsonIO& jio);
|
||||
String ToString() const { return data->AsString(); }
|
||||
|
||||
bool operator==(const ValueMap& v) const;
|
||||
bool operator!=(const ValueMap& v) const { return !operator==(v); }
|
||||
};
|
||||
|
||||
class ValueGen {
|
||||
public:
|
||||
virtual Value Get() = 0;
|
||||
Value operator++() { return Get(); }
|
||||
virtual ~ValueGen() {}
|
||||
};
|
||||
|
||||
|
||||
#include "Value.hpp"
|
||||
|
||||
#endif
|
||||
|
|
@ -290,9 +290,9 @@ String StoreAsXML(Callback1<XmlIO> xmlize, const char *name);
|
|||
bool LoadFromXML(Callback1<XmlIO> xmlize, const String& xml);
|
||||
|
||||
template <class T>
|
||||
String StoreAsXML(T& data, const char *name)
|
||||
String StoreAsXML(const T& data, const char *name)
|
||||
{
|
||||
ParamHelper__<T> p(data);
|
||||
ParamHelper__<T> p(const_cast<T &>(data));
|
||||
return StoreAsXML(callback(&p, &ParamHelper__<T>::Invoke), name);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ NAMESPACE_UPP
|
|||
static StaticMutex sDrawLock;
|
||||
|
||||
INITBLOCK {
|
||||
RichValue<Painting>::Register();
|
||||
RichValue<Drawing>::Register();
|
||||
Value::Register<Painting>("Painting");
|
||||
Value::Register<Drawing>("Drawing");
|
||||
}
|
||||
|
||||
void Draw::SinCos(int angle, double& sina, double& cosa)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ const int FONT_V = 40;
|
|||
|
||||
class FontInfo;
|
||||
|
||||
class Font : public AssignValueTypeNo<Font, FONT_V, Moveable<Font> >{
|
||||
class Font : public ValueType<Font, FONT_V, Moveable<Font> >{
|
||||
union {
|
||||
int64 data;
|
||||
struct {
|
||||
|
|
@ -373,7 +373,7 @@ void SColorDkShadow_Write(Color c);
|
|||
inline Color InvertColor() { return Color(255, 0); }
|
||||
inline Color DefaultInk() { return Black(); } //TODO!
|
||||
|
||||
class Painting : public AssignValueTypeNo<Painting, 48, Moveable<Painting> > {
|
||||
class Painting : public ValueType<Painting, 48, Moveable<Painting> > {
|
||||
String cmd;
|
||||
ValueArray data;
|
||||
Sizef size;
|
||||
|
|
@ -386,6 +386,10 @@ public:
|
|||
|
||||
void Clear() { size = Null; data.Clear(); cmd.Clear(); }
|
||||
void Serialize(Stream& s) { s % cmd % data % size; }
|
||||
#ifdef SVO_VALUE
|
||||
void Xmlize(XmlIO& xio) { XmlizeBySerialize(xio, *this); }
|
||||
void Jsonize(JsonIO& jio) { JsonizeBySerialize(jio, *this); }
|
||||
#endif
|
||||
bool IsNullInstance() const { return cmd.IsEmpty(); }
|
||||
void SetNull() { size = Null; }
|
||||
bool operator==(const Painting& b) const { return cmd == b.cmd && data == b.data && size == b.size; }
|
||||
|
|
@ -624,7 +628,7 @@ public:
|
|||
template <class T> static void Register(const char *id) { AddFormat(id, &DataDrawer::FactoryFn<T>); }
|
||||
};
|
||||
|
||||
class Drawing : public AssignValueTypeNo<Drawing, 49, Moveable<Drawing> > {
|
||||
class Drawing : public ValueType<Drawing, 49, Moveable<Drawing> > {
|
||||
Size size;
|
||||
String data;
|
||||
ValueArray val;
|
||||
|
|
@ -646,6 +650,10 @@ public:
|
|||
void Append(Drawing& dw);
|
||||
|
||||
void Serialize(Stream& s);
|
||||
#ifdef SVO_VALUE
|
||||
void Xmlize(XmlIO& xio) { XmlizeBySerialize(xio, *this); }
|
||||
void Jsonize(JsonIO& jio) { JsonizeBySerialize(jio, *this); }
|
||||
#endif
|
||||
|
||||
bool IsNullInstance() const { return data.IsEmpty(); }
|
||||
void SetNull() { size = Null; }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -25,7 +25,7 @@ Size Font::StdFontSize;
|
|||
Font Font::AStdFont;
|
||||
|
||||
INITBLOCK {
|
||||
RichValue<Font>::Register();
|
||||
Value::Register<Font>("Font");
|
||||
}
|
||||
|
||||
const Vector<FaceInfo>& Font::List()
|
||||
|
|
@ -292,6 +292,7 @@ String Font::GetFaceNameStd() const
|
|||
return GetFaceName();
|
||||
}
|
||||
|
||||
#ifdef SVO_VALUE
|
||||
void Font::Jsonize(JsonIO& jio)
|
||||
{
|
||||
String n, tf;
|
||||
|
|
@ -330,6 +331,7 @@ void Font::Xmlize(XmlIO& xio)
|
|||
ParseTextFlags(tf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template<>
|
||||
String AsString(const Font& f) {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,343 +1,347 @@
|
|||
#define NEWIMAGE
|
||||
|
||||
enum ImageKind {
|
||||
IMAGE_UNKNOWN,
|
||||
IMAGE_EMPTY,
|
||||
IMAGE_ALPHA,
|
||||
IMAGE_MASK,
|
||||
IMAGE_OPAQUE,
|
||||
};
|
||||
|
||||
inline bool operator==(const RGBA& a, const RGBA& b)
|
||||
{
|
||||
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
|
||||
}
|
||||
|
||||
inline bool operator!=(const RGBA& a, const RGBA& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
inline RGBA RGBAZero() { RGBA c; c.r = c.g = c.b = c.a = 0; return c; }
|
||||
|
||||
void Fill(RGBA *t, const RGBA& src, int n);
|
||||
void FillColor(RGBA *t, const RGBA& src, int n);
|
||||
|
||||
void Copy(RGBA *t, const RGBA *s, int n);
|
||||
|
||||
int Premultiply(RGBA *t, const RGBA *s, int len);
|
||||
int Unmultiply(RGBA *t, const RGBA *s, int len);
|
||||
|
||||
void TransformComponents(RGBA *t, const RGBA *s, int len,
|
||||
const byte r[], const byte g[], const byte b[], const byte a[]);
|
||||
void MultiplyComponents(RGBA *t, const RGBA *s, int len, int num, int den = 256);
|
||||
|
||||
void AlphaBlend(RGBA *t, const RGBA *s, int len);
|
||||
void AlphaBlend(RGBA *t, const RGBA *s, int len, Color color);
|
||||
|
||||
void AlphaBlendOpaque(RGBA *t, const RGBA *s, int len, Color color);
|
||||
void AlphaBlendOpaque(RGBA *t, const RGBA *s, int len);
|
||||
|
||||
void AlphaBlendStraight(RGBA *b, const RGBA *f, int len);
|
||||
void AlphaBlendStraight(RGBA *b, const RGBA *f, int len, Color color);
|
||||
void AlphaBlendStraightOpaque(RGBA *t, const RGBA *s, int len);
|
||||
void AlphaBlendStraightOpaque(RGBA *t, const RGBA *s, int len, int alpha);
|
||||
|
||||
int GetChMaskPos32(dword mask);
|
||||
void AlphaBlendOverBgST(RGBA *b, RGBA bg, int len);
|
||||
|
||||
const byte *UnpackRLE(RGBA *t, const byte *src, int len);
|
||||
String PackRLE(const RGBA *s, int len);
|
||||
|
||||
inline int Grayscale(int r, int g, int b) { return (77 * r + 151 * g + 28 * b) >> 8; }
|
||||
inline int Grayscale(const RGBA& c) { return Grayscale(c.r, c.g, c.b); }
|
||||
inline byte Saturate255(int x) { return byte(~(x >> 24) & (x | (-(x >> 8) >> 24)) & 0xff); }
|
||||
|
||||
class Image;
|
||||
|
||||
class ImageBuffer : NoCopy {
|
||||
mutable int kind;
|
||||
Size size;
|
||||
Buffer<RGBA> pixels;
|
||||
Point hotspot;
|
||||
Point spot2;
|
||||
Size dots;
|
||||
|
||||
void Set(Image& img);
|
||||
void DeepCopy(const ImageBuffer& img);
|
||||
|
||||
RGBA* Line(int i) const { ASSERT(i >= 0 && i < size.cy); return (RGBA *)~pixels + i * size.cx; }
|
||||
friend void DropPixels___(ImageBuffer& b) { b.pixels.Clear(); }
|
||||
|
||||
friend class Image;
|
||||
|
||||
public:
|
||||
void SetKind(int k) { kind = k; }
|
||||
int GetKind() const { return kind; }
|
||||
int ScanKind() const;
|
||||
int GetScanKind() const { return kind == IMAGE_UNKNOWN ? ScanKind() : kind; }
|
||||
|
||||
void SetHotSpot(Point p) { hotspot = p; }
|
||||
Point GetHotSpot() const { return hotspot; }
|
||||
|
||||
void Set2ndSpot(Point p) { spot2 = p; }
|
||||
Point Get2ndSpot() const { return spot2; }
|
||||
|
||||
void SetHotSpots(const Image& src);
|
||||
|
||||
void SetDots(Size sz) { dots = sz; }
|
||||
Size GetDots() const { return dots; }
|
||||
void SetDPI(Size sz);
|
||||
Size GetDPI();
|
||||
|
||||
Size GetSize() const { return size; }
|
||||
int GetWidth() const { return size.cx; }
|
||||
int GetHeight() const { return size.cy; }
|
||||
int GetLength() const { return size.cx * size.cy; }
|
||||
|
||||
RGBA *operator[](int i) { return Line(i); }
|
||||
const RGBA *operator[](int i) const { return Line(i); }
|
||||
RGBA *operator~() { return pixels; }
|
||||
operator RGBA*() { return pixels; }
|
||||
const RGBA *operator~() const { return pixels; }
|
||||
operator const RGBA*() const { return pixels; }
|
||||
RGBA *Begin() { return pixels; }
|
||||
const RGBA *Begin() const { return pixels; }
|
||||
RGBA *End() { return pixels + GetLength(); }
|
||||
const RGBA *End() const { return pixels + GetLength(); }
|
||||
|
||||
void Create(int cx, int cy);
|
||||
void Create(Size sz) { Create(sz.cx, sz.cy); }
|
||||
bool IsEmpty() const { return (size.cx | size.cy) == 0; }
|
||||
void Clear() { Create(0, 0); }
|
||||
|
||||
void operator=(Image& img);
|
||||
void operator=(ImageBuffer& img);
|
||||
|
||||
ImageBuffer() { Create(0, 0); }
|
||||
ImageBuffer(int cx, int cy) { Create(cx, cy); }
|
||||
ImageBuffer(Size sz) { Create(sz.cx, sz.cy); }
|
||||
ImageBuffer(Image& img);
|
||||
ImageBuffer(ImageBuffer& b);
|
||||
// BW, defined in CtrlCore:
|
||||
ImageBuffer(ImageDraw& iw);
|
||||
};
|
||||
|
||||
void Premultiply(ImageBuffer& b);
|
||||
void Unmultiply(ImageBuffer& b);
|
||||
|
||||
class Image : public AssignValueTypeNo< Image, 150, Moveable<Image> > {
|
||||
private:
|
||||
struct Data : Link<Data> {
|
||||
Atomic refcount;
|
||||
int64 serial;
|
||||
int paintcount;
|
||||
|
||||
static Link<Data> ResData[1];
|
||||
static int ResCount;
|
||||
|
||||
void Retain() { AtomicInc(refcount); }
|
||||
void Release() { if(AtomicDec(refcount) == 0) delete this; }
|
||||
|
||||
struct SystemData;
|
||||
|
||||
void *system_buffer[6];
|
||||
SystemData& Sys() const;
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
void CreateHBMP(HDC dc, const RGBA *data);
|
||||
#endif
|
||||
|
||||
ImageBuffer buffer;
|
||||
bool paintonly;
|
||||
|
||||
void SysInitImp();
|
||||
void SysReleaseImp();
|
||||
int GetResCountImp() const;
|
||||
void PaintImp(SystemDraw& w, int x, int y, const Rect& src, Color c);
|
||||
|
||||
void SysInit();
|
||||
void SysRelease();
|
||||
int GetResCount() const;
|
||||
void Paint(SystemDraw& w, int x, int y, const Rect& src, Color c);
|
||||
|
||||
int GetKind();
|
||||
void PaintOnlyShrink();
|
||||
|
||||
Data(ImageBuffer& b);
|
||||
~Data();
|
||||
|
||||
static void (Image::Data::*sSysInit)();
|
||||
static void (Image::Data::*sSysRelease)();
|
||||
static int (Image::Data::*sGetResCount)() const;
|
||||
static void (Image::Data::*sPaint)(SystemDraw& w, int x, int y, const Rect& src, Color c);
|
||||
|
||||
friend void InstallSystemImage();
|
||||
static void InitSystemImage(
|
||||
void (Image::Data::*fSysInit)(),
|
||||
void (Image::Data::*fSysRelease)(),
|
||||
int (Image::Data::*fGetResCount)() const,
|
||||
void (Image::Data::*fPaint)(SystemDraw& w, int x, int y, const Rect& src, Color c)
|
||||
);
|
||||
};
|
||||
|
||||
Data *data;
|
||||
|
||||
static Link<Image::Data> ResData[1];
|
||||
static int ResCount;
|
||||
|
||||
void Set(ImageBuffer& b);
|
||||
|
||||
friend class ImageBuffer;
|
||||
friend struct Data;
|
||||
|
||||
friend void SetPaintOnly___(Image& m);
|
||||
friend void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp);
|
||||
friend void InstallSystemImage();
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
#ifndef PLATFORM_WINCE
|
||||
void SetCursorCheat(LPCSTR id);
|
||||
LPCSTR GetCursorCheat() const;
|
||||
friend Image Win32IconCursor(LPCSTR id, int iconsize, bool cursor);
|
||||
friend HICON IconWin32(const Image& img, bool cursor);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_POSIX // These are only implemented for X11...
|
||||
void SetCursorCheat(int id);
|
||||
int GetCursorCheat() const;
|
||||
friend void *CursorX11(const Image&);
|
||||
friend Image X11Cursor(int c);
|
||||
#endif
|
||||
|
||||
public:
|
||||
const RGBA* operator~() const;
|
||||
operator const RGBA*() const;
|
||||
const RGBA* operator[](int i) const;
|
||||
|
||||
Size GetSize() const;
|
||||
int GetWidth() const { return GetSize().cx; }
|
||||
int GetHeight() const { return GetSize().cy; }
|
||||
int GetLength() const;
|
||||
Point GetHotSpot() const;
|
||||
Point Get2ndSpot() const;
|
||||
Size GetDots() const;
|
||||
Size GetDPI();
|
||||
int GetKindNoScan() const;
|
||||
int GetKind() const;
|
||||
|
||||
int64 GetSerialId() const { return data ? data->serial : 0; }
|
||||
bool IsSame(const Image& img) const { return GetSerialId() == img.GetSerialId(); }
|
||||
|
||||
bool operator==(const Image& img) const;
|
||||
bool operator!=(const Image& img) const;
|
||||
dword GetHashValue() const;
|
||||
String ToString() const;
|
||||
|
||||
void Serialize(Stream& s);
|
||||
void Clear();
|
||||
|
||||
Image& operator=(const Image& img);
|
||||
Image& operator=(ImageBuffer& img);
|
||||
|
||||
bool IsNullInstance() const { Size sz = GetSize(); return (sz.cx|sz.cy) == 0; }
|
||||
|
||||
bool IsEmpty() const { return IsNullInstance(); }
|
||||
operator Value() const { return RichValue<Image>(*this); }
|
||||
|
||||
Image() { data = NULL; }
|
||||
Image(const Nuller&) { data = NULL; }
|
||||
Image(const Value& src);
|
||||
Image(const Image& img);
|
||||
Image(Image (*fn)());
|
||||
Image(ImageBuffer& b);
|
||||
~Image();
|
||||
|
||||
void PaintImage(SystemDraw& w, int x, int y, const Rect& src, Color c) const;
|
||||
|
||||
static Image Arrow();
|
||||
static Image Wait();
|
||||
static Image IBeam();
|
||||
static Image No();
|
||||
static Image SizeAll();
|
||||
static Image SizeHorz();
|
||||
static Image SizeVert();
|
||||
static Image SizeTopLeft();
|
||||
static Image SizeTop();
|
||||
static Image SizeTopRight();
|
||||
static Image SizeLeft();
|
||||
static Image SizeRight();
|
||||
static Image SizeBottomLeft();
|
||||
static Image SizeBottom();
|
||||
static Image SizeBottomRight();
|
||||
static Image Cross();
|
||||
static Image Hand();
|
||||
|
||||
// IML support ("private"), deprecated - legacy .iml
|
||||
struct Init {
|
||||
const char *const *scans;
|
||||
int16 scan_count;
|
||||
char info[24];
|
||||
};
|
||||
explicit Image(const Init& init);
|
||||
};
|
||||
|
||||
Image Premultiply(const Image& img);
|
||||
Image Unmultiply(const Image& img);
|
||||
|
||||
Vector<Image> UnpackImlData(const void *ptr, int len);
|
||||
Vector<Image> UnpackImlData(const String& d);
|
||||
|
||||
class Iml {
|
||||
struct IImage : Moveable<IImage> {
|
||||
bool loaded;
|
||||
Image image;
|
||||
|
||||
IImage() { loaded = false; }
|
||||
};
|
||||
struct Data : Moveable<Data> {
|
||||
const char *data;
|
||||
int len, count;
|
||||
};
|
||||
Vector<Data> data;
|
||||
VectorMap<String, IImage> map;
|
||||
const Image::Init *img_init;
|
||||
const char **name;
|
||||
bool premultiply;
|
||||
|
||||
void Init(int n);
|
||||
|
||||
public:
|
||||
void Reset();
|
||||
int GetCount() const { return map.GetCount(); }
|
||||
String GetId(int i) { return map.GetKey(i); }
|
||||
Image Get(int i);
|
||||
int Find(const String& s) const { return map.Find(s); }
|
||||
void Set(int i, const Image& img);
|
||||
void Premultiplied() { premultiply = false; }
|
||||
|
||||
#ifdef _DEBUG
|
||||
int GetBinSize() const;
|
||||
#endif
|
||||
|
||||
Iml(const Image::Init *img_init, const char **name, int n);//Deprecated - legacy .iml
|
||||
void AddData(const byte *data, int len, int count);
|
||||
};
|
||||
|
||||
void Register(const char *imageclass, Iml& iml);
|
||||
|
||||
int GetImlCount();
|
||||
String GetImlName(int i);
|
||||
Iml& GetIml(int i);
|
||||
int FindIml(const char *name);
|
||||
Image GetImlImage(const char *name);
|
||||
void SetImlImage(const char *name, const Image& m);
|
||||
|
||||
String StoreImageAsString(const Image& img);
|
||||
Image LoadImageFromString(const String& s);
|
||||
Size GetImageStringSize(const String& src);
|
||||
Size GetImageStringDots(const String& src);
|
||||
|
||||
#include "Raster.h"
|
||||
#include "ImageOp.h"
|
||||
#define NEWIMAGE
|
||||
|
||||
enum ImageKind {
|
||||
IMAGE_UNKNOWN,
|
||||
IMAGE_EMPTY,
|
||||
IMAGE_ALPHA,
|
||||
IMAGE_MASK,
|
||||
IMAGE_OPAQUE,
|
||||
};
|
||||
|
||||
inline bool operator==(const RGBA& a, const RGBA& b)
|
||||
{
|
||||
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
|
||||
}
|
||||
|
||||
inline bool operator!=(const RGBA& a, const RGBA& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
inline RGBA RGBAZero() { RGBA c; c.r = c.g = c.b = c.a = 0; return c; }
|
||||
|
||||
void Fill(RGBA *t, const RGBA& src, int n);
|
||||
void FillColor(RGBA *t, const RGBA& src, int n);
|
||||
|
||||
void Copy(RGBA *t, const RGBA *s, int n);
|
||||
|
||||
int Premultiply(RGBA *t, const RGBA *s, int len);
|
||||
int Unmultiply(RGBA *t, const RGBA *s, int len);
|
||||
|
||||
void TransformComponents(RGBA *t, const RGBA *s, int len,
|
||||
const byte r[], const byte g[], const byte b[], const byte a[]);
|
||||
void MultiplyComponents(RGBA *t, const RGBA *s, int len, int num, int den = 256);
|
||||
|
||||
void AlphaBlend(RGBA *t, const RGBA *s, int len);
|
||||
void AlphaBlend(RGBA *t, const RGBA *s, int len, Color color);
|
||||
|
||||
void AlphaBlendOpaque(RGBA *t, const RGBA *s, int len, Color color);
|
||||
void AlphaBlendOpaque(RGBA *t, const RGBA *s, int len);
|
||||
|
||||
void AlphaBlendStraight(RGBA *b, const RGBA *f, int len);
|
||||
void AlphaBlendStraight(RGBA *b, const RGBA *f, int len, Color color);
|
||||
void AlphaBlendStraightOpaque(RGBA *t, const RGBA *s, int len);
|
||||
void AlphaBlendStraightOpaque(RGBA *t, const RGBA *s, int len, int alpha);
|
||||
|
||||
int GetChMaskPos32(dword mask);
|
||||
void AlphaBlendOverBgST(RGBA *b, RGBA bg, int len);
|
||||
|
||||
const byte *UnpackRLE(RGBA *t, const byte *src, int len);
|
||||
String PackRLE(const RGBA *s, int len);
|
||||
|
||||
inline int Grayscale(int r, int g, int b) { return (77 * r + 151 * g + 28 * b) >> 8; }
|
||||
inline int Grayscale(const RGBA& c) { return Grayscale(c.r, c.g, c.b); }
|
||||
inline byte Saturate255(int x) { return byte(~(x >> 24) & (x | (-(x >> 8) >> 24)) & 0xff); }
|
||||
|
||||
class Image;
|
||||
|
||||
class ImageBuffer : NoCopy {
|
||||
mutable int kind;
|
||||
Size size;
|
||||
Buffer<RGBA> pixels;
|
||||
Point hotspot;
|
||||
Point spot2;
|
||||
Size dots;
|
||||
|
||||
void Set(Image& img);
|
||||
void DeepCopy(const ImageBuffer& img);
|
||||
|
||||
RGBA* Line(int i) const { ASSERT(i >= 0 && i < size.cy); return (RGBA *)~pixels + i * size.cx; }
|
||||
friend void DropPixels___(ImageBuffer& b) { b.pixels.Clear(); }
|
||||
|
||||
friend class Image;
|
||||
|
||||
public:
|
||||
void SetKind(int k) { kind = k; }
|
||||
int GetKind() const { return kind; }
|
||||
int ScanKind() const;
|
||||
int GetScanKind() const { return kind == IMAGE_UNKNOWN ? ScanKind() : kind; }
|
||||
|
||||
void SetHotSpot(Point p) { hotspot = p; }
|
||||
Point GetHotSpot() const { return hotspot; }
|
||||
|
||||
void Set2ndSpot(Point p) { spot2 = p; }
|
||||
Point Get2ndSpot() const { return spot2; }
|
||||
|
||||
void SetHotSpots(const Image& src);
|
||||
|
||||
void SetDots(Size sz) { dots = sz; }
|
||||
Size GetDots() const { return dots; }
|
||||
void SetDPI(Size sz);
|
||||
Size GetDPI();
|
||||
|
||||
Size GetSize() const { return size; }
|
||||
int GetWidth() const { return size.cx; }
|
||||
int GetHeight() const { return size.cy; }
|
||||
int GetLength() const { return size.cx * size.cy; }
|
||||
|
||||
RGBA *operator[](int i) { return Line(i); }
|
||||
const RGBA *operator[](int i) const { return Line(i); }
|
||||
RGBA *operator~() { return pixels; }
|
||||
operator RGBA*() { return pixels; }
|
||||
const RGBA *operator~() const { return pixels; }
|
||||
operator const RGBA*() const { return pixels; }
|
||||
RGBA *Begin() { return pixels; }
|
||||
const RGBA *Begin() const { return pixels; }
|
||||
RGBA *End() { return pixels + GetLength(); }
|
||||
const RGBA *End() const { return pixels + GetLength(); }
|
||||
|
||||
void Create(int cx, int cy);
|
||||
void Create(Size sz) { Create(sz.cx, sz.cy); }
|
||||
bool IsEmpty() const { return (size.cx | size.cy) == 0; }
|
||||
void Clear() { Create(0, 0); }
|
||||
|
||||
void operator=(Image& img);
|
||||
void operator=(ImageBuffer& img);
|
||||
|
||||
ImageBuffer() { Create(0, 0); }
|
||||
ImageBuffer(int cx, int cy) { Create(cx, cy); }
|
||||
ImageBuffer(Size sz) { Create(sz.cx, sz.cy); }
|
||||
ImageBuffer(Image& img);
|
||||
ImageBuffer(ImageBuffer& b);
|
||||
// BW, defined in CtrlCore:
|
||||
ImageBuffer(ImageDraw& iw);
|
||||
};
|
||||
|
||||
void Premultiply(ImageBuffer& b);
|
||||
void Unmultiply(ImageBuffer& b);
|
||||
|
||||
class Image : public ValueType< Image, 150, Moveable<Image> > {
|
||||
private:
|
||||
struct Data : Link<Data> {
|
||||
Atomic refcount;
|
||||
int64 serial;
|
||||
int paintcount;
|
||||
|
||||
static Link<Data> ResData[1];
|
||||
static int ResCount;
|
||||
|
||||
void Retain() { AtomicInc(refcount); }
|
||||
void Release() { if(AtomicDec(refcount) == 0) delete this; }
|
||||
|
||||
struct SystemData;
|
||||
|
||||
void *system_buffer[6];
|
||||
SystemData& Sys() const;
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
void CreateHBMP(HDC dc, const RGBA *data);
|
||||
#endif
|
||||
|
||||
ImageBuffer buffer;
|
||||
bool paintonly;
|
||||
|
||||
void SysInitImp();
|
||||
void SysReleaseImp();
|
||||
int GetResCountImp() const;
|
||||
void PaintImp(SystemDraw& w, int x, int y, const Rect& src, Color c);
|
||||
|
||||
void SysInit();
|
||||
void SysRelease();
|
||||
int GetResCount() const;
|
||||
void Paint(SystemDraw& w, int x, int y, const Rect& src, Color c);
|
||||
|
||||
int GetKind();
|
||||
void PaintOnlyShrink();
|
||||
|
||||
Data(ImageBuffer& b);
|
||||
~Data();
|
||||
|
||||
static void (Image::Data::*sSysInit)();
|
||||
static void (Image::Data::*sSysRelease)();
|
||||
static int (Image::Data::*sGetResCount)() const;
|
||||
static void (Image::Data::*sPaint)(SystemDraw& w, int x, int y, const Rect& src, Color c);
|
||||
|
||||
friend void InstallSystemImage();
|
||||
static void InitSystemImage(
|
||||
void (Image::Data::*fSysInit)(),
|
||||
void (Image::Data::*fSysRelease)(),
|
||||
int (Image::Data::*fGetResCount)() const,
|
||||
void (Image::Data::*fPaint)(SystemDraw& w, int x, int y, const Rect& src, Color c)
|
||||
);
|
||||
};
|
||||
|
||||
Data *data;
|
||||
|
||||
static Link<Image::Data> ResData[1];
|
||||
static int ResCount;
|
||||
|
||||
void Set(ImageBuffer& b);
|
||||
|
||||
friend class ImageBuffer;
|
||||
friend struct Data;
|
||||
|
||||
friend void SetPaintOnly___(Image& m);
|
||||
friend void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp);
|
||||
friend void InstallSystemImage();
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
#ifndef PLATFORM_WINCE
|
||||
void SetCursorCheat(LPCSTR id);
|
||||
LPCSTR GetCursorCheat() const;
|
||||
friend Image Win32IconCursor(LPCSTR id, int iconsize, bool cursor);
|
||||
friend HICON IconWin32(const Image& img, bool cursor);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_POSIX // These are only implemented for X11...
|
||||
void SetCursorCheat(int id);
|
||||
int GetCursorCheat() const;
|
||||
friend void *CursorX11(const Image&);
|
||||
friend Image X11Cursor(int c);
|
||||
#endif
|
||||
|
||||
public:
|
||||
const RGBA* operator~() const;
|
||||
operator const RGBA*() const;
|
||||
const RGBA* operator[](int i) const;
|
||||
|
||||
Size GetSize() const;
|
||||
int GetWidth() const { return GetSize().cx; }
|
||||
int GetHeight() const { return GetSize().cy; }
|
||||
int GetLength() const;
|
||||
Point GetHotSpot() const;
|
||||
Point Get2ndSpot() const;
|
||||
Size GetDots() const;
|
||||
Size GetDPI();
|
||||
int GetKindNoScan() const;
|
||||
int GetKind() const;
|
||||
|
||||
int64 GetSerialId() const { return data ? data->serial : 0; }
|
||||
bool IsSame(const Image& img) const { return GetSerialId() == img.GetSerialId(); }
|
||||
|
||||
bool operator==(const Image& img) const;
|
||||
bool operator!=(const Image& img) const;
|
||||
dword GetHashValue() const;
|
||||
String ToString() const;
|
||||
|
||||
void Serialize(Stream& s);
|
||||
#ifdef SVO_VALUE
|
||||
void Xmlize(XmlIO& xio) { XmlizeBySerialize(xio, *this); }
|
||||
void Jsonize(JsonIO& jio) { JsonizeBySerialize(jio, *this); }
|
||||
#endif
|
||||
void Clear();
|
||||
|
||||
Image& operator=(const Image& img);
|
||||
Image& operator=(ImageBuffer& img);
|
||||
|
||||
bool IsNullInstance() const { Size sz = GetSize(); return (sz.cx|sz.cy) == 0; }
|
||||
|
||||
bool IsEmpty() const { return IsNullInstance(); }
|
||||
operator Value() const { return RichValue<Image>(*this); }
|
||||
|
||||
Image() { data = NULL; }
|
||||
Image(const Nuller&) { data = NULL; }
|
||||
Image(const Value& src);
|
||||
Image(const Image& img);
|
||||
Image(Image (*fn)());
|
||||
Image(ImageBuffer& b);
|
||||
~Image();
|
||||
|
||||
void PaintImage(SystemDraw& w, int x, int y, const Rect& src, Color c) const;
|
||||
|
||||
static Image Arrow();
|
||||
static Image Wait();
|
||||
static Image IBeam();
|
||||
static Image No();
|
||||
static Image SizeAll();
|
||||
static Image SizeHorz();
|
||||
static Image SizeVert();
|
||||
static Image SizeTopLeft();
|
||||
static Image SizeTop();
|
||||
static Image SizeTopRight();
|
||||
static Image SizeLeft();
|
||||
static Image SizeRight();
|
||||
static Image SizeBottomLeft();
|
||||
static Image SizeBottom();
|
||||
static Image SizeBottomRight();
|
||||
static Image Cross();
|
||||
static Image Hand();
|
||||
|
||||
// IML support ("private"), deprecated - legacy .iml
|
||||
struct Init {
|
||||
const char *const *scans;
|
||||
int16 scan_count;
|
||||
char info[24];
|
||||
};
|
||||
explicit Image(const Init& init);
|
||||
};
|
||||
|
||||
Image Premultiply(const Image& img);
|
||||
Image Unmultiply(const Image& img);
|
||||
|
||||
Vector<Image> UnpackImlData(const void *ptr, int len);
|
||||
Vector<Image> UnpackImlData(const String& d);
|
||||
|
||||
class Iml {
|
||||
struct IImage : Moveable<IImage> {
|
||||
bool loaded;
|
||||
Image image;
|
||||
|
||||
IImage() { loaded = false; }
|
||||
};
|
||||
struct Data : Moveable<Data> {
|
||||
const char *data;
|
||||
int len, count;
|
||||
};
|
||||
Vector<Data> data;
|
||||
VectorMap<String, IImage> map;
|
||||
const Image::Init *img_init;
|
||||
const char **name;
|
||||
bool premultiply;
|
||||
|
||||
void Init(int n);
|
||||
|
||||
public:
|
||||
void Reset();
|
||||
int GetCount() const { return map.GetCount(); }
|
||||
String GetId(int i) { return map.GetKey(i); }
|
||||
Image Get(int i);
|
||||
int Find(const String& s) const { return map.Find(s); }
|
||||
void Set(int i, const Image& img);
|
||||
void Premultiplied() { premultiply = false; }
|
||||
|
||||
#ifdef _DEBUG
|
||||
int GetBinSize() const;
|
||||
#endif
|
||||
|
||||
Iml(const Image::Init *img_init, const char **name, int n);//Deprecated - legacy .iml
|
||||
void AddData(const byte *data, int len, int count);
|
||||
};
|
||||
|
||||
void Register(const char *imageclass, Iml& iml);
|
||||
|
||||
int GetImlCount();
|
||||
String GetImlName(int i);
|
||||
Iml& GetIml(int i);
|
||||
int FindIml(const char *name);
|
||||
Image GetImlImage(const char *name);
|
||||
void SetImlImage(const char *name, const Image& m);
|
||||
|
||||
String StoreImageAsString(const Image& img);
|
||||
Image LoadImageFromString(const String& s);
|
||||
Size GetImageStringSize(const String& src);
|
||||
Size GetImageStringDots(const String& src);
|
||||
|
||||
#include "Raster.h"
|
||||
#include "ImageOp.h"
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ String GetDisplayName(const GUID& guid);
|
|||
template <> bool IsNull(const GUID& guid);
|
||||
GUID GetCoClassGUID(const char *name, bool prog_id = true);
|
||||
|
||||
class Guid : public AssignValueTypeNo<Guid, 70, Moveable<Guid> >
|
||||
class Guid : public ValueType<Guid, 70, Moveable<Guid> >
|
||||
{
|
||||
public:
|
||||
Guid(const Nuller& = Null) { Clear(); }
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public:
|
|||
|
||||
enum { SQLRAW_V = 34 };
|
||||
|
||||
class SqlRaw : public String, AssignValueTypeNo<SqlRaw, SQLRAW_V> {
|
||||
class SqlRaw : public String, ValueType<SqlRaw, SQLRAW_V> {
|
||||
public:
|
||||
operator Value() const { return RawValue<SqlRaw>(*this); }
|
||||
SqlRaw(const Value& q)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue