void GuiFormCtrl::onMouseDown(const GuiEvent &event) { Point2I localClick = globalToLocalCoord(event.mousePoint); // If we're clicking in the header then resize if(localClick.y < mThumbSize.y) { mouseLock(); mDepressed = true; mMouseMovingWin = mCanMove; //update setUpdate(); } mOrigBounds = getBounds(); mMouseDownPosition = event.mousePoint; if (mMouseMovingWin ) { mouseLock(); } else { GuiControl *ctrl = findHitControl(localClick); if (ctrl && ctrl != this) ctrl->onMouseDown(event); } }
GuiControl* GuiInspectorMountingGroup::buildMenuCtrl() { GuiControl* retCtrl = new GuiPopUpMenuCtrl(); // If we couldn't construct the control, bail! if( retCtrl == NULL ) return retCtrl; GuiPopUpMenuCtrl *menu = dynamic_cast<GuiPopUpMenuCtrl*>(retCtrl); // Let's make it look pretty. retCtrl->setDataField( StringTable->insert("profile"), NULL, "GuiPopUpMenuProfile" ); //GuiInspectorTypeMenuBase::_registerEditControl( retCtrl ); char szName[512]; dSprintf( szName, 512, "IE_%s_%d_%s_Field", retCtrl->getClassName(), mParentInspector->getInspectObject()->getId(), mCaption.c_str()); // Register the object retCtrl->registerObject( szName ); // Configure it to update our value when the popup is closed char szBuffer[512]; dSprintf( szBuffer, 512, "%d.apply( %d.getText() );", getId(), menu->getId() ); menu->setField("Command", szBuffer ); return menu; }
void GuiContainer::loadFromXml(string file) { controls.clear(); ofxXmlSettings xml; res.init(file); xml.loadFile(file); loadBaseInfo("view", xml, 0); x = 0; y = 0; load(); //movable = xml.getAttribute("view", "movable", 0, 0); xml.pushTag("view"); int numControls = xml.getNumTags("control"); for(int i = 0; i < numControls; i++) { GuiControl *c = instantiator( xml.getAttribute("control", "type", "", i), xml.getAttribute("control", "name", "", i), xml.getAttribute("control", "id", "", i), &res, this); string valueStr = xml.getAttribute("control", "value", "", i); if(valueStr!="") { c->valueFromString(valueStr); } c->loadBaseInfo("control", xml, i); c->load(); c->listeners = listeners; c->numListeners = numListeners; c->load(xml, i); add(c); } }
bool GuiRolloutCtrl::resize( const Point2I &newPosition, const Point2I &newExtent ) { if ( !Parent::resize( newPosition, newExtent ) ) return false; // Recalculate Heights and resize ourself appropriately. calculateHeights(); GuiControl *content = dynamic_cast<GuiControl*>( at(0) ); // Size Content Properly?! if ( mNotifyChildrenResized && content != NULL ) { S32 barHeight = ( mHideHeader ) ? 0 : 20; if( !mHideHeader && mHasTexture && mProfile && mProfile->mBitmapArrayRects.size() >= NumBitmaps ) { barHeight = mProfile->mBitmapArrayRects[ TopLeftHeader ].extent.y; } mChildRect.set( mMargin.point.x, mHeader.extent.y + mMargin.point.y, getWidth() - ( mMargin.point.x + mMargin.extent.x ), getHeight() - ( barHeight + ( mMargin.point.y + mMargin.extent.y ) ) ); if ( content->resize( mChildRect.point, mChildRect.extent ) ) return true; } // Nothing sized return false; }
bool GuiPaneControl::resize(const Point2I &newPosition, const Point2I &newExtent) { // CodeReview WTF is going on here that we need to bypass parent sanity? // Investigate this [7/1/2007 justind] if( !Parent::resize( newPosition, newExtent ) ) return false; mOriginalExtents.x = getWidth(); /* GuiControl *parent = getParent(); if (parent) parent->childResized(this); setUpdate(); */ // Resize the child control if we're not collapsed if(size() && !mCollapsed) { GuiControl *gc = dynamic_cast<GuiControl*>(operator[](0)); if(gc) { Point2I offset(0, mThumbSize.y); gc->resize(offset, newExtent - offset); } } // For now. return true; }
GuiControl *GuiTabPageCtrl::findPrevTabable(GuiControl *curResponder, bool firstCall) { if (firstCall) { GuiControl::smPrevResponder = NULL; } //if the window does not already contain the first responder, return false //ie. Can't tab into or out of a window if (! controlIsChild(curResponder)) { return NULL; } //loop through, checking each child to see if it is the one that follows the firstResponder GuiControl *tabCtrl = NULL; iterator i; for (i = begin(); i != end(); i++) { GuiControl *ctrl = static_cast<GuiControl *>(*i); tabCtrl = ctrl->findPrevTabable(curResponder, false); if (tabCtrl) break; } //to ensure the tab cycles within the current window... if (! tabCtrl) { tabCtrl = findLastTabable(); } mFirstResponder = tabCtrl; return tabCtrl; }
void GuiPaneControl::setCollapsed(bool isCollapsed) { // Get the child if(size() == 0 || !mCollapsable) return; GuiControl *gc = dynamic_cast<GuiControl*>(operator[](0)); if(mCollapsed && !isCollapsed) { resize(getPosition(), mOriginalExtents); mCollapsed = false; if(gc) gc->setVisible(true); } else if(!mCollapsed && isCollapsed) { mCollapsed = true; mOriginalExtents = getExtent(); resize(getPosition(), Point2I(getExtent().x, mThumbSize.y)); if(gc) gc->setVisible(false); } }
bool GuiTextEditSliderCtrl::onMouseWheelDown(const GuiEvent &event) { if ( !mActive || !mAwake || !mVisible ) return Parent::onMouseWheelDown(event); if ( !isFirstResponder() && !mFocusOnMouseWheel ) { GuiControl *parent = getParent(); if ( parent ) return parent->onMouseWheelUp( event ); return false; } mValue -= mIncAmount; checkRange(); setValue(); setFirstResponder(); mCursorPos = mBlockStart = mBlockEnd = 0; setUpdate(); return true; }
void GuiContainer::parentResized(const RectI &oldParentRect, const RectI &newParentRect) { //if(!mCanResize) // return; // If it's a control that specifies invalid docking, we'll just treat it as an old GuiControl if( getDocking() & Docking::dockInvalid || getDocking() & Docking::dockNone) return Parent::parentResized( oldParentRect, newParentRect ); S32 deltaX = newParentRect.extent.x - oldParentRect.extent.x; S32 deltaY = newParentRect.extent.y - oldParentRect.extent.y; // Update Self RectI oldThisRect = getBounds(); anchorControl( this, Point2I( deltaX, deltaY ) ); RectI newThisRect = getBounds(); // Update Deltas to pass on to children deltaX = newThisRect.extent.x - oldThisRect.extent.x; deltaY = newThisRect.extent.y - oldThisRect.extent.y; // Iterate over all children and update their anchors iterator nI = begin(); for( ; nI != end(); nI++ ) { // Sanity GuiControl *control = dynamic_cast<GuiControl*>( (*nI) ); if( control ) control->parentResized( oldThisRect, newThisRect ); } }
void GuiDecoyCtrl::onMouseUp(const GuiEvent &event) { mouseUnlock(); setUpdate(); //this code is pretty hacky. right now there is no way that guiCanvas will allow sending more than //one signal to one gui control at a time. if(mIsDecoy == true) { mVisible = false; GuiControl *parent = getParent(); Point2I localPoint = parent->globalToLocalCoord(event.mousePoint); GuiControl *tempControl = parent->findHitControl(localPoint); //the decoy control has the responsibility of keeping track of the decoyed controls status if( mDecoyReference != NULL && tempControl == mDecoyReference) tempControl->onMouseUp(event); else if(mDecoyReference != NULL && tempControl != mDecoyReference) { //as explained earlier, this control was written in the mindset for buttons. //nothing bad should ever happen if not a button due to the checks in this function though. GuiButtonBaseCtrl *unCastCtrl = NULL; unCastCtrl = dynamic_cast<GuiButtonBaseCtrl *>( mDecoyReference ); if(unCastCtrl != NULL) unCastCtrl->resetState(); } mVisible = true; } }
void MenuBar::attachToCanvas(GuiCanvas *owner, S32 pos) { if(owner == NULL || isAttachedToCanvas()) return; // This is set for popup menus in the onAttachToMenuBar() callback mCanvas = owner; PlatformWindowSDL *pWindow = dynamic_cast<PlatformWindowSDL*>(owner->getPlatformWindow()); if(pWindow == NULL) return; // Setup the native menu bar GuiMenuBar *hWindowMenu = static_cast<GuiMenuBar*>( pWindow->getMenuHandle() ); if( hWindowMenu == NULL && !Journal::IsPlaying() ) hWindowMenu = _FindMenuBarCtrl(); if(hWindowMenu) { pWindow->setMenuHandle( hWindowMenu ); GuiControl *base = hWindowMenu->getParent(); while( base->getParent() ) { base = base->getParent(); } mCanvas->setMenuBar( base ); } }
void PostEffectVis::clear() { GuiControl *content = _getContentControl(); content->clear(); mWindows.clear(); }
void GuiRolloutCtrl::calculateHeights() { S32 barHeight = 20; if ( mHasTexture && mProfile && mProfile->mBitmapArrayRects.size() >= NumBitmaps ) { // Store Header Rectangle mHeader.set( 0, 0, getWidth(), mProfile->mBitmapArrayRects[ CollapsedCenter ].extent.y ); // Bottom Bar Max barHeight = mProfile->mBitmapArrayRects[ TopLeftHeader ].extent.y; } else { mHeader.set( 0, 0, getWidth(), barHeight ); } if ( mHideHeader ) { barHeight = 0; mHeader.extent.y = 0; } GuiControl *content = static_cast<GuiControl*>( at(0) ); if ( content != NULL ) mExpanded.set( 0, 0, getWidth(), barHeight + content->getHeight() + ( mMargin.point.y + mMargin.extent.y ) ); else mExpanded.set( 0, 0, getWidth(), barHeight + mDefaultHeight ); }
void GuiTabPageCtrl::setText(const char *txt) { Parent::setText( txt ); GuiControl *parent = getParent(); if( parent ) parent->setUpdate(); };
void GuiRolloutCtrl::onRender( Point2I offset, const RectI &updateRect ) { if( !mProfile || mProfile->mFont == NULL ) return; // Calculate actual world bounds for rendering RectI worldBounds( offset, getExtent() ); // if opaque, fill the update rect with the fill color if ( mProfile->mOpaque ) GFX->getDrawUtil()->drawRectFill( worldBounds, mProfile->mFillColor ); if ( mProfile->mBitmapArrayRects.size() >= NumBitmaps ) { GFX->getDrawUtil()->clearBitmapModulation(); // Draw Rollout From Skin if ( !mIsExpanded && !mIsAnimating ) renderFixedBitmapBordersFilled( worldBounds, 1, mProfile ); else if ( mHideHeader ) renderSizableBitmapBordersFilledIndex( worldBounds, MidPageLeft, mProfile ); else renderSizableBitmapBordersFilledIndex( worldBounds, TopLeftHeader, mProfile ); } if ( !(mIsExpanded && mHideHeader ) ) { // Draw Caption ( Vertically Centered ) ColorI currColor; GFX->getDrawUtil()->getBitmapModulation( &currColor ); Point2I textPosition = mHeader.point + offset + mProfile->mTextOffset; GFX->getDrawUtil()->setBitmapModulation( mProfile->mFontColor ); renderJustifiedText( textPosition, mHeader.extent, mCaption ); GFX->getDrawUtil()->setBitmapModulation( currColor ); } // If we're collapsed we contain the first child as our content // thus we don't render it when collapsed. but to support modified // rollouts with custom header buttons etc we still render our other // children. -JDD GuiControl *pChild = dynamic_cast<GuiControl*>( at(0) ); if ( pChild ) { if ( !mIsExpanded && !mIsAnimating && pChild->isVisible() ) { pChild->setVisible( false ); } else if ( (mIsExpanded || mIsAnimating) && !pChild->isVisible() ) { pChild->setVisible( true ); } } renderChildControls( offset, updateRect ); // Render our border should we have it specified in our profile. renderBorder(worldBounds, mProfile); }
GuiControl *GuiContainer::add(string _type, string _name, string _controlId) { GuiControl *ctrl = instantiator(_type, _name, _controlId, &res, this); ctrl->load(); add(ctrl); return ctrl; }
void GuiTabPageCtrl::onMouseDown(const GuiEvent &event) { setUpdate(); Point2I localPoint = globalToLocalCoord( event.mousePoint ); GuiControl *ctrl = findHitControl(localPoint); if (ctrl && ctrl != this) { ctrl->onMouseDown(event); } }
void GuiTabPageCtrl::selectWindow(void) { //first make sure this window is the front most of its siblings GuiControl *parent = getParent(); if (parent) { parent->pushObjectToBack(this); } //also set the first responder to be the one within this window setFirstResponder(mFirstResponder); }
void GuiTextEditSliderCtrl::onMouseDragged(const GuiEvent &event) { // If we're not active then skip out. if ( !mActive || !mAwake || !mVisible ) { Parent::onMouseDragged(event); return; } if(mTextAreaHit == None || mTextAreaHit == Slider) { mTextAreaHit = Slider; GuiControl *parent = getParent(); if(!parent) return; Point2I camPos = event.mousePoint; Point2I point = parent->localToGlobalCoord(getPosition()); F32 maxDis = 100; F32 val; if(camPos.y < point.y) { if((F32)point.y < maxDis) maxDis = (F32)point.y; val = point.y - maxDis; if(point.y > 0) mMulInc= 1.0f-(((float)camPos.y - val) / maxDis); else mMulInc = 1.0f; checkIncValue(); return; } else if(camPos.y > point.y + getExtent().y) { GuiCanvas *root = getRoot(); val = (F32)(root->getHeight() - (point.y + getHeight())); if(val < maxDis) maxDis = val; if( val > 0) mMulInc= -(F32)(camPos.y - (point.y + getHeight()))/maxDis; else mMulInc = -1.0f; checkIncValue(); return; } mTextAreaHit = None; Parent::onMouseDragged(event); } }
GuiPlatformGenericMenuBar* _FindMenuBarCtrl() { GuiControl* control; Sim::findObject("PlatformGenericMenubar", control); AssertFatal(control, ""); if( !control ) return NULL; GuiPlatformGenericMenuBar* menuBar; menuBar = dynamic_cast<GuiPlatformGenericMenuBar*>( control->findObjectByInternalName( StringTable->insert("menubar"), true) ); AssertFatal(menuBar, ""); return menuBar; }
bool GuiDecoyCtrl::onMouseWheelDown( const GuiEvent &event ) { //if this control is a dead end, make sure the event stops here if ( !mVisible || !mAwake ) return true; //pass the event to the parent GuiControl *parent = getParent(); if ( parent ) return parent->onMouseWheelDown( event ); else return false; }
void GuiTextEditSliderCtrl::onMouseDown(const GuiEvent &event) { // If we're not active then skip out. if ( !mActive || !mAwake || !mVisible ) { Parent::onMouseDown(event); return; } char txt[20]; Parent::getText(txt); mValue = dAtof(txt); mMouseDownTime = Sim::getCurrentTime(); GuiControl *parent = getParent(); if(!parent) return; Point2I camPos = event.mousePoint; Point2I point = parent->localToGlobalCoord(getPosition()); if(camPos.x > point.x + getExtent().x - 14) { if(camPos.y > point.y + (getExtent().y/2)) { mValue -=mIncAmount; mTextAreaHit = ArrowDown; mMulInc = -0.15f; } else { mValue +=mIncAmount; mTextAreaHit = ArrowUp; mMulInc = 0.15f; } checkRange(); setValue(); mouseLock(); // We should get the focus and set the // cursor to the start of the text to // mimic the standard Windows behavior. setFirstResponder(); mCursorPos = mBlockStart = mBlockEnd = 0; setUpdate(); return; } Parent::onMouseDown(event); }
bool GuiControl::IsAltEnabled() { GuiControl* control = this; while (control) { if (!control->GetVisible() || !control->GetEnabled()) { return false; } control = control->GetParent(); } return true; }
GuiControl* GuiInspectorDatablockField::constructEditControl() { GuiControl* retCtrl = new GuiPopUpMenuCtrl(); // If we couldn't construct the control, bail! if( retCtrl == NULL ) return retCtrl; GuiPopUpMenuCtrl *menu = dynamic_cast<GuiPopUpMenuCtrl*>(retCtrl); // Let's make it look pretty. retCtrl->setDataField( StringTable->insert("profile"), NULL, "InspectorTypeEnumProfile" ); menu->setField("text", getData()); _registerEditControl( retCtrl ); // Configure it to update our value when the popup is closed char szBuffer[512]; dSprintf( szBuffer, 512, "%d.apply(%d.getText());%d.inspect(%d);",getId(), retCtrl->getId(),mParent->mParent->getId(), mTarget->getId() ); //dSprintf( szBuffer, 512, "%d.%s = %d.getText();%d.inspect(%d);",mTarget->getId(), getFieldName(), menu->getId(), mParent->mParent->getId(), mTarget->getId() ); menu->setField("Command", szBuffer ); Vector<StringTableEntry> entries; SimDataBlockGroup * grp = Sim::getDataBlockGroup(); for(SimDataBlockGroup::iterator i = grp->begin(); i != grp->end(); i++) { SimDataBlock * datablock = dynamic_cast<SimDataBlock*>(*i); // Skip non-datablocks if we somehow encounter them. if(!datablock) continue; // Ok, now we have to figure inheritance info. if( datablock && datablock->getClassRep()->isClass(mDesiredClass) ) entries.push_back(datablock->getName()); } // sort the entries dQsort(entries.address(), entries.size(), sizeof(StringTableEntry), stringCompare); // add them to our enum for(U32 j = 0; j < entries.size(); j++) menu->addEntry(entries[j], 0); return retCtrl; }
void PostEffectVis::setVisible( bool visible ) { GuiCanvas *canvas = NULL; if ( !Sim::findObject( "Canvas", canvas ) ) { Con::errorf( "PostEffectVis::setVisible, Canvas was not found." ); return; } GuiControl *content = _getContentControl(); if ( visible && !content->isAwake() ) canvas->pushDialogControl( content, 100 ); if ( !visible && content->isAwake() ) canvas->popDialogControl( content ); }
void GuiControl::saveBaseInfo(string tag, ofxXmlSettings xml, int pos) { xml.addAttribute(tag, "type", type, pos); xml.addAttribute(tag, "width", width, pos); xml.addAttribute(tag, "height", height, pos); xml.addAttribute(tag, "x", x, pos); xml.addAttribute(tag, "y", y, pos); xml.addAttribute(tag, "id", controlId, pos); xml.addAttribute(tag, "name", name, pos); xml.addAttribute(tag, "value", this->valueToString(), pos); vector<ParameterInfo> params = this->getParameterInfo(); for(int i = 0; i < params.size(); i++) { GuiControl *g = instantiator(params[i].type, "", "", resources, this); g->value = params[i].value; xml.addAttribute(tag, params[i].xmlName, g->valueToString(), pos); } }
/** * loads an xml file with the values specified * in the file. If the file doesn't exist, it just * returns. */ void GuiContainer::loadValues(string file) { if(!guiFileExists(ofToDataPath(file))) return; ofxXmlSettings xml; xml.loadFile(file); xml.pushTag("values"); int numVals = xml.getNumTags("value"); for(int i = 0; i < numVals; i++) { string controlId = xml.getAttribute("value", "controlId", "", i); if(controlId!="") { GuiControl *ctrl = getControlById(controlId); if(ctrl!=NULL) { ctrl->valueFromString(xml.getAttribute("value", "value", "", i)); } } } }
//----------------------------------------------------------------------------- // GuiInspectorDynamicGroup - add custom controls //----------------------------------------------------------------------------- bool GuiInspectorDynamicGroup::createContent() { if(!Parent::createContent()) return false; // encapsulate the button in a dummy control. GuiControl* shell = new GuiControl(); shell->setDataField( StringTable->insert("profile"), NULL, "GuiTransparentProfile" ); if( !shell->registerObject() ) { delete shell; return false; } // add a button that lets us add new dynamic fields. GuiBitmapButtonCtrl* addFieldBtn = new GuiBitmapButtonCtrl(); { SimObject* profilePtr = Sim::findObject("InspectorDynamicFieldButton"); if( profilePtr != NULL ) addFieldBtn->setControlProfile( dynamic_cast<GuiControlProfile*>(profilePtr) ); // FIXME Hardcoded image addFieldBtn->setBitmap("tools/gui/images/iconAdd.png"); char commandBuf[64]; dSprintf(commandBuf, 64, "%d.addDynamicField();", this->getId()); addFieldBtn->setField("command", commandBuf); addFieldBtn->setSizing(horizResizeLeft,vertResizeCenter); //addFieldBtn->setField("buttonMargin", "2 2"); addFieldBtn->resize(Point2I(getWidth() - 20,2), Point2I(16, 16)); addFieldBtn->registerObject("zAddButton"); } shell->resize(Point2I(0,0), Point2I(getWidth(), 28)); shell->addObject(addFieldBtn); // save off the shell control, so we can push it to the bottom of the stack in inspectGroup() mAddCtrl = shell; mStack->addObject(shell); return true; }
void GuiControl::loadBaseInfo(string tag, ofxXmlSettings xml, int pos) { x = xml.getAttribute(tag, "x", 0.f, pos); y = xml.getAttribute(tag, "y", 0.f, pos); width = xml.getAttribute(tag, "width", 0.f, pos); height = xml.getAttribute(tag, "height", 0.f, pos); controlId = xml.getAttribute(tag, "id", "", pos); name = xml.getAttribute(tag, "name", "", pos); vector<ParameterInfo> params = this->getParameterInfo(); for(int i = 0; i < params.size(); i++) { GuiControl *g = instantiator(params[i].type, "", "", resources, this); g->valueFromString(xml.getAttribute(tag, params[i].xmlName, "", pos)); // this is re-pointing a pointer - what we actually want to do is copy memcpy(params[i].value, g->value, sizeof(void*)); } }
GuiControl* GuiInspectorField::constructEditControl() { GuiControl* retCtrl = new GuiTextEditCtrl(); static StringTableEntry sProfile = StringTable->insert( "profile" ); retCtrl->setDataField( sProfile, NULL, "GuiInspectorTextEditProfile" ); _registerEditControl( retCtrl ); char szBuffer[512]; dSprintf( szBuffer, 512, "%d.apply(%d.getText());",getId(), retCtrl->getId() ); // Suffices to hook on to "validate" as regardless of whether we lose // focus through the user pressing enter or clicking away on another // keyboard control, we will see a validate call. retCtrl->setField("validate", szBuffer ); return retCtrl; }