コード例 #1
0
/*
 * WinNewDrawPad - create a new drawing pad for Windows version
 */
HWND WinNewDrawPad( img_node *node )
{
    MDICREATESTRUCT     mdicreate;
    short               y_adjustment;
    short               x_adjustment;
    short               pad_x;
    short               pad_y;
    int                 i;
    img_node            *temp;
    POINT               origin;
    char                filename[_MAX_PATH];
    HWND                drawarea;
    HMENU               sys_menu;

    node->viewhwnd = CreateViewWin( node->width, node->height );
    pad_x = 0;
    pad_y = 0;

    temp = node->nexticon;

    for( i = 1; i < node->num_of_images; i++ ) {
        temp->viewhwnd = node->viewhwnd;
        temp = temp->nexticon;
    }

    if( node->imgtype == BITMAP_IMG ) {
        mdicreate.szClass = DrawAreaClassB;
    } else if( node->imgtype == ICON_IMG ) {
        mdicreate.szClass = DrawAreaClassI;
    } else {
        mdicreate.szClass = DrawAreaClassC;
    }

    GetFnameFromPath( node->fname, filename );
    mdicreate.szTitle = filename;
    mdicreate.hOwner = Instance;

    x_adjustment = (short)(2 * GetSystemMetrics( SM_CXFRAME ));
    y_adjustment = (short)(2 * GetSystemMetrics( SM_CYFRAME ) +
                           GetSystemMetrics( SM_CYCAPTION ) - 1);

    origin.x = 0;
    origin.y = 0;
    FindOrigin( &origin );
    CalculateDims( node->width, node->height, &pad_x, &pad_y );

    mdicreate.cx = x_adjustment + pad_x;
    mdicreate.cy = y_adjustment + pad_y;
    mdicreate.x = origin.x;
    mdicreate.y = origin.y;
    mdicreate.style = WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE |
                      WS_CLIPSIBLINGS | WS_DLGFRAME | WS_MINIMIZEBOX |
                      WS_THICKFRAME;
    mdicreate.lParam = (LPARAM)(LPVOID)node;

    drawarea = (HWND)SendMessage( ClientWindow, WM_MDICREATE, 0,
                                  (LPARAM)(LPVOID)&mdicreate );

    if( drawarea != (HWND)NULL ) {
        RECT    rect;
        int     w, h;
        _wpi_getclientrect( drawarea, &rect );
        w = _wpi_getwidthrect( rect );
        h = _wpi_getheightrect( rect );
        if( w != pad_x || h != pad_y ) {
            GetWindowRect( drawarea, &rect );
            w = _wpi_getwidthrect( rect ) + (pad_x - w);
            h = _wpi_getheightrect( rect ) + (pad_y - h);
            SetWindowPos( drawarea, HWND_TOP, 0, 0, w, h,
                          SWP_SIZE | SWP_NOZORDER | SWP_NOMOVE );
        }
    }

    if( ImgedIsDDE ) {
        sys_menu = GetSystemMenu( drawarea, FALSE );
        if( sys_menu != (HMENU)NULL ) {
            EnableMenuItem( sys_menu, SC_CLOSE, MF_GRAYED );
        }
    }

    BlowupImage( NULL, NULL );
    return( drawarea );

} /* WinNewDrawPad */
コード例 #2
0
  //
  // Check
  //
  // Check if allowed to build at the given location
  //
  Placement::Result Placement::Check(const Matrix &location, U32 flags)
  {
    ASSERT(IsSetup());

    S32 xZip, zZip, xFoot, zFoot;
    S32 xMax, zMax;
    S32 x, z;

    // Reset the array
    Reset();

    // Set default result
    result = PR_OK;

    // Get direction
    dir = WorldCtrl::GetCompassDirection(location.front);

    // Get cell in bottom left corner of footprint
    FindOrigin(location, dir, min);

    // Setup extents using current direction
    SetupMaximums(xMax, zMax, size.x, size.z, dir);

    // Save max point
    max.Set(min.x + xMax - 3, min.z + zMax - 3);

    // Step over footprint in terrain space
    // This loop must occur before the thump simulation, as cell.map has to be set up
    for (z = 0; z < zMax; z++)
    {
      for (x = 0; x < xMax; x++)
      {
        // Convert the terrain offset to footprint offsets
        CalculateOffsets(dir, size.x, size.z, x, z, xZip, zZip, xFoot, zFoot);

        // Get the placement cell at this position
        Cell &cell = GetCell(xFoot, zFoot);

        // Is this a zipping location (not on a lower fringe)
        if (x > 0 && z > 0)
        {
          // Save zipping value, adjusting for fringe
          cell.zip.Set(xZip - 1, zZip - 1);

          ASSERT(cell.zip.x >= 0);
          ASSERT(cell.zip.z >= 0);
        }

        // Get actual terrain cell position
        cell.map.Set(min.x + x - 1, min.z + z - 1);
      }
    }

    // If we are doing a thumping simulation, then thumped.valid is TRUE and the
    // real TerrainData::Cell will be substituted for the thumped version when
    // performing the placement check.
    // Otherwise, the real terrain cell will be used
    if (flags & CHECK_NOTHUMPTEST)
    {
      // Thumped is no longer valid
      thumped.Invalidate();
    }
    else
    {
      // Copy terrain into thumped buffer
      if (thumped.CopyTerrain())
      {
        // Calculate the best height to build at
        thumpHeight = thumped.CalcBestHeight();

        // Thump terrain into the thumped buffer
        ThumpTerrain(thumpHeight, 0.0F, THUMP_TOBUFFER);

        // Update slopes
        thumped.UpdateCells();
      }
    }

    // UnitObjType is used inside the loop
    UnitObjType *unitObjType = Promote::Type<UnitObjType>(&type->GetMapType());

    // Step over footprint in terrain space
    for (z = 0; z < zMax; z++)
    {
      for (x = 0; x < xMax; x++)
      {
        // Default cell result to ok
        Result r = PR_OK;

        // Convert the terrain offset to footprint offsets
        CalculateOffsets(dir, size.x, size.z, x, z, xZip, zZip, xFoot, zFoot);

        // Get the placement cell at this position
        Cell &cell = GetCell(xFoot, zFoot);

        // Is this position on the map
        if (WorldCtrl::CellOnMapNoEdge(cell.map.x, cell.map.z))
        {
          // Get the map cell at this location
          TerrainData::Cell &origCell = TerrainData::GetCell(cell.map.x, cell.map.z);

          // Get the thumped cell at this location
          TerrainData::Cell *thumpCell = thumped.IsValid() ? thumped.GetCell(x, z) : NULL;

          // Is there another footprint at this location
          if (!AvailableInstanceIndex(origCell.footIndex))
          {           
            r = (cell.onFoot) ? PR_FOOTON : PR_FOOTOFF;
          }
          else

          if (!TestThumpArea(cell.map, cell.map))
          {
            r = PR_THUMPING;
          }
          else

          // Is this position on the footprint
          if (cell.onFoot)
          {
            Point<S32> g;
          
            // Convert cell to grain
            WorldCtrl::CellToFirstGrain(cell.map.x, cell.map.z, g.x, g.z);

            // Get the type cell
            Type::Cell &typeCell = GetType().GetCell(cell.type.x, cell.type.z);

            // Probe lower grains
            if (typeCell.GetFlag(Type::CLAIMLO) && ClaimBlock(g, Claim::LAYER_LOWER, flags))
            {
              r = PR_CLAIM;
            }
            else

            // Probe upper grains
            if (typeCell.GetFlag(Type::CLAIMHI) && ClaimBlock(g, Claim::LAYER_UPPER, flags))
            {
              r = PR_CLAIM;
            }
            else

            // Can this object build on this location
            if (!PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), origCell))
            {
              r = PR_CANMOVETO;
            }
            else

            if (thumpCell && !PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), *thumpCell))
            {
              r = PR_CANMOVETO;
            }
            else

            // Is this cell shrouded
            if (!(flags & CHECK_IGNORESHROUD) && team && !Sight::Seen(cell.map.x, cell.map.z, team))
            {
              r = PR_SHROUDED;
            }
          }
          else
          {
            if (unitObjType)
            {
              if (unitObjType->CanBoard())
              {
                // The pathability check is extended to the fringe cells for objects that can have a board manager
                if (!PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), origCell))
                {
                  r = PR_CANMOVETO;
                }
                else

                if (thumpCell && !PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), *thumpCell))
                {
                  r = PR_CANMOVETO;
                }
              }
              else
              {
                // Not allowed to change the pathability state from passabable to impassable
                if (PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), origCell))
                {
                  if (thumpCell && !PathSearch::CanMoveToCell(type->GetMapType().GetTractionIndex(type->GetMapType().GetDefaultLayer()), *thumpCell))
                  {
                    r = PR_CANMOVETO;
                  }
                }
              }
            }
          }
        }
        else
        {
          r = PR_OFFMAP;
        }

        // Save result in cell
        cell.result = r;

        // Save significant results
        if (!Acceptable(r) || result == PR_OK)
        {
          result = r;
        }
      }
    }

    return (result);
  }