Example #1
0
void VEditTab::handleFocusChanged(QWidget * /* p_old */, QWidget *p_now)
{
    if (p_now == this) {
        // When VEditTab get focus, it should focus to current widget.
        focusChild();

        emit getFocused();
        updateStatus();
    } else if (isAncestorOf(p_now)) {
        emit getFocused();
        updateStatus();
    }
}
Example #2
0
    void Frame::repaint()
    {
        if (this->__g == NULL) return;
        /* 矩形ウィンドウ */
        int w = getWidth();
        int h = getHeight();
        /* 外枠 */
        __g->setColor(Color::lightGray);
        __g->fillRect(0, 0, w, h);
        __g->setColor(Color::black);
        __g->drawRect(0, 0, w, h);
        /* 内枠 */
        __g->setColor(Color::black);
        __g->drawRect(5, 21, w - 10, h - 26);

        /* 枠 */
        __g->setColor(Color::white);
        __g->drawLine(1, 1, w - 2, 1);
        __g->drawLine(1, 1, 1, h - 2);
        __g->drawLine(w - 5, 21, w - 5, h - 5);
        __g->drawLine(5, h - 5, w - 5, h - 5);
        __g->setColor(Color::gray);
        __g->drawLine(w - 2, 2, w - 2, h - 2);
        __g->drawLine(2, h - 2, w - 2, h - 2);
        __g->drawLine(4, 20, w - 6, 20);
        __g->drawLine(4, 20, 4, h - 6);

        if (getFocused() == true) {
            /* タイトルバー */
            for (int i = 4; i <= 14; i = i + 2) {
                __g->setColor(Color::gray);
                __g->drawLine(20, i, w - 7, i);
                __g->setColor(Color::white);
                __g->drawLine(21, i + 1, w - 6, i + 1);
            }
            drawCloseButton(__g);
        }

        /* タイトル */
        int fw = getFontMetrics()->getWidth(getTitle());
        int fh = getFontMetrics()->getHeight(getTitle());
        __g->setColor(Color::lightGray);
        __g->fillRect(((w - fw) / 2) - 4, 2, fw + 8, getInsets()->top - 4);
        if (getFocused() == true) {
            __g->setColor(Color::black);
        } else {
            __g->setColor(Color::gray);
        }
        __g->drawString(getTitle(), ((w - fw) / 2), ((getInsets()->top - fh) / 2));
        Container::repaint();
    }
bool InternalWindow::takeFocus(bool Temporary)
{

    if(getFocused() &&
       getDrawingSurface() != NULL &&
       getDrawingSurface()->getFocusedWindow() == InternalWindowRefPtr(this))
    {
        return true;
    }
    setFocused(true);
    if(Temporary || getDrawingSurface() == NULL)
    {
        focusGained(FocusEvent::create(ComponentRefPtr(this),getSystemTime(),Temporary, NULL));
    }
    else
    {
        if(getDrawingSurface()->getFocusedWindow() != NULL)
        {
            getDrawingSurface()->getFocusedWindow()->giveFocus(this);
        }
        getDrawingSurface()->setFocusedWindow(this);
        focusGained(FocusEvent::create(ComponentRefPtr(this),getSystemTime(),Temporary, getDrawingSurface()->getFocusedWindow()));
    }
    return true;
}
Example #4
0
Border* AbstractWindow::getDrawnBorder(void) const
{
    if(getDrawDecorations())
    {
        if(getEnabled())
        {
            if(getFocused())
            {
                return getFocusedBorder();
            }
            else if(_MouseInComponentLastMouse)
            {
                return getRolloverBorder();
            }
            else
            {
                return getBorder();
            }
        }
        else
        {
            return getDisabledBorder();
        }
    }
    else
    {
        return NULL;
    }
}
Example #5
0
	void TMenuItem::paintAt(Graphics* g, int x, int y) {
		switch (type) {
			case TYPE_ITEM:
				if (getEnabled()) {
					if (getFocused()) {
						g->setColor(Color::blue);
						g->drawRect(x, y, getWidth(), getHeight());
						g->setColor(COLOR_BLUEGRAY);
						g->fillRect(x + 1, y + 1, getWidth() - 2, getHeight() - 2);
					} else {
						g->setColor(getBackground());
						g->fillRect(x, y, getWidth(), getHeight());
					}
					g->setColor(getForeground());
					g->drawString(title, x + 10, y + 3);
				} else {
					g->setColor(getBackground());
					g->fillRect(x, y, getWidth(), getHeight());
					g->setColor(Color::gray);
					g->drawString(title, 10 + x, 3 + y);
				}
				break;
			case TYPE_SEPARATOR:
				g->setColor(getForeground());
				g->drawLine(x + 5, y + 3, x + getWidth() - 5, y + 3);
				break;
			default:
				break;
		}
	}
