From 8cad2a3ca509480ad0fb9d43c81fecf6a64c0e6b Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sat, 18 Jan 2014 23:49:26 +0100 Subject: [PATCH] CComponentsWindow: add member doCenter() Allows centering of window on screen, mostly senseful for window objects without parent --- src/gui/components/cc_frm_window.cpp | 17 ++++++++++++----- src/gui/components/cc_frm_window.h | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/gui/components/cc_frm_window.cpp b/src/gui/components/cc_frm_window.cpp index 4daada27f..0b7358700 100644 --- a/src/gui/components/cc_frm_window.cpp +++ b/src/gui/components/cc_frm_window.cpp @@ -80,11 +80,13 @@ void CComponentsWindow::initVarWindow( const int& x_pos, const int& y_pos, const //CComponentsForm cc_item_type = CC_ITEMTYPE_FRM_WINDOW; - //using current screen settings for default dimensions, do centering if default values == 0 - width = w == 0 ? frameBuffer->getScreenWidth(true) : w; - height = h == 0 ? frameBuffer->getScreenHeight(true) : h; - x = x_pos == (CC_CENTERED || 0) ? getScreenStartX(width)/2 - width/2 : x_pos; - y = y_pos == (CC_CENTERED || 0) ? getScreenStartY(height)/2 - height/2 : y_pos; + //using current screen settings for default dimensions, do use full screen if default values for width/height = 0 + int w_tmp = frameBuffer->getScreenWidth(w == 0 ? true : false); + int h_tmp = frameBuffer->getScreenHeight(h == 0 ? true : false); + width = w == 0 ? w_tmp : w; + height = h == 0 ? h_tmp : h; + x = x_pos; + y = y_pos; ccw_caption = caption; ccw_icon_name = iconname; @@ -108,6 +110,11 @@ void CComponentsWindow::initVarWindow( const int& x_pos, const int& y_pos, const initCCWItems(); } +void CComponentsWindow::doCenter(){ + x = cc_parent ? cc_parent->getWidth() - width/2 : frameBuffer->getScreenWidth(true)/2 - width/2; + y = cc_parent ? cc_parent->getHeight() - height/2 : frameBuffer->getScreenHeight(true)/2 -height/2; +} + void CComponentsWindow::setWindowCaption(neutrino_locale_t locale_text, const int& align_mode) { ccw_caption = g_Locale->getText(locale_text); diff --git a/src/gui/components/cc_frm_window.h b/src/gui/components/cc_frm_window.h index 81c8c415b..43e22724f 100644 --- a/src/gui/components/cc_frm_window.h +++ b/src/gui/components/cc_frm_window.h @@ -89,6 +89,8 @@ class CComponentsWindow : public CComponentsForm fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); + ///allow centering of window on screen, mostly senseful for window object without parent + void doCenter(); public: enum