Added vaca_fusion directory.

This commit is contained in:
David Capello 2010-01-25 22:01:52 +00:00
parent 8f03d54562
commit 4e101699ff
12 changed files with 3289 additions and 0 deletions

View File

@ -0,0 +1,12 @@
======================
What is Vaca Fusion?
======================
This directory contains some code that is an attempt to merge Jinete
source code (the original ASE GUI library which uses Allegro) and Vaca
library (a Win32 wrapper).
Some of this code should be merge to Vaca trunk in the near future.
See Vaca home page for more information:
http://vaca.sourceforge.net/

View File

@ -0,0 +1,643 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_BIND_H
#define VACA_BIND_H
namespace Vaca {
/**
@defgroup bind_group Bind Classes and Functions
@{
*/
// ======================================================================
// BindAdapter0_fun
/**
@see @ref page_bind
*/
template<typename R, typename F>
class BindAdapter0_fun
{
F f;
public:
BindAdapter0_fun(const F& f) : f(f) { }
R operator()() { return f(); }
template<typename A1>
R operator()(const A1& a1) { return f(); }
template<typename A1, typename A2>
R operator()(const A1& a1, const A2& a2) { return f(); }
template<typename A1, typename A2, typename A3>
R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(); }
template<typename A1, typename A2, typename A3, typename A4>
R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(); }
};
/**
@see @ref page_bind
*/
template<typename F>
class BindAdapter0_fun<void, F>
{
F f;
public:
BindAdapter0_fun(const F& f) : f(f) { }
void operator()() { f(); }
template<typename A1>
void operator()(const A1& a1) { f(); }
template<typename A1, typename A2>
void operator()(const A1& a1, const A2& a2) { f(); }
template<typename A1, typename A2, typename A3>
void operator()(const A1& a1, const A2& a2, const A3& a3) { f(); }
template<typename A1, typename A2, typename A3, typename A4>
void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(); }
};
/**
@see @ref page_bind
*/
template<typename R, typename F>
BindAdapter0_fun<R, F>
Bind(const F& f)
{
return BindAdapter0_fun<R, F>(f);
}
// ======================================================================
// BindAdapter0_mem
/**
@see @ref page_bind
*/
template<typename R, typename T>
class BindAdapter0_mem
{
R (T::*m)();
T* t;
public:
template<typename T2>
BindAdapter0_mem(R (T::*m)(), T2* t) : m(m), t(t) { }
R operator()() { return (t->*m)(); }
template <typename A1>
R operator()(const A1& a1) { return (t->*m)(); }
template <typename A1, typename A2>
R operator()(const A1& a1, const A2& a2) { return (t->*m)(); }
template <typename A1, typename A2, typename A3>
R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(); }
template <typename A1, typename A2, typename A3, typename A4>
R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(); }
};
/**
@see @ref page_bind
*/
template<typename T>
class BindAdapter0_mem<void, T>
{
void (T::*m)();
T* t;
public:
template<typename T2>
BindAdapter0_mem(void (T::*m)(), T2* t) : m(m), t(t) { }
void operator()() { (t->*m)(); }
template <typename A1>
void operator()(const A1& a1) { (t->*m)(); }
template <typename A1, typename A2>
void operator()(const A1& a1, const A2& a2) { (t->*m)(); }
template <typename A1, typename A2, typename A3>
void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(); }
template <typename A1, typename A2, typename A3, typename A4>
void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(); }
};
/**
@see @ref page_bind
*/
template<typename R, typename T, typename T2>
BindAdapter0_mem<R, T>
Bind(R (T::*m)(), T2* t)
{
return BindAdapter0_mem<R, T>(m, t);
}
// ======================================================================
// BindAdapter1_fun
/**
@see @ref page_bind
*/
template<typename R, typename F,
typename X1>
class BindAdapter1_fun
{
F f;
X1 x1;
public:
BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { }
R operator()() { return f(x1); }
template<typename A1>
R operator()(const A1& a1) { return f(x1); }
template<typename A1, typename A2>
R operator()(const A1& a1, const A2& a2) { return f(x1); }
template<typename A1, typename A2, typename A3>
R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1); }
template<typename A1, typename A2, typename A3, typename A4>
R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1); }
};
/**
@see @ref page_bind
*/
template<typename F,
typename X1>
class BindAdapter1_fun<void, F, X1>
{
F f;
X1 x1;
public:
BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { }
void operator()() { f(x1); }
template<typename A1>
void operator()(A1& a1) { f(x1); }
template<typename A1, typename A2>
void operator()(A1& a1, A2& a2) { f(x1); }
template<typename A1, typename A2, typename A3>
void operator()(A1& a1, A2& a2, A3& a3) { f(x1); }
template<typename A1, typename A2, typename A3, typename A4>
void operator()(A1& a1, A2& a2, A3& a3, A4& a4) { f(x1); }
};
/**
@see @ref page_bind
*/
template<typename R, typename F,
typename X1>
BindAdapter1_fun<R, F, X1>
Bind(const F& f, X1 x1)
{
return BindAdapter1_fun<R, F, X1>(f, x1);
}
// ======================================================================
// BindAdapter1_mem
/**
@see @ref page_bind
*/
template<typename R, typename T,
typename B1,
typename X1>
class BindAdapter1_mem
{
R (T::*m)(B1);
T* t;
X1 x1;
public:
template<typename T2>
BindAdapter1_mem(R (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { }
R operator()() { return (t->*m)(x1); }
template <typename A1>
R operator()(const A1& a1) { return (t->*m)(x1); }
template <typename A1, typename A2>
R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1); }
template <typename A1, typename A2, typename A3>
R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1); }
template <typename A1, typename A2, typename A3, typename A4>
R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1); }
};
/**
@see @ref page_bind
*/
template<typename T,
typename B1,
typename X1>
class BindAdapter1_mem<void, T, B1, X1>
{
void (T::*m)(B1);
T* t;
X1 x1;
public:
template<typename T2>
BindAdapter1_mem(void (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { }
void operator()() { (t->*m)(x1); }
template <typename A1>
void operator()(const A1& a1) { (t->*m)(x1); }
template <typename A1, typename A2>
void operator()(const A1& a1, const A2& a2) { (t->*m)(x1); }
template <typename A1, typename A2, typename A3>
void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1); }
template <typename A1, typename A2, typename A3, typename A4>
void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1); }
};
/**
@see @ref page_bind
*/
template<typename R, typename T, typename T2,
typename B1, typename X1>
BindAdapter1_mem<R, T, B1, X1>
Bind(R (T::*m)(B1), T2* t, X1 x1)
{
return BindAdapter1_mem<R, T, B1, X1>(m, t, x1);
}
// ======================================================================
// BindAdapter2_fun
/**
@see @ref page_bind
*/
template<typename R, typename F,
typename X1, typename X2>
class BindAdapter2_fun
{
F f;
X1 x1;
X2 x2;
public:
BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { }
R operator()() { return f(x1, x2); }
template<typename A1>
R operator()(const A1& a1) { return f(x1, x2); }
template<typename A1, typename A2>
R operator()(const A1& a1, const A2& a2) { return f(x1, x2); }
template<typename A1, typename A2, typename A3>
R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2); }
template<typename A1, typename A2, typename A3, typename A4>
R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2); }
};
/**
@see @ref page_bind
*/
template<typename F,
typename X1, typename X2>
class BindAdapter2_fun<void, F, X1, X2>
{
F f;
X1 x1;
X2 x2;
public:
BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { }
void operator()() { f(x1, x2); }
template<typename A1>
void operator()(const A1& a1) { f(x1, x2); }
template<typename A1, typename A2>
void operator()(const A1& a1, const A2& a2) { f(x1, x2); }
template<typename A1, typename A2, typename A3>
void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2); }
template<typename A1, typename A2, typename A3, typename A4>
void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2); }
};
/**
@see @ref page_bind
*/
template<typename R, typename F,
typename X1, typename X2>
BindAdapter2_fun<R, F, X1, X2>
Bind(const F& f, X1 x1, X2 x2)
{
return BindAdapter2_fun<R, F, X1, X2>(f, x1, x2);
}
// ======================================================================
// BindAdapter2_mem
/**
@see @ref page_bind
*/
template<typename R, typename T,
typename B1, typename B2,
typename X1, typename X2>
class BindAdapter2_mem
{
R (T::*m)(B1, B2);
T* t;
X1 x1;
X2 x2;
public:
template<typename T2>
BindAdapter2_mem(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { }
R operator()() { return (t->*m)(x1, x2); }
template<typename A1>
R operator()(const A1& a1) { return (t->*m)(x1, x2); }
template<typename A1, typename A2>
R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2); }
template<typename A1, typename A2, typename A3>
R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2); }
template<typename A1, typename A2, typename A3, typename A4>
R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2); }
};
/**
@see @ref page_bind
*/
template<typename T,
typename B1, typename B2,
typename X1, typename X2>
class BindAdapter2_mem<void, T, B1, B2, X1, X2>
{
void (T::*m)(B1, B2);
T* t;
X1 x1;
X2 x2;
public:
template<typename T2>
BindAdapter2_mem(void (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { }
void operator()() { (t->*m)(x1, x2); }
template<typename A1>
void operator()(const A1& a1) { (t->*m)(x1, x2); }
template<typename A1, typename A2>
void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2); }
template<typename A1, typename A2, typename A3>
void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2); }
template<typename A1, typename A2, typename A3, typename A4>
void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2); }
};
/**
@see @ref page_bind
*/
template<typename R, typename T, typename T2, typename B1, typename B2, typename X1, typename X2>
BindAdapter2_mem<R, T, B1, B2, X1, X2>
Bind(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2)
{
return BindAdapter2_mem<R, T, B1, B2, X1, X2>(m, t, x1, x2);
}
// ======================================================================
// BindAdapter3_fun
/**
@see @ref page_bind
*/
template<typename R, typename F,
typename X1, typename X2, typename X3>
class BindAdapter3_fun
{
F f;
X1 x1;
X2 x2;
X3 x3;
public:
BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { }
R operator()() { return f(x1, x2, x3); }
template<typename A1>
R operator()(const A1& a1) { return f(x1, x2, x3); }
template<typename A1, typename A2>
R operator()(const A1& a1, const A2& a2) { return f(x1, x2, x3); }
template<typename A1, typename A2, typename A3>
R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2, x3); }
template<typename A1, typename A2, typename A3, typename A4>
R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2, x3); }
};
/**
@see @ref page_bind
*/
template<typename F,
typename X1, typename X2, typename X3>
class BindAdapter3_fun<void, F, X1, X2, X3>
{
F f;
X1 x1;
X2 x2;
X3 x3;
public:
BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { }
void operator()() { f(x1, x2, x3); }
template<typename A1>
void operator()(const A1& a1) { f(x1, x2, x3); }
template<typename A1, typename A2>
void operator()(const A1& a1, const A2& a2) { f(x1, x2, x3); }
template<typename A1, typename A2, typename A3>
void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2, x3); }
template<typename A1, typename A2, typename A3, typename A4>
void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2, x3); }
};
/**
@see @ref page_bind
*/
template<typename R, typename F,
typename X1, typename X2, typename X3>
BindAdapter3_fun<R, F, X1, X2, X3>
Bind(const F& f, X1 x1, X2 x2, X3 x3)
{
return BindAdapter3_fun<R, F, X1, X2, X3>(f, x1, x2, x3);
}
// ======================================================================
// BindAdapter3_mem
/**
@see @ref page_bind
*/
template<typename R, typename T,
typename B1, typename B2, typename B3,
typename X1, typename X2, typename X3>
class BindAdapter3_mem
{
R (T::*m)(B1, B2, B3);
T* t;
X1 x1;
X2 x2;
X3 x3;
public:
template<typename T2>
BindAdapter3_mem(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2, X3 x3) : m(m), t(t), x1(x1), x2(x2), x3(x3) { }
R operator()() { return (t->*m)(x1, x2, x3); }
template<typename A1>
R operator()(const A1& a1) { return (t->*m)(x1, x2, x3); }
template<typename A1, typename A2>
R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2, x3); }
template<typename A1, typename A2, typename A3>
R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2, x3); }
template<typename A1, typename A2, typename A3, typename A4>
R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2, x3); }
};
/**
@see @ref page_bind
*/
template<typename T,
typename B1, typename B2, typename B3,
typename X1, typename X2, typename X3>
class BindAdapter3_mem<void, T, B1, B2, B3, X1, X2, X3>
{
void (T::*m)(B1, B2, B3);
T* t;
X1 x1;
X2 x2;
X3 x3;
public:
template<typename T2>
BindAdapter3_mem(void (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { }
void operator()() { (t->*m)(x1, x2, x3); }
template<typename A1>
void operator()(const A1& a1) { (t->*m)(x1, x2, x3); }
template<typename A1, typename A2>
void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2, x3); }
template<typename A1, typename A2, typename A3>
void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2, x3); }
template<typename A1, typename A2, typename A3, typename A4>
void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2, x3); }
};
/**
@see @ref page_bind
*/
template<typename R, typename T, typename T2,
typename B1, typename B2, typename B3,
typename X1, typename X2, typename X3>
BindAdapter3_mem<R, T, B1, B2, B3, X1, X2, X3>
Bind(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2)
{
return BindAdapter3_mem<R, T, B1, B2, B3, X1, X2, X3>(m, t, x1, x2);
}
// ======================================================================
// RefWrapper
/**
@todo
@see @ref page_bind
*/
template<class T>
class RefWrapper
{
T* ptr;
public:
RefWrapper(T& ref) : ptr(&ref) { }
operator T&() const { return *ptr; }
};
/**
Creates RefWrappers, useful to wrap arguments that have to be
passed as a reference when you use Bind.
@see @ref page_bind
*/
template<class T>
RefWrapper<T> Ref(T& ref)
{
return RefWrapper<T>(ref);
}
/** @} */
} // namespace Vaca
#endif // VACA_BIND_H

