예제 #1
0
/* if the_style ends with '0' then do not insert the style sequence \s2
   and just insert the rtf commands, otherwise do both 
   This is needed so that chapter headings work properly in the table
   of contents
*/
void InsertStyle(const char *the_style)
{
    char *rtf, *last_char;
    int how = INSERT_STYLE_NORMAL;
    char *style = strdup(the_style);

    last_char = style + strlen(style) - 1;
    if (*last_char == '0') {
        how = INSERT_STYLE_NO_STYLE;
        *last_char = '\0'; 
    }
    
    if (strcmp(style,"Normal")==0) {

        if (getAlignment()==CENTERED) {
            InsertStyle("centerpar");
            free(style);
            return;
        }
        if (getAlignment()==RIGHT) {
            InsertStyle("rightpar");
            free(style);
            return;
        }
        if (getAlignment()==LEFT) {
            InsertStyle("leftpar");
            free(style);
            return;
        }
    }

    diagnostics(4, "InsertStyle(%s)", style);
    rtf = SearchCfgRtf(style, STYLE_A);
    if (rtf == NULL) {
        diagnostics(WARNING, "Cannot find '%s' style using 'Normal' style", style);
        SetCurrentStyle("Normal");
        rtf = SearchCfgRtf("Normal", STYLE_A);
        InsertBasicStyle(rtf, INSERT_STYLE_NORMAL);
    } else {
        SetCurrentStyle(style);
        InsertBasicStyle(rtf, how);
    }
    
    free(style);
}
예제 #2
0
			/**
			 * fill FastQ pattern
			 *
			 * @param pattern FastQ pattern object
			 * @return true if pattern was filled, false if no more pattern were available
			 **/
			bool getNextPatternUnlocked(pattern_type & pattern)
			{
				if ( !readAlignment() )
					return false;
				
				getAlignment().toPattern(pattern,patid++);
				
				return true;
			}
예제 #3
0
AllocaInst* Variables::changeLocal(Value* value, StructType* newType/*, int field*/) {

  errs() << "At changeLocalStruct\n";
  AllocaInst* newTarget = NULL;
  vector<Instruction*> erase;

  if (AllocaInst *oldTarget = dyn_cast<AllocaInst>(value)) {
    if (PointerType *oldPointer = dyn_cast<PointerType>(oldTarget->getType())) {
      if (StructType *oldType = dyn_cast<StructType>(oldPointer->getElementType())) {
	
	errs() << "Changing the precision of variable \"" << oldTarget->getName() << "\" from " << *oldType 
	       << " to " << *newType << ".\n";
      
	if (diffStructTypes(oldType, newType)) {
	  unsigned alignment = oldTarget->getAlignment();
	  
	  newTarget = new AllocaInst(newType, 0, alignment, "new", oldTarget);
	  newTarget->takeName(oldTarget);
	
	  // iterating through instructions using old getelementptr instructions
	  Value::use_iterator it = oldTarget->use_begin();
	  for(; it != oldTarget->use_end(); it++) {
	    
	    if (GetElementPtrInst *getElementPtrInst = dyn_cast<GetElementPtrInst>(*it)) {
	      if (ConstantInt *constantIntIndex = dyn_cast<ConstantInt>(getElementPtrInst->getOperand(2))) {
		unsigned int index = constantIntIndex->getLimitedValue(); // the index of the field accessed by this use
		
		Type *newFieldType = newType->getElementType(index);
		Type *oldFieldType = oldType->getElementType(index);
		unsigned alignment = getAlignment(newFieldType); // 4 hard coded for now
		bool is_erased = Transformer::transform(it, newTarget, oldTarget, newFieldType, oldFieldType, alignment);
		
		if (!is_erased) {
		  erase.push_back(dyn_cast<Instruction>(*it));
		}  
	      }
	    }
	    else {
	      errs() << "WARNING: unexpected use of struct\n";
	    }
	  }
	  
	  // erasing uses of old instructions
	  for(unsigned int i = 0; i < erase.size(); i++) {
	    erase[i]->eraseFromParent();
	  }
	  
	}
	else {
	  errs() << "\tNo changes required.\n";
	}
      } 
    }
  }
  return newTarget;
}
예제 #4
0
void ToolTip::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    if(getText() != "" && getFont() != NULL)
    {
        Pnt2f TopLeft, BottomRight;
        getInsideBorderBounds(TopLeft, BottomRight);

        Pnt2f TextTopLeft, TextBottomRight;
        getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);
        TheGraphics->drawText(calculateAlignment(TopLeft,
                              BottomRight-TopLeft,
                              (TextBottomRight-TextTopLeft),
                              getAlignment().y(),
                              getAlignment().x()),
                              getText(),
                              getFont(),
                              getTextColor(),
                              getOpacity()*Opacity);
    }
}
예제 #5
0
	void FixedLabel::draw(gcn::Graphics *graphics)
	{
		graphics->setFont(getFont());
        graphics->setColor(getForegroundColor());
		
		int i = 0;
		for ( std::list<std::string>::iterator iter = _rows.begin(); iter != _rows.end(); iter++, i++ )
		{
			graphics->drawText(*iter, 0, i * getFont()->getHeight(), getAlignment());
		}
	}
