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>
* Add macro _METHOD_CALLBACK and _FUNCTION_CALLBACK
to simplify the use callback functions

View File

@ -1,6 +1,6 @@
#ifndef _SRC_FCONFIG_H
#define _SRC_FCONFIG_H 1
/* src/fconfig.h. Generated automatically at end of configure. */
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
@ -171,6 +171,6 @@
#ifndef F_VERSION
#define F_VERSION "0.1.1"
#endif
/* once: _SRC_FCONFIG_H */
#endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -67,6 +67,20 @@ void FRect::setY (int n)
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)
{

View File

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

View File

@ -1483,6 +1483,41 @@ void FWidget::setY (int y, bool adjust)
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)
{

View File

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