View File

@ -0,0 +1,169 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_ENUM_H
#define VACA_ENUM_H
namespace Vaca {
/**
This class is used to define enumerations "a la" C++0x.
"Base" policy must be like this:
@code
struct Base {
enum enumeration { ... };
static const enumeration default_value = ...;
};
@endcode
Example of how to use this:
@code
struct NumbersEnum
{
enum enumeration {
Zero,
One,
Two,
Three,
};
static const enumeration default_value = Zero;
};
typedef Enum<NumbersEnum> Numbers;
main() {
Numbers n1, n2 = Numbers::One;
n1 = n2;
n2 = Numbers::Two;
}
@endcode
*/
template<typename Base>
struct Enum : public Base
{
typedef typename Base::enumeration enumeration;
Enum() : m_value(Base::default_value)
{ }
Enum(enumeration value) : m_value(value)
{ }
operator enumeration() const
{ return m_value; }
Enum<Base> &operator=(enumeration value)
{ m_value = value;
return *this; }
private:
enumeration m_value;
};
/**
This class is used to define sets of enumerated values.
"Base" policy must be like this:
@code
struct Base {
enum { ... };
};
@endcode
A EnumSet doesn't need a @c default_value like a Enum because the
default value is zero which means: a empty set.
Example of how to use this:
@code
struct ColorsEnumSet
{
enum {
Red = 1,
Blue = 2,
Yellow = 4,
Magenta = Red | Blue
};
};
typedef EnumSet<ColorsEnumSet> Colors;
main() {
Colors red, blue, magenta;
red = Colors::Red;
blue = Colors::Blue;
magenta = red | blue;
if (magenta == Colors::Magenta) { ... }
}
@endcode
*/
template<typename Base>
struct EnumSet : public Base
{
EnumSet() : m_value(0)
{ }
EnumSet(int value) : m_value(value)
{ }
operator int() const
{ return m_value; }
EnumSet<Base> operator|(int value)
{ return m_value | value; }
EnumSet<Base> operator&(int value)
{ return m_value & value; }
EnumSet<Base> operator^(int value)
{ return m_value ^ value; }
EnumSet<Base> &operator=(int value)
{ m_value = value;
return *this; }
EnumSet<Base> &operator|=(int value)
{ m_value |= value;
return *this; }
EnumSet<Base> &operator&=(int value)
{ m_value &= value;
return *this; }
EnumSet<Base> &operator^=(int value)
{ m_value ^= value;
return *this; }
private:
int m_value;
};
} // namespace Vaca
#endif // VACA_ENUM_H