예제 #6
0
void TSpriteButton::draw(gcn::Graphics* graphics){
    delete image_;
    image_ = InfraellyImageLoader().load( sprite_.getFrame(sprite_.getFrameProgression()) );
    setImage(image_);

// from guichan/widgets/button.c
    int textX;
    int textY = getHeight() / 2 - getFont()->getHeight() / 2;

    switch (getAlignment())
    {
      case gcn::Graphics::LEFT:
          textX = mSpacing;
          break;
      case gcn::Graphics::CENTER:
          textX = getWidth() / 2;
          break;
      case gcn::Graphics::RIGHT:
          textX = getWidth() - mSpacing;
          break;
      default:
          throw GCN_EXCEPTION("Unknown alignment.");
    }

    graphics->setFont(getFont());

    if (isPressed())
    {
        graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
    }
    else
    {
        graphics->drawText(getCaption(), textX, textY, getAlignment());

        if (isFocused())
        {
            graphics->drawRectangle(gcn::Rectangle(2, 2, getWidth() - 4,
                                              getHeight() - 4));
        }
    }
}
예제 #7
0
void QG_DlgText::destroy() {
    if (isNew&&saveSettings) {
        RS_SETTINGS->beginGroup("/Draw");
        RS_SETTINGS->writeEntry("/TextHeight", leHeight->text());
        RS_SETTINGS->writeEntry("/TextFont", cbFont->currentText());
        RS_SETTINGS->writeEntry("/TextAlignmentT", getAlignment());
        RS_SETTINGS->writeEntry("/TextWidthRelation", leWidthRel->text());
        RS_SETTINGS->writeEntry("/TextStringT", teText->text());
        RS_SETTINGS->writeEntry("/TextAngle", leAngle->text());
        RS_SETTINGS->endGroup();
    }
}
예제 #8
0
void Variables::changeGlobal(Change* change, Module &module) {

  GlobalValue* oldTarget = dyn_cast<GlobalValue>(change->getValue());
  Type* oldType = oldTarget->getType()->getElementType();
  Type* newType = change->getType()[0];
  errs() << "Changing the precision of variable \"" << oldTarget->getName() << "\" from " << *oldType << " to " << *newType << ".\n";

  if (diffTypes(oldType, newType)) {      
    Constant *initializer;
    GlobalVariable* newTarget;

    if (PointerType *newPointerType = dyn_cast<PointerType>(newType)) {
      initializer = ConstantPointerNull::get(newPointerType);
      newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
    }
    else if (ArrayType * atype = dyn_cast<ArrayType>(newType)) {

      // preparing initializer
      Type *temp = Type::getFloatTy(module.getContext());
      vector<Constant*> operands;
      operands.push_back(ConstantFP::get(temp, 0));
      ArrayRef<Constant*> *arrayRef = new ArrayRef<Constant*>(operands);
      initializer = ConstantArray::get(atype, *arrayRef);

      newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
    }
    else {
      initializer = ConstantFP::get(newType, 0);
      newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
    }

    /*
    GlobalVariable* newTarget = new GlobalVariable(module, newType, false, GlobalValue::CommonLinkage, initializer, "");
    */

    unsigned alignment = getAlignment(newType);
    newTarget->setAlignment(alignment);

    newTarget->takeName(oldTarget);
    
    // iterating through instructions using old AllocaInst
    Value::use_iterator it = oldTarget->use_begin();
    for(; it != oldTarget->use_end(); it++) {
      Transformer::transform(it, newTarget, oldTarget, newType, oldType, alignment);
    }	  
    //oldTarget->eraseFromParent();
  }
  else {
    errs() << "No changes required.\n";
  }
  return;
}
예제 #9
0
void
TR::AMD64ABILinkage::mapIncomingParms(
      TR::ResolvedMethodSymbol *method,
      uint32_t &stackIndex)
   {
   ListIterator<TR::ParameterSymbol> parameterIterator(&method->getParameterList());
   TR::ParameterSymbol *parmCursor = parameterIterator.getFirst();

   if (!parmCursor) return;

   if (parmCursor->getLinkageRegisterIndex() < 0)
      {
      copyLinkageInfoToParameterSymbols();
      }

   // 1st: handle parameters which are passed through stack
   //
   TR::X86SystemLinkage::mapIncomingParms(method);

   // 2nd: handle parameters which are passed through linkage registers, but are
   // not assigned any register after RA (or say, by their first usage point,
   // a MOV is needed to load it from stack to register).
   //
   // AMD64 SysV ABI says that: a parameter is placed either in registers or
   // pushed on the stack, but can't take both.  So, for parms passed through
   // linkage registers but don't have physical registers assigned after RA,
   // we will allocate stack space in local variable region.
   //
   for (parmCursor = parameterIterator.getFirst(); parmCursor; parmCursor = parameterIterator.getNext())
      {
      if ((parmCursor->getLinkageRegisterIndex() >= 0) && (parmCursor->getAllocatedIndex() < 0 || hasToBeOnStack(parmCursor)))
         {
         uint32_t align = getAlignment(parmCursor->getDataType());
         uint32_t alignMinus1 = (align <= AMD64_STACK_SLOT_SIZE) ? (AMD64_STACK_SLOT_SIZE - 1) : (align - 1);
         uint32_t pos = -stackIndex;
         pos += parmCursor->getSize();
         pos = (pos + alignMinus1) & (~alignMinus1);
         stackIndex = -pos;
         parmCursor->setParameterOffset(stackIndex);

         if (comp()->getOption(TR_TraceCG))
            traceMsg(comp(), "mapIncomingParms setParameterOffset %d for param symbol (reg param without home location) %p, hasToBeOnStack() %d\n", parmCursor->getParameterOffset(), parmCursor, hasToBeOnStack(parmCursor));
         }
      else if (parmCursor->getLinkageRegisterIndex() >=0 && parmCursor->getAllocatedIndex() >= 0)
         {
         //parmCursor->setDontHaveStackSlot(0); // this is a hack , so as we could print stack layout table in createPrologue
         if (comp()->getOption(TR_TraceCG))
            traceMsg(comp(), "mapIncomingParms no need to set parm %p, for it has got register %d assigned\n", parmCursor, parmCursor->getAllocatedIndex());
         }
      }
   }
