Esempio n. 1
0
Chatbox::Chatbox(const std::string& id, Vector2& position, float width) : GUIImage(id, "demo/images/chatbox/CHAT_BACK.tga") {
	setLocalTranslation(position);
	resize(width, 200);
	setDraggable(true);

	p_messageArea = new ScrollPane(id + "_scroll", Vector2(10, 38), Vector2(width - 20, 190));
	p_messageArea->setBackground("demo/images/chatbox/CHAT_FORE.tga");

	p_inputField = new TextField(id + "_input", Vector2(10, 10), width - 20);
	p_inputField->setCharacterLimit(32);
	p_inputField->setBackground("demo/images/chatbox/CHAT_FIELD.tga");
	p_inputField->setForegroundColour(ColourRGBA(ColourRGBA::WHITE));

	setPassFocusElement(p_messageArea);

	for (int i = 0; i != bufferSize; i++) {
		entryLabels.push_back(new Label("", "", 9, Vector2(4, (i + 1) * 10))); // We don't care about their IDs
		p_messageArea->attachChild(entryLabels[i]);
	}

	p_messageArea->floor();

	attachChild(p_messageArea);
	attachChild(p_inputField);
}
Esempio n. 2
0
Menu::Menu(Layer& layer):
  Widget(layer),
  m_selection(NO_ITEM)
{
  setDraggable(true);
  setFocusable(true);
  hide();
}
Esempio n. 3
0
ofxLiteGroup::ofxLiteGroup(string name) : ofxLiteBox(name){
	setSpacing();
	setMaxHeight();
	setHoverable(false);
	setDraggable(false);
	setSelectable(false);
	setTriggerable(false);
	setSortable(false, false);
	singleSelected = NULL;
	setSingleSelect(false);
	dragBox = NULL;
}
Esempio n. 4
0
CNrpBrowserWindow::CNrpBrowserWindow( gui::IGUIEnvironment* env, 
									  video::ITexture* texture, 
									  s32 id, 
									  core::position2di pos,
									  core::dimension2du size ) : CNrpWindow( env, env->getRootGUIElement(), texture, id, 
																			  core::recti( pos, size+core::dimension2du( 10, 25 ) ) )
{
	 _ApplyViewerStyle( size, dynamic_cast< CImageGUISkin* >( Environment->getSkin() ) );
	bringToFront( getCloseButton() );
		
	setDraggable( true );
	drop();  
}
Esempio n. 5
0
Button::Button(Layer& layer, Widget* parent, ButtonType type, const std::string& text):
  Widget(layer, parent),
  m_type(type),
  m_text(text),
  m_selected(false),
  m_checked(false)
{
  Font& font = layer.drawer().theme().font();
  const float em = font.height();
  const float textWidth = font.boundsOf(m_text.c_str()).size.x;

  setDesiredSize(vec2(em * 2.f + textWidth, em * 2.f));
  setDraggable(true);
  setFocusable(true);
}
Esempio n. 6
0
Scroller::Scroller(Layer& layer, Widget* parent, Orientation orientation):
  Widget(layer, parent),
  m_minValue(0.f),
  m_maxValue(1.f),
  m_value(0.f),
  m_percentage(0.5f),
  m_reference(0.f),
  m_orientation(orientation)
{
  const float em = layer.drawer().theme().em();

  if (m_orientation == HORIZONTAL)
    setDesiredSize(vec2(0.f, em * 1.5f));
  else
    setDesiredSize(vec2(em * 1.5f, 0.f));

  setDraggable(true);
  setFocusable(true);
}
Esempio n. 7
0
 void handleEvent(SDL_Event evt) {
     /* Left Ctrl+s -> Save level
      * Delete -> delete current block
      * Space -> Make current block draggable
      * Arrow keys -> Set direction of current block
      * Any valid letter -> create block of that type
      */
     
     if(evt.type != SDL_KEYDOWN) return;
     
     if(evt.key.keysym.mod & KMOD_LCTRL && evt.key.keysym.sym == SDLK_s) {
         saveLevel();
     }
     
     else if(evt.key.keysym.sym == SDLK_DELETE) {
         deleteBlock();
     }
     
     else {
         switch(evt.key.keysym.sym) {
             case SDLK_UP:
                 setBlockDirection(rtBlock::UP);
                 break;
             case SDLK_DOWN:
                 setBlockDirection(rtBlock::DOWN);
                 break;
             case SDLK_RIGHT:
                 setBlockDirection(rtBlock::RIGHT);
                 break;
             case SDLK_LEFT:
                 setBlockDirection(rtBlock::LEFT);
                 break;
                 
             case SDLK_SPACE:
                 setDraggable();
                 break;
                 
             default:setBlock(evt.key.keysym.sym);
         }
     }
 }