View File

@ -0,0 +1,81 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_POINT_H
#define VACA_POINT_H
#include "Vaca/base.h"
namespace Vaca {
/**
A 2D coordinate in the screen or client area of a widget.
*/
class VACA_DLL Point
{
public:
int x, y;
Point();
Point(int x, int y);
Point(const Point& point);
explicit Point(const Size& size);
const Point& operator=(const Point& pt);
const Point& operator+=(const Point& pt);
const Point& operator-=(const Point& pt);
const Point& operator+=(int value);
const Point& operator-=(int value);
const Point& operator*=(int value);
const Point& operator/=(int value);
Point operator+(const Point& pt) const;
Point operator-(const Point& pt) const;
Point operator+(int value) const;
Point operator-(int value) const;
Point operator*(int value) const;
Point operator/(int value) const;
Point operator-() const;
bool operator==(const Point& pt) const;
bool operator!=(const Point& pt) const;
#ifdef VACA_WINDOWS
explicit Point(CONST LPPOINT pt);
explicit Point(CONST LPPOINTS pt);
operator POINT() const;
#endif
};
} // namespace Vaca
#endif // VACA_POINT_H

View File

@ -0,0 +1,122 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_RECT_H
#define VACA_RECT_H
#include "Vaca/base.h"
namespace Vaca {
/**
A rectangle.
*/
class VACA_DLL Rect
{
public:
/**
Horizontal position of the rectangle's upper-left corner (increase from left to right).
@c x=0 means the beginning of the left side in the screen or
@link Widget#getClientBounds Widget's client area@endlink.
*/
int x;
/**
Vertical position of the rectangle's upper-left corner (increase from top to bottom).
@c y=0 means the beginning of the top side in the screen or
@link Widget#getClientBounds Widget's client area@endlink.
*/
int y;
/**
Width of the rectangle (increase from left to right).
@c w<1 means an empty rectangle.
*/
int w;
/**
Height of the rectangle (increase from left to right).
@c h<1 means an empty rectangle.
*/
int h;
Rect();
Rect(int w, int h);
explicit Rect(const Size& size);
Rect(const Rect& rect);
Rect(const Point& point, const Size& size);
Rect(const Point& point1, const Point& point2);
Rect(int x, int y, int w, int h);
bool isEmpty() const;
Point getCenter() const;
Point getOrigin() const;
Point getPoint2() const;
Size getSize() const;
Rect& setOrigin(const Point& pt);
Rect& setSize(const Size& sz);
Rect& offset(int dx, int dy);
Rect& offset(const Point& point);
Rect& inflate(int dw, int dh);
Rect& inflate(const Size& size);
Rect& enlarge(int unit);
Rect& shrink(int unit);
bool contains(const Point& pt) const;
bool contains(const Rect& rc) const;
bool intersects(const Rect& rc) const;
Rect createUnion(const Rect& rc) const;
Rect createIntersect(const Rect& rc) const;
bool operator==(const Rect& rc) const;
bool operator!=(const Rect& rc) const;
#ifdef VACA_WINDOWS
explicit Rect(LPCRECT rc);
operator RECT() const;
#endif
};
} // namespace Vaca
#endif // VACA_RECT_H

View File

