Click here to Skip to main content
15,883,705 members
Articles / Multimedia / GDI+

Tile Scaling for Maximum Area Coverage Based Upon Aspect Ratio of Tiles

Rate me:
Please Sign up or sign in to vote.
4.50/5 (5 votes)
21 Sep 2012CPOL6 min read 25.6K   368   12  
This is an algorithm for maximizing coverage of a rectangular area with scaling tile children.
<Window x:Class="ScalingTiles.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Shawn Pavel's Scaling Tiles" Height="350" Width="525">
    <!--Root-->
    <DockPanel>
        <!--
            Children Count Option
            Default is Four 
        -->
        <StackPanel Orientation="Horizontal" VerticalAlignment="Top" DockPanel.Dock="Top">
            <TextBlock Text="Number of Child Rectangles:" VerticalAlignment="Center"/>
            <TextBox x:Name="txtRectangles" Text="4" Margin="5,0" MinWidth="50"  />
        </StackPanel>
        <!--
            Aspect Ratio Option
            Default is 1.33
        -->
        <StackPanel Orientation="Horizontal" VerticalAlignment="Top" DockPanel.Dock="Top">
            <TextBlock Text="Aspect Ratio:" VerticalAlignment="Center"/>
            <TextBox x:Name="txtAspectRatio" Text="1.3333" Margin="5,0" MinWidth="50"/>
            <Button x:Name="btnUpdateRectangles" Content="Update" Click="btnUpdateRectangles_Click" />
        </StackPanel>
        <!--
            Status and Test Info Display
        -->
        <Grid DockPanel.Dock="Top">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <TextBlock x:Name="txtStatus" Text="No status yet" HorizontalAlignment="Center" />
            <TextBlock x:Name="txtMaximized" Text="" HorizontalAlignment="Center" Grid.Row="1"/>
        </Grid>

        <!--    
            WrapPanel to take care of position of the children
        -->
        <Border x:Name="brdRectangles" BorderBrush="Black" BorderThickness="1" Margin="5" CornerRadius="5">
            <WrapPanel x:Name="wpParentContainer" ItemHeight="50" ItemWidth="50" SizeChanged="wpParentContainer_SizeChanged_1" />
        </Border>
    </DockPanel>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions