Beispiel #1
0
void csRectRegion::nkSplit (csRect &r1, csRect &r2)
{
  r2.Intersect (r1);

  if (r1.ymin < r2.ymin) // upper stripe
  {
    region.Push (csRect(r1.xmin,r1.ymin, r1.xmax, r2.ymin));
  }

  if (r1.xmin < r2.xmin) // left stripe
  {
    region.Push (csRect(r1.xmin,r2.ymin, r2.xmin, r2.ymax));
  }

  if (r1.xmax > r2.xmax) // right stripe
  {
    //region.Push (csRect(r2.xmin, r2.ymin, r1.xmax, r2.ymax));
    region.Push( csRect(r2.xmax, r2.ymin, r1.xmax, r2.ymax) );
  }

  if (r1.ymax > r2.ymax) // lower stripe
  {
    region.Push (csRect(r1.xmin, r2.ymax, r1.xmax, r1.ymax));
  }
}
void pawsSkillIndicator::DrawSkillProgressBar(int x, int y, int width, int height,
                                int start_r, int start_g, int start_b)
{
    pawsProgressBar::DrawProgressBar(
        csRect(x, y, x+width-1, y+height-1), PawsManager::GetSingleton().GetGraphics3D(), 1,
        start_r, start_g, start_b, 100, 100, 100 );
}
void csTerrainModifiableDataFeeder::RemoveModifier (iTerrainModifier* modifier)
{
  if (modifiers.Delete(modifier))
  {
    //Collect all cells that are altered by this modifier.
    csRefArray<iTerrainCell> affectedCells;
    for (size_t i = 0; i < cells.GetSize(); i++)
    {
      if (modifier->InBounds(WorldArea(cells[i])))
      {
        affectedCells.Push(cells[i]);
      }
    }

    // Reload affected cells
    for (size_t i = 0; i < affectedCells.GetSize(); i++)
    {
      iTerrainCell* cell = affectedCells[i];

      csTerrainModifiableDataFeederProperties* properties = 
        (csTerrainModifiableDataFeederProperties*)cell->GetFeederProperties ();

      if (!loader || !properties)
        continue;

      if (properties->heightmapSource.IsEmpty ())
        continue;

      int width = cell->GetGridWidth ();
      int height = cell->GetGridHeight ();

      csLockedHeightData data = cell->LockHeightData (csRect(0, 0, width, height));

      HeightFeederParser mapReader (properties->heightmapSource, 
        properties->heightmapFormat, loader, objectReg);
      mapReader.Load (data.data, width, height, data.pitch, cell->GetSize ().y, 
        properties->heightOffset);

      if (properties->smoothHeightmap)
      {
        SmoothHeightmap (data.data, width, height, data.pitch);    
      }

      cell->UnlockHeightData ();
      cell->RecalculateNormalData ();
    }

    //Reapply modifiers
    for (size_t j = 0; j < modifiers.GetSize(); j++)
      for (size_t i = 0; i < affectedCells.GetSize(); i++)
      {
        if (modifiers[j]->InBounds(WorldArea(affectedCells[i])))
        {
          modifiers[j]->Displace(affectedCells[i], 1.0f);
        }
      }

  }  
}
Beispiel #4
0
mng_bool ImageJngFile::cb_imagerefresh (mng_handle hHandle,
					 mng_uint32 iX, mng_uint32 iY, 
					 mng_uint32 iWidth, mng_uint32 iHeight)
{
  ImageJngFile *this_ = (ImageJngFile *)mng_get_userdata (hHandle);

  if (this_->dirtyrect)
  {
    this_->dirtyrect->Join (csRect (iX, iY, iX+iWidth, iY+iHeight));
  }
  return MNG_TRUE;
}
Beispiel #5
0
void csTerrainCell::SetMaterialMask (unsigned int material, iImage* image)
{
  if (image->GetFormat () != CS_IMGFMT_PALETTED8) 
    return;

  Touch();
  
  if (image->GetWidth () != materialMapWidth || 
    image->GetHeight () != materialMapHeight)
  {
    image = csImageManipulate::Rescale (image, materialMapWidth,
      materialMapHeight);
  }
    
  terrain->GetRenderer ()->OnMaterialMaskUpdate (this, material,
    csRect(0, 0, image->GetWidth (), image->GetHeight ()),
    (const unsigned char*)image->GetImageData (), image->GetWidth ());
}
Beispiel #6
0
void CListBoxST::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
	ASSERT(lpMeasureItemStruct->CtlType == ODT_LISTBOX);
	CDC*    pDC = GetDC();
	int		nHeight = 0;
	
	CString	sText;
	CListBox::GetText(lpMeasureItemStruct->itemID, sText);

	CRect	csRect(0, 0, lpMeasureItemStruct->itemWidth, lpMeasureItemStruct->itemHeight);
	nHeight = pDC->DrawText(sText, -1, csRect, DT_WORDBREAK | DT_EXPANDTABS | DT_CALCRECT);

	if (m_pImageList)
		lpMeasureItemStruct->itemHeight = max(nHeight, m_szImage.cy + CY_BORDER*2);
	else
		lpMeasureItemStruct->itemHeight  = nHeight;

	lpMeasureItemStruct->itemHeight += CY_BORDER*2;
} // End of MeasureItem
Beispiel #7
0
Lightmap::Lightmap (int w, int h)
    : colorArray (0), width (0), height (0),
      lightmapAllocator (csRect (0, 0, w, h)), texture (0)
{
    lightmapAllocator.SetGrowPO2 (true);
}
Beispiel #8
0
//  This operation takes a rect r1 which completely contains rect r2
// and turns it into as many rects as it takes to exclude r2 from the
// area controlled by r1.
void csRectRegion::fragmentContainedRect (csRect &r1t, csRect &r2t)
{
  // Edge flags
  const unsigned int LX = 1, TY = 2, RX = 4, BY = 8;
  unsigned int edges = 0;

  csRect r1 (r1t), r2 (r2t);

  // First check for edging.
  edges |= (r1.xmin == r2.xmin ? LX : 0);
  edges |= (r1.ymin == r2.ymin ? TY : 0);
  edges |= (r1.xmax == r2.xmax ? RX : 0);
  edges |= (r1.ymax == r2.ymax ? BY : 0);

  //csPrintf("csrectrgn: fragmenting with rule %u\n", edges);
  //csPrintf("\t%d,%d,%d,%d\n", r1.xmin, r1.ymin, r1.xmax, r1.ymax);
  //csPrintf("\t%d,%d,%d,%d\n", r2.xmin, r2.ymin, r2.xmax, r2.ymax);
  switch (edges)
  {
    case 0:
      // This is the easy case. Split the r1 into four pieces that exclude r2.
      // The include function pre-checks for this case and exits, so it is
      // properly handled.
      region.Push (csRect (r1.xmin, r1.ymin, r2.xmin, r1.ymax)); //left
      region.Push (csRect (r2.xmax, r1.ymin, r1.xmax, r1.ymax)); //right
      region.Push (csRect (r2.xmin, r1.ymin, r2.xmax, r2.ymin)); //top
      region.Push (csRect (r2.xmin, r2.ymax, r2.xmax, r1.ymax)); //bottom
      return;

    case 1:
      // Three rects (top, right, bottom) [rect on left side, middle]
      region.Push (csRect (r1.xmin, r1.ymin, r1.xmax, r2.ymin)); //top
      region.Push (csRect (r2.xmax, r2.ymin, r1.xmax, r2.ymax)); //right
      region.Push (csRect (r1.xmin, r2.ymax, r1.xmax, r1.ymax)); //bot
      return;

    case 2:
      // Three rects (bot, left, right)   [rect on top side, middle]
      region.Push (csRect (r1.xmin, r2.ymax, r1.xmax, r1.ymax)); //bot
      region.Push (csRect (r1.xmin, r1.ymin, r2.xmin, r2.ymax)); //left
      region.Push (csRect (r2.xmax, r1.ymin, r1.xmax, r2.ymax)); //right
      return;

    case 3:
      // Two rects (right, bottom)        [rect on top left corner]
      region.Push (csRect (r2.xmax, r1.ymin, r1.xmax, r2.ymax)); //right
      region.Push (csRect (r1.xmin, r2.ymax, r1.xmax, r1.ymax)); //bot
      return;

    case 4:
      // Three rects (top, left, bottom)  [rect on right side, middle]
      region.Push (csRect (r1.xmin, r1.ymin, r1.xmax, r2.ymin)); //top
      region.Push (csRect (r1.xmin, r2.ymin, r2.xmin, r2.ymax)); //left
      region.Push (csRect (r1.xmin, r2.ymax, r1.xmax, r1.ymax)); //bot
      return;

    case 5:
      // Two rects (top, bottom)          [rect in middle, horizontally
      //                                  touches left and right sides]
      region.Push (csRect (r1.xmin, r1.ymin, r1.xmax, r2.ymin)); //top
      region.Push (csRect (r1.xmin, r2.ymax, r1.xmax, r1.ymax)); //bot
      return;

    case 6:
      // Two rects (left, bottom)         [rect on top, right corner]
      region.Push (csRect (r1.xmin, r1.ymin, r2.xmin, r1.ymax)); //left
      region.Push (csRect (r2.xmin, r2.ymax, r1.xmax, r1.ymax)); //bot
      return;

    case 7:
      // One rect (bottom)                [rect covers entire top]
      region.Push (csRect (r1.xmin, r2.ymax, r1.xmax, r1.ymax)); //bot
      return;

    case 8:
      // Three rects (top, left, right)   [rect on bottom side, middle]
      region.Push (csRect (r1.xmin, r1.ymin, r1.xmax, r2.ymin)); //top
      region.Push (csRect (r1.xmin, r2.ymin, r2.xmin, r1.ymax)); //left
      region.Push (csRect (r2.xmax, r2.ymin, r1.xmax, r1.ymax)); //right
      return;

    case 9:
      // Two rects (right, top)           [rect on bottom, left corner]
      region.Push (csRect (r2.xmax, r2.ymin, r1.xmax, r1.ymax)); //right
      region.Push (csRect (r1.xmin, r1.ymin, r1.xmax, r2.ymin)); //top
      return;

    case 10:
      // Two rects (left, right)          [rect middle, vert touches top/bot]
      region.Push (csRect (r1.xmin, r1.ymin, r2.xmin, r1.ymax)); //left
      region.Push (csRect (r2.xmax, r1.ymin, r1.xmax, r1.ymax)); //right
      return;

    case 11:
      // One rect (right)                 [rect left, vert touches top/bot]
      region.Push (csRect (r2.xmax, r1.ymin, r1.xmax, r1.ymax)); //right
      return;

    case 12:
      // Two rects (left, top)            [rect bottom, right corner]
      region.Push (csRect (r1.xmin, r1.ymin, r2.xmin, r1.ymax)); //left
      region.Push (csRect (r2.xmin, r1.ymin, r1.xmax, r2.ymin)); //top
      return;

    case 13:
      // One rect (top)                   [rect bottom, hor touches left/right]
      region.Push (csRect (r1.xmin, r1.ymin, r1.xmax, r2.ymin)); //top
      return;

    case 14:
      // One rect (left)                   [rect right, vert touches top/bot]
      region.Push (csRect (r1.xmin, r1.ymin, r2.xmin, r1.ymax)); //bottom
      return;

    case 15:
      // No rects
      // In this case, the rects cancel themselves out.
      // Include needs to special case this, otherwise it will not
      //  be handled correctly.
      return;
  }
}
bool csTerrainModifiableDataFeeder::Load (iTerrainCell* cell)
{
  cells.PushSmart(cell);

  csTerrainModifiableDataFeederProperties* properties = 
    (csTerrainModifiableDataFeederProperties*)cell->GetFeederProperties ();

  if (!loader || !properties)
    return false;

  if (properties->heightmapSource.IsEmpty ())
    return false;

  int width = cell->GetGridWidth ();
  int height = cell->GetGridHeight ();

  csLockedHeightData data = cell->LockHeightData (csRect(0, 0, width, height));
  
  HeightFeederParser mapReader (properties->heightmapSource, 
    properties->heightmapFormat, loader, objectReg);
  mapReader.Load (data.data, width, height, data.pitch, cell->GetSize ().y, 
    properties->heightOffset);

  if (properties->smoothHeightmap)
  {
    SmoothHeightmap (data.data, width, height, data.pitch);    
  }

  cell->UnlockHeightData ();

  if (!properties->normalmapSource.IsEmpty ())
  {
    csLockedNormalData ndata = cell->LockNormalData (csRect(0, 0, width, height));

    NormalFeederParser nmapReader (properties->normalmapSource, loader, objectReg);
    nmapReader.Load (ndata.data, width, height, ndata.pitch);

    cell->UnlockNormalData ();
  }
  else
  {
    cell->RecalculateNormalData ();
  }
  
  if (!properties->materialmapSource.IsEmpty ())
  {  
    csRef<iImage> materialMap = loader->LoadImage (properties->materialmapSource.GetDataSafe (),
      CS_IMGFMT_PALETTED8);

    if (!materialMap) 
      return false;
    
    if (materialMap->GetWidth () != cell->GetMaterialMapWidth () ||
        materialMap->GetHeight () != cell->GetMaterialMapHeight ())
    {
      materialMap = csImageManipulate::Rescale (materialMap,
        cell->GetMaterialMapWidth (), cell->GetMaterialMapHeight ());
    }
    
    int mwidth = materialMap->GetWidth ();
    int mheight = materialMap->GetHeight ();

    csLockedMaterialMap mdata = cell->LockMaterialMap (csRect (0, 0, mwidth, mheight));

    const unsigned char* materialmap = (const unsigned char*)materialMap->GetImageData ();
      
    for (int y = 0; y < mheight; ++y)
    {
      memcpy (mdata.data, materialmap, mwidth);
      mdata.data += mdata.pitch;
      materialmap += mwidth;
    } 
    
    cell->UnlockMaterialMap ();
  }

  if (engine)
  {
    for (size_t i = 0; i < properties->alphaMaps.GetSize (); ++i)
    {
      iMaterialWrapper* mat = engine->FindMaterial (
        properties->alphaMaps[i].material.GetDataSafe ());

      csRef<iImage> alphaMap = loader->LoadImage (
        properties->alphaMaps[i].alphaSource.GetDataSafe (),
        CS_IMGFMT_ANY);

      if (mat && alphaMap)
      {
        cell->SetAlphaMask (mat, alphaMap);
      }
    }
  }

  //Apply modifiers
  for (size_t j = 0; j < modifiers.GetSize(); j++)
    if (modifiers[j]->InBounds(WorldArea(cell)))
    {
      modifiers[j]->Displace(cell, 1.0f);
    }

  return true;
}
pawsRadioButton* pawsRadioButton::Create(const char* txt, psRadioPos pos , bool /*state*/)
{
    pawsRadioButtonGroup* rbg = dynamic_cast<pawsRadioButtonGroup*>(parent);

    // if this radio button is part of a radio group
    if(rbg!=NULL)
    {
        // get the way the off and up radio buttons should look from there
        radioOff = rbg->GetRadioOffImage();
        radioOn  = rbg->GetRadioOnImage();
        size     = rbg->GetRadioSize();
    }
    radioOff ="radiooff";
    radioOn  ="radioon";
    size = 16;

    ///////////////////////////////////////////////////////////////////////
    // Create the radio button
    ///////////////////////////////////////////////////////////////////////
    radioButton = new pawsButton;
    AddChild(radioButton);

    csRect buttonRect;
    csRect textRect;

    if(pos == POS_LEFT)
    {
        buttonRect = csRect(defaultFrame.Width()-size, 4,
                            defaultFrame.Width(), size+4);

        textRect   = csRect(0, 4, defaultFrame.Width() - size, defaultFrame.Height());
    }

    if(pos == POS_RIGHT)
    {
        buttonRect = csRect(4, 4,
                            size+4, size+4);

        textRect   = csRect(size+6, 4, defaultFrame.Width()-size, defaultFrame.Height());
    }

    if(pos == POS_UNDERNEATH)
    {
        buttonRect = csRect(defaultFrame.Width() / 2 - size /2, 4, defaultFrame.Width()/2 + size/2, 4+size);
        textRect = csRect(0,size+6, defaultFrame.Width() , defaultFrame.Height()-(size+6));
    }

    if(pos == POS_ABOVE)
    {
        buttonRect = csRect(defaultFrame.Width() / 2 - size /2, 22, defaultFrame.Width()/2 + size/2, size+22);
        textRect = csRect(0,4, defaultFrame.Width() , size+4);
    }

    radioButton->SetRelativeFrame(buttonRect.xmin, buttonRect.ymin,
                                  buttonRect.Width(), buttonRect.Height());
    radioButton->SetUpImage(radioOff);
    radioButton->SetDownImage(radioOn);
    radioButton->SetState(false);
    radioButton->SetToggle(true);
    radioButton->PostSetup();
    radioButton->SetID(id);


    ///////////////////////////////////////////////////////////////////////
    // Create the textbox that has the current selected choice
    ///////////////////////////////////////////////////////////////////////

    text = new pawsTextBox;
    AddChild(text);

    // Puts the button at the edge of the text box widget
    text->SetRelativeFrame(textRect.xmin, textRect.ymin,
                           textRect.Width(), textRect.Height());
    text->PostSetup();

    text->SetText(txt);
    text->SetID(id);

    return this;
}
bool pawsRadioButton::Setup(iDocumentNode* node)
{
    csRef<iDocumentNode> textNode = node->GetNode("text");

    if(!textNode)
    {
        Error2("%s XML is defined incorrectly. No <text /> tag found", name.GetData());
        return false;
    }

    csString pos(textNode->GetAttributeValue("position"));

    pawsRadioButtonGroup* rbg = dynamic_cast<pawsRadioButtonGroup*>(parent);

    // if this radio button is part of a radio group
    if(rbg!=NULL)
    {
        // get the way the off and up radio buttons should look from there
        radioOff = rbg->GetRadioOffImage();
        radioOn  = rbg->GetRadioOnImage();
        size     = rbg->GetRadioSize();
    }
    //override group settings
    csRef<iDocumentNode> radioNode = node->GetNode("radio");

    if(radioNode)
    {
        csRef<iDocumentAttribute> attr;

        attr = radioNode->GetAttribute("off");
        if(attr)
            radioOff = attr->GetValue();

        attr = radioNode->GetAttribute("on");
        if(attr)
            radioOn  = attr->GetValue();

        attr = radioNode->GetAttribute("size");
        if(attr)
            size     = attr->GetValueAsInt();
    }



    ///////////////////////////////////////////////////////////////////////
    // Create the radio button
    ///////////////////////////////////////////////////////////////////////
    radioButton = new pawsButton;
    AddChild(radioButton);

    csRect buttonRect;
    csRect textRect;

    if(pos == "left")
    {
        buttonRect = csRect(defaultFrame.Width()-size, 4,
                            defaultFrame.Width(), size+4);

        textRect   = csRect(0, 4, defaultFrame.Width() - size, defaultFrame.Height());
    }

    if(pos == "right")
    {
        buttonRect = csRect(4, 4,
                            size+4, size+4);

        textRect   = csRect(size+6, 4, defaultFrame.Width()-size, defaultFrame.Height());
    }

    if(pos == "underneath")
    {
        buttonRect = csRect(defaultFrame.Width() / 2 - size /2, 4, defaultFrame.Width()/2 + size/2, 4+size);
        textRect = csRect(0,size+6, defaultFrame.Width() , defaultFrame.Height()-(size+6));
    }

    if(pos == "above")
    {
        buttonRect = csRect(defaultFrame.Width() / 2 - size /2, 22, defaultFrame.Width()/2 + size/2, size+22);
        textRect = csRect(0,4, defaultFrame.Width() , size+4);
    }

    radioButton->SetRelativeFrame(buttonRect.xmin, buttonRect.ymin,
                                  buttonRect.Width(), buttonRect.Height());
    radioButton->SetUpImage(radioOff);
    radioButton->SetDownImage(radioOn);
    radioButton->SetState(false);
    radioButton->SetToggle(true);
    radioButton->PostSetup();
    radioButton->SetID(id);


    ///////////////////////////////////////////////////////////////////////
    // Create the textbox that has the current selected choice
    ///////////////////////////////////////////////////////////////////////
    csString str(textNode->GetAttributeValue("string"));

    text = new pawsTextBox;
    AddChild(text);

    // Puts the button at the edge of the text box widget
    text->SetRelativeFrame(textRect.xmin, textRect.ymin,
                           textRect.Width(), textRect.Height());
    text->PostSetup();

    text->SetText(str);
    text->SetID(id);

    return true;
}