@ -0,0 +1,507 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_SIGNAL_H
#define VACA_SIGNAL_H
#include "Vaca/base.h"
#include "Vaca/Slot.h"
#include <vector>
namespace Vaca {
/**
@defgroup signal_group Signal Classes
@{
*/
// ======================================================================
// Signal0_base<R>
/**
Base class for signals which call functions without parameters.
*/
template<typename R>
class Signal0_base
{
public:
typedef R ReturnType;
typedef Slot0<R> SlotType;
typedef std::vector<SlotType*> SlotList;
protected:
SlotList m_slots;
public:
Signal0_base() { }
Signal0_base(const Signal0_base<R>& s)
{
copy(s);
}
~Signal0_base()
{
disconnectAll();
}
SlotType* addSlot(SlotType* slot)
{
m_slots.push_back(slot);
return slot;
}
template<typename F>
SlotType* connect(const F& f)
{
return addSlot(new Slot0_fun<R, F>(f));
}
template<class T>
SlotType* connect(R (T::*m)(), T* t)
{
return addSlot(new Slot0_mem<R, T>(m, t));
}
const SlotList& getSlots() const
{
return m_slots;
}
void disconnect(SlotType* slot)
{
remove_from_container(m_slots, slot);
}
void disconnectAll()
{
typename SlotList::iterator end = m_slots.end();
for (typename SlotList::iterator
it = m_slots.begin(); it != end; ++it)
delete *it;
m_slots.clear();
}
bool empty() const
{
return m_slots.empty();
}
Signal0_base& operator=(const Signal0_base<R>& s) {
copy(s);
return *this;
}
private:
void copy(const Signal0_base<R>& s)
{
typename SlotList::const_iterator end = s.m_slots.end();
for (typename SlotList::const_iterator
it = s.m_slots.begin(); it != end; ++it) {
m_slots.push_back((*it)->clone());
}
}
};
// ======================================================================
// Signal0<R>
template<typename R>
class Signal0 : public Signal0_base<R>
{
public:
Signal0() { }
Signal0(const Signal0<R>& s)
: Signal0_base<R>(s) { }
R operator()(R default_result = R())
{
R result(default_result);
typename Signal0_base<R>::SlotList::iterator end = Signal0_base<R>::m_slots.end();
for (typename Signal0_base<R>::SlotList::iterator
it = Signal0_base<R>::m_slots.begin(); it != end; ++it) {
typename Signal0_base<R>::SlotType* slot = *it;
result = (*slot)();
}
return result;
}
template<typename Merger>
R operator()(R default_result, const Merger& m)
{
R result(default_result);
Merger merger(m);
typename Signal0_base<R>::SlotList::iterator end = Signal0_base<R>::m_slots.end();
for (typename Signal0_base<R>::SlotList::iterator
it = Signal0_base<R>::m_slots.begin(); it != end; ++it) {
typename Signal0_base<R>::SlotType* slot = *it;
result = merger(result, (*slot)());
}
return result;
}
};
// ======================================================================
// Signal0<void>
template<>
class Signal0<void> : public Signal0_base<void>
{
public:
Signal0() { }
Signal0(const Signal0<void>& s)
: Signal0_base<void>(s) { }
void operator()()
{
SlotList::iterator end = m_slots.end();
for (SlotList::iterator
it = m_slots.begin(); it != end; ++it) {
SlotType* slot = *it;
(*slot)();
}
}
};
// ======================================================================
// Signal1_base<R, A1>
/**
Base class for signals which call functions with one parameter.
*/
template<typename R, typename A1>
class Signal1_base
{
public:
typedef R ReturnType;
typedef Slot1<R, A1> SlotType;
typedef std::vector<SlotType*> SlotList;
protected:
SlotList m_slots;
public:
Signal1_base() { }
Signal1_base(const Signal1_base<R, A1>& s)
{
copy(s);
}
~Signal1_base()
{
disconnectAll();
}
SlotType* addSlot(SlotType* slot)
{
m_slots.push_back(slot);
return slot;
}
template<typename F>
SlotType* connect(const F& f)
{
return addSlot(new Slot1_fun<R, F, A1>(f));
}
template<class T>
SlotType* connect(R (T::*m)(A1), T* t)
{
return addSlot(new Slot1_mem<R, T, A1>(m, t));
}
const SlotList& getSlots() const
{
return m_slots;
}
void disconnect(SlotType* slot)
{
remove_from_container(m_slots, slot);
}
void disconnectAll()
{
typename SlotList::iterator end = m_slots.end();
for (typename SlotList::iterator
it = m_slots.begin(); it != end; ++it)
delete *it;
m_slots.clear();
}
bool empty() const
{
return m_slots.empty();
}
Signal1_base& operator=(const Signal1_base<R, A1>& s) {
copy(s);
return *this;
}
private:
void copy(const Signal1_base<R, A1>& s)
{
typename SlotList::const_iterator end = s.m_slots.end();
for (typename SlotList::const_iterator
it = s.m_slots.begin(); it != end; ++it) {
m_slots.push_back((*it)->clone());
}
}
};
// ======================================================================
// Signal1<R, A1>
template<typename R, typename A1>
class Signal1 : public Signal1_base<R, A1>
{
public:
Signal1() { }
Signal1(const Signal1<R, A1>& s)
: Signal1_base<R, A1>(s) { }
R operator()(A1 a1, R default_result = R())
{
R result(default_result);
typename Signal1_base<R, A1>::SlotList::iterator end = Signal1_base<R, A1>::m_slots.end();
for (typename Signal1_base<R, A1>::SlotList::iterator
it = Signal1_base<R, A1>::m_slots.begin(); it != end; ++it) {
typename Signal1_base<R, A1>::SlotType* slot = *it;
result = (*slot)(a1);
}
return result;
}
template<typename Merger>
R operator()(A1 a1, R default_result, const Merger& m)
{
R result(default_result);
Merger merger(m);
typename Signal1_base<R, A1>::SlotList::iterator end = Signal1_base<R, A1>::m_slots.end();
for (typename Signal1_base<R, A1>::SlotList::iterator
it = Signal1_base<R, A1>::m_slots.begin(); it != end; ++it) {
typename Signal1_base<R, A1>::SlotType* slot = *it;
result = merger(result, (*slot)(a1));
}
return result;
}
};
// ======================================================================
// Signal1<void, A1>
template<typename A1>
class Signal1<void, A1> : public Signal1_base<void, A1>
{
public:
Signal1() { }
Signal1(const Signal1<void, A1>& s)
: Signal1_base<void, A1>(s) { }
void operator()(A1 a1)
{
typename Signal1_base<void, A1>::SlotList::iterator end = Signal1_base<void, A1>::m_slots.end();
for (typename Signal1_base<void, A1>::SlotList::iterator
it = Signal1_base<void, A1>::m_slots.begin(); it != end; ++it) {
typename Signal1_base<void, A1>::SlotType* slot = *it;
(*slot)(a1);
}
}
};
// ======================================================================
// Signal2_base<R, A1, A2>
/**
Base class for signals which call functions with two parameters.
*/
template<typename R, typename A1, typename A2>
class Signal2_base
{
public:
typedef R ReturnType;
typedef Slot2<R, A1, A2> SlotType;
typedef std::vector<SlotType*> SlotList;
protected:
SlotList m_slots;
public:
Signal2_base() { }
Signal2_base(const Signal2_base<R, A1, A2>& s)
{
copy(s);
}
~Signal2_base()
{
disconnectAll();
}
SlotType* addSlot(SlotType* slot)
{
m_slots.push_back(slot);
return slot;
}
template<typename F>
SlotType* connect(const F& f)
{
return addSlot(new Slot2_fun<R, F, A1, A2>(f));
}
template<class T>
SlotType* connect(R (T::*m)(A1, A2), T* t)
{
return addSlot(new Slot2_mem<R, T, A1, A2>(m, t));
}
const SlotList& getSlots() const
{
return m_slots;
}
void disconnect(SlotType* slot)
{
remove_from_container(m_slots, slot);
}
void disconnectAll()
{
typename SlotList::iterator end = m_slots.end();
for (typename SlotList::iterator
it = m_slots.begin(); it != end; ++it)
delete *it;
m_slots.clear();
}
bool empty() const
{
return m_slots.empty();
}
Signal2_base& operator=(const Signal2_base<R, A1, A2>& s) {
copy(s);
return *this;
}
private:
void copy(const Signal2_base<R, A1, A2>& s)
{
typename SlotList::const_iterator end = s.m_slots.end();
for (typename SlotList::const_iterator
it = s.m_slots.begin(); it != end; ++it) {
m_slots.push_back((*it)->clone());
}
}
};
// ======================================================================
// Signal2<R, A1>
template<typename R, typename A1, typename A2>
class Signal2 : public Signal2_base<R, A1, A2>
{
public:
Signal2() { }
Signal2(const Signal2<R, A1, A2>& s)
: Signal2_base<R, A1, A2>(s) { }
R operator()(A1 a1, A2 a2, R default_result = R())
{
R result(default_result);
typename Signal2_base<R, A1, A2>::SlotList::iterator end = Signal2_base<R, A1, A2>::m_slots.end();
for (typename Signal2_base<R, A1, A2>::SlotList::iterator
it = Signal2_base<R, A1, A2>::m_slots.begin(); it != end; ++it) {
typename Signal2_base<R, A1, A2>::SlotType* slot = *it;
result = (*slot)(a1, a2);
}
return result;
}
template<typename Merger>
R operator()(A1 a1, A2 a2, R default_result, const Merger& m)
{
R result(default_result);
Merger merger(m);
typename Signal2_base<R, A1, A2>::SlotList::iterator end = Signal2_base<R, A1, A2>::m_slots.end();
for (typename Signal2_base<R, A1, A2>::SlotList::iterator
it = Signal2_base<R, A1, A2>::m_slots.begin(); it != end; ++it) {
typename Signal2_base<R, A1, A2>::SlotType* slot = *it;
result = merger(result, (*slot)(a1, a2));
}
return result;
}
};
// ======================================================================
// Signal2<void, A1>
template<typename A1, typename A2>
class Signal2<void, A1, A2> : public Signal2_base<void, A1, A2>
{
public:
Signal2() { }
Signal2(const Signal2<void, A1, A2>& s)
: Signal2_base<void, A1, A2>(s) { }
void operator()(A1 a1, A2 a2)
{
typename Signal2_base<void, A1, A2>::SlotList::iterator end = Signal2_base<void, A1, A2>::m_slots.end();
for (typename Signal2_base<void, A1, A2>::SlotList::iterator
it = Signal2_base<void, A1, A2>::m_slots.begin(); it != end; ++it) {
typename Signal2_base<void, A1, A2>::SlotType* slot = *it;
(*slot)(a1, a2);
}
}
};
/** @} */
} // namespace Vaca
#endif // VACA_SIGNAL_H

View File

@ -0,0 +1,83 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_SIZE_H
#define VACA_SIZE_H
#include "Vaca/base.h"
namespace Vaca {
/**
A 2D size.
*/
class VACA_DLL Size
{
public:
int w, h;
Size();
Size(int w, int h);
Size(const Size& size);
explicit Size(const Point& point);
Size createUnion(const Size& sz) const;
Size createIntersect(const Size& sz) const;
const Size& operator=(const Size& sz);
const Size& operator+=(const Size& sz);
const Size& operator-=(const Size& sz);
const Size& operator+=(int value);
const Size& operator-=(int value);
const Size& operator*=(int value);
const Size& operator/=(int value);
Size operator+(const Size& sz) const;
Size operator-(const Size& sz) const;
Size operator+(int value) const;
Size operator-(int value) const;
Size operator*(int value) const;
Size operator/(int value) const;
Size operator-() const;
bool operator==(const Size& sz) const;
bool operator!=(const Size& sz) const;
#ifdef VACA_WINDOWS
explicit Size(CONST LPSIZE sz);
operator SIZE() const;
#endif
};
} // namespace Vaca
#endif // VACA_SIZE_H

View File