Example #6
0
////////////////////////
// Internal function for setting the selected item
// The caller is responsible for the valid input
void CListview::setSelected(const std::list<CListviewItem *>::iterator& item, int index)
{
	if (iSelected == index)
		return;

	// Call the OnChange event
	bool cancel = false;
	CALL_EVENT(OnChange, (this, ((index < 0 || item == tItems.end()) ? NULL : *item), index, cancel));
	if (cancel)
		return;

	iSelected = index;
	if (iSelected >= 0 && item != tItems.end())  {
		// Take off focus from the old item
		if (tSelected)  {
			tSelected->setSelected(false);
			tSelected->setSelectedInactive(false);
		}

		tSelected = (*item);
		if (getFocused())
			tSelected->setSelected(true);
		else
			tSelected->setSelectedInactive(true);

	} else  {
		iSelected = -1;
		tSelected = NULL;
	}

	// Repaint
	Repaint();
}
Example #7
0
Layer* AbstractWindow::getDrawnForeground(void) const
{
	if(getDrawDecorations())
    {
        if(getEnabled())
        {
            if(getFocused())
            {
                return getFocusedForeground();
            }
            else if(_MouseInComponentLastMouse)
            {
                return getRolloverForeground();
            }
            else
            {
                return getForeground();
            }
        }
        else
        {
            return getDisabledForeground();
        }
    }
    else
	{
		return NULL;
	}
}
Example #8
0
bool InternalWindow::takeFocus(bool Temporary)
{

    if(getFocused() &&
       getParentDrawingSurface() != NULL &&
       getParentDrawingSurface()->getFocusedWindow() == this)
    {
        return true;
    }
    setFocused(true);
    if(Temporary || getParentDrawingSurface() == NULL)
    {
        FocusEventDetailsUnrecPtr Details(FocusEventDetails::create(this,getSystemTime(),Temporary, NULL));

        focusGained(Details);
    }
    else
    {
        if(getParentDrawingSurface()->getFocusedWindow() != NULL)
        {
            getParentDrawingSurface()->getFocusedWindow()->giveFocus(this);
        }
        getParentDrawingSurface()->setFocusedWindow(this);
        FocusEventDetailsUnrecPtr Details(FocusEventDetails::create(this,getSystemTime(),Temporary, getParentDrawingSurface()->getFocusedWindow()));
        focusGained(Details);
    }
    return true;
}
Example #9
0
    void TextField::paint(Graphics* g)
    {
        int w = getWidth(), h = getHeight();

        // 外枠
        if (getFocused() == true && getEnabled() == true) {
            g->setColor(0, 128, 255);
            g->drawRect(0, 0, w, h);
        } else {
            g->setColor(getParent()->getBackground());
            g->drawRect(0, 0, w, h);
        }
        // 内枠
        g->setColor(getBackground());
        g->fillRect(1, 1, w - 2, h - 2);
        g->setColor(getForeground());
        g->drawRect(1, 1, w - 2, h - 2);
        // 文字
        int fh = getFontMetrics()->getHeight(getText());
        int fw = getFontMetrics()->getWidth(getText());

        if (getEnabled() == true) {
            g->setColor(getForeground());
        } else {
            g->setColor(Color::gray);
        }
        g->drawString(getText(), this->offx, (h - fh) / 2);

        // キャレット
        if (getFocused() == true && getEnabled() == true) {
            g->drawLine(offx + fw, offy, offx + fw, offy + 12);
        }
        // todo pullup
        int width = _imeManager->isOn() ? 100 : 0;
        _imeManager->setBounds(getX() + offx + fw, getY() + offy, width, getHeight() - offy * 2);
    }
