Add methods getPos and setPos to FRect and FWidget

This commit is contained in:
Markus Gans 2015-09-27 16:00:13 +02:00
parent 2afa9907ac
commit 2a44a415f3
13 changed files with 149 additions and 49 deletions

View File

@ -1,3 +1,6 @@
2015-09-27 Markus Gans <guru.mail@muenster.de>
* Add methods getPos and setPos to FRect and FWidget
2015-09-24 Markus Gans <guru.mail@muenster.de> 2015-09-24 Markus Gans <guru.mail@muenster.de>
* Add macro _METHOD_CALLBACK and _FUNCTION_CALLBACK * Add macro _METHOD_CALLBACK and _FUNCTION_CALLBACK
to simplify the use callback functions to simplify the use callback functions

View File

@ -13,6 +13,7 @@ FMenu::FMenu(FWidget* parent)
: FWindow(parent) : FWindow(parent)
, item(0) , item(0)
, super_menu(0) , super_menu(0)
, next_item_pos(1,1)
, maxItemWidth(0) , maxItemWidth(0)
, current(0) , current(0)
, mouse_down(false) , mouse_down(false)
@ -25,6 +26,7 @@ FMenu::FMenu (FString& txt, FWidget* parent)
: FWindow(parent) : FWindow(parent)
, item(0) , item(0)
, super_menu(0) , super_menu(0)
, next_item_pos(1,1)
, maxItemWidth(0) , maxItemWidth(0)
, current(0) , current(0)
, mouse_down(false) , mouse_down(false)
@ -38,6 +40,7 @@ FMenu::FMenu (const std::string& txt, FWidget* parent)
: FWindow(parent) : FWindow(parent)
, item(0) , item(0)
, super_menu(0) , super_menu(0)
, next_item_pos(1,1)
, maxItemWidth(0) , maxItemWidth(0)
, current(0) , current(0)
, mouse_down(false) , mouse_down(false)
@ -51,6 +54,7 @@ FMenu::FMenu (const char* txt, FWidget* parent)
: FWindow(parent) : FWindow(parent)
, item(0) , item(0)
, super_menu(0) , super_menu(0)
, next_item_pos(1,1)
, maxItemWidth(0) , maxItemWidth(0)
, current(0) , current(0)
, mouse_down(false) , mouse_down(false)

View File

@ -16,16 +16,16 @@
// ▕▁▁▁▁▁▁▁▁▁▏ // ▕▁▁▁▁▁▁▁▁▁▏
// ▲ // ▲
// │ // │
// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▏ // ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▔▔▏
// ▕ FWindow ▏ ▕ FMenuList ▏- - - -▕ FMenuItem ▏ // ▕ FWindow ▏ ▕ FMenuList ▏- - - -▕ FMenuItem ▏
// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▏ // ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▏1 *▕▁▁▁▁▁▁▁▁▁▁▁▏
// ▲ ▲ // ▲ ▲ 1:
// │ │ // │ │ :
// └─────┬─────┘ // └─────┬─────┘ :
// │ // │ 1 :
// ▕▔▔▔▔▔▔▔▏ // ▕▔▔▔▔▔▔▔▏- - - ┘ ▕▔▔▔▔▔▔▔▔▔▔▔▏
// ▕ FMenu ▏ // ▕ FMenu ▏- - - - - - - -▕ FMenuItem ▏
// ▕▁▁▁▁▁▁▁▏ // ▕▁▁▁▁▁▁▁▏1 1▕▁▁▁▁▁▁▁▁▁▁▁▏
#ifndef _FMENU_H #ifndef _FMENU_H
#define _FMENU_H #define _FMENU_H
@ -47,6 +47,7 @@ class FMenu : public FWindow, public FMenuList
private: private:
FMenuItem* item; FMenuItem* item;
FMenuList* super_menu; FMenuList* super_menu;
FPoint next_item_pos;
uInt maxItemWidth; uInt maxItemWidth;
int current; int current;
bool mouse_down; bool mouse_down;

View File