@ -0,0 +1,260 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_SLOT_H
#define VACA_SLOT_H
#include "Vaca/base.h"
namespace Vaca {
/**
@defgroup slot_group Slot Classes
@{
*/
// ======================================================================
// Slot0
template<typename R>
class Slot0
{
public:
Slot0() { }
Slot0(const Slot0& s) { (void)s; }
virtual ~Slot0() { }
virtual R operator()() = 0;
virtual Slot0* clone() const = 0;
};
// ======================================================================
// Slot0_fun - hold a F instance and use the function call operator
template<typename R, typename F>
class Slot0_fun : public Slot0<R>
{
F f;
public:
Slot0_fun(const F& f) : f(f) { }
Slot0_fun(const Slot0_fun& s) : Slot0<R>(s), f(s.f) { }
~Slot0_fun() { }
R operator()() { return f(); }
Slot0_fun* clone() const { return new Slot0_fun(*this); }
};
template<typename F>
class Slot0_fun<void, F> : public Slot0<void>
{
F f;
public:
Slot0_fun(const F& f) : f(f) { }
Slot0_fun(const Slot0_fun& s) : Slot0<void>(s), f(s.f) { }
~Slot0_fun() { }
void operator()() { f(); }
Slot0_fun* clone() const { return new Slot0_fun(*this); }
};
// ======================================================================
// Slot0_mem - pointer to a member function of the T class
template<typename R, class T>
class Slot0_mem : public Slot0<R>
{
R (T::*m)();
T* t;
public:
Slot0_mem(R (T::*m)(), T* t) : m(m), t(t) { }
Slot0_mem(const Slot0_mem& s) : Slot0<R>(s), m(s.m), t(s.t) { }
~Slot0_mem() { }
R operator()() { return (t->*m)(); }
Slot0_mem* clone() const { return new Slot0_mem(*this); }
};
template<class T>
class Slot0_mem<void, T> : public Slot0<void>
{
void (T::*m)();
T* t;
public:
Slot0_mem(void (T::*m)(), T* t) : m(m), t(t) { }
Slot0_mem(const Slot0_mem& s) : Slot0<void>(s), m(s.m), t(s.t) { }
~Slot0_mem() { }
void operator()() { (t->*m)(); }
Slot0_mem* clone() const { return new Slot0_mem(*this); }
};
// ======================================================================
// Slot1
template<typename R, typename A1>
class Slot1
{
public:
Slot1() { }
Slot1(const Slot1& s) { (void)s; }
virtual ~Slot1() { }
virtual R operator()(A1 a1) = 0;
virtual Slot1* clone() const = 0;
};
// ======================================================================
// Slot1_fun - hold a F instance and use the function call operator
template<typename R, typename F, typename A1>
class Slot1_fun : public Slot1<R, A1>
{
F f;
public:
Slot1_fun(const F& f) : f(f) { }
Slot1_fun(const Slot1_fun& s) : Slot1<R, A1>(s), f(s.f) { }
~Slot1_fun() { }
R operator()(A1 a1) { return f(a1); }
Slot1_fun* clone() const { return new Slot1_fun(*this); }
};
template<typename F, typename A1>
class Slot1_fun<void, F, A1> : public Slot1<void, A1>
{
F f;
public:
Slot1_fun(const F& f) : f(f) { }
Slot1_fun(const Slot1_fun& s) : Slot1<void, A1>(s), f(s.f) { }
~Slot1_fun() { }
void operator()(A1 a1) { f(a1); }
Slot1_fun* clone() const { return new Slot1_fun(*this); }
};
// ======================================================================
// Slot1_mem - pointer to a member function of the T class
template<typename R, class T, typename A1>
class Slot1_mem : public Slot1<R, A1>
{
R (T::*m)(A1);
T* t;
public:
Slot1_mem(R (T::*m)(A1), T* t) : m(m), t(t) { }
Slot1_mem(const Slot1_mem& s) : Slot1<R, A1>(s), m(s.m), t(s.t) { }
~Slot1_mem() { }
R operator()(A1 a1) { return (t->*m)(a1); }
Slot1_mem* clone() const { return new Slot1_mem(*this); }
};
template<class T, typename A1>
class Slot1_mem<void, T, A1> : public Slot1<void, A1>
{
void (T::*m)(A1);
T* t;
public:
Slot1_mem(void (T::*m)(A1), T* t) : m(m), t(t) { }
Slot1_mem(const Slot1_mem& s) : Slot1<void, A1>(s), m(s.m), t(s.t) { }
~Slot1_mem() { }
void operator()(A1 a1) { (t->*m)(a1); }
Slot1_mem* clone() const { return new Slot1_mem(*this); }
};
// ======================================================================
// Slot2
template<typename R, typename A1, typename A2>
class Slot2
{
public:
Slot2() { }
Slot2(const Slot2& s) { (void)s; }
virtual ~Slot2() { }
virtual R operator()(A1 a1, A2 a2) = 0;
virtual Slot2* clone() const = 0;
};
// ======================================================================
// Slot2_fun - hold a F instance and use the function call operator
template<typename R, typename F, typename A1, typename A2>
class Slot2_fun : public Slot2<R, A1, A2>
{
F f;
public:
Slot2_fun(const F& f) : f(f) { }
Slot2_fun(const Slot2_fun& s) : Slot2<R, A1, A2>(s), f(s.f) { }
~Slot2_fun() { }
R operator()(A1 a1, A2 a2) { return f(a1, a2); }
Slot2_fun* clone() const { return new Slot2_fun(*this); }
};
template<typename F, typename A1, typename A2>
class Slot2_fun<void, F, A1, A2> : public Slot2<void, A1, A2>
{
F f;
public:
Slot2_fun(const F& f) : f(f) { }
Slot2_fun(const Slot2_fun& s) : Slot2<void, A1, A2>(s), f(s.f) { }
~Slot2_fun() { }
void operator()(A1 a1, A2 a2) { f(a1, a2); }
Slot2_fun* clone() const { return new Slot2_fun(*this); }
};
// ======================================================================
// Slot2_mem - pointer to a member function of the T class
template<typename R, class T, typename A1, typename A2>
class Slot2_mem : public Slot2<R, A1, A2>
{
R (T::*m)(A1, A2);
T* t;
public:
Slot2_mem(R (T::*m)(A1, A2), T* t) : m(m), t(t) { }
Slot2_mem(const Slot2_mem& s) : Slot2<R, A1, A2>(s), m(s.m), t(s.t) { }
~Slot2_mem() { }
R operator()(A1 a1, A2 a2) { return (t->*m)(a1, a2); }
Slot2_mem* clone() const { return new Slot2_mem(*this); }
};
template<class T, typename A1, typename A2>
class Slot2_mem<void, T, A1, A2> : public Slot2<void, A1, A2>
{
void (T::*m)(A1, A2);
T* t;
public:
Slot2_mem(void (T::*m)(A1, A2), T* t) : m(m), t(t) { }
Slot2_mem(const Slot2_mem& s) : Slot2<void, A1, A2>(s), m(s.m), t(s.t) { }
~Slot2_mem() { }
void operator()(A1 a1, A2 a2) { return (t->*m)(a1, a2); }
Slot2_mem* clone() const { return new Slot2_mem(*this); }
};
// ======================================================================
/** @} */
} // namespace Vaca
#endif // VACA_SLOT_H

View File