void Component::keyTyped(KeyEventDetails* const e)
{
    produceKeyTyped(e);

    if(getFocused() &&
       !e->isConsumed() &&
       e->getKey() == KeyEventDetails::KEY_TAB)
    {
        if(e->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT)
        {
            moveFocusPrev();
        }
        else if(e->getModifiers() == 0)
        {
            moveFocusNext();
        }
    }
}
Example #11
0
Color4f ProgressBar::getDrawnTextColor(void) const
{
    if(getEnabled())
    {
        if(getFocused())
        {
            return getFocusedTextColor();
        }
        else if(_MouseInComponentLastMouse)
        {
            return getRolloverTextColor();
        }
        else
        {
            return getTextColor();
        }
    }
    else
    {
        return getDisabledTextColor();
    }
}
Example #12
0
UIDrawObjectCanvas* ProgressBar::getDrawnDrawObject(void) const
{
    if(getEnabled())
    {
        if(getFocused())
        {
            return getFocusedDrawObject();
        }
        else if(_MouseInComponentLastMouse)
        {
            return getRolloverDrawObject();
        }
        else
        {
            return getDrawObject();
        }
    }
    else
    {
        return getDisabledDrawObject();
    }
}
Border* Component::getDrawnBorder(void) const
{
    if(getEnabled())
    {
        if(getMouseOver())
        {
            return getRolloverBorder();
        }
        else if(getFocused())
        {
            return getFocusedBorder();
        }
        else
        {
            return getBorder();
        }
    }
    else
    {
        return getDisabledBorder();
    }
}
Layer* Component::getDrawnForeground(void) const
{
    if(getEnabled())
    {
        if(getMouseOver())
        {
            return getFocusedForeground();
        }
        else if(getFocused())
        {
            return getRolloverForeground();
        }
        else
        {
            return getForeground();
        }
    }
    else
    {
        return getDisabledForeground();
    }
}
Example #15
0
void ofxDatGui::update()
{
    if (!mVisible) return;

    // check if we need to update components //
    for (int i=0; i<items.size(); i++) {
        if (mAlphaChanged) items[i]->setOpacity(mAlpha);
        if (mThemeChanged) items[i]->setTheme(mTheme);
        if (mWidthChanged) items[i]->setWidth(mWidth, mLabelWidth);
        if (mAlignmentChanged) items[i]->setLabelAlignment(mAlignment);
    }
   if (mThemeChanged || mWidthChanged) layoutGui();

    mTheme = nullptr;
    mAlphaChanged = false;
    mWidthChanged = false;
    mThemeChanged = false;
    mAlignmentChanged = false;
    
    // check for gui focus change //
    if (ofGetMousePressed() && mActiveGui->mMoving == false){
        ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
        for (int i=mGuis.size()-1; i>-1; i--){
        // ignore guis that are invisible //
            if (mGuis[i]->getVisible() && mGuis[i]->hitTest(mouse)){
                if (mGuis[i] != mActiveGui) mGuis[i]->focus();
                break;
            }
        }
    }

    if (!getFocused() || !mEnabled){
    // update children but ignore mouse & keyboard events //
        for (int i=0; i<items.size(); i++) items[i]->update(false);
    }   else {
        mMoving = false;
        mMouseDown = false;
    // this gui has focus so let's see if any of its components were interacted with //
        if (mExpanded == false){
            mGuiFooter->update();
            mMouseDown = mGuiFooter->getMouseDown();
        }   else{
            bool hitComponent = false;
            for (int i=0; i<items.size(); i++) {
                if (hitComponent == false){
                    items[i]->update(true);
                    if (items[i]->getFocused()) {
                        hitComponent = true;
                        mMouseDown = items[i]->getMouseDown();
                        if (mGuiHeader != nullptr && mGuiHeader->getDraggable() && mGuiHeader->getFocused()){
                    // track that we're moving to force preserve focus //
                            mMoving = true;
                            ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
                            moveGui(mouse - mGuiHeader->getDragOffset());
                        }
                    }   else if (items[i]->getIsExpanded()){
                    // check if one of its children has focus //
                        for (int j=0; j<items[i]->children.size(); j++) {
                            if (items[i]->children[j]->getFocused()){
                                hitComponent = true;
                                mMouseDown = items[i]->children[j]->getMouseDown();
                                break;
                            }
                        }
                    }
                }   else{
            // update component but ignore mouse & keyboard events //
                    items[i]->update(false);
                    if (items[i]->getFocused()) items[i]->setFocused(false);
                }
            }
        }
    }
// empty the trash //
    for (int i=0; i<trash.size(); i++) delete trash[i];
    trash.clear();
}
Example #16
0
void Button::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    //If I have a DrawObject then Draw it
    UIDrawObjectCanvasRefPtr DrawnDrawObject = getDrawnDrawObject();
    UIDrawObjectCanvasRefPtr BaseDrawObject = getBaseDrawObject();

    if(DrawnDrawObject != NULL)
    {
        //Get the Draw Object Size
        Vec2f DrawObjectSize = DrawnDrawObject->getRequestedSize();

        Vec2f BaseDrawObjectSize = BaseDrawObject->getRequestedSize();

        if(getText() != "" && getFont() != NULL)
        {
            //Draw both the text and Draw Object

            //Get the Text Size
            Pnt2f TextTopLeft, TextBottomRight;
            getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);

            Vec2f InternalsSize;
            if(getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_LEFT_OF_TEXT || 
               getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT)
            {
                InternalsSize.setValues((TextBottomRight.x()-TextTopLeft.x()) + DrawObjectSize.x() + getDrawObjectToTextPadding(),
                                        osgMax((TextBottomRight.y()-TextTopLeft.y()), DrawObjectSize.y()));
            }
            else
            {
                InternalsSize.setValues(osgMax((TextBottomRight.x()-TextTopLeft.x()), DrawObjectSize.x()),
                                        (TextBottomRight.y()-TextTopLeft.y()) + DrawObjectSize.y() + getDrawObjectToTextPadding());
            }

            Pnt2f InternalAlignment;
            InternalAlignment = calculateAlignment(TopLeft, (BottomRight-TopLeft), InternalsSize,getAlignment().y(), getAlignment().x());

            //Draw Object Alignment
            Pnt2f DrawObjectAlignedPosition;
            switch(getDrawObjectToTextAlignment())
            {
                case ALIGN_DRAW_OBJECT_LEFT_OF_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, DrawObjectSize,0.5f, 0.0);
                    break;
                case ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, DrawObjectSize,0.5f, 1.0);
                    break;
                case ALIGN_DRAW_OBJECT_ABOVE_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, DrawObjectSize,0.0f, 0.5);
                    break;
                case ALIGN_DRAW_OBJECT_BELOW_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, DrawObjectSize,1.0f, 0.5);
                    break;
            }
            //If active then translate the Text by the Active Offset
            DrawObjectAlignedPosition = DrawObjectAlignedPosition + getDrawnOffset();

            DrawnDrawObject->setPosition( DrawObjectAlignedPosition );

            //Text Alignment
            Pnt2f TextAlignedPosition;
            switch(getDrawObjectToTextAlignment())
            {
                case ALIGN_DRAW_OBJECT_LEFT_OF_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),0.5f, 1.0);
                    break;
                case ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),0.5f, 0.0);
                    break;
                case ALIGN_DRAW_OBJECT_ABOVE_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),1.0f, 0.5);
                    break;
                case ALIGN_DRAW_OBJECT_BELOW_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),0.0f, 0.5);
                    break;
            }

            drawText(TheGraphics, TextAlignedPosition, Opacity);
        }
        else
        {
            //Just Draw the Draw Object
            Pnt2f AlignedPosition;
            AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), BaseDrawObjectSize,getAlignment().y(), getAlignment().x());

            //If active then translate the Text by the Active Offset
            AlignedPosition = AlignedPosition + getDrawnOffset();

            DrawnDrawObject->setPosition( AlignedPosition );
        }

        //Draw the DrawnDrawObject
        DrawnDrawObject->draw(TheGraphics, getOpacity()*Opacity);

    }
    else if(getText() != "" && getFont() != NULL)
    {
        //Just Draw the Text
        Pnt2f AlignedPosition;
        Pnt2f TextTopLeft, TextBottomRight;
        getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);

        AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (TextBottomRight - TextTopLeft),getAlignment().y(), getAlignment().x());

        drawText(TheGraphics, AlignedPosition, Opacity);
    }

    //Focus Border
    if(getFocused() && getFocusedBorder() != NULL)
    {
        getFocusedBorder()->activateInternalDrawConstraints(TheGraphics,0,0,getSize().x(),getSize().y());
        drawBorder(TheGraphics, getFocusedBorder(), Opacity);
    }
}
Example #17
0
void VEditTab::focusTab()
{
    focusChild();
    emit getFocused();
    updateStatus();
}
Example #18
0
void ofxDatGui::update()
{
    if (!mVisible) return;

    if (mAlphaChanged) setGuiAlpha();
    if (mTemplateChanged) setGuiTemplate();
    if (mWidthChanged) setGuiWidth();
    if (mAlignmentChanged) setGuiAlignment();
    
    // first check for gui focus change //
    if (ofGetMousePressed() && mActiveGui->isMoving() == false){
        ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
        for (int i=mGuis.size()-1; i>-1; i--){
        // ignore guis that are invisible //
            if (mGuis[i]->getVisible() && mGuis[i]->hitTest(mouse)){
                if (mGuis[i] != mActiveGui) mGuis[i]->focus();
                break;
            }
        }
    }

    if (!getFocused() || !mEnabled){
    // update children but ignore mouse & keyboard events //
        for (int i=0; i<items.size(); i++) items[i]->update(false);
    }   else {
        mMoving = false;
    // this gui has focus so let's see if any of its components were interacted with //
        if (mExpanded == false){
            mGuiFooter->update();
        }   else{
            int activeItemIndex = -1;
            for (int i=0; i<items.size(); i++) {
                items[i]->update();
                if (items[i]->getFocused()) {
                    activeItemIndex = i;
                    if (mGuiHeader != nullptr && mGuiHeader->getDraggable() && mGuiHeader->getPressed()){
                // track that we're moving to force preserve focus //
                        mMoving = true;
                        ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
                        moveGui(mouse - mGuiHeader->dragOffset);
                    }
                    break;
                }   else if (items[i]->getIsExpanded()){
                // check if one of its children has focus //
                    for (int j=0; j<items[i]->children.size(); j++) {
                        if (items[i]->children[j]->getFocused()){
                            activeItemIndex = i;
                            break;
                        }
                    }
                    if (activeItemIndex != -1) break;
                }
            }
        // update the remaining components //
            if (activeItemIndex != -1){
                for (int i=activeItemIndex + 1; i<items.size(); i++) {
        //  but tell them to ignore mouse & keyboard events since we're already determined the active component //
                    items[i]->update(false);
                    if (items[i]->getFocused()) items[i]->setFocused(false);
                }
            }
        }
    }
    
// empty the trash //
    for (int i=0; i<trash.size(); i++) delete trash[i];
    trash.clear();
}
void InternalWindow::changed(ConstFieldMaskArg whichField, 
                             UInt32            origin,
                             BitVector         details)
{
    if( ((whichField & FocusedFieldMask) ||
         (whichField & TitlebarFieldMask))&&
        getTitlebar() != NULL)
    {
        getTitlebar()->setEnabled(getFocused());
    }

    if( (whichField & ActiveToolTipFieldMask) &&
        getActiveToolTip() != NULL)
    {
        getActiveToolTip()->updateClipBounds();
    }

    if( (whichField & ActivePopupMenusFieldMask) &&
        getMFActivePopupMenus()->size() > 0)
    {
        for(UInt32 i(0) ; i<getMFActivePopupMenus()->size() ; ++i)
        {
            getActivePopupMenus(i)->setParentContainer(this);
            getActivePopupMenus(i)->setParentWindow(this);
        }

        getDrawingSurface()->getEventProducer()->addMouseListener(&_PopupMenuInteractionListener);
        getDrawingSurface()->getEventProducer()->addMouseMotionListener(&_PopupMenuInteractionListener);
        getDrawingSurface()->getEventProducer()->addKeyListener(&_PopupMenuInteractionListener);
        setLockInput(true);
    }

    if( (whichField & MenuBarFieldMask) && getMenuBar() != NULL)
    {
        getMenuBar()->setParentContainer(this);
        getMenuBar()->setParentWindow(this);
    }

    if( (whichField & MenuBarFieldMask) || (whichField & TitlebarFieldMask))
    {
        updateLayout();
    }

    if( (whichField & TitleFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setTitle(getTitle());
    }

    if( (whichField & TitlebarFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setParentContainer(this);
        getTitlebar()->setParentWindow(this);
    }

    if((whichField & TitlebarFieldMask) ||
       (whichField & BorderFieldMask) ||
       (whichField & DisabledBorderFieldMask) ||
       (whichField & FocusedBorderFieldMask) ||
       (whichField & RolloverBorderFieldMask) ||
       (whichField & DrawTitlebarFieldMask))
    {
        TitlebarRefPtr TheTitlebar;
        if(getDrawTitlebar())
        {
            TheTitlebar = getTitlebar();
        }
        else
        {
            TheTitlebar = NULL;
        }

        if(getBorder() != NULL && getBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getBorder())->setTitlebar(TheTitlebar);
        }
        if(getDisabledBorder() != NULL && getDisabledBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getDisabledBorder())->setTitlebar(TheTitlebar);
        }
        if(getFocusedBorder() != NULL && getFocusedBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getFocusedBorder())->setTitlebar(TheTitlebar);
        }
        if(getRolloverBorder() != NULL && getRolloverBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getRolloverBorder())->setTitlebar(TheTitlebar);
        }
    }

    if( whichField & ClipBoundsFieldMask)
    {
        if(getTitlebar() != NULL)
        {
            getTitlebar()->updateClipBounds();
        }
    }

    if( (whichField & TitlebarFieldMask) &&
        getTitlebar() != NULL)
    {
        if(getTitlebar()->getTitleLabel() != NULL)
        {
            getTitlebar()->getTitleLabel()->addMouseListener(&_TitlebarStartDragListener);
        }
        if(getTitlebar()->getCloseButton() != NULL)
        {
            getTitlebar()->getCloseButton()->addActionListener(&_CloseButtonListener);
        }
        if(getTitlebar()->getMaximizeButton() != NULL)
        {
            getTitlebar()->getMaximizeButton()->addActionListener(&_MaximizeButtonListener);
        }
        if(getTitlebar()->getIconifyButton() != NULL)
        {
            getTitlebar()->getIconifyButton()->addActionListener(&_IconifyButtonListener);
        }
    }

    if( (whichField & IconableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawIconify(getIconable());
    }
    if( (whichField & MaximizableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawMaximize(getMaximizable());
    }
    if( (whichField & ClosableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawClose(getClosable());
    }

    Inherited::changed(whichField, origin, details);
}
Example #20
0
void TextField::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    Pnt2f Alignment;
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    //Text Color
    Color4f TextColor = getDrawnTextColor();

    if(getDrawnText() != "" && getFont() != NULL)
    {
        Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds(getDrawnText()), getAlignment().y(), getAlignment().x());


        if(_TextSelectionStart >= _TextSelectionEnd)
        {
            TheGraphics->drawText(Alignment, getDrawnText(), getFont(), TextColor, getOpacity()*Opacity);
        }
        else
        {
            //Draw Text Befor the Selection
            TheGraphics->drawText(Alignment, getDrawnText().substr(0, _TextSelectionStart), getFont(), TextColor, getOpacity()*Opacity);

            //Draw Selection
            Pnt2f TextTopLeft, TextBottomRight;
            getFont()->getBounds(getDrawnText().substr(0, _TextSelectionStart), TextTopLeft, TextBottomRight);

            TheGraphics->drawQuad(Alignment + Vec2f(TextBottomRight.x(),0),
                                  Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd)).x(), 0),
                                  Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd))),
                                  Alignment + Vec2f(TextBottomRight),
                                  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(), getOpacity());

            //Draw Selected Text
            TheGraphics->drawText(Alignment + Vec2f(TextBottomRight.x(), 0), 
                                  getDrawnText().substr(_TextSelectionStart, _TextSelectionEnd-_TextSelectionStart), getFont(), getSelectionTextColor(), getOpacity()*Opacity);

            //Draw Text After selection
            getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd), TextTopLeft, TextBottomRight);
            TheGraphics->drawText(Alignment + Vec2f(TextBottomRight.x(), 0),
                                  getDrawnText().substr(_TextSelectionEnd, getDrawnText().size()-_TextSelectionEnd), getFont(), TextColor, getOpacity()*Opacity);
        }
    }
    else
    {
        Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds("|"), getAlignment().y(), getAlignment().x());
    }

    if(getEnabled() && getEditable() && getFocused() && _CurrentCaretBlinkElps <= 0.5*LookAndFeelManager::the()->getLookAndFeel()->getTextCaretRate())
    {
        //Draw the caret
        TheGraphics->drawLine(Alignment+Vec2f(getFont()->getBounds(getDrawnText().substr(0, getCaretPosition())).x(), 0),
                              Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, getCaretPosition())).x(),  getFont()->getBounds(getDrawnText()).y()), 
                              .5, TextColor, getOpacity()*Opacity);
    }

    //Draw the Descriptive text if empty
    if(getDrawnText().empty() && !getEmptyDescText().empty()  && getEmptyDescTextFont() != NULL)
    {
        Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getEmptyDescTextFont()->getBounds(getEmptyDescText()), getAlignment().y(), getAlignment().x());
        TheGraphics->drawText(Alignment, getEmptyDescText(), getEmptyDescTextFont(), getEmptyDescTextColor(), getOpacity()*Opacity);
    }
}
Example #21
0
void Widget::handleInput(){

	if(!initializedJoysticks){
		SDL_Init(SDL_INIT_JOYSTICK);
		if(SDL_NumJoysticks() > 0){
			guiLogger.log("found joysticks: " + std::to_string(SDL_NumJoysticks()));
			SDL_JoystickEventState(SDL_ENABLE);
			SDL_JoystickOpen(0);
		}
		else{
			guiLogger.log("found no joystick. SDL Init stat: " + std::to_string(SDL_WasInit(SDL_INIT_JOYSTICK)));
		}
		initializedJoysticks = true;
	}

	while(SDL_PollEvent(&event)){
		float *s;
		std::vector<Widget*> *widgets;
		switch(event.type){

		case SDL_JOYAXISMOTION:
			if(focused != NULL){
				if(event.jaxis.value < -3200 || event.jaxis.value > 3200){
					focused->handleAxisEvent(event.jaxis.axis, event.jaxis.value / 32767.0);
				}
				else{
					focused->handleAxisEvent(event.jaxis.axis, 0);
				}
			}
			break;
		case SDL_JOYBUTTONDOWN:
			if(focused != NULL){
				focused->handleButtonEvent(event.jbutton.button, true);
			}
			break;
		case SDL_JOYBUTTONUP:
			if(focused != NULL){
				focused->handleButtonEvent(event.jbutton.button, false);
			}
			break;

		case SDL_MOUSEMOTION:
			s = pixelToScreenSpace(event.motion.x, event.motion.y);

			updateMousePosition(s[0], s[1]);

			widgets = new std::vector<Widget*>();
			getWidgetsAt(s[0], s[1], widgets);
			Widget *w;
			//if(getFocused() != NULL && getFocused()->isListeningToMouse()){
			while(!widgets->empty()){
				w = widgets->back();
				widgets->pop_back();
				if(w->isListeningToMouse()){
					w->handleMouseMotionEvent(s[0] - w->getAbsoluteLeft(), s[1] - w->getAbsoluteTop());
					for(Widget *w1 : w->children){
						if(!w1->isFocusable()){
							w1->handleMouseMotionEvent(s[0] - w1->getAbsoluteLeft(), s[1] - w1->getAbsoluteTop());
						}
					}
				}
			}
			//}

			delete widgets;
			delete[] s;
			break;
		case SDL_MOUSEBUTTONDOWN:
			updateMouseButton(event.button.button, true);

			s = pixelToScreenSpace(event.button.x, event.button.y);

			widgets = new std::vector<Widget*>();
			getWidgetsAt(s[0], s[1], widgets);
			if(consoleActive && game::physics::pointInRect(s[0], s[1], console.getAbsoluteLeft(), console.getAbsoluteTop(), console.getWidth(), console.getHeight())){
				widgets->push_back(&console);
			}
		
			while(widgets->size() > 0){
				//Widget *w = widgets->at(i);
				Widget *w = widgets->back();
				widgets->pop_back();
				/**
				 * if the widget is listening to mouse events and focusable, let it handle the event, transforming the global event coordinates in local coordinates
				 * if the widget is also listening to keys, make it the currently focused widget
				 */
				if(w->isListeningToMouse() && w->isFocusable()){
					if(w->isListeningToKeys()){
						setFocus(w);
						//						if(focused != NULL)
						//							focused->hasFocus = false;
						//						focused = w;
						//						focused->hasFocus = true;
					}
					w->handleMouseButtonEvent(event.button.button, s[0] - w->getAbsoluteLeft(), s[1] - w->getAbsoluteTop(), true);
					for(Widget *h : w->children){
						if(!h->isFocusable()){
							h->handleMouseButtonEvent(event.button.button, s[0] - h->getAbsoluteLeft(), s[1] - h->getAbsoluteTop(), true);
						}
					}

					break;
				}
			}
			delete widgets;
			delete[] s;
			break;
		case SDL_MOUSEBUTTONUP:
			updateMouseButton(event.button.button, false);

			s = pixelToScreenSpace(event.button.x, event.button.y);

			widgets = new std::vector<Widget*>();
			getWidgetsAt(s[0], s[1], widgets);
			if(consoleActive && game::physics::pointInRect(s[0], s[1], console.getAbsoluteLeft(), console.getAbsoluteTop(), console.getWidth(), console.getHeight())){
				widgets->push_back(&console);
			}
			while(widgets->size() > 0){
				//Widget *w = widgets->at(i);
				Widget *w = widgets->back();
				widgets->pop_back();
				/**
				 * if the widget is listening to mouse events and focusable, let it handle the event, transforming the global event coordinates in local coordinates
				 * if the widget is also listening to keys, make it the currently focused widget
				 */
				if(w->isListeningToMouse() && w->isFocusable()){
					if(w->isListeningToKeys()){
						setFocus(w);
						//						if(focused != NULL)
						//							focused->hasFocus = false;
						//						focused = w;
						//						focused->hasFocus = true;
					}
					w->handleMouseButtonEvent(event.button.button, s[0] - w->getAbsoluteLeft(), s[1] - w->getAbsoluteTop(), false);
					for(Widget *h : w->children){
						if(!h->isFocusable()){
							h->handleMouseButtonEvent(event.button.button, s[0] - h->getAbsoluteLeft(), s[1] - h->getAbsoluteTop(), false);
						}
					}

					break;
				}
			}
			delete widgets;
			delete[] s;
			break;
		case SDL_MOUSEWHEEL:
			if(getFocused() != NULL && getFocused()->isListeningToMouse()){
				getFocused()->handleMouseWheelEvent(event.wheel.y);
			}
			break;
		case SDL_KEYDOWN:
			updateKey(event.key.keysym.scancode, true);
			//mapKey(event.key.keysym.scancode, true);
			if(event.key.keysym.sym == SDLK_ESCAPE){
				if(game::isInHomescreen()){
					render::stop();
					game::stop();
				}
				else{
					game::toHomescreenWidget();
					audio::clearMusicQueue();
					audio::queueMusic("sfx/temp/pippin_the_hunchback.wav");
					audio::nextSong();
				}
			}
#ifdef unix
			if(event.key.keysym.sym == SDLK_BACKQUOTE && (event.key.keysym.mod & (KMOD_SHIFT | KMOD_CAPS)) > 0){
#else
#ifdef windows
				if(event.key.keysym.sym == SDLK_BACKQUOTE){ // TODO find way to get shift mod with wine SDL
#else
					if(false){
#endif
#endif
						consoleActive = !consoleActive;
						if(consoleActive){
							setFocus(&console);
						}
						else if(getFocused() == &console){
							if(children.size() > 0){
								setFocus(children[0]);
							}
							else{
								setFocus(NULL);
							}
						}
					}
					if(focused != NULL){
						focused->handleKeyEvent(event.key.keysym.sym, event.key.keysym.mod, true);
					}
					break;
		case SDL_TEXTINPUT:
			if(focused != NULL){
				focused->handleTextEvent(std::string(event.text.text));
			}
			break;
		case SDL_KEYUP:
			updateKey(event.key.keysym.scancode, false);
			//mapKey(event.key.keysym.scancode, false);
			if(focused != NULL){
				focused->handleKeyEvent(event.key.keysym.sym, event.key.keysym.mod, false);
			}
			break;
				}
			}

		}

		void Widget::render(float updateFactor){
			render::setRenderTarget(render::HUD); //TODO unnecessary repeated setting of render Target
			for(Widget *w : children){
				render::setScissorArea(w->getAbsoluteLeft(), w->getAbsoluteTop() + w->getHeight(), w->getWidth(), w->getHeight());
				w->render(updateFactor);
			}
		}

		void Widget::renderConsole(float updateFactor){
			render::setRenderTarget(render::HUD);
			if(consoleActive){
				render::setScissorArea(console.getAbsoluteLeft(), console.getAbsoluteTop() + console.getHeight(), console.getWidth(), console.getHeight());
				console.render(updateFactor);
			}
		}
Example #22
0
void InternalWindow::changed(ConstFieldMaskArg whichField, 
                             UInt32            origin,
                             BitVector         details)
{
    if( ((whichField & FocusedFieldMask) ||
         (whichField & TitlebarFieldMask))&&
         getTitlebar() != NULL &&
         getDrawTitlebar() &&
         !getTitlebar()->getEnabled())
    {
        getTitlebar()->setEnabled(getFocused());
    }

    if( (whichField & ActiveToolTipFieldMask) &&
        getActiveToolTip() != NULL)
    {
        getActiveToolTip()->updateClipBounds();
    }

    if( (whichField & ActivePopupMenusFieldMask) &&
        getMFActivePopupMenus()->size() > 0)
    {
        _PopupConnections.clear();
        for(UInt32 i(0) ; i<getMFActivePopupMenus()->size() ; ++i)
        {
            getActivePopupMenus(i)->setParentWindow(this);
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMouseClicked(boost::bind(&InternalWindow::popupMenuMousePressed, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMousePressed(boost::bind(&InternalWindow::popupMenuMousePressed, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMouseReleased(boost::bind(&InternalWindow::popupMenuMouseReleased, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectKeyPressed(boost::bind(&InternalWindow::popupMenuKeyPressed, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMouseMoved(boost::bind(&InternalWindow::popupMenuMouseMoved, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMouseDragged(boost::bind(&InternalWindow::popupMenuMouseDragged, this, _1)))));
        }
        setLockInput(true);
    }

    if( (whichField & MenuBarFieldMask) && getMenuBar() != NULL)
    {
        getMenuBar()->setParentWindow(this);
    }

    if( (whichField & MenuBarFieldMask) || (whichField & TitlebarFieldMask))
    {
        updateLayout();
    }

    if( (whichField & TitleFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setTitle(getTitle());
    }

    if( (whichField & TitlebarFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setParentWindow(this);
    }

    if((whichField & TitlebarFieldMask) ||
       (whichField & BorderFieldMask) ||
       (whichField & DisabledBorderFieldMask) ||
       (whichField & FocusedBorderFieldMask) ||
       (whichField & RolloverBorderFieldMask) ||
       (whichField & DrawTitlebarFieldMask))
    {
        TitlebarRefPtr TheTitlebar;
        if(getDrawTitlebar())
        {
            TheTitlebar = getTitlebar();
        }
        else
        {
            TheTitlebar = NULL;
        }

        if(getBorder() != NULL && getBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getBorder())->setTitlebar(TheTitlebar);
        }
        if(getDisabledBorder() != NULL && getDisabledBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getDisabledBorder())->setTitlebar(TheTitlebar);
        }
        if(getFocusedBorder() != NULL && getFocusedBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getFocusedBorder())->setTitlebar(TheTitlebar);
        }
        if(getRolloverBorder() != NULL && getRolloverBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getRolloverBorder())->setTitlebar(TheTitlebar);
        }
    }

    if( whichField & ClipBoundsFieldMask)
    {
        if(getTitlebar() != NULL)
        {
            getTitlebar()->updateClipBounds();
        }
    }

    if( (whichField & TitlebarFieldMask) &&
        getTitlebar() != NULL)
    {
        if(getTitlebar()->getTitleLabel() != NULL)
        {
            _TitleBarMousePressedConnection = getTitlebar()->getTitleLabel()->connectMousePressed(boost::bind(&InternalWindow::titlebarMousePressed, this, _1));
        }
        if(getTitlebar()->getCloseButton() != NULL)
        {
            _CloseButtonActionConnection = getTitlebar()->getCloseButton()->connectActionPerformed(boost::bind(&InternalWindow::closeButtonAction, this, _1));
        }
        if(getTitlebar()->getMaximizeButton() != NULL)
        {
            _MaximizeButtonActionConnection = getTitlebar()->getMaximizeButton()->connectActionPerformed(boost::bind(&InternalWindow::maximizeButtonAction, this, _1));
        }
        if(getTitlebar()->getIconifyButton() != NULL)
        {
            _IconifyButtonActionConnection = getTitlebar()->getIconifyButton()->connectActionPerformed(boost::bind(&InternalWindow::iconifyButtonAction, this, _1));
        }
    }

    if( (whichField & IconableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawIconify(getIconable());
    }
    if( (whichField & MaximizableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawMaximize(getMaximizable());
    }
    if( (whichField & ClosableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawClose(getClosable());
    }

    Inherited::changed(whichField, origin, details);
}
Example #23
0
	/** 再描画 */
	void TextArea::paint(Graphics *g)
	{
		/*if( firstpaint == false ) firstpaint = true;*/

		// 色
		int clr_focuse = 0xffc8c8c8;
		int clr_border = 0xff000000;
		int clr_back   = 0xffffffff;
		int clr_fore   = 0xff000000;
		int clr_caret  = 0xff000000;
		int clr_line   = 0xff000000;
		if (getFocused() == true && getEnabled() == true) {
			clr_focuse = 0xff0080ff;
		}
		if (getEnabled() == false) {
			clr_fore = 0xff808080;
		}

		// 文字サイズ
		int fh = getFontMetrics()->getHeight(WIDTH_BASE);
		int fw = getFontMetrics()->getWidth(WIDTH_BASE);

		// 枠線
		g->setColor(clr_focuse);
		g->drawRect(0, 0, getWidth(), getHeight());
		g->setColor(clr_border);
		g->drawRect(1, 1, getWidth() - 2, getHeight() - 2);
		g->setColor(clr_back);
		g->fillRect(2, 2, getWidth() - 3, getHeight() - 3);

		int draw_left = 4;
		int draw_top = 4;

		g->setColor(clr_line);
		if( _draw_line ) {
			draw_left += 2;
			int fw = getFontMetrics()->getWidth("0");
			int keta = 1, tmp = LineCount(); while( tmp >= 10 ) { keta++; tmp/=10; }
			_keta = keta;

			char* buff = new char[keta+1];
			for(int i=0; i<_max_line + 1; i++) {
				if( i + _offset_y >= LineCount() ) break;
				LineNoFormat( buff, i + _offset_y + 1, keta );
				g->drawString(buff, draw_left, i * fh + draw_top );
			}
			delete[] buff;

			draw_left += keta * fw + 3;
			g->drawLine( draw_left - 3, draw_top, draw_left - 3, getHeight() - draw_top );
		}

		// キャレットの描画
		if (getFocused() == true && getEnabled() == true) {
			if (_overwrite) {
				g->setColor(clr_caret);
				g->fillRect( (_ptr_x-_offset_x) * fw + draw_left - 1, (_ptr_y-_offset_y) * fh + draw_top, fw, fh );
			} else {
				g->setColor(clr_caret);
				g->drawLine( (_ptr_x-_offset_x) * fw + draw_left - 1, (_ptr_y-_offset_y) * fh + draw_top,
				              (_ptr_x-_offset_x) * fw + draw_left - 1, (_ptr_y-_offset_y) * fh + draw_top + fh - 2 );
			}
		}

		// 一行ずつ描画
		char* draw_text = text + Y2P(_offset_y);
		for(int i=0; i<_max_line + 1; i++) {
			int col = 0;

			// 表示しない文字を飛ばす
			for(int j=0; j<_offset_x; ) {
				if( *draw_text == '\0' || *draw_text == '\n' ) break;
				if( *draw_text == '\t' ) j+=TAB_SIZE; else j++;
				if( j >= _offset_x ) col = j - _offset_x;
				draw_text++;
			}

			// 一文字ずつ描画
			for(; col<_max_col; col++) {
				if( *draw_text == '\0' || *draw_text == '\n' ) break;
				if( *draw_text == '\t' ) {
					col += TAB_SIZE - ( (col+_offset_x) % TAB_SIZE ) - 1;
				} else {
					char tmp[2] = { *draw_text, '\0' };
					int width = getFontMetrics()->getWidth(tmp);
					if( _overwrite && draw_text == text+XY2P(_ptr_x,_ptr_y) ) {
						g->setColor(clr_back);
					} else {
						g->setColor(clr_fore);
					}
					g->drawString(tmp, col * fw + draw_left + (fw-width) / 2, i * fh + draw_top );
				}
				draw_text++;
			}

			// 残りも飛ばす
			while( *draw_text != '\0' && *draw_text != '\n' ) draw_text++;
			if( *draw_text == '\0' ) break;
			draw_text++;
		}
	}