00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef BGRAPHICS_H
00015 #define BGRAPHICS_H
00016
00017
00018 #include <nds.h>
00019
00020
00021 #include "BImage.h"
00022
00023 class BImage;
00024
00025 class BPoint {
00026 public:
00027 BPoint(int x=0, int y=0)
00028 {
00029 this->x = x; this->y = y;
00030 }
00031
00032 BPoint operator+(const BPoint& pt) { return BPoint(x+pt.x, y+pt.y); }
00033 BPoint operator-(const BPoint& pt) { return BPoint(x-pt.x, y-pt.y); }
00034 int x, y;
00035 };
00036
00037 class BSize {
00038 public:
00039 BSize(unsigned int width=0, unsigned int height=0)
00040 {
00041 this->width = width; this->height = height;
00042 }
00043
00044 inline bool isZeroSize() { return width==0 || height==0; }
00045 int width, height;
00046 };
00047
00048 class BLine {
00049 public:
00050 BLine(const BPoint& p0, const BPoint& p1)
00051 {
00052 this->p0 = p0; this->p1 = p1;
00053 }
00054 BLine(int x1, int y1, int x2, int y2)
00055 {
00056 BLine(BPoint(x1, y1), BPoint(x2, y2));
00057 }
00058
00059 BPoint p0, p1;
00060 void draw(BImage& img, uint16 color) const;
00061 };
00062
00063 class BRect {
00064 public:
00065 BRect(int x=0, int y=0, unsigned int width=0, unsigned int height=0);
00066 BRect(const BPoint& point, const BSize& size);
00067 BRect(const BPoint& p1, const BPoint& p2);
00068
00069 BPoint pt;
00070 BSize sz;
00071
00072 inline BPoint topLeft() const {
00073 return pt;
00074 }
00075 inline BPoint topRight() const {
00076 return BPoint(pt.x+sz.width, pt.y);
00077 }
00078 inline BPoint bottomLeft() const {
00079 return BPoint(pt.x, pt.y+sz.height);
00080 }
00081 inline BPoint bottomRight() const {
00082 return BPoint(pt.x+sz.width, pt.y+sz.height);
00083 }
00084
00085 BRect insetRect(int left, int right, int top, int bottom) const;
00086
00087 inline bool intersects(const BRect& r) const {
00088 return (pt.x + sz.width > r.pt.x && pt.x < r.pt.x + r.sz.width &&
00089 pt.y + sz.height > r.pt.y && pt.y < r.pt.y + r.sz.height);
00090 }
00091
00092 void outline(BImage& img, uint16 color) const;
00093 void fill(BImage& img, uint16 color) const;
00094 bool containsPoint(const BPoint& p) const;
00095 };
00096
00097 inline uint16 alphablend(uint16 rgb1, uint16 rgb2, char alpha)
00098 {
00099 alpha &= 0x1f;
00100 uint16 rb1 = rgb1 & 0x7c1f;
00101 uint16 rb2 = rgb2 & 0x7c1f;
00102 uint16 g1 = rgb1 & 0x3e0;
00103 uint16 g2 = rgb2 & 0x3e0;
00104 uint16 rbout = (rb2 + (((rb1-rb2)*alpha + 0x4010) >> 5)) & 0x7c1f;
00105 uint16 gout = (g2 + (((g1-g2)*alpha + 0x200) >> 5)) & 0x3e0;
00106
00107 return rbout | gout | 0x8000;
00108 }
00109
00110 #endif