@ -0,0 +1,603 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_BASE_H
#define VACA_BASE_H
// Windows is the default Vaca platform
#if !defined(VACA_ALLEGRO) && !defined(VACA_GTK)
#define VACA_WINDOWS
#endif
#pragma warning(disable: 4251)
#pragma warning(disable: 4275)
#pragma warning(disable: 4355)
#pragma warning(disable: 4996)
#include <algorithm>
#include <stdarg.h>
#include <string>
#ifdef VACA_WINDOWS
#include <windows.h>
#include <commctrl.h>
#endif
#include "Vaca/Enum.h"
// memory leaks
#ifdef MEMORY_LEAK_DETECTOR
#include "debug_new.h"
#endif
namespace Vaca {
#define VACA_VERSION 0
#define VACA_SUB_VERSION 0
#define VACA_WIP_VERSION 8
/**
@def VACA_MAIN()
@brief Defines the name and arguments that the main routine
of the program should contain.
You can use it as:
@code
int VACA_MAIN()
{
...
}
@endcode
@win32
It is the signature of @msdn{WinMain}. In other
operating systems this could be @c "main(int argc, char* argv[])".
@endwin32
*/
#ifdef VACA_WINDOWS
#define VACA_MAIN() \
PASCAL WinMain(HINSTANCE hInstance, \
HINSTANCE hPrevInstance, \
LPSTR lpCmdLine, \
int nCmdShow)
#else
#define VACA_MAIN() \
int main(int argc, char* argv[])
#endif
/**
@def VACA_DLL
@brief Used to export/import symbols to/from the dynamic library.
*/
#ifdef VACA_WINDOWS
#ifdef VACA_STATIC
#define VACA_DLL
#else
#ifdef VACA_SRC
#define VACA_DLL __declspec(dllexport)
#else
#define VACA_DLL __declspec(dllimport)
#endif
#endif
#else
#define VACA_DLL
#endif
/**
Returns the minimum of @a x and @a y.
@note It is just like @b std::min, but there are problems
in MSVC++ because a macro named @b min.
@see max_value, clamp_value
*/
template<typename T>
inline T min_value(T x, T y)
{
return x < y ? x: y;
}
/**
Returns the maximum of @a x and @a y.
@note It is just like @b std::max, but there are problems
in MSVC++ because a macro named @b max.
@see min_value, clamp_value
*/
template<typename T>
inline T max_value(T x, T y)
{
return x > y ? x: y;
}
/**
Limits the posible values of @a x to the speficied range.
If @a x is great than @a high, then @a high is returned,
if @a x is less than @a low, then @a low is returned.
In other case, @a x is in the range, and @a x is returned.
@see min_value, max_value
*/
template<typename T>
inline T clamp_value(T x, T low, T high)
{
return x > high ? high: (x < low ? low: x);
}
/**
A wide character used in a String.
@see String, @ref page_tn_008
*/
typedef wchar_t Char;
/**
String type used through the Vaca API.
It is a std::wstring.
@see Char, @ref page_tn_008
*/
typedef std::wstring String;
/**
An identifier for an application's Command.
@see Widget#onCommand, Command
*/
typedef unsigned int CommandId;
/**
An identifier for a Thread.
*/
typedef unsigned int ThreadId;
// ======================================================================
/**
It's like a namespace for Orientation.
@see Orientation
*/
struct OrientationEnum
{
enum enumeration {
Horizontal,
Vertical
};
static const enumeration default_value = Horizontal;
};
/**
Horizontal or vertical orientation.
One of the following values:
@li Orientation::Horizontal (default)
@li Orientation::Vertical
*/
typedef Enum<OrientationEnum> Orientation;
// ======================================================================
/**
It's like a namespace for TextAlign.
@see TextAlign
*/
struct TextAlignEnum
{
enum enumeration {
Left,
Center,
Right
};
static const enumeration default_value = Left;
};
/**
Horizontal alignment.
One of the following values:
@li TextAlign::Left (default)
@li TextAlign::Center
@li TextAlign::Right
*/
typedef Enum<TextAlignEnum> TextAlign;
// ======================================================================
/**
It's like a namespace for VerticalAlign.
@see VerticalAlign
*/
struct VerticalAlignEnum
{
enum enumeration {
Top,
Middle,
Bottom
};
static const enumeration default_value = Top;
};
/**
Vertical alignment.
One of the following values:
@li VerticalAlign::Top
@li VerticalAlign::Middle
@li VerticalAlign::Bottom
*/
typedef Enum<VerticalAlignEnum> VerticalAlign;
// ======================================================================
/**
It's like a namespace for Side.
@see Side
*/
struct SideEnum
{
enum enumeration {
Left,
Top,
Right,
Bottom
};
static const enumeration default_value = Left;
};
/**
A side.
One of the following values:
@li Side::Left
@li Side::Top
@li Side::Right
@li Side::Bottom
*/
typedef Enum<SideEnum> Side;
// ======================================================================
/**
It's like a namespace for Sides.
@see Sides
*/
struct SidesEnumSet
{
enum {
None = 0,
Left = 1,
Top = 2,
Right = 4,
Bottom = 8,
All = Left | Top | Right | Bottom
};
};
/**
A set of sides.
Zero or more of the following values:
@li Sides::Left
@li Sides::Top
@li Sides::Right
@li Sides::Bottom
*/
typedef EnumSet<SidesEnumSet> Sides;
// ======================================================================
/**
It's like a namespace for CardinalDirection.
@see CardinalDirection
*/
struct CardinalDirectionEnum
{
enum enumeration {
North,
Northeast,
East,
Southeast,
South,
Southwest,
West,
Northwest
};
static const enumeration default_value = North;
};
/**
A cardinal direction.
One of the following values:
@li CardinalDirection::North
@li CardinalDirection::Northeast
@li CardinalDirection::East
@li CardinalDirection::Southeast
@li CardinalDirection::South
@li CardinalDirection::Southwest
@li CardinalDirection::West
@li CardinalDirection::Northwest
*/
typedef Enum<CardinalDirectionEnum> CardinalDirection;
// ======================================================================
/**
Removes an @a element from the specified STL @a container.
This routine removes the first ocurrence of @a element in @a container.
It is just a helper function to avoid cryptic STL code.
@tparam ContainerType A STL container type.
@param container The container to be modified.
@param element The element to be removed from the container.
*/
template<typename ContainerType>
void remove_from_container(ContainerType& container,
typename ContainerType::const_reference element)
{
typename ContainerType::iterator
it = std::find(container.begin(),
container.end(),
element);
if (it != container.end())
container.erase(it);
}
// ======================================================================
// Classes
class Anchor;
class AnchorLayout;
class Application;
class BandedDockArea;
class BasicDockArea;
class Bix;
class BoxConstraint;
class BoxLayout;
class Brush;
class Button;
class ButtonBase;
class CancelableEvent;
class CheckBox;
class ChildEvent;
class ClientLayout;
class Clipboard;
class CloseEvent;
class Color;
class ColorDialog;
class ComboBox;
class Command;
class CommandEvent;
class CommandsClient;
class CommonDialog;
class Component;
class ConditionVariable;
class Constraint;
class Cursor;
class CustomButton;
class CustomLabel;
class Dialog;
class DockArea;
class DockBar;
class DockFrame;
class DockInfo;
class DragListBox;
class DropFilesEvent;
class Event;
class Exception;
class FileDialog;
class FindTextDialog;
class FocusEvent;
class Font;
class FontDialog;
class FontMetrics;
class Frame;
class Graphics;
class GraphicsPath;
class GroupBox;
class HttpRequest;
class HttpRequestException;
class Icon;
class Image;
class ImageHandle;
class ImageList;
class ImagePixels;
class KeyEvent;
class Label;
class Layout;
class LayoutEvent;
class LinkLabel;
class ListBox;
class ListColumn;
class ListItem;
class ListView;
class ListViewEvent;
class MdiChild;
class MdiClient;
class MdiFrame;
class MdiListMenu;
class Menu;
class MenuBar;
class MenuItem;
class MenuItemEvent;
class MenuSeparator;
class Message;
class MouseEvent;
class MsgBox;
class Mutex;
class Node;
class NonCopyable;
class OpenFileDialog;
class PaintEvent;
class Pen;
class Point;
class PopupMenu;
class PreferredSizeEvent;
class ProgressBar;
class RadioButton;
class RadioGroup;
class ReBar;
class ReBarBand;
class Rect;
class Referenceable;
class Region;
class ResizeEvent;
class ResourceId;
class SaveFileDialog;
class SciEdit;
class SciRegister;
class ScopedLock;
class ScreenGraphics;
class ScrollEvent;
class ScrollInfo;
class Separator;
class SetCursorEvent;
class Size;
class Slider;
class SpinButton;
class Spinner;
class SplitBar;
class StatusBar;
class System;
class Tab;
class TabBase;
class TabPage;
class TextEdit;
class Thread;
class TimePoint;
class Timer;
class ToggleButton;
class ToolBar;
class ToolButton;
class ToolSet;
class TreeNode;
class TreeView;
class TreeViewEvent;
class TreeViewIterator;
class Widget;
class WidgetClassName;
template<class T>
class SharedPtr;
// ======================================================================
// Smart Pointers
/**
@defgroup smart_pointers Smart Pointers
@{
*/
typedef SharedPtr<Anchor> AnchorPtr;
typedef SharedPtr<AnchorLayout> AnchorLayoutPtr;
typedef SharedPtr<BandedDockArea> BandedDockAreaPtr;
typedef SharedPtr<BasicDockArea> BasicDockAreaPtr;
typedef SharedPtr<Bix> BixPtr;
typedef SharedPtr<BoxConstraint> BoxConstraintPtr;
typedef SharedPtr<BoxLayout> BoxLayoutPtr;
typedef SharedPtr<Button> ButtonPtr;
typedef SharedPtr<ButtonBase> ButtonBasePtr;
typedef SharedPtr<CheckBox> CheckBoxPtr;
typedef SharedPtr<ClientLayout> ClientLayoutPtr;
typedef SharedPtr<ColorDialog> ColorDialogPtr;
typedef SharedPtr<ComboBox> ComboBoxPtr;
typedef SharedPtr<Command> CommandPtr;
typedef SharedPtr<CommonDialog> CommonDialogPtr;
typedef SharedPtr<Component> ComponentPtr;
typedef SharedPtr<Constraint> ConstraintPtr;
typedef SharedPtr<CustomButton> CustomButtonPtr;
typedef SharedPtr<CustomLabel> CustomLabelPtr;
typedef SharedPtr<Dialog> DialogPtr;
typedef SharedPtr<DockArea> DockAreaPtr;
typedef SharedPtr<DockBar> DockBarPtr;
typedef SharedPtr<DockFrame> DockFramePtr;
typedef SharedPtr<DockInfo> DockInfoPtr;
typedef SharedPtr<DragListBox> DragListBoxPtr;
typedef SharedPtr<FileDialog> FileDialogPtr;
typedef SharedPtr<FindTextDialog> FindTextDialogPtr;
typedef SharedPtr<FontDialog> FontDialogPtr;
typedef SharedPtr<Frame> FramePtr;
typedef SharedPtr<GroupBox> GroupBoxPtr;
typedef SharedPtr<Label> LabelPtr;
typedef SharedPtr<Layout> LayoutPtr;
typedef SharedPtr<LinkLabel> LinkLabelPtr;
typedef SharedPtr<ListBox> ListBoxPtr;
typedef SharedPtr<ListItem> ListItemPtr;
typedef SharedPtr<ListView> ListViewPtr;
typedef SharedPtr<MdiChild> MdiChildPtr;
typedef SharedPtr<MdiClient> MdiClientPtr;
typedef SharedPtr<MdiFrame> MdiFramePtr;
typedef SharedPtr<MdiListMenu> MdiListMenuPtr;
typedef SharedPtr<Menu> MenuPtr;
typedef SharedPtr<MenuBar> MenuBarPtr;
typedef SharedPtr<MenuItem> MenuItemPtr;
typedef SharedPtr<MenuSeparator> MenuSeparatorPtr;
typedef SharedPtr<OpenFileDialog> OpenFileDialogPtr;
typedef SharedPtr<PopupMenu> PopupMenuPtr;
typedef SharedPtr<ProgressBar> ProgressBarPtr;
typedef SharedPtr<RadioButton> RadioButtonPtr;
typedef SharedPtr<ReBar> ReBarPtr;
typedef SharedPtr<SaveFileDialog> SaveFileDialogPtr;
typedef SharedPtr<SciEdit> SciEditPtr;
typedef SharedPtr<Separator> SeparatorPtr;
typedef SharedPtr<Slider> SliderPtr;
typedef SharedPtr<SpinButton> SpinButtonPtr;
typedef SharedPtr<Spinner> SpinnerPtr;
typedef SharedPtr<SplitBar> SplitBarPtr;
typedef SharedPtr<StatusBar> StatusBarPtr;
typedef SharedPtr<Tab> TabPtr;
typedef SharedPtr<TabBase> TabBasePtr;
typedef SharedPtr<TabPage> TabPagePtr;
typedef SharedPtr<TextEdit> TextEditPtr;
typedef SharedPtr<ToggleButton> ToggleButtonPtr;
typedef SharedPtr<ToolBar> ToolBarPtr;
typedef SharedPtr<ToolSet> ToolSetPtr;
typedef SharedPtr<TreeNode> TreeNodePtr;
typedef SharedPtr<TreeView> TreeViewPtr;
typedef SharedPtr<Widget> WidgetPtr;
/** @} */
} // namespace Vaca
#endif // VACA_BASE_H