예제 #10
0
    void Label::draw(Graphics* graphics)
    {
        int textX;
        int textY = getHeight() / 2 - getFont()->getHeight() / 2;

        switch (getAlignment())
        {
          case Graphics::LEFT:
              textX = 0;
              break;
          case Graphics::CENTER:
              textX = getWidth() / 2;
              break;
          case Graphics::RIGHT:
              textX = getWidth();
              break;
          default:
              throw GCN_EXCEPTION("Unknown alignment.");
        }

        graphics->setFont(getFont());
        graphics->setColor(getForegroundColor());
        graphics->drawText(getCaption(), textX, textY, getAlignment());
    }
예제 #11
0
/**
 * Updates the text entity represented by the dialog to fit the choices of the user.
 */
void QG_DlgText::updateText() {
    if (text!=NULL) {
        text->setStyle(cbFont->currentText());
        text->setHeight(leHeight->text().toDouble());
        text->setWidthRel(leWidthRel->text().toDouble());

        text->setText(teText->text());
        text->setAlignment(getAlignment());
        text->setAngle(RS_Math::deg2rad(leAngle->text().toDouble()));
    }
    if (text!=NULL && !isNew) {
        text->setPen(wPen->getPen());
        text->setLayer(cbLayer->currentText());
        text->update();
    }
}
예제 #12
0
void DBSH07Button::draw(gcn::Graphics* graphics)
{
    int textX = getWidth() / 2;
    int textY = getHeight() / 2 - getFont()->getHeight() / 2;

    if (mHasMouse)
    {
        graphics->setFont(mHighLightFont);
    }
    else
    {
        graphics->setFont(mNormalFont);
    }

    graphics->drawText(getCaption(), textX, textY, getAlignment());
}
예제 #13
0
void CharAlignment::callbackActive(Widget &widget) {
	if (widget.getTag() == "OkButton") {
		_choices->setCharAlign(_goodness, _loyalty);
		_returnCode = 2;
		return;
	}

	if (widget.getTag() == "CancelButton") {
		_returnCode = 1;
		return;
	}

	_buttons->setActive(dynamic_cast<WidgetButton *>(&widget));
	getAlignment();
	getButton("OkButton", true)->setDisabled(false);
}
예제 #14
0
void QG_DlgMText::destroy() {
    if (isNew&&saveSettings) {
        RS_SETTINGS->beginGroup("/Draw");
        RS_SETTINGS->writeEntry("/TextHeight", leHeight->text());
        RS_SETTINGS->writeEntry("/TextFont", cbFont->currentText());
        RS_SETTINGS->writeEntry("/TextDefault", (int)cbDefault->isChecked());
        RS_SETTINGS->writeEntry("/TextAlignment", getAlignment());
        //RS_SETTINGS->writeEntry("/TextLetterSpacing", leLetterSpacing->text());
        //RS_SETTINGS->writeEntry("/TextWordSpacing", leWordSpacing->text());
        RS_SETTINGS->writeEntry("/TextLineSpacingFactor",
                                leLineSpacingFactor->text());
        RS_SETTINGS->writeEntry("/TextString", teText->toPlainText());
        //RS_SETTINGS->writeEntry("/TextShape", getShape());
        RS_SETTINGS->writeEntry("/TextAngle", leAngle->text());
        //RS_SETTINGS->writeEntry("/TextRadius", leRadius->text());
        RS_SETTINGS->endGroup();
    }
}
예제 #15
0
AllocaInst* Variables::changeLocal(Value* value, Type* newType) {

  AllocaInst* newTarget = NULL;
  vector<Instruction*> erase;

  if (AllocaInst *oldTarget = dyn_cast<AllocaInst>(value)) {
    Type* oldType = oldTarget->getType()->getElementType();

    errs() << "Changing the precision of variable \"" << oldTarget->getName() << "\" from " << *oldType 
	   << " to " << *newType << ".\n";

    if (diffTypes(oldType, newType)) {      
      unsigned alignment = getAlignment(newType);

      newTarget = new AllocaInst(newType, 0, alignment, "new", oldTarget);
      newTarget->takeName(oldTarget);

      // iterating through instructions using old AllocaInst
      Value::use_iterator it = oldTarget->use_begin();
      for(; it != oldTarget->use_end(); it++) {
        bool is_erased = Transformer::transform(it, newTarget, oldTarget, newType, oldType, alignment);

	if (!is_erased) {
	  erase.push_back(dyn_cast<Instruction>(*it));
	}
      }
      // erasing old uses of instructions
      for(unsigned int i = 0; i < erase.size(); i++) {
	erase[i]->eraseFromParent();
      }
      // erase old instruction
      //oldTarget->eraseFromParent();      
    }
    else {
      errs() << "\tNo changes required.\n";
    }
  }
  else if (Argument *argument = dyn_cast<Argument>(value)){
    errs() << "WARNING: Function argument instead of Alloca for: " << argument->getName() << ".\n";
  }

  return newTarget;
}
예제 #16
0
static void printMasmHeader( section_ptr sec )
{
    orl_sec_alignment   alignment;
    orl_sec_flags       flags;
    orl_sec_type        type;
    orl_sec_frame       frame;
    orl_sec_combine     combine;
    orl_sec_size        size;
    char                *name;
    char                *class;
    char                *gname;
    char                *astr;
    orl_sec_handle      sh;
    orl_group_handle    grp = NULL;
    char                comname[ MAX_LINE_LEN ];

    size = ORLSecGetSize( sec->shnd );

    // Load all necessary information
    name = sec->name;
    if( !name ) {
        name = "";
    }
    type = ORLSecGetType( sec->shnd );
    flags = ORLSecGetFlags( sec->shnd );
    frame = ORLSecGetAbsFrame( sec->shnd );

    if( DFormat & DFF_ASM ) {
        class = ORLSecGetClassName( sec->shnd );
        if( !class ) {
            class = "";
        }
        if( flags & ORL_SEC_FLAG_COMDAT ) {
            BufferConcat( "; ERROR: Comdat symbols cannot be assembled." );
        } else if( frame == ORL_SEC_NO_ABS_FRAME ) {
            alignment = ORLSecGetAlignment( sec->shnd );
            combine = ORLSecGetCombine( sec->shnd );
            BufferQuoteName( name );
            BufferStore( "\t\tSEGMENT\t%s %s %s '%s'",
                         getAlignment( alignment ), getCombine( combine ),
                         getUse( flags ), class );
        } else {
예제 #17
0
파일: halGenome.cpp 프로젝트: dayin1989/hal
void Genome::copyDimensions(Genome *dest) const
{
  vector<Sequence::Info> dimensions;
  const Alignment *inAlignment = getAlignment();
  SequenceIteratorConstPtr seqIt = getSequenceIterator();
  SequenceIteratorConstPtr seqEndIt = getSequenceEndIterator();

  bool root = inAlignment->getParentName(getName()).empty();
  bool leaf = inAlignment->getChildNames(getName()).empty();     
  
  for (; seqIt != seqEndIt; seqIt->toNext())
  {
    const Sequence* sequence = seqIt->getSequence();
    Sequence::Info info(sequence->getName(),
                        sequence->getSequenceLength(),
                        root ? 0 : sequence->getNumTopSegments(),
                        leaf ? 0 : sequence->getNumBottomSegments());
    dimensions.push_back(info);
  }
  dest->setDimensions(dimensions);
}
예제 #18
0
파일: FontStyle.cpp 프로젝트: libavg/libavg
void FontStyle::setDefaultedArgs(const ArgList& args)
{
    // Warning: The ArgList here contains args that are for a different class originally,
    // so the member offsets are wrong.
    setDefaultedArg(m_sName, "font", args);
    setDefaultedArg(m_sVariant, "variant", args);
    setDefaultedArg(m_Color, "color", args);
    setDefaultedArg(m_AAGamma, "aagamma", args);
    setDefaultedArg(m_Size, "fontsize", args);
    setDefaultedArg(m_Indent, "indent", args);
    setDefaultedArg(m_LineSpacing, "linespacing", args);
    UTF8String s = getAlignment();
    setDefaultedArg(s, "alignment", args);
    setAlignment(s);
    s = getWrapMode();
    setDefaultedArg(s, "wrapmode", args);
    setWrapMode(s);
    setDefaultedArg(m_bJustify, "justify", args);
    setDefaultedArg(m_LetterSpacing, "letterspacing", args);
    setDefaultedArg(m_bHint, "hint", args);
}
예제 #19
0
void EllipsizedLabel::paintEvent(QPaintEvent *)
{
	FontMetrics metrics(font());
	QRect r = contentsRect();

	int w = getTextWidth();
	if(w != lastWidth)
	{
		lastWidth = w;
		ellipsizedText = metrics.ellipsizedText(originalText, w);
	}

	QStyleOption opt;
	opt.initFrom(this);

	QPainter painter(this);
	drawFrame(&painter);

	style()->drawItemText(&painter, r, getAlignment(), opt.palette,
	                      isEnabled(), ellipsizedText, foregroundRole());
}
예제 #20
0
void tMercuryControlRPMIndicator::paintEvent(QPaintEvent*)
{
    tMercuryStyle* style = GetMercuryStyle();
    if( style == 0 || m_Font.isNull() || m_FontBottom.isNull() )
    {
        return;
    }

    QPainter painter(this);
    QRect contentRect(GetContentRect());
    painter.setPen(style->GetColor(tMercuryStyle::eColorRoleIndicatorText));

    float textHeight = float(m_Font->GetRect(m_PropText).height());
    float bottomHeight = float(m_FontBottom->GetRect(m_PropTextBottom).height());

    float totalHeight = textHeight * (m_PropDoubleValue ? 2.f : 1.f) + bottomHeight;

    QRect textRect;
    painter.setFont(m_Font->GetFont());

    float ypos = contentRect.center().y() - totalHeight * 0.5f;
    int alignment = (getAlignment() & (Qt::AlignLeft | Qt::AlignRight)) | Qt::AlignTop;
    int flippedAlignment = alignment ^ (Qt::AlignLeft | Qt::AlignRight);

    painter.drawText(contentRect.left(), qRound(ypos), contentRect.width(), contentRect.height(),
        m_PropDoubleValue ? flippedAlignment : alignment, m_PropText, &textRect);

    if( m_PropDoubleValue )
    {
        ypos += textHeight;
        painter.drawText(contentRect.left(), qRound(ypos), contentRect.width(), contentRect.height(),
            alignment, m_PropText2, &textRect);
    }

    painter.setFont(m_FontBottom->GetFont());

    ypos += textHeight - bottomHeight * 0.2f;
    painter.drawText(textRect.left(), qRound(ypos), textRect.width(), contentRect.height(),
        flippedAlignment, m_PropTextBottom);
}
void OpenInfraPlatform::UserInterface::VerticalAlignmentWindow::onChange()
{
	auto& data = OpenInfraPlatform::DataManagement::DocumentManager::getInstance().getData();
	auto alignmentModel = data.getAlignmentModel();
	auto elevationModel = data.getDigitalElevationModel();

	OpenInfraPlatform::DataManagement::ChangeFlag flag = data.getLatesChangeFlag();

	if ((flag & OpenInfraPlatform::DataManagement::ChangeFlag::Preferences || flag & OpenInfraPlatform::DataManagement::ChangeFlag::AlignmentModel) && alignmentModel->getAlignmentCount() > 0)
	{
		scene_->setAlignment(alignmentModel);
	}

	if (flag & OpenInfraPlatform::DataManagement::ChangeFlag::DigitalElevationModel)
	{
		scene_->setDigitalElevationModel(elevationModel);
	}

	if (flag & OpenInfraPlatform::DataManagement::ChangeFlag::Preferences)
	{
		int index = data.getSelectedAlignment();
		if (index >= 0)
		{
			if (scene_)
			{
				scene_->clearSurfaceProfile();
				scene_->setSelectedAlignment(index);
			}
			if (alignmentModel->getAlignmentCount() > 0)
			{
				QString name = QString::fromStdWString(alignmentModel->getAlignment(index)->getName().toWStdString());
				setWindowTitle("Vertical Alignment - " + name);
			}
		}
	}
}
예제 #22
0
    void Window::draw(Graphics* graphics)
    {
        const Color &faceColor = getBaseColor();
        Color highlightColor, shadowColor;
        const int alpha = getBaseColor().a;
        highlightColor = faceColor + 0x303030;
        highlightColor.a = alpha;
        shadowColor = faceColor - 0x303030;
        shadowColor.a = alpha;

        Rectangle d = getChildrenArea();

        // Fill the background around the content
        graphics->setColor(faceColor);
        // Fill top
        graphics->fillRectangle(Rectangle(0,0,getWidth(),d.y - 1));
        // Fill left
        graphics->fillRectangle(Rectangle(0,d.y - 1, d.x - 1, getHeight() - d.y + 1));
        // Fill right
        graphics->fillRectangle(Rectangle(d.x + d.width + 1,
                                          d.y - 1,
                                          getWidth() - d.x - d.width - 1,
                                          getHeight() - d.y + 1));
        // Fill bottom
        graphics->fillRectangle(Rectangle(d.x - 1,
                                          d.y + d.height + 1,
                                          d.width + 2,
                                          getHeight() - d.height - d.y - 1));

        if (isOpaque())
        {
            graphics->fillRectangle(d);
        }

        // Construct a rectangle one pixel bigger than the content
        d.x -= 1;
        d.y -= 1;
        d.width += 2;
        d.height += 2;

        // Draw a border around the content
        graphics->setColor(shadowColor);
        // Top line
        graphics->drawLine(d.x,
                           d.y,
                           d.x + d.width - 2,
                           d.y);

        // Left line
        graphics->drawLine(d.x,
                           d.y + 1,
                           d.x,
                           d.y + d.height - 1);

        graphics->setColor(highlightColor);
        // Right line
        graphics->drawLine(d.x + d.width - 1,
                           d.y,
                           d.x + d.width - 1,
                           d.y + d.height - 2);
        // Bottom line
        graphics->drawLine(d.x + 1,
                           d.y + d.height - 1,
                           d.x + d.width - 1,
                           d.y + d.height - 1);

        drawChildren(graphics);

        int textX;
        int textY;

        textY = ((int)getTitleBarHeight() - getFont()->getHeight()) / 2;

        switch (getAlignment())
        {
          case Graphics::LEFT:
              textX = 4;
              break;
          case Graphics::CENTER:
              textX = getWidth() / 2;
              break;
          case Graphics::RIGHT:
              textX = getWidth() - 4;
              break;
          default:
              throw GCN_EXCEPTION("Unknown alignment.");
        }

        graphics->setColor(getForegroundColor());
        graphics->setFont(getFont());
        graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1));
        graphics->drawText(getCaption(), textX, textY, getAlignment());
        graphics->popClipArea();
    }
예제 #23
0
    void Button::draw(Graphics* graphics)
    {
        Color faceColor = getBaseColor();
        Color highlightColor, shadowColor;
        int alpha = getBaseColor().a;

        if (isPressed())
        {
            faceColor = faceColor - 0x303030;
            faceColor.a = alpha;
            highlightColor = faceColor - 0x303030;
            highlightColor.a = alpha;
            shadowColor = faceColor + 0x303030;
            shadowColor.a = alpha;
        }
        else
        {
            highlightColor = faceColor + 0x303030;
            highlightColor.a = alpha;
            shadowColor = faceColor - 0x303030;
            shadowColor.a = alpha;
        }

        graphics->setColor(faceColor);
        graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1));

        graphics->setColor(highlightColor);
        graphics->drawLine(0, 0, getWidth() - 1, 0);
        graphics->drawLine(0, 1, 0, getHeight() - 1);

        graphics->setColor(shadowColor);
        graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
        graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);

        graphics->setColor(getForegroundColor());

        int textX;
        int textY = getHeight() / 2 - getFont()->getHeight() / 2;

        switch (getAlignment())
        {
          case Graphics::LEFT:
              textX = mSpacing;
              break;
          case Graphics::CENTER:
              textX = getWidth() / 2;
              break;
          case Graphics::RIGHT:
              textX = getWidth() - mSpacing;
              break;
          default:
              throw GCN_EXCEPTION("Unknown alignment.");
        }

        graphics->setFont(getFont());

        if (isPressed())
        {
            graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
        }
        else
        {
            graphics->drawText(getCaption(), textX, textY, getAlignment());

            if (isFocused())
            {
                graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4,
                                                  getHeight() - 4));
            }
        }
    }