Esempio n. 8
0
Button::Button(Layer& layer, const char* initText):
  Widget(layer),
  selected(false),
  text(initText)
{
  Drawer& drawer = getLayer().getDrawer();

  const float em = drawer.getCurrentEM();

  float textWidth;

  if (text.empty())
    textWidth = em * 3.f;
  else
    textWidth = drawer.getCurrentFont().getTextMetrics(text.c_str()).size.x;

  setSize(vec2(em * 2.f + textWidth, em * 2.f));
  setDraggable(true);

  getDragEndedSignal().connect(*this, &Button::onDragEnded);
  getButtonClickedSignal().connect(*this, &Button::onButtonClicked);
  getKeyPressedSignal().connect(*this, &Button::onKeyPressed);
}
Esempio n. 9
0
Scroller::Scroller(Layer& layer, Orientation orientation):
  Widget(layer),
  m_minValue(0.f),
  m_maxValue(1.f),
  m_value(0.f),
  m_percentage(0.5f),
  m_reference(0.f),
  m_orientation(orientation)
{
  const float em = layer.drawer().currentEM();

  if (m_orientation == HORIZONTAL)
    setSize(vec2(em * 10.f, em * 1.5f));
  else
    setSize(vec2(em * 1.5f, em * 10.f));

  keyPressedSignal().connect(*this, &Scroller::onKey);
  buttonClickedSignal().connect(*this, &Scroller::onMouseButton);
  scrolledSignal().connect(*this, &Scroller::onScroll);
  dragBegunSignal().connect(*this, &Scroller::onDragBegun);
  dragMovedSignal().connect(*this, &Scroller::onDragMoved);

  setDraggable(true);
}
Esempio n. 10
0
Scroller::Scroller(Layer& layer, Orientation initOrientation):
  Widget(layer),
  minValue(0.f),
  maxValue(1.f),
  value(0.f),
  percentage(0.5f),
  reference(0.f),
  orientation(initOrientation)
{
  const float em = layer.getDrawer().getCurrentEM();

  if (orientation == HORIZONTAL)
    setSize(vec2(em * 10.f, em * 1.5f));
  else
    setSize(vec2(em * 1.5f, em * 10.f));

  getKeyPressedSignal().connect(*this, &Scroller::onKeyPressed);
  getButtonClickedSignal().connect(*this, &Scroller::onButtonClicked);
  getScrolledSignal().connect(*this, &Scroller::onScrolled);
  getDragBegunSignal().connect(*this, &Scroller::onDragBegun);
  getDragMovedSignal().connect(*this, &Scroller::onDragMoved);

  setDraggable(true);
}
Esempio n. 11
0
DesignPreview::FramePreview::FramePreview(void) : scv::InternalFrame(0, 0, "SCV Application") {
   setDraggable(false);
   setResizable(false);
}
Esempio n. 12
0
void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
{
    // load styles used by all widgets
    for(const OTMLNodePtr& node : styleNode->children()) {
        if(node->tag() == "color")
            setColor(node->value<Color>());
        else if(node->tag() == "x")
            setX(node->value<int>());
        else if(node->tag() == "y")
            setY(node->value<int>());
        else if(node->tag() == "pos")
            setPosition(node->value<Point>());
        else if(node->tag() == "width")
            setWidth(node->value<int>());
        else if(node->tag() == "height")
            setHeight(node->value<int>());
        else if(node->tag() == "rect")
            setRect(node->value<Rect>());
        else if(node->tag() == "background")
            setBackgroundColor(node->value<Color>());
        else if(node->tag() == "background-color")
            setBackgroundColor(node->value<Color>());
        else if(node->tag() == "background-offset-x")
            setBackgroundOffsetX(node->value<int>());
        else if(node->tag() == "background-offset-y")
            setBackgroundOffsetY(node->value<int>());
        else if(node->tag() == "background-offset")
            setBackgroundOffset(node->value<Point>());
        else if(node->tag() == "background-width")
            setBackgroundWidth(node->value<int>());
        else if(node->tag() == "background-height")
            setBackgroundHeight(node->value<int>());
        else if(node->tag() == "background-size")
            setBackgroundSize(node->value<Size>());
        else if(node->tag() == "background-rect")
            setBackgroundRect(node->value<Rect>());
        else if(node->tag() == "icon")
            setIcon(stdext::resolve_path(node->value(), node->source()));
        else if(node->tag() == "icon-source")
            setIcon(stdext::resolve_path(node->value(), node->source()));
        else if(node->tag() == "icon-color")
            setIconColor(node->value<Color>());
        else if(node->tag() == "icon-offset-x")
            setIconOffsetX(node->value<int>());
        else if(node->tag() == "icon-offset-y")
            setIconOffsetY(node->value<int>());
        else if(node->tag() == "icon-offset")
            setIconOffset(node->value<Point>());
        else if(node->tag() == "icon-width")
            setIconWidth(node->value<int>());
        else if(node->tag() == "icon-height")
            setIconHeight(node->value<int>());
        else if(node->tag() == "icon-size")
            setIconSize(node->value<Size>());
        else if(node->tag() == "icon-rect")
            setIconRect(node->value<Rect>());
        else if(node->tag() == "icon-clip")
            setIconClip(node->value<Rect>());
        else if(node->tag() == "opacity")
            setOpacity(node->value<float>());
        else if(node->tag() == "enabled")
            setEnabled(node->value<bool>());
        else if(node->tag() == "visible")
            setVisible(node->value<bool>());
        else if(node->tag() == "checked")
            setChecked(node->value<bool>());
        else if(node->tag() == "dragable")
            setDraggable(node->value<bool>());
        else if(node->tag() == "on")
            setOn(node->value<bool>());
        else if(node->tag() == "focusable")
            setFocusable(node->value<bool>());
        else if(node->tag() == "phantom")
            setPhantom(node->value<bool>());
        else if(node->tag() == "size")
            setSize(node->value<Size>());
        else if(node->tag() == "fixed-size")
            setFixedSize(node->value<bool>());
        else if(node->tag() == "clipping")
            setClipping(node->value<bool>());
        else if(node->tag() == "border") {
            auto split = stdext::split(node->value(), " ");
            if(split.size() == 2) {
                setBorderWidth(stdext::safe_cast<int>(split[0]));
                setBorderColor(stdext::safe_cast<Color>(split[1]));
            } else
            throw OTMLException(node, "border param must have its width followed by its color");
        }
        else if(node->tag() == "border-width")
            setBorderWidth(node->value<int>());
        else if(node->tag() == "border-width-top")
            setBorderWidthTop(node->value<int>());
        else if(node->tag() == "border-width-right")
            setBorderWidthRight(node->value<int>());
        else if(node->tag() == "border-width-bottom")
            setBorderWidthBottom(node->value<int>());
        else if(node->tag() == "border-width-left")
            setBorderWidthLeft(node->value<int>());
        else if(node->tag() == "border-color")
            setBorderColor(node->value<Color>());
        else if(node->tag() == "border-color-top")
            setBorderColorTop(node->value<Color>());
        else if(node->tag() == "border-color-right")
            setBorderColorRight(node->value<Color>());
        else if(node->tag() == "border-color-bottom")
            setBorderColorBottom(node->value<Color>());
        else if(node->tag() == "border-color-left")
            setBorderColorLeft(node->value<Color>());
        else if(node->tag() == "margin-top")
            setMarginTop(node->value<int>());
        else if(node->tag() == "margin-right")
            setMarginRight(node->value<int>());
        else if(node->tag() == "margin-bottom")
            setMarginBottom(node->value<int>());
        else if(node->tag() == "margin-left")
            setMarginLeft(node->value<int>());
        else if(node->tag() == "margin") {
            std::string marginDesc = node->value();
            std::vector<std::string> split = stdext::split(marginDesc, " ");
            if(split.size() == 4) {
                setMarginTop(stdext::safe_cast<int>(split[0]));
                setMarginRight(stdext::safe_cast<int>(split[1]));
                setMarginBottom(stdext::safe_cast<int>(split[2]));
                setMarginLeft(stdext::safe_cast<int>(split[3]));
            } else if(split.size() == 3) {
                int marginTop = stdext::safe_cast<int>(split[0]);
                int marginHorizontal = stdext::safe_cast<int>(split[1]);
                int marginBottom = stdext::safe_cast<int>(split[2]);
                setMarginTop(marginTop);
                setMarginRight(marginHorizontal);
                setMarginBottom(marginBottom);
                setMarginLeft(marginHorizontal);
            } else if(split.size() == 2) {
                int marginVertical = stdext::safe_cast<int>(split[0]);
                int marginHorizontal = stdext::safe_cast<int>(split[1]);
                setMarginTop(marginVertical);
                setMarginRight(marginHorizontal);
                setMarginBottom(marginVertical);
                setMarginLeft(marginHorizontal);
            } else if(split.size() == 1) {
                int margin = stdext::safe_cast<int>(split[0]);
                setMarginTop(margin);
                setMarginRight(margin);
                setMarginBottom(margin);
                setMarginLeft(margin);
            }
        }
        else if(node->tag() == "padding-top")
            setPaddingTop(node->value<int>());
        else if(node->tag() == "padding-right")
            setPaddingRight(node->value<int>());
        else if(node->tag() == "padding-bottom")
            setPaddingBottom(node->value<int>());
        else if(node->tag() == "padding-left")
            setPaddingLeft(node->value<int>());
        else if(node->tag() == "padding") {
            std::string paddingDesc = node->value();
            std::vector<std::string> split = stdext::split(paddingDesc, " ");
            if(split.size() == 4) {
                setPaddingTop(stdext::safe_cast<int>(split[0]));
                setPaddingRight(stdext::safe_cast<int>(split[1]));
                setPaddingBottom(stdext::safe_cast<int>(split[2]));
                setPaddingLeft(stdext::safe_cast<int>(split[3]));
            } else if(split.size() == 3) {
                int paddingTop = stdext::safe_cast<int>(split[0]);
                int paddingHorizontal = stdext::safe_cast<int>(split[1]);
                int paddingBottom = stdext::safe_cast<int>(split[2]);
                setPaddingTop(paddingTop);
                setPaddingRight(paddingHorizontal);
                setPaddingBottom(paddingBottom);
                setPaddingLeft(paddingHorizontal);
            } else if(split.size() == 2) {
                int paddingVertical = stdext::safe_cast<int>(split[0]);
                int paddingHorizontal = stdext::safe_cast<int>(split[1]);
                setPaddingTop(paddingVertical);
                setPaddingRight(paddingHorizontal);
                setPaddingBottom(paddingVertical);
                setPaddingLeft(paddingHorizontal);
            } else if(split.size() == 1) {
                int padding = stdext::safe_cast<int>(split[0]);
                setPaddingTop(padding);
                setPaddingRight(padding);
                setPaddingBottom(padding);
                setPaddingLeft(padding);
            }
        }
        // layouts
        else if(node->tag() == "layout") {
            std::string layoutType;
            if(node->hasValue())
                layoutType = node->value();
            else
                layoutType = node->valueAt<std::string>("type", "");

            if(!layoutType.empty()) {
                UILayoutPtr layout;
                if(layoutType == "horizontalBox")
                    layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(static_self_cast<UIWidget>()));
                else if(layoutType == "verticalBox")
                    layout = UIVerticalLayoutPtr(new UIVerticalLayout(static_self_cast<UIWidget>()));
                else if(layoutType == "grid")
                    layout = UIGridLayoutPtr(new UIGridLayout(static_self_cast<UIWidget>()));
                else if(layoutType == "anchor")
                    layout = UIAnchorLayoutPtr(new UIAnchorLayout(static_self_cast<UIWidget>()));
                else
                    throw OTMLException(node, "cannot determine layout type");
                setLayout(layout);
            }

            if(node->hasChildren())
                m_layout->applyStyle(node);
        }
        // anchors
        else if(stdext::starts_with(node->tag(), "anchors.")) {
            UIWidgetPtr parent = getParent();
            if(!parent) {
                if(m_firstOnStyle)
                    throw OTMLException(node, "cannot create anchor, there is no parent widget!");
                else
                    continue;
            }

            UILayoutPtr layout = parent->getLayout();
            UIAnchorLayoutPtr anchorLayout;
            if(layout->isUIAnchorLayout())
                anchorLayout = layout->static_self_cast<UIAnchorLayout>();

            if(!anchorLayout)
                throw OTMLException(node, "cannot create anchor, the parent widget doesn't use anchor layout!");

            std::string what = node->tag().substr(8);
            if(what == "fill") {
                fill(node->value());
            } else if(what == "centerIn") {
                centerIn(node->value());
            } else {
                Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what);

                if(node->value() == "none") {
                    removeAnchor(anchoredEdge);
                } else {
                    std::vector<std::string> split = stdext::split(node->value(), ".");
                    if(split.size() != 2)
                        throw OTMLException(node, "invalid anchor description");

                    std::string hookedWidgetId = split[0];
                    Fw::AnchorEdge hookedEdge = Fw::translateAnchorEdge(split[1]);

                    if(anchoredEdge == Fw::AnchorNone)
                        throw OTMLException(node, "invalid anchor edge");

                    if(hookedEdge == Fw::AnchorNone)
                        throw OTMLException(node, "invalid anchor target edge");

                    addAnchor(anchoredEdge, hookedWidgetId, hookedEdge);
                }
            }
        // lua functions
        } else if(stdext::starts_with(node->tag(), "@")) {
            // load once
            if(m_firstOnStyle) {
                std::string funcName = node->tag().substr(1);
                std::string funcOrigin = "@" + node->source() + "[" + node->tag() + "]";
                g_lua.loadFunction(node->value(), funcOrigin);
                luaSetField(funcName);
            }
        // lua fields value
        } else if(stdext::starts_with(node->tag(), "&")) {
            std::string fieldName = node->tag().substr(1);
            std::string fieldOrigin = "@" + node->source() + "[" + node->tag() + "]";

            g_lua.evaluateExpression(node->value(), fieldOrigin);
            luaSetField(fieldName);
        }
    }
}