View File

@ -0,0 +1,177 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Vaca/Point.h"
#include "Vaca/Size.h"
using namespace Vaca;
Point::Point()
{
x = 0;
y = 0;
}
Point::Point(int x, int y)
{
this->x = x;
this->y = y;
}
Point::Point(const Point& point)
{
x = point.x;
y = point.y;
}
Point::Point(const Size& size)
{
x = size.w;
y = size.h;
}
const Point& Point::operator=(const Point& pt)
{
x = pt.x;
y = pt.y;
return *this;
}
const Point& Point::operator+=(const Point& pt)
{
x += pt.x;
y += pt.y;
return *this;
}
const Point& Point::operator-=(const Point& pt)
{
x -= pt.x;
y -= pt.y;
return *this;
}
const Point& Point::operator+=(int value)
{
x += value;
y += value;
return *this;
}
const Point& Point::operator-=(int value)
{
x -= value;
y -= value;
return *this;
}
const Point& Point::operator*=(int value)
{
x *= value;
y *= value;
return *this;
}
const Point& Point::operator/=(int value)
{
x /= value;
y /= value;
return *this;
}
Point Point::operator+(const Point& pt) const
{
return Point(x+pt.x, y+pt.y);
}
Point Point::operator-(const Point& pt) const
{
return Point(x-pt.x, y-pt.y);
}
Point Point::operator+(int value) const
{
return Point(x+value, y+value);
}
Point Point::operator-(int value) const
{
return Point(x-value, y-value);
}
Point Point::operator*(int value) const
{
return Point(x*value, y*value);
}
Point Point::operator/(int value) const
{
return Point(x/value, y/value);
}
Point Point::operator-() const
{
return Point(-x, -y);
}
bool Point::operator==(const Point& pt) const
{
return x == pt.x && y == pt.y;
}
bool Point::operator!=(const Point& pt) const
{
return x != pt.x || y != pt.y;
}
#ifdef VACA_WINDOWS
Point::Point(CONST LPPOINT pt)
{
x = pt->x;
y = pt->y;
}
Point::Point(CONST LPPOINTS pt)
{
x = pt->x;
y = pt->y;
}
Point::operator POINT() const
{
POINT pt;
pt.x = x;
pt.y = y;
return pt;
}
#endif

View File