예제 #24
0
Pnt2f Slider::getSliderTrackTopLeft(void) const
{
    Pnt2f BorderTopLeft, BorderBottomRight;
    getInsideInsetsBounds(BorderTopLeft, BorderBottomRight);

    Pnt2f Pos;

    if(getOrientation() == VERTICAL_ORIENTATION)
    {
        Pos = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Vec2f(0,0), 0.0, getAlignment());
        Pos[1] += getTrackInset();
    }
    else
    {
        Pos = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Vec2f(0,0), getAlignment(), 0.0);
        Pos[0] += getTrackInset();
    }

    return Pos;
}
예제 #25
0
void Slider::updateLayout(void)
{

    UInt16 MajorAxis, MinorAxis;
    if(getOrientation() == VERTICAL_ORIENTATION)
    {
        MajorAxis = 1;
    }
    else
    {
        MajorAxis = 0;
    }
    MinorAxis = (MajorAxis+1)%2;

    updateSliderTrack();

    //Update the Track
    if(getDrawTrack() && getTrackDrawObject() != NULL)
    {
        Pnt2f BorderTopLeft, BorderBottomRight;
        getInsideInsetsBounds(BorderTopLeft, BorderBottomRight);

        Vec2f Size(getTrackDrawObject()->getPreferredSize());
        Pnt2f AlignedPosition;
        Size[MajorAxis] = getTrackLength();

        if(getOrientation() == VERTICAL_ORIENTATION)
        {
            AlignedPosition = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Size, 0.5, getAlignment());
        }
        else
        {
            AlignedPosition = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Size, getAlignment(), 0.5);
        }

        getTrackDrawObject()->setPosition(AlignedPosition);
        getTrackDrawObject()->setSize(Size);
    }

    //Update the MinorTickMarks
    if(getDrawMinorTicks() && getRangeModel() != NULL)
    {
        Pnt2f MinorTickTopLeft, MinorTickBottomRight;
        getDrawObjectBounds(*editMFMinorTickDrawObjects(), MinorTickTopLeft, MinorTickBottomRight);

        Vec2f Alignment;

        Real32 MaxLength(0.0);
        for(UInt32 i(0) ; i<getMFMinorTickDrawObjects()->size() ; ++i)
        {
            Pnt2f DrawObjectTopLeft, DrawObjectBottomRight;
            getMinorTickDrawObjects(i)->getBounds(DrawObjectTopLeft, DrawObjectBottomRight);
            MaxLength = osgMax(MaxLength, DrawObjectBottomRight.x()-DrawObjectTopLeft.x());
        }
        editMFMinorTickPositions()->clear();

        for(UInt32 i(0) ; i< osgAbs<Int32>(getMaximum() - getMinimum())/getMinorTickSpacing() ; ++i)
        {
            if( (i * getMinorTickSpacing())%getMajorTickSpacing() != 0 )
            {
                Alignment[MajorAxis] = static_cast<Real32>(i * getMinorTickSpacing())/static_cast<Real32>(getMaximum() - getMinimum());
                editMFMinorTickPositions()->push_back(
                                                  calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), (MinorTickBottomRight - MinorTickTopLeft), Alignment.y(), Alignment.x()));
                if(getTicksOnRightBottom())
                {
                    editMFMinorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] + getTrackDrawObject()->getSize()[MinorAxis] + getTrackToTickOffset();
                }
                else
                {
                    editMFMinorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] - getTrackToTickOffset() - MaxLength;
                }
            }
        }

    }

    //Update the MajorTickMarks
    if(getDrawMajorTicks() && getRangeModel() != NULL)
    {
        Pnt2f MajorTickTopLeft, MajorTickBottomRight;
        getDrawObjectBounds(*editMFMajorTickDrawObjects(), MajorTickTopLeft, MajorTickBottomRight);

        Vec2f Alignment;

        Real32 MaxLength(0.0);
        for(UInt32 i(0) ; i<getMFMajorTickDrawObjects()->size() ; ++i)
        {
            Pnt2f DrawObjectTopLeft, DrawObjectBottomRight;
            getMajorTickDrawObjects(i)->getBounds(DrawObjectTopLeft, DrawObjectBottomRight);
            MaxLength = osgMax(MaxLength, DrawObjectBottomRight.x()-DrawObjectTopLeft.x());
        }
        editMFMajorTickPositions()->clear();

        for(UInt32 i(0) ; i<= osgAbs<Int32>(getMaximum() - getMinimum())/getMajorTickSpacing() ; ++i)
        {
            Alignment[MajorAxis] = static_cast<Real32>(i * getMajorTickSpacing())/static_cast<Real32>(getMaximum() - getMinimum());
            editMFMajorTickPositions()->push_back(
                                              calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), (MajorTickBottomRight - MajorTickTopLeft), Alignment.y(), Alignment.x()));
            if(getTicksOnRightBottom())
            {
                editMFMajorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] + getTrackDrawObject()->getSize()[MinorAxis] + getTrackToTickOffset();
            }
            else
            {
                editMFMajorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] - getTrackToTickOffset() - MaxLength;
            }
        }

    }

    //Update the Labels
    if(getDrawLabels() && getRangeModel() != NULL)
    {
        Vec2f Alignment;
        Pnt2f Pos;
        FieldContainerMap::const_iterator Itor;
        for(Itor = getLabelMap().begin() ; Itor != getLabelMap().end() ; ++Itor)
        {
            Alignment[MajorAxis] = static_cast<Real32>((*Itor).first - getMinimum())/static_cast<Real32>(getMaximum() - getMinimum());
            Pos = calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), dynamic_pointer_cast<Component>((*Itor).second)->getPreferredSize(), Alignment.y(), Alignment.x());
            if(getTicksOnRightBottom())
            {
                Pos[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] + getTrackDrawObject()->getSize()[MinorAxis] + getTrackToLabelOffset();
            }
            else
            {
                Pos[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] - getTrackToLabelOffset() - dynamic_pointer_cast<Component>((*Itor).second)->getPreferredSize()[MinorAxis];
            }

            dynamic_pointer_cast<Component>((*Itor).second)->setPosition(Pos);
            dynamic_pointer_cast<Component>((*Itor).second)->setSize(dynamic_pointer_cast<Component>((*Itor).second)->getPreferredSize());
        }
    }
}
예제 #26
0
void Label::calculateTextBounds(const UInt32 StartIndex, const UInt32 EndIndex, Pnt2f& TopLeft, Pnt2f& BottomRight)
{
    Pnt2f ComponentTopLeft, ComponentBottomRight;
    getInsideBorderBounds(ComponentTopLeft, ComponentBottomRight);

    Pnt2f AlignmentOffset = calculateAlignment(ComponentTopLeft, ComponentBottomRight-ComponentTopLeft, getFont()->getBounds(getText()), getAlignment().y(), getAlignment().x());

    getFont()->getBounds(getText().substr(StartIndex, EndIndex), TopLeft, BottomRight);
    TopLeft = TopLeft + Vec2f(AlignmentOffset);
    BottomRight = BottomRight + Vec2f(AlignmentOffset);
}
예제 #27
0
void Label::mouseClicked(MouseEventDetails* const e)
{    
    if(getTextSelectable())
    {
        Int32 Position(0);
        Int32 BeginWord = 0;
        Int32 EndWord = getText().size();
        if(e->getButton() == MouseEventDetails::BUTTON1)
        {

            if(e->getClickCount() == 2)
            {
                Pnt2f TopLeftText, BottomRightText, TempPos;
                Pnt2f TopLeftText1, BottomRightText1;
                Pnt2f TopLeft, BottomRight;
                getFont()->getBounds(getText(), TopLeftText, BottomRightText);
                getInsideBorderBounds(TopLeft, BottomRight);
                TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, BottomRightText-TopLeftText, getAlignment().y(), getAlignment().x());

                //set caret position to proper place
                //if the mouse is to the left of the text, set it to the begining.
                Pnt2f temp = DrawingSurfaceToComponent(e->getLocation(), this);
                if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= TempPos.x())
                {
                    Position = 0;
                }//if the mouse is to the right of the text, set it to the end
                else if(DrawingSurfaceToComponent(e->getLocation(), this).x() >= TempPos.x()+BottomRightText.x())
                {
                    Position = getText().size();
                }
                else
                {
                    for(UInt32 i = 0; i <getText().size(); i++)
                    {        
                        calculateTextBounds(0,i, TopLeftText, BottomRightText);
                        calculateTextBounds(0,i+1, TopLeftText1, BottomRightText1);
                        if(DrawingSurfaceToComponent(e->getLocation(), this).x()>BottomRightText.x()
                           && DrawingSurfaceToComponent(e->getLocation(), this).x() <= BottomRightText1.x())//check to see if it's in the right spot
                        {
                            Position = i;
                            break;
                        }
                    }
                }
                if(isPunctuationChar(getText()[Position]))
                {
                    EndWord = Position + 1;
                    BeginWord = Position;
                }
                else{
                    for(Int32 i = Position; i < getText().size(); i++)
                    {
                        if(!isWordChar(getText()[i]))
                        {
                            EndWord = i;
                            break;
                        }
                    }
                    for(Int32 i = Position; i >= 0; i--)
                    {
                        if(!isWordChar(getText()[i]))
                        {
                            BeginWord = i + 1;
                            break;
                        }
                    }
                }
                _TextSelectionEnd = EndWord;
                _TextSelectionStart = BeginWord;
                setCaretPosition(EndWord);
            }
        }
    }
    Inherited::mouseClicked(e);

}
예제 #28
0
void Label::mouseDragged(MouseEventDetails* const e)
{
    if(getTextSelectable())
    {
        Pnt2f TopLeftText, BottomRightText, TempPos;
        Pnt2f TopLeftText1, BottomRightText1;
        Pnt2f TopLeft, BottomRight;
        Int32 OriginalPosition = getCaretPosition();
        getFont()->getBounds(getText(), TopLeftText, BottomRightText);
        getInsideBorderBounds(TopLeft, BottomRight);
        TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, BottomRightText-TopLeftText, getAlignment().y(), getAlignment().x());
        if(e->getButton() == MouseEventDetails::BUTTON1)
        {
            //set caret position to proper place
            //if the mouse is to the left of the text, set it to the begining.
            Pnt2f temp = DrawingSurfaceToComponent(e->getLocation(), this);
            if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= TempPos.x())
            {
                setCaretPosition(0);
            }        //if the mouse is to the right of the text, set it to the end
            else if(DrawingSurfaceToComponent(e->getLocation(), this).x() >= TempPos.x()+BottomRightText.x())
            {
                setCaretPosition(getText().size());
            }
            else
            {
                //check letter by letter for the mouse's position
                for(UInt32 i = 0; i <getText().size(); i++)
                {        
                    calculateTextBounds(0,i, TopLeftText, BottomRightText);
                    calculateTextBounds(0,i+1, TopLeftText1, BottomRightText1);
                    if(DrawingSurfaceToComponent(e->getLocation(), this).x()>BottomRightText.x()
                       && DrawingSurfaceToComponent(e->getLocation(), this).x() <= BottomRightText1.x())//check to see if it's in the right spot
                    {
                        if(DrawingSurfaceToComponent(e->getLocation(), this).x() < (BottomRightText1.x()-BottomRightText.x())/2.0 + BottomRightText.x())
                        {

                            setCaretPosition(i);
                            break;
                        }
                        else
                        {

                            setCaretPosition(i+1);
                            break;
                        }
                    }
                }
            }
            if(getCaretPosition() < OriginalPosition)
            {
                if(getCaretPosition() < _TextSelectionStart)
                {
                    _TextSelectionStart = getCaretPosition();
                }
                else
                {
                    _TextSelectionEnd = getCaretPosition();
                }
            }
            else if(getCaretPosition() > OriginalPosition)
            {
                if(getCaretPosition() > _TextSelectionEnd)
                {
                    _TextSelectionEnd = getCaretPosition();
                }
                else
                {
                    _TextSelectionStart = getCaretPosition();
                }
            }
        }
    }
    

    Inherited::mouseDragged(e);
}
예제 #29
0
void ToggleButton::draw(Graphics *graphics) {
    Color faceColor = getBaseColor();
    Color highlightColor;
    Color shadowColor;
    int32_t alpha = getBaseColor().a;

    Image* img = NULL;
    int32_t xoffset = 0;
    int32_t yoffset = 0;

    if (isPressed() || m_toggled) {
        faceColor = faceColor - 0x303030;
        faceColor.a = alpha;
        highlightColor = faceColor - 0x303030;
        highlightColor.a = alpha;
        shadowColor = faceColor + 0x303030;
        shadowColor.a = alpha;

        if( m_downImage ) {
            img = m_downImage;
            xoffset = x_downoffset;
            yoffset = y_downoffset;
        }
    } else if(mHasMouse) {
        faceColor = faceColor + 0x303030;
        faceColor.a = alpha;
        highlightColor = faceColor + 0x303030;
        highlightColor.a = alpha;
        shadowColor = faceColor - 0x303030;
        shadowColor.a = alpha;

        if ( m_hoverImage ) {
            img = m_hoverImage;
        }
    } else {
        highlightColor = faceColor + 0x303030;
        highlightColor.a = alpha;
        shadowColor = faceColor - 0x303030;
        shadowColor.a = alpha;

        if (m_upImage) {
            img = m_upImage;
        }
    }


    graphics->setColor(faceColor);
    graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1));

    graphics->setColor(highlightColor);
    graphics->drawLine(0, 0, getWidth() - 1, 0);
    graphics->drawLine(0, 1, 0, getHeight() - 1);

    graphics->setColor(shadowColor);
    graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
    graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);

    graphics->setColor(getForegroundColor());

    if (img) {
        graphics->drawImage(img, xoffset, yoffset);
    }

    int32_t textX;
    int32_t textY = getHeight() / 2 - getFont()->getHeight() / 2;
    switch (getAlignment())
    {
    case Graphics::Left:
        textX = 4;
        break;
    case Graphics::Center:
        textX = getWidth() / 2;
        break;
    case Graphics::Right:
        textX = getWidth() - 4;
        break;
    default:
        //use the default of Graphics::LEFT
        textX = 4;
        FL_WARN(_log, FIFE::LMsg("ToggleButton::draw() - ") << "Unknown alignment: "
                << getAlignment() << ".  Using the default of Graphics::LEFT");
    }

    graphics->setFont(getFont());
    if (mCaption.size() > 0) {
        if (isPressed())
            graphics->drawText(getCaption(), textX + 1,
                               textY + 1, getAlignment());
        else
            graphics->drawText(getCaption(), textX, textY, getAlignment());
    }
}
예제 #30
0
void Label::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    if(getText() != "" && getFont() != NULL)
    {
        Pnt2f TopLeft, BottomRight;
        Pnt2f TempPos;
        getInsideBorderBounds(TopLeft, BottomRight);
        TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds(getText()), getAlignment().y(), getAlignment().x());
        
        //Text Color
        Color4f TextColor = getDrawnTextColor();

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

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

            TheGraphics->drawQuad(TempPos + Vec2f(TextBottomRight.x(),0),
                                  TempPos + Vec2f(getFont()->getBounds(getText().substr(0, _TextSelectionEnd)).x(), 0),
                                  TempPos + Vec2f(getFont()->getBounds(getText().substr(0, _TextSelectionEnd))),
                                  TempPos + Vec2f(TextBottomRight),
                                  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(), getOpacity()*Opacity);

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

            //Draw Text After selection
            getFont()->getBounds(getText().substr(0, _TextSelectionEnd), TextTopLeft, TextBottomRight);
            TheGraphics->drawText(TempPos + Vec2f(TextBottomRight.x(), 0),
                                  getText().substr(_TextSelectionEnd, getText().size()-_TextSelectionEnd), getFont(), TextColor, getOpacity()*Opacity);
        }
    }
}