@ -12,6 +12,7 @@
FMenuBar::FMenuBar(FWidget* parent) FMenuBar::FMenuBar(FWidget* parent)
: FWindow(parent) : FWindow(parent)
, mouse_down(false) , mouse_down(false)
, next_item_pos(1,1)
, x(-1) , x(-1)
{ {
init(); init();

View File

@ -44,8 +44,9 @@
class FMenuBar : public FWindow, public FMenuList class FMenuBar : public FWindow, public FMenuList
{ {
private: private:
bool mouse_down; bool mouse_down;
int x; FPoint next_item_pos;
int x;
private: private:
FMenuBar (const FMenuBar&); FMenuBar (const FMenuBar&);

View File

@ -19,6 +19,7 @@ FMenuItem::FMenuItem (FWidget* parent)
, selected(false) , selected(false)
, separator(false) , separator(false)
, checked(false) , checked(false)
, text_length(0)
, hotkey(0) , hotkey(0)
//, accel_key(0) //, accel_key(0)
, menu(0) , menu(0)
@ -35,6 +36,7 @@ FMenuItem::FMenuItem (FString& txt, FWidget* parent)
, selected(false) , selected(false)
, separator(false) , separator(false)
, checked(false) , checked(false)
, text_length(0)
, hotkey(0) , hotkey(0)
//, accel_key(0) //, accel_key(0)
, menu(0) , menu(0)
@ -51,6 +53,7 @@ FMenuItem::FMenuItem (const std::string& txt, FWidget* parent)
, selected(false) , selected(false)
, separator(false) , separator(false)
, checked(false) , checked(false)
, text_length(0)
, hotkey(0) , hotkey(0)
//, accel_key(0) //, accel_key(0)
, menu(0) , menu(0)
@ -67,6 +70,7 @@ FMenuItem::FMenuItem (const char* txt, FWidget* parent)
, selected(false) , selected(false)
, separator(false) , separator(false)
, checked(false) , checked(false)
, text_length(0)
, hotkey(0) , hotkey(0)
//, accel_key(0) //, accel_key(0)
, menu(0) , menu(0)
@ -84,8 +88,11 @@ FMenuItem::~FMenuItem() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::init (FWidget* parent) void FMenuItem::init (FWidget* parent)
{ {
text_length = text.getLength();
hotkey = getHotkey(); hotkey = getHotkey();
setGeometry (1,1,1,1); if ( hotkey )
text_length--;
setGeometry (1,1,text_length+2,1);
if ( parent ) if ( parent )
{ {
@ -200,19 +207,31 @@ void FMenuItem::setSelected()
inline void FMenuItem::setText (FString& txt) inline void FMenuItem::setText (FString& txt)
{ {
text = txt; text = txt;
text_length = text.getLength();
hotkey = getHotkey(); hotkey = getHotkey();
if ( hotkey )
text_length--;
setWidth(text_length);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenuItem::setText (const std::string& txt) inline void FMenuItem::setText (const std::string& txt)
{ {
text = txt; text = txt;
text_length = text.getLength();
hotkey = getHotkey(); hotkey = getHotkey();
if ( hotkey )
text_length--;
setWidth(text_length);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenuItem::setText (const char* txt) inline void FMenuItem::setText (const char* txt)
{ {
text = txt; text = txt;
text_length = text.getLength();
hotkey = getHotkey(); hotkey = getHotkey();
if ( hotkey )
text_length--;
setWidth(text_length);
} }

View File

@ -48,6 +48,7 @@ class FMenuItem : public FWidget
bool selected; bool selected;
bool separator; bool separator;
bool checked; bool checked;
uInt text_length;
int hotkey; int hotkey;
//int accel_key; //int accel_key;
FMenu* menu; FMenu* menu;

View File

@ -16,15 +16,22 @@
#include "fwidget.h" #include "fwidget.h"
/* /*
- FMenuBar muß die x + y Positionen des nächsten
FWindow FMenuBar einzufügenden FMenuItem kennen
- FMenu muß die x + y Positionen des nächsten
FMenuList ----- FMenu einzufügenden FMenuItem kennen
:
:
---- FMenuItem FWindow FMenuBar
FMenuList FMenu
:
----------------- FMenuItem
*/ */
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -67,6 +67,20 @@ void FRect::setY (int n)
Y2 = short(Y1 + dY); Y2 = short(Y1 + dY);
} }
//----------------------------------------------------------------------
void FRect::setPos (int x, int y)
{
X1 = short(x);
Y1 = short(y);
}
//----------------------------------------------------------------------
void FRect::setPos (const FPoint& p)
{
X1 = short(p.getX());
Y1 = short(p.getY());
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FRect::setWidth (int w) void FRect::setWidth (int w)
{ {

View File

@ -37,34 +37,37 @@ class FRect
virtual ~FRect(); // destructor virtual ~FRect(); // destructor
virtual const char* getClassName(); virtual const char* getClassName();
bool isNull() const; bool isNull() const;
int getX1() const; int getX1() const;
int getY1() const; int getY1() const;
int getX2() const; int getX2() const;
int getY2() const; int getY2() const;
int getX() const; int getX() const;
int getY() const; int getY() const;
int getWidth() const; FPoint getPos() const;
int getHeight() const; int getWidth() const;
int getHeight() const;
void setX1 (int); void setX1 (int);
void setY1 (int); void setY1 (int);
void setX2 (int); void setX2 (int);
void setY2 (int); void setY2 (int);
void setX (int); void setX (int);
void setY (int); void setY (int);
void setWidth (int); void setPos (int, int);
void setHeight (int); void setPos (const FPoint&);
void setRect (const FRect&); void setWidth (int);
void setRect (int, int, int, int); void setHeight (int);
void setRect (const FRect&);
void setRect (int, int, int, int);
void move (int, int); void move (int, int);
void move (const FPoint&); void move (const FPoint&);
bool contains (int, int) const; bool contains (int, int) const;
bool contains (const FPoint&) const; bool contains (const FPoint&) const;
bool contains (const FRect&) const; bool contains (const FRect&) const;
bool overlap (const FRect&) const; bool overlap (const FRect&) const;
FRect intersect (const FRect&) const; FRect intersect (const FRect&) const;
friend FRect operator + (const FRect&, const FPoint&); friend FRect operator + (const FRect&, const FPoint&);
friend FRect operator - (const FRect&, const FPoint&); friend FRect operator - (const FRect&, const FPoint&);
@ -119,6 +122,10 @@ inline int FRect::getX() const
inline int FRect::getY() const inline int FRect::getY() const
{ return Y1; } { return Y1; }
//----------------------------------------------------------------------
inline FPoint FRect::getPos() const
{ return FPoint(X1,Y1); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline int FRect::getWidth() const inline int FRect::getWidth() const
{ return X2 - X1 + 1; } { return X2 - X1 + 1; }

View File

@ -1483,6 +1483,41 @@ void FWidget::setY (int y, bool adjust)
adjustSize(); adjustSize();
} }
//----------------------------------------------------------------------
void FWidget::setPos (const FPoint& p, bool adjust)
{
setPos (p.getX(), p.getY(), adjust);
}
//----------------------------------------------------------------------
void FWidget::setPos (int x, int y, bool adjust)
{
if ( xpos == x && widgetSize.getX() == x )
return;
if ( ypos == y && widgetSize.getY() == y )
return;
if ( ! isWindow() )
{
(x > 0) ? xpos = x : xpos = 1;
(y > 0) ? ypos = y : ypos = 1;
}
else
{
xpos = x;
ypos = y;
}
widgetSize.setPos(xpos,ypos);
adjustWidgetSize.setPos(xpos,ypos);
adjustWidgetSizeShadow = adjustWidgetSize + shadow;
adjustWidgetSizeGlobal.setPos(xpos + xmin - 1, ypos + ymin - 1);
adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal + shadow;
if ( adjust )
adjustSize();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::setWidth (int w, bool adjust) void FWidget::setWidth (int w, bool adjust)
{ {

View File

@ -391,6 +391,7 @@ class FWidget : public FObject, public FTerm
int getBackgroundColor() const; int getBackgroundColor() const;
int getX() const; int getX() const;
int getY() const; int getY() const;
const FPoint getPos() const;
int getGlobalX() const; int getGlobalX() const;
int getGlobalY() const; int getGlobalY() const;
const FPoint getGlobalPos() const; const FPoint getGlobalPos() const;
@ -412,6 +413,8 @@ class FWidget : public FObject, public FTerm
void setBackgroundColor (int); void setBackgroundColor (int);
void setX (int, bool adjust=true); void setX (int, bool adjust=true);
void setY (int, bool adjust=true); void setY (int, bool adjust=true);
void setPos (const FPoint&, bool adjust=true);
void setPos (int, int, bool adjust=true);
void setWidth (int, bool adjust=true); void setWidth (int, bool adjust=true);
void setHeight (int, bool adjust=true); void setHeight (int, bool adjust=true);
void setTopPadding (int, bool adjust=true); void setTopPadding (int, bool adjust=true);
@ -585,6 +588,10 @@ inline int FWidget::getX() const
inline int FWidget::getY() const inline int FWidget::getY() const
{ return ypos; } { return ypos; }
//----------------------------------------------------------------------
inline const FPoint FWidget::getPos() const
{ return adjustWidgetSize.getPos(); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline int FWidget::getGlobalX() const inline int FWidget::getGlobalX() const
{ return xpos+xmin-1; } { return xpos+xmin-1; }