@ -0,0 +1,449 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Vaca/Rect.h"
#include "Vaca/Point.h"
#include "Vaca/Size.h"
using namespace Vaca;
/**
Creates a new empty rectangle with the origin in @c Point(0,0).
The rectangle will be @c #x=#y=#w=#h=0
@see isEmpty
*/
Rect::Rect()
{
x = 0;
y = 0;
w = 0;
h = 0;
}
/**
Creates a new rectangle with the specified size with the origin in @c Point(0,0).
The rectangle will be @c #x=#y=0.
*/
Rect::Rect(int w, int h)
{
this->x = 0;
this->y = 0;
this->w = w;
this->h = h;
}
/**
Creates a new rectangle with the specified size with the origin in @c Point(0,0).
The rectangle will be @c #x=#y=0.
*/
Rect::Rect(const Size& size)
{
x = 0;
y = 0;
w = size.w;
h = size.h;
}
/**
Creates a copy of @a rect.
*/
Rect::Rect(const Rect& rect)
{
x = rect.x;
y = rect.y;
w = rect.w;
h = rect.h;
}
/**
Creates a new rectangle with the origin in @a point
and the specified @a size.
*/
Rect::Rect(const Point& point, const Size& size)
{
this->x = point.x;
this->y = point.y;
this->w = size.w;
this->h = size.h;
}
/**
Creates a new rectangle with the origin in @a point1 and size equal
to @a point2 - @a point1.
If a coordinate of @a point1 is greater than @a point2 (Point#x
and/or Point#y), the coordinates are swapped. So the rectangle
will be:
@code
#x = MIN(point1.x, point2.x)
#y = MIN(point1.y, point2.y)
#w = MAX(point1.x, point2.x) - #x
#h = MAX(point1.x, point2.x) - #y
@endcode
See that @a point2 isn't included in the rectangle, it's
like the point returned by #getPoint2 member function.
@see #getPoint2
*/
Rect::Rect(const Point& point1, const Point& point2)
{
Point leftTop = point1;
Point rightBottom = point2;
register int t;
if (leftTop.x > rightBottom.x) {
t = leftTop.x;
leftTop.x = rightBottom.x;
rightBottom.x = t;
}
if (leftTop.y > rightBottom.y) {
t = leftTop.y;
leftTop.y = rightBottom.y;
rightBottom.y = t;
}
this->x = leftTop.x;
this->y = leftTop.y;
this->w = rightBottom.x - leftTop.x;
this->h = rightBottom.y - leftTop.y;
}
Rect::Rect(int x, int y, int w, int h)
{
this->x = x;
this->y = y;
this->w = w;
this->h = h;
}
/**
Verifies if the width and/or height of the rectangle are less or
equal than zero.
*/
bool Rect::isEmpty() const
{
return (w < 1 || h < 1);
}
/**
Returns the middle point of the rectangle (the centroid).
@return
Point(#x+#w/2, #y+#h/2)
*/
Point Rect::getCenter() const
{
return Point(x+w/2, y+h/2);
}
/**
Returns the point in the upper-left corner (that is inside the rectangle).
@return
Point(#x, #y)
*/
Point Rect::getOrigin() const
{
return Point(x, y);
}
/**
Returns point in the lower-right corner (that is outside the rectangle).
@return
Point(#x+#w, #y+#h)
*/
Point Rect::getPoint2() const
{
return Point(x+w, y+h);
}
/**
Returns the size of the rectangle.
@return
Size(#w, #h)
*/
Size Rect::getSize() const
{
return Size(w, h);
}
/**
Changes the origin of the rectangle without modifying its size.
*/
Rect& Rect::setOrigin(const Point& pt)
{
x = pt.x;
y = pt.y;
return *this;
}
/**
Changes the size of the rectangle without modifying its origin.
*/
Rect& Rect::setSize(const Size& sz)
{
w = sz.w;
h = sz.h;
return *this;
}
/**
Moves the rectangle origin in the specified delta.
@param dx
How many pixels displace the #x coordinate (#x+=dx).
@param dy
How many pixels displace the #y coordinate (#y+=dy).
@return
A reference to @c this.
*/
Rect& Rect::offset(int dx, int dy)
{
x += dx;
y += dy;
return *this;
}
/**
Moves the rectangle origin in the specified delta.
@param point
How many pixels displace the origin (#x+=point.x, #y+=point.y).
@return
A reference to @c this.
*/
Rect& Rect::offset(const Point& point)
{
x += point.x;
y += point.y;
return *this;
}
/**
Increases (or decreases if the delta is negative) the size of the
rectangle.
@param dw
How many pixels to increase the width of the rectangle #w.
@param dh
How many pixels to increase the height of the rectangle #h.
@return
A reference to @c this.
*/
Rect& Rect::inflate(int dw, int dh)
{
w += dw;
h += dh;
return *this;
}
/**
Increases (or decreases if the delta is negative) the size of the
rectangle.
@param size
How many pixels to increase the size of the
rectangle (#w+=size.w, #h+=size.h).
@return
A reference to @c this.
*/
Rect& Rect::inflate(const Size& size)
{
w += size.w;
h += size.h;
return *this;
}
/**
@todo docme
@return
A reference to @c this.
*/
Rect& Rect::enlarge(int unit)
{
x -= unit;
y -= unit;
w += unit<<1;
h += unit<<1;
return *this;
}
/**
@todo docme
@return
A reference to @c this.
*/
Rect& Rect::shrink(int unit)
{
x += unit;
y += unit;
w -= unit<<1;
h -= unit<<1;
return *this;
}
/**
Returns true if this rectangle encloses the @a pt point.
*/
bool Rect::contains(const Point& pt) const
{
return
pt.x >= x && pt.x < x+w &&
pt.y >= y && pt.y < y+h;
}
/**
Returns true if this rectangle entirely contains the @a rc rectangle.
@warning
If some rectangle is empty, this member function returns false.
*/
bool Rect::contains(const Rect& rc) const
{
if (isEmpty() || rc.isEmpty())
return false;
return
rc.x >= x && rc.x+rc.w <= x+w &&
rc.y >= y && rc.y+rc.h <= y+h;
}
/**
Returns true if the intersection between this rectangle with @a rc
rectangle is not empty.
@warning
If some rectangle is empty, this member function returns false.
*/
bool Rect::intersects(const Rect& rc) const
{
if (isEmpty() || rc.isEmpty())
return false;
return
rc.x <= x+w && rc.x+rc.w > x &&
rc.y <= y+h && rc.y+rc.h > y;
}
/**
Returns the union rectangle between this and @c rc rectangle.
@warning
If some rectangle is empty, this member function will return the
other rectangle.
*/
Rect Rect::createUnion(const Rect& rc) const
{
if (isEmpty())
return rc;
else if (rc.isEmpty())
return *this;
else
return Rect(Point(x < rc.x ? x: rc.x,
y < rc.y ? y: rc.y),
Point(x+w > rc.x+rc.w ? x+w: rc.x+rc.w,
y+h > rc.y+rc.h ? y+h: rc.y+rc.h));
}
/**
Returns the intersection rectangle between this and @c rc rectangles.
*/
Rect Rect::createIntersect(const Rect& rc) const
{
if (intersects(rc))
return Rect(Point(x > rc.x ? x: rc.x,
y > rc.y ? y: rc.y),
Point(x+w < rc.x+rc.w ? x+w: rc.x+rc.w,
y+h < rc.y+rc.h ? y+h: rc.y+rc.h));
else
return Rect();
}
bool Rect::operator==(const Rect& rc) const
{
return
x == rc.x && w == rc.w &&
y == rc.y && h == rc.h;
}
bool Rect::operator!=(const Rect& rc) const
{
return
x != rc.x || w != rc.w ||
y != rc.y || h != rc.h;
}
#ifdef VACA_WINDOWS
/**
Converts a Win32's rectangle (RECT structure) to a Vaca's rectangle
(Rect class).
@internal
*/
Rect::Rect(LPCRECT rc)
{
x = rc->left;
y = rc->top;
w = rc->right-rc->left;
h = rc->bottom-rc->top;
}
/**
Converts a Vaca's rectangle (Rect class) to a Win32's rectangle
(RECT structure).
@internal
*/
Rect::operator RECT() const
{
RECT rc;
rc.left = x;
rc.top = y;
rc.right = x+w;
rc.bottom = y+h;
return rc;
}
#endif

View File

@ -0,0 +1,183 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Vaca/Size.h"
#include "Vaca/Point.h"
using namespace Vaca;
Size::Size()
{
w = 0;
h = 0;
}
Size::Size(int w, int h)
{
this->w = w;
this->h = h;
}
Size::Size(const Size& size)
{
w = size.w;
h = size.h;
}
Size::Size(const Point& point)
{
w = point.x;
h = point.y;
}
Size Size::createUnion(const Size& sz) const
{
return Size(max_value(w, sz.w),
max_value(h, sz.h));
}
Size Size::createIntersect(const Size& sz) const
{
return Size(min_value(w, sz.w),
min_value(h, sz.h));
}
const Size& Size::operator=(const Size& sz)
{
w = sz.w;
h = sz.h;
return *this;
}
const Size& Size::operator+=(const Size& sz)
{
w += sz.w;
h += sz.h;
return *this;
}
const Size& Size::operator-=(const Size& sz)
{
w -= sz.w;
h -= sz.h;
return *this;
}
const Size& Size::operator+=(int value)
{
w += value;
h += value;
return *this;
}
const Size& Size::operator-=(int value)
{
w -= value;
h -= value;
return *this;
}
const Size& Size::operator*=(int value)
{
w *= value;
h *= value;
return *this;
}
const Size& Size::operator/=(int value)
{
w /= value;
h /= value;
return *this;
}
Size Size::operator+(const Size& sz) const
{
return Size(w+sz.w, h+sz.h);
}
Size Size::operator-(const Size& sz) const
{
return Size(w-sz.w, h-sz.h);
}
Size Size::operator+(int value) const
{
return Size(w+value, h+value);
}
Size Size::operator-(int value) const
{
return Size(w-value, h-value);
}
Size Size::operator*(int value) const
{
return Size(w*value, h*value);
}
Size Size::operator/(int value) const
{
return Size(w/value, h/value);
}
Size Size::operator-() const
{
return Size(-w, -h);
}
bool Size::operator==(const Size& sz) const
{
return w == sz.w && h == sz.h;
}
bool Size::operator!=(const Size& sz) const
{
return w != sz.w || h != sz.h;
}
#ifdef VACA_WINDOWS
Size::Size(CONST LPSIZE sz)
{
w = sz->cx;
h = sz->cy;
}
Size::operator SIZE() const
{
SIZE sz;
sz.cx = w;
sz.cy = h;
return sz;
}
#endif