Commit 9ec7aa82 authored by ahoms's avatar ahoms
Browse files

* renamed FrameDim to SizeUtils; added basic Point and Size functionality

* added AlignDir enum to global Constants


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@10 45c4679d-1946-429d-baad-37912b19538b
parent ff2c2d5b
MAKE_CMD = $(MAKE) -C src
all:
$(MAKE_CMD) all
clean:
$(MAKE_CMD) clean
......@@ -4,6 +4,10 @@
namespace lima
{
enum AlignDir {
Floor, Ceil,
};
enum ImageType {
Bpp8, Bpp10, Bpp12, Bpp14, Bpp16, Bpp32
};
......
#ifndef FRAMEDIM_H
#define FRAMEDIM_H
class FrameDim
{
public:
FrameDim(int width, int height, Type type);
int getWidth() const;
int getHeight() const;
Type getType() const;
int getDepth() const;
static int getTypeBpp(Type type);
static int getTypeDepth(Type depth);
private:
FrameDim();
int m_width;
int m_height;
Type m_type;
int m_depth;
};
inline FrameDim::getWidth() const
{
return m_width();
}
#endif // FRAMEDIM_H
#ifndef SIZEUTILS_H
#define SIZEUTILS_H
#include "Constants.h"
namespace lima
{
/*******************************************************************
* \class Point
* \brief Basic two-dimension arithmetic class
*
* This utility class provides basic arithmetic in two dimensions
*******************************************************************/
class Point
{
public:
Point() : x(0), y(0) {}
Point(int i) : x(i), y(i) {}
Point(int x0, int y0) : x(x0), y(y0) {}
Point(const Point& p) : x(p.x), y(p.y) {}
Point& operator =(const Point& p)
{ x = p.x, y = p.y; return *this; }
Point& operator +=(const Point& p)
{ x += p.x, y += p.y; return *this; }
Point& operator -=(const Point& p)
{ x -= p.x, y -= p.y; return *this; }
Point& operator *=(const Point& p)
{ x *= p.x, y *= p.y; return *this; }
Point& operator /=(const Point& p)
{ x /= p.x, y /= p.y; return *this; }
int getArea() const
{ return x * y; }
bool isNull() const
{ return (x == 0) && (y == 0); }
bool contains(const Point& p) const
{ return (p.x <= x) && (p.y <= y); }
void alignTo(const Point& p, AlignDir align_dir);
int x, y;
};
inline Point operator +(const Point& p1, const Point& p2)
{
Point p = p1;
return p += p2;
}
inline Point operator -(const Point& p1, const Point& p2)
{
Point p = p1;
return p -= p2;
}
inline Point operator *(const Point& p1, const Point& p2)
{
Point p = p1;
return p *= p2;
}
inline Point operator /(const Point& p1, const Point& p2)
{
Point p = p1;
return p /= p2;
}
inline bool operator ==(const Point& p1, const Point& p2)
{
return (p1.x == p2.x) && (p1.y == p2.y);
}
inline bool operator !=(const Point& p1, const Point& p2)
{
return !(p1 == p2);
}
/*******************************************************************
* \class Size
* \brief Basic rectangle size class
*
* This class helps managing the size of rectangular objects
*******************************************************************/
class Size
{
public:
Size() {}
Size(int w, int h) : m_xy(w, h) {}
Size(const Point& w_h) : m_xy(w_h) {}
Size(const Size& s) : m_xy(s.m_xy) {}
int getWidth() const
{ return m_xy.x; }
int getHeight() const
{ return m_xy.y; }
operator Point() const
{ return m_xy; }
private:
Point m_xy;
};
class FrameDim
{
public:
FrameDim(const Size& size, ImageType type);
FrameDim(int width, int height, ImageType type);
const Size& getSize() const;
ImageType getImageType() const;
int getDepth() const;
static int getImageTypeBpp(ImageType type);
static int getImageTypeDepth(ImageType type);
private:
FrameDim();
Size m_size;
ImageType m_type;
int m_depth;
};
} // lima
#endif // SIZEUTILS_H
#include "FrameDim.h"
FrameDim::FrameDim(int width, int height, Type type)
{
width = height = 0;
}
common-objs := SizeUtils.o
CXXFLAGS += -I../include -Wall
all: clean Common.o
Common.o: $(common-objs)
ld -o $@ -r $+
clean:
rm -f Common.o $(common-objs)
#include "SizeUtils.h"
using namespace lima;
/*******************************************************************
* \brief Aligns the Point to the nearest boundary another Point
*
* This method aligns the point to the nearest boundary that is
* a multiple of another Point. The align_dir parameter controls
* if the alignment is done towards the smaller or equal boundary
* (Floor) or towards the greater boundary (Ceil)
*******************************************************************/
void Point::alignTo(const Point& p, AlignDir align_dir)
{
if (align_dir == Ceil)
*this += p - 1;
*this /= p;
*this *= p;
}
FrameDim::FrameDim(const Size& size, ImageType type)
{
m_size = size;
m_type = type;
m_depth = getImageTypeDepth(type);
}
FrameDim::FrameDim(int width, int height, ImageType type)
{
m_size = Size(width, height);
m_type = type;
m_depth = getImageTypeDepth(type);
}
const Size& FrameDim::getSize() const
{
return m_size;
}
ImageType FrameDim::getImageType() const
{
return m_type;
}
int FrameDim::getDepth() const
{
return m_depth;
}
int FrameDim::getImageTypeBpp(ImageType type)
{
switch (type) {
case Bpp8: return 8;
case Bpp10: return 10;
case Bpp12: return 12;
case Bpp14: return 14;
case Bpp16: return 16;
case Bpp32: return 32;
default: return 0;
}
}
int FrameDim::getImageTypeDepth(ImageType type)
{
switch (type) {
case Bpp8:
return 1;
case Bpp10:
case Bpp12:
case Bpp14:
case Bpp16:
return 2;
case Bpp32:
return 4;
default:
return 0;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment