diff --git a/ChangeLog b/ChangeLog index 28b7e46c..36bb1f19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2015-09-27 Markus Gans + * Add methods getPos and setPos to FRect and FWidget + 2015-09-24 Markus Gans * Add macro _METHOD_CALLBACK and _FUNCTION_CALLBACK to simplify the use callback functions diff --git a/src/fconfig.h b/src/fconfig.h index fcb80772..6bbb1b4f 100644 --- a/src/fconfig.h +++ b/src/fconfig.h @@ -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 diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 8ca7e6af..27d64743 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -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) diff --git a/src/fmenu.h b/src/fmenu.h index 51ca8084..a6b2e70b 100644 --- a/src/fmenu.h +++ b/src/fmenu.h @@ -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; diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index b36ac374..f16d2008 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -12,6 +12,7 @@ FMenuBar::FMenuBar(FWidget* parent) : FWindow(parent) , mouse_down(false) + , next_item_pos(1,1) , x(-1) { init(); diff --git a/src/fmenubar.h b/src/fmenubar.h index dec3a2dd..2e4fa9fa 100644 --- a/src/fmenubar.h +++ b/src/fmenubar.h @@ -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&); diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 59910dff..7b41bc5f 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -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); } diff --git a/src/fmenuitem.h b/src/fmenuitem.h index 4a4d9fc8..98ec746a 100644 --- a/src/fmenuitem.h +++ b/src/fmenuitem.h @@ -48,6 +48,7 @@ class FMenuItem : public FWidget bool selected; bool separator; bool checked; + uInt text_length; int hotkey; //int accel_key; FMenu* menu; diff --git a/src/fmenulist.h b/src/fmenulist.h index 1177527c..b393c002 100644 --- a/src/fmenulist.h +++ b/src/fmenulist.h @@ -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 │ + └───────────┘ */ //---------------------------------------------------------------------- diff --git a/src/frect.cpp b/src/frect.cpp index 94bac303..e8b8095b 100644 --- a/src/frect.cpp +++ b/src/frect.cpp @@ -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) { diff --git a/src/frect.h b/src/frect.h index c3110eb3..f64b5418 100644 --- a/src/frect.h +++ b/src/frect.h @@ -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; } diff --git a/src/fwidget.cpp b/src/fwidget.cpp index d1ef48bb..207f6de2 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -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) { diff --git a/src/fwidget.h b/src/fwidget.h index 92997adc..69775227 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -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; }