Patch level : 2.1 nopatch
Files correlati : agalib.lib Ricompilazione Demo : [ ] Commento : Aggiunta classe TRectangle (TPoint esisteva gia') per gestire rettangoli logici ed operazioni con punti logici git-svn-id: svn://10.65.10.50/trunk@11919 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
0d1caf6829
commit
aa56dda073
@ -11,6 +11,79 @@
|
||||
#include <window.h>
|
||||
#include <xvtility.h>
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TRectangle
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
void TRectangle::copy(const TRectangle& r)
|
||||
{
|
||||
x = r.x; y = r.y;
|
||||
_size = r._size;
|
||||
}
|
||||
|
||||
void TRectangle::normalize()
|
||||
{
|
||||
if (_size.x < 0)
|
||||
{
|
||||
x += _size.x;
|
||||
_size.x = -_size.x;
|
||||
}
|
||||
if (_size.y < 0)
|
||||
{
|
||||
y += _size.y;
|
||||
_size.y = -_size.y;
|
||||
}
|
||||
}
|
||||
|
||||
void TRectangle::set(long cx, long cy, long dx, long dy)
|
||||
{
|
||||
x = cx; y = cy;
|
||||
_size.set(dx, dy);
|
||||
normalize();
|
||||
}
|
||||
|
||||
void TRectangle::set(const TPoint& pt, const TPoint& sz)
|
||||
{
|
||||
set(pt.x, pt.y, sz.x, sz.y);
|
||||
}
|
||||
|
||||
void TRectangle::set_bounds(long left, long top, long right, long bottom)
|
||||
{
|
||||
set(left, top, right-left, bottom-top);
|
||||
}
|
||||
|
||||
bool TRectangle::contains(const TPoint& p) const
|
||||
{
|
||||
if (p.x < left()) return false;
|
||||
if (p.y < top()) return false;
|
||||
if (p.x > right()) return false;
|
||||
if (p.y > bottom()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TRectangle::intersects(const TRectangle& r) const
|
||||
{
|
||||
if (left() > r.right()) return false;
|
||||
if (right() < r.left()) return false;
|
||||
if (top() > r.bottom()) return false;
|
||||
if (bottom() < r.top()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TRectangle::merge(const TRectangle& rct)
|
||||
{
|
||||
long l = x, t = y, r = right(), b = bottom();
|
||||
if (rct.x < l) l = rct.x;
|
||||
if (rct.y < t) t = rct.y;
|
||||
if (rct.right() > r) r = rct.right();
|
||||
if (rct.bottom() > b) b = rct.bottom();
|
||||
set_bounds(l, t, r, b);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Utilities
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
HIDDEN MENU_ITEM* find_menu_item(MENU_ITEM* menu, MENU_TAG id, bool ismbar)
|
||||
{
|
||||
MENU_ITEM* fnd = NULL;
|
||||
@ -761,9 +834,7 @@ int TWindow::char2pixel(int len) const
|
||||
|
||||
PNT TWindow::log2dev(long x, long y) const
|
||||
{
|
||||
PNT pnt;
|
||||
pnt.h = (int)x;
|
||||
pnt.v = (int)y;
|
||||
PNT pnt = { short(y), short(x) };
|
||||
if (!_pixmap)
|
||||
{
|
||||
pnt.h = char2pixel(pnt.h);
|
||||
@ -783,6 +854,23 @@ TPoint TWindow::dev2log(const PNT& p) const
|
||||
return pnt;
|
||||
}
|
||||
|
||||
void TWindow::log2dev(const TRectangle& lrct, RCT& drct) const
|
||||
{
|
||||
const PNT dp0 = log2dev(lrct.x, lrct.y);
|
||||
const PNT dp1 = log2dev(lrct.right(), lrct.bottom());
|
||||
drct.left = dp0.h; drct.top = dp0.v;
|
||||
drct.right = dp1.h; drct.bottom = dp1.v;
|
||||
}
|
||||
|
||||
void TWindow::dev2log(const RCT& rctd, TRectangle& rctl) const
|
||||
{
|
||||
const PNT dp0 = { rctd.top, rctd.left };
|
||||
const PNT dp1 = { rctd.bottom, rctd.right };
|
||||
const TPoint lp0 = dev2log(dp0);
|
||||
const TPoint lp1 = dev2log(dp1);
|
||||
rctl.set_bounds(lp0.x, lp0.y, lp1.x, lp1.y);
|
||||
}
|
||||
|
||||
void TWindow::stringat(short x, short y, const char* str)
|
||||
{
|
||||
PNT pnt = log2dev(x,y);
|
||||
|
@ -20,28 +20,28 @@ WINDOW cur_win();
|
||||
// @author:(INTERNAL) Guido
|
||||
struct TPoint
|
||||
{
|
||||
// @cmember Coordinata x del punto
|
||||
long x;
|
||||
// @cmember Coordinata y del punto
|
||||
long y;
|
||||
// @cmember Coordinate del punto
|
||||
long x,y;
|
||||
|
||||
// @cmember Costruttore
|
||||
TPoint(long sx = 0, long sy = 0) : x(sx), y(sy)
|
||||
{}
|
||||
// @cmember Costruttore (occorre passare il punto)
|
||||
TPoint(const PNT& pnt)
|
||||
{ set(pnt); }
|
||||
// @cmember Setta le coordinate x e y del punto
|
||||
void set(long sx, long sy)
|
||||
{ x = sx; y = sy; }
|
||||
|
||||
/*
|
||||
//TPoint(const PNT& pnt) { set(pnt); }
|
||||
// @cmember Setta le coordinate x e y del punto
|
||||
void set(const PNT& pnt)
|
||||
{ x = pnt.h/CHARX; y = pnt.v/CHARY; }
|
||||
// @cmember Setta le coordinate x e y del punto
|
||||
// @cmember Operatore di assegnamento tra punti
|
||||
TPoint& operator= (const PNT& pnt)
|
||||
{ set(pnt); return *this; }
|
||||
*/
|
||||
|
||||
void set(long sx, long sy)
|
||||
{ x = sx; y = sy; }
|
||||
// @cmember Operatore di assegnamento tra punti
|
||||
TPoint& operator= (TPoint pnt)
|
||||
TPoint& operator= (const TPoint& pnt)
|
||||
{ set(pnt.x,pnt.y); return *this; }
|
||||
// @cmember Confronta se due punti sono uguali (TRUE se uguali)
|
||||
bool operator ==(const TPoint& p)
|
||||
@ -51,6 +51,42 @@ struct TPoint
|
||||
{ return p.x != x || p.y != y; }
|
||||
};
|
||||
|
||||
class TRectangle : public TPoint
|
||||
{
|
||||
TPoint _size;
|
||||
|
||||
protected:
|
||||
void copy(const TRectangle& r);
|
||||
void normalize();
|
||||
|
||||
public:
|
||||
long left() const { return x; }
|
||||
long right() const { return x + _size.x; }
|
||||
long top() const { return y; }
|
||||
long bottom() const { return y + _size.y; }
|
||||
long width() const { return _size.x; }
|
||||
long height() const { return _size.y; }
|
||||
const TPoint& pos() const { return *this; }
|
||||
const TPoint& size() const { return _size; }
|
||||
|
||||
void set_width(long w) { _size.x = w; normalize(); }
|
||||
void set_height(long h) { _size.y = h; normalize(); }
|
||||
void set(long cx, long cy, long dx, long dy);
|
||||
void set(const TPoint& pt, const TPoint& sz);
|
||||
void set_bounds(long left, long top, long right, long bottom);
|
||||
|
||||
bool contains(const TPoint& p) const;
|
||||
bool intersects(const TRectangle& r) const;
|
||||
void merge(const TRectangle& r);
|
||||
bool is_empty() const { return _size.x > 0 && _size.y > 0; }
|
||||
|
||||
TRectangle& operator=(const TRectangle& r) { copy(r); return *this; }
|
||||
TRectangle() : TPoint(0,0), _size(0,0) { }
|
||||
TRectangle(const TPoint& p, const TPoint& s) : TPoint(p), _size(s) { }
|
||||
TRectangle(long cx, long cy, long dx, long dy) { set(cx, cy, dx, dy); }
|
||||
TRectangle(const TRectangle& r) { copy(r); }
|
||||
};
|
||||
|
||||
// @doc EXTERNAL
|
||||
|
||||
// @class TWindow | Classe per la definizione di una finestra generica
|
||||
@ -238,6 +274,9 @@ public:
|
||||
// @cmember Converte le coordinate fisiche (pixel) in coordinate logiche (caratteri)
|
||||
virtual TPoint dev2log(const PNT& p) const;
|
||||
|
||||
virtual void log2dev(const TRectangle& rctl, RCT& rctd) const;
|
||||
virtual void dev2log(const RCT& rctd, TRectangle& rctl) const;
|
||||
|
||||
// @cmember Disegna un rettangolo con la possibilita' di settare la penna e il draw_mode
|
||||
void frame(short left, short top, short right, short bottom, int flag);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user