Exemplo n.º 1
0
 public void With_Should_Add_Strip_To_Current_Instance()
 {
     var strip = new Strip();
     _sut.With(() => strip);
     Assert.AreEqual(1, _sut._strips.Count);
     Assert.AreEqual(strip, _sut._strips[0]);
 }
Exemplo n.º 2
0
        private void PopulateEmail()
        {
            IFunStripItem stripItem = null;

            if (Identity.MockUser.IsActiveMail ?? false)
            {
                FunToolStripButton dd = new FunToolStripButton();
                dd.ProcessHandler = "CheckEmailHandler";
                dd.Name           = "checkEmail";
                dd.Image          = Resources.mail;
                dd.Text           = "查看邮件";
                dd.ToolTipText    = dd.Text;
                dd.Click         += new EventHandler(email_Click);
                stripItem         = dd;
            }
            else
            {
                FunToolStripButton dd = new FunToolStripButton();
                dd.Name           = "registerEmail";
                dd.ProcessHandler = "RegisterEmailHandler";
                dd.Image          = Resources.register_email;
                dd.Text           = "注册邮箱";
                dd.ToolTipText    = dd.Text;
                dd.Click         += new EventHandler(email_Click);
                stripItem         = dd;
            }
            Strip.SiteIn(stripItem);
        }
Exemplo n.º 3
0
        private void DataGridSelectie(object sender, System.Windows.Controls.SelectionChangedEventArgs e) //als er een strip geselecteerd is
        {
            if (StripDataGrid.SelectedItem != null)
            {
                selectedStrip = null;
                String   x     = StripDataGrid.SelectedItem.ToString();
                string[] words = x.Split(',');

                x = words.Where(x => x.Contains("ID =")).FirstOrDefault();
                x = x.Replace("ID = ", "").Replace("{", "").Replace("}", "").Trim();

                //haalt de gekozen strip op en geeft die weer mee
                selectedStrip = stripsFromDb.Where(s => s.ID.ToString().Equals(x)).FirstOrDefault();
                if (selectedStrip != null)
                {
                    stripBewerken_button.Visibility = Visibility.Visible;
                    bin_image.Visibility            = Visibility.Visible;
                }
                else
                {
                    stripBewerken_button.Visibility = Visibility.Collapsed;
                    bin_image.Visibility            = Visibility.Collapsed;
                }
            }
        }
Exemplo n.º 4
0
        public void CreateStrip_Empty_AuteurList_ThrowsArgumentException()
        {
            List <Auteur> lA = new List <Auteur>();
            Strip         s;

            Assert.ThrowsException <System.ArgumentException>(() => s = new Strip(1, "Test", 1, lA, new Reeks("Test"), new Uitgeverij("Test")));
        }
Exemplo n.º 5
0
        public void AddStrip_date(string striplabel, Color color, DateTime t1, DateTime t2)
        {
            Strip strip1 = new Strip(striplabel, t1, t2);

            strip1.Color = color;
            _xydiagram.AxisX.Strips.Add(strip1);
        }
Exemplo n.º 6
0
    // Creates a new honeycomb in the game, initialized with the given data.
    public void InitializeWithData(HoneycombData data)
    {
        // Destroy all old game objects.
        foreach (Strip strip in this.strips)
        {
            GameObject.Destroy(strip);
        }
        this.strips.Clear();

        // Compute the honeycomb properties.
        float stripWidth = Util.edgeLengthToStripWidth(this.edgeLength);

        // Compute the position of the first strip.
        // The center of each strip is the middle of the strip.
        // Each strip runs parallel to the y-axis. Their centers are in a line parallel to the x-axis.
        Vector3 nextPosition = this.transform.position;

        nextPosition.x -= (data.strips.Length - 1f) * 0.5f * stripWidth;
        // Create the strips.
        for (int i = 0; i < data.strips.Length; ++i)
        {
            StripData stripData = data.strips[i];
            Strip     strip     = Instantiate <Strip>(this.stripPrefab, nextPosition, Quaternion.identity);
            strip.stripNumber = i;
            this.strips.Add(strip);
            strip.InitializeWithData(stripData, this.edgeLength);
            // Set the next hex's position.
            nextPosition.x += stripWidth;
        }
    }
        public EditStrip(Strip strip) //meegegeven strip wordt bewerkt
        {
            this.Strip_id = strip.ID; //weten welke strip we bewerken

            InitializeComponent();
            TextBox_titel.Text = strip.StripTitel;
            TextBox_nr.Text    = strip.StripNr.ToString();

            //reeksbox
            var allSeries = generalManager.ReeksManager.GetAll().OrderBy(b => b.Naam);          //alle reeksen opvragen op alfabetisch volgorde

            TextBox_reeks.ItemsSource  = allSeries;                                             //reeksen meegeven aan de combobox
            TextBox_reeks.SelectedItem = allSeries.Where(s => s.ID == strip.Reeks.ID).Single(); //huidige strip reeks geselecteerd zetten

            //uitgeverijbox
            var allPublishers = generalManager.UitgeverijManager.GetAll().OrderBy(b => b.Naam);               //alle uitgeverijen opvragen op alfabetisch volgorde

            TextBox_uitgeverij.ItemsSource  = allPublishers;                                                  //uitgeverijen meegeven aan de combobox
            TextBox_uitgeverij.SelectedItem = allPublishers.Where(p => p.ID == strip.Uitgeverij.ID).Single(); //huidige strip uitgeverij geselecteerd zetten

            //auteurs
            var allAuteurs = ConvertToGUI.ListAuteurs(generalManager.AuteurManager.GetAll()).OrderByDescending(b => b.Ischecked).ThenBy(b => b.Naam); //huidige strip auteurs geselecteerd zetten, we sorteren eerst op al geselecteerd en dan op naam

            foreach (var aut in strip.Auteurs)                                                                                                        // alle huidige auteurs van strip selecteren
            {
                AuteurGUI selected = allAuteurs.Where(a => a.ID == aut.ID).Single();
                selected.Ischecked = true;
                _selectedAuteurs.Add(selected.ID, selected);
            }
            TextBox_auteurs.ItemsSource = allAuteurs;
        }
Exemplo n.º 8
0
        public void Challenge(Strip Strip, uint Degree, uint CacheHits)
        {
            if (Strip.Size < m_MinStripSize)
            {
                return;
            }

            if (!m_Cache)
            {
                //Cache is disabled, take the longest strip
                if (Strip.Size > m_Strip.Size)
                {
                    m_Strip = Strip;
                }
            }
            else
            {
                //Cache simulator enabled
                if (CacheHits > m_CacheHits)
                {
                    //Priority 1: Keep the strip with the best cache hit count
                    m_Strip     = Strip;
                    m_Degree    = Degree;
                    m_CacheHits = CacheHits;
                }
                else if ((CacheHits == m_CacheHits) && (((m_Strip.Size != 0) && (Degree < m_Degree)) || (Strip.Size > m_Strip.Size)))
                {
                    //Priority 2: Keep the strip with the loneliest start triangle
                    //Priority 3: Keep the longest strip
                    m_Strip  = Strip;
                    m_Degree = Degree;
                }
            }
        }
Exemplo n.º 9
0
        public Strip GetStrip(int id)
        {
            Strip result = new Strip();
            result.Gain = GetStripParameter("Gain", id);
            result.PanX = GetStripParameter("Pan_x", id);
            result.PanY = GetStripParameter("Pan_y", id);
            result.ColorX = GetStripParameter("Color_x", id);
            result.ColorY = GetStripParameter("Color_y", id);
            result.FxX = GetStripParameter("fx_x", id);
            result.FxY = GetStripParameter("fx_y", id);
            result.Audibility = GetStripParameter("Audibility", id);
            result.Comp = GetStripParameter("Comp", id);
            result.Gate = GetStripParameter("Gate", id);
            result.EqGain1 = GetStripParameter("EQGain1", id);
            result.EqGain2 = GetStripParameter("EQGain2", id);
            result.EqGain3 = GetStripParameter("EQGain3", id);

            result.Mono = Convert.ToBoolean(GetStripParameter("Mono", id));
            result.Mute = Convert.ToBoolean(GetStripParameter("Mute", id));
            result.Solo = Convert.ToBoolean(GetStripParameter("Solo", id));
            result.Mc = Convert.ToBoolean(GetStripParameter("MC", id));
            result.A1 = Convert.ToBoolean(GetStripParameter("A1", id));
            result.A2 = Convert.ToBoolean(GetStripParameter("A2", id));
            result.A3 = Convert.ToBoolean(GetStripParameter("A3", id));
            result.B1 = Convert.ToBoolean(GetStripParameter("B1", id));
            result.B2 = Convert.ToBoolean(GetStripParameter("B2", id));

            return result;
        }
Exemplo n.º 10
0
        private ImmutableArray <Strip> LoadStrips(BinaryReader reader, int count)
        {
            Strip[] strips = new Strip[count];
            for (int i = 0; i < count; ++i)
            {
                long offset = reader.BaseStream.Position;

                int        indexCount             = reader.ReadInt32();
                int        indexOffset            = reader.ReadInt32();
                int        vertexCount            = reader.ReadInt32();
                int        vertexOffset           = reader.ReadInt32();
                int        boneCount              = reader.ReadUInt16();
                StripFlags flags                  = (StripFlags)reader.ReadByte();
                int        boneStateChangesCount  = reader.ReadInt32();
                long       boneStateChangesOffset = offset + reader.ReadInt32();

                long save = reader.BaseStream.Position;
                reader.BaseStream.Position = boneStateChangesOffset;

                strips[i] = new Strip(indexCount, indexOffset, vertexCount, vertexOffset, boneCount, flags,
                                      LoadBoneStateChanges(reader, boneStateChangesCount));

                reader.BaseStream.Position = save;
            }
            return(new ImmutableArray <Strip>(strips));
        }
Exemplo n.º 11
0
        public Task Save()
        {
            var strappStrip = Strip.Select(i => i.Strapp).ToList();
            var strip       = new StartStrip(strappStrip);

            return(_client.SetStartStripAsync(strip));
        }
Exemplo n.º 12
0
        public string GetStrip(string parameter)
        {
            Strip  result = VoiceMeeterConnector.Instance.GetStrip(0);
            string output = JsonConvert.SerializeObject(result);

            return(output);
        }
Exemplo n.º 13
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            CheckStateChanges();

            switch (WhichButtonIsBeingHovered(e.Location))
            {
            case WhichButton.Left:
                if (ButtonClick != null)
                {
                    ButtonClick(this, e);
                }
                break;

            case WhichButton.Right:
                if (Strip != null)
                {
                    Strip.Show(Parent.PointToScreen(new Point(Left + Width - Strip.Width, Bottom)), ToolStripDropDownDirection.BelowRight);
                }
                if (DropDownClick != null)
                {
                    DropDownClick(this, e);
                }
                break;
            }

            base.OnMouseUp(e);
        }
Exemplo n.º 14
0
    Mesh FirstEverTest()
    {
        Strip s = new Strip(
            -1, 2, -1,
            -1, 2, 1,
            0, 2, -1,
            0, 2, 1,
            1, 2, -1,
            1, 2, 1,
            2, 2, -1,
            2, 2, -1);

        Fan f = new Fan(
            -1, 5, -1,
            -1, 5, 1,
            1, 5, 1,
            2, 5, 1,
            2, 5, -1);

        Vector3 v0a = new Vector3(-1, 0, -1);
        Vector3 v0b = new Vector3(-1, 0, 1);
        Vector3 v1a = new Vector3(0, 0, -1);
        Vector3 v1b = new Vector3(0, 0, 1);
        Vector3 v2a = new Vector3(1, 0, -1);
        Vector3 v2b = new Vector3(1, 0, 1);
        Vector3 v3a = new Vector3(2, 0, -1);
        Vector3 v3b = new Vector3(2, 0, -1);

        Strip s2 = new Strip(v0a, v0b, v1a, v1b, v2a, v2b, v3a, v3b);

        return(MeshXN.Combine(s, f, s2));
    }
Exemplo n.º 15
0
 public override void View()
 {
     Strip.Clean();
     PopulateAccountTools();
     PopulateEmail();
     PopulateFun();
 }
        public void Add(Strip strip)
        {
            StripDB stripDB         = ConvertToDatalayer.convertToStripDb(strip);
            var     sqlQueryBuilder = new SqlQueryBuilder <StripDB>(stripDB);

            ExecuteCommand(sqlQueryBuilder.GetInsertCommand());
            AddStripHasAuteur(stripDB);
        }
Exemplo n.º 17
0
        public EFMTracing(Strip strip)
        {
            InitializeComponent();
            DataContext = this;

            wfStrip = strip;
            UpdateInterface(null, null);
        }
Exemplo n.º 18
0
        private void postaviNastavke()
        {
            Strip st = (Strip)bindingStrip.Current;

            bindingNastavak.DataSource      = new BindingList <Nastavak>(st.Nastavci);
            dataGridViewNastavak.DataSource = bindingNastavak;
            dataGridViewNastavak.Refresh();
        }
Exemplo n.º 19
0
        public async Task <Strip> AddStrip(Strip strip)
        {
            var result = await context.Strip.AddAsync(strip);

            await context.SaveChangesAsync();

            return(result.Entity);
        }
Exemplo n.º 20
0
    // Use this for initialization
    void Start()
    {
        strip = GetComponent <Strip>();

        lastColors = new Color32[strip._numLeds];

        strip.SetAll(new Color32(0, 0, 33, 255));
    }
Exemplo n.º 21
0
 /// <summary>
 /// Adds a strip to the collection
 /// </summary>
 /// <param name="strip"></param>
 public void AddStrip(Strip strip)
 {
     strip.StripItems       = GetListofStripItems(DefaultStripColor);
     strip.ColorValues      = new ObservableCollection <string>(stripColors);
     strip.viewmodel        = this;
     strip.PropertyChanged += Strip_PropertyChanged;
     Strips.Add(strip);
 }
Exemplo n.º 22
0
    internal static bool StartEqual(string?s1, string?s2, bool ignoreCase = false)
    {
        var strip1 = new Strip(s1, !ignoreCase);
        var strip2 = new Strip(s2, !ignoreCase);

        return(strip1.GetLength() < strip2.GetLength() ? strip2.StartsWith(strip1)
                                                       : strip1.StartsWith(strip2));
    }
Exemplo n.º 23
0
        public void updateStrip_succesvol()
        {
            Strip og = generalManager.StripManager.GetById(9999);

            og.StripTitel = "inserted test value";
            generalManager.StripManager.Update(og);
            Assert.AreEqual(og.StripTitel, "inserted test value");
        }
Exemplo n.º 24
0
        public void DeleteStrip_succesvol()
        {
            int   begincount = generalManager.StripManager.GetAll().Count;
            Strip strip      = generalManager.StripManager.GetById(9999);

            generalManager.StripManager.Delete(strip);
            Assert.IsTrue(generalManager.StripManager.GetAll().Count == begincount - 1);
        }
Exemplo n.º 25
0
    public void OnTriggerEnter(Collider collider)
    {
        Strip strip = stripController.GameObjectToStrip(collider.gameObject);

        if (strip != null)
        {
            this.strip = strip;
        }
    }
Exemplo n.º 26
0
        public void CreateStrip_Empty_Title_ThrowsArgumentException()
        {
            List <Auteur> lA = new List <Auteur> {
                new Auteur("test")
            };
            Strip s;

            Assert.ThrowsException <System.ArgumentException>(() => s = new Strip(1, "", 1, lA, new Reeks("test"), new Uitgeverij("test")));
        }
Exemplo n.º 27
0
        public void Add_Auteur_ToStrip_Double_ThrowsArgumentException()
        {
            List <Auteur> lA = new List <Auteur> {
                new Auteur(1, "test")
            };
            Strip s = new Strip(1, "Test", 1, lA, new Reeks("test"), new Uitgeverij("test"));

            Assert.ThrowsException <System.ArgumentException>(() => s.addAuteur(new Auteur(1, "test")));
        }
Exemplo n.º 28
0
        public RangeMessage(Strip strip, byte index, Color color)
        {
            var position = index << 2;

            Position = (byte)(position | (int)strip);
            Red      = color.R;
            Green    = color.G;
            Blue     = color.B;
        }
Exemplo n.º 29
0
        public RangeMessage(Strip strip, byte index, byte red, byte green, byte blue)
        {
            var position = index << 2;

            Position = (byte)(position | (int)strip);
            Red      = red;
            Green    = green;
            Blue     = blue;
        }
Exemplo n.º 30
0
        private void Save()
        {
            bindingStrip.EndEdit();
            Strip s = (Strip)bindingStrip.Current;

            _mainController.UpdateStrip(s);
            MessageBox.Show("Podaci pohranjeni u bazu");
            UpdateDisplay(false);
        }
        public MonitorTracing(Strip strip)
        {
            InitializeComponent();
            DataContext = this;

            Strip = strip;

            InitInterface();
            UpdateInterface(null, null);
        }
Exemplo n.º 32
0
        static void ParsePomcomic()
        {
            var comic = new Comic()
            {
                Name = "Piece Of Me",
                Source = "http://www.pomcomic.com/"
            };
            var issue = new Issue()
            {
                Name = "Web Comic",
                Cover = "http://www.pomcomic.com/comics/292-bus-stop.jpg"
            };
            comic.Issues.Add(issue);

            string init = "http://www.pomcomic.com/comic-1";
            using (var client = new WebClient())
            {
                string next = init;
                while (next != null)
                {
                    Console.WriteLine("Downloading {0}...", next);
                    string data = client.DownloadString(next);
                    var doc = new HtmlDocument();
                    doc.LoadHtml(data);

                    var strip = new Strip();

                    strip.Title = doc.DocumentNode.SelectSingleNode("//h1[@id=\"comic-name\"]")?.InnerText;
                    strip.Url = "http://www.pomcomic.com/" + doc.DocumentNode.SelectSingleNode("//div[@class=\"comic\"]/a/img")?.GetAttributeValue("src", null);

                    if (strip.Title != null)
                    {
                        strip.Title = HttpUtility.HtmlDecode(strip.Title.Trim());
                    }

                    issue.Strips.Add(strip);

                    var nextref = doc.DocumentNode.SelectSingleNode("//a[@id=\"next\"]")?.GetAttributeValue("href", null);

                    next = null;
                    if (nextref != null)
                        next = "http://www.pomcomic.com/" + nextref;
                }
            }

            using (var fs = File.Open("pomcomic.xml", FileMode.Create, FileAccess.Write))
            {
                comic.Save(fs);
            }
        }
Exemplo n.º 33
0
Arquivo: Vtx.cs Projeto: Frassle/Ibasa
        private ImmutableArray<Strip> LoadStrips(BinaryReader reader, int count)
        {
            Strip[] strips = new Strip[count];
            for (int i = 0; i < count; ++i)
            {
                long offset = reader.BaseStream.Position;

                int indexCount = reader.ReadInt32();
                int indexOffset = reader.ReadInt32();
                int vertexCount = reader.ReadInt32();
                int vertexOffset = reader.ReadInt32();
                int boneCount = reader.ReadUInt16();
                StripFlags flags = (StripFlags)reader.ReadByte();
                int boneStateChangesCount = reader.ReadInt32();
                long boneStateChangesOffset = offset + reader.ReadInt32();

                long save = reader.BaseStream.Position;
                reader.BaseStream.Position = boneStateChangesOffset;

                strips[i] = new Strip(indexCount, indexOffset, vertexCount, vertexOffset, boneCount, flags,
                    LoadBoneStateChanges(reader, boneStateChangesCount));

                reader.BaseStream.Position = save;
            }
            return new ImmutableArray<Strip>(strips);
        }
Exemplo n.º 34
0
 //allocate space for all absolutely sized strips. Set the size of the rest of the strips to 0.
 private void InitializeStrips(Strip[] strips, IList styles) {
     Strip strip;
     for (int i = 0; i < strips.Length; i++) {
         TableLayoutStyle style = i < styles.Count ? (TableLayoutStyle)styles[i] : null;
         strip = strips[i];
         if (style != null && style.SizeType == SizeType.Absolute) {  
             strip.MinSize = (int)Math.Round((double)((TableLayoutStyle)styles[i]).Size); 
             strip.MaxSize = strip.MinSize;
         }
         else {
             strip.MinSize = 0;
             strip.MaxSize = 0;
         }
         strip.IsStart = false;
         strips[i] = strip;
     }
 }
Exemplo n.º 35
0
 public void Setup()
 {
     _sut = Strip.Create("MyStrip");
 }
Exemplo n.º 36
0
 internal int SumStrips(Strip[] strips, int start, int span) {
     int size = 0;
     for(int i = start; i < Math.Min(start + span, strips.Length); i++) {
         Strip strip = strips[i];
         size += strip.MinSize;
     }
     return size;
 }
Exemplo n.º 37
0
 //set the minimum size for each element
 private void DistributeSize(IList styles, Strip[] strips, int start, int stop, int min, int max, int cellBorderWidth) {
     Debug.Assert(min <= max, "Error computing min/max strip size. (Min expected to be less than max).");
     
     xDistributeSize(styles, strips, start, stop, min, MinSizeProxy.GetInstance, cellBorderWidth);
     xDistributeSize(styles, strips, start, stop, max, MaxSizeProxy.GetInstance, cellBorderWidth);
 }
Exemplo n.º 38
0
        private void xDistributeSize(IList styles, Strip[] strips, int start, int stop, int desiredLength, SizeProxy sizeProxy, int cellBorderWidth) {

            int currentLength = 0;   //total length allocated so far
            int numUninitializedStrips = 0;  //number of strips whose Size is 0 and is not absolutely positioned
            
            //subtract the space for cell borders. Notice if a control spans two columns its 
            //proposed size is 10 and the border width is 3, we actually only need to distribute
            //7 pixels among the two cells it spans    
            desiredLength -= cellBorderWidth * (stop - start - 1);
            desiredLength = Math.Max(0, desiredLength);
            
            for(int i = start; i < stop; i++) {
                sizeProxy.Strip = strips[i];
                if (!IsAbsolutelySized(i, styles) && sizeProxy.Size == 0) {
                    //the strip is not absolutely sized and it hasn't been initialized
                    numUninitializedStrips++;
                }
                currentLength += sizeProxy.Size;   
            }
            int missingLength = desiredLength - currentLength;
   
            if (missingLength <= 0) {
                //no extra space left. Simply return.
                return;
            }

            if (numUninitializedStrips == 0) {
                //look for any strip whose style is percent. If there is one, dump all space in it
                int lastPercent;
                for (lastPercent = stop - 1; lastPercent >= start; lastPercent--) {
                    if (lastPercent < styles.Count && ((TableLayoutStyle) styles[lastPercent]).SizeType == SizeType.Percent) {
                        break;
                    }
                }
                //we have found one strip whose style is percent. 
                //make sure that the for loop below only looks at this strip
                if (lastPercent != start - 1) {
                    stop = lastPercent + 1; 
                }
                //every strip has absolute width or all of them have already been allocated space
                //walk backwards
                for (int i = stop - 1; i >= start; i--) {
                    if (!IsAbsolutelySized(i, styles)) {
                        //dump the extra space to this strip
                        sizeProxy.Strip = strips[i];      
                        
                        if (!(i == strips.Length - 1)               //this is not the last strip
                            && !strips[i+1].IsStart                 //and there is no control starting from the strip next to it
                            && !IsAbsolutelySized(i+1, styles)) {  // and the strip next to it is not absolutely sized
                            //try to "borrow" space from the strip next to it
                            sizeProxy.Strip = strips[i+1];
                            int offset = Math.Min(sizeProxy.Size, missingLength);
                            sizeProxy.Size -= offset;
                            strips[i+1] = sizeProxy.Strip;

                            sizeProxy.Strip = strips[i];    
                        }
                        //put whatever left into this strip
                        sizeProxy.Size += missingLength;
                        strips[i] = sizeProxy.Strip;
                        break;
                    }
                }
                //if we fall through here, everything is absolutely positioned. discard the extra space
            }
            //there are some uninitialized strips
            else {
                //average space to be distributed
                int average = missingLength / numUninitializedStrips;
                //total number of uninitialized strips encountered so far
                int uninitializedStripIndex = 0;
                for (int i = start; i < stop; i++) {
                    sizeProxy.Strip = strips[i];
                    //this is an uninitialized strip
                    if (!IsAbsolutelySized(i, styles) && sizeProxy.Size == 0) {
                        uninitializedStripIndex++;
                        if (uninitializedStripIndex == numUninitializedStrips) {
                            //we are at the last strip. place round off error here
                            average = missingLength - average * (numUninitializedStrips - 1);
                        }
                        sizeProxy.Size += average;
                        strips[i] = sizeProxy.Strip;
                    }
                }

#if DEBUG
                // not using assert here to prevent concatination in debug builds.
                if (uninitializedStripIndex != numUninitializedStrips) {      
                    Debug.Fail("should always get the same number of strips with size 0. " + "expecting: " + numUninitializedStrips + " actual: " + uninitializedStripIndex);
                }
#endif

            } 
        }
Exemplo n.º 39
0
        ///<devdoc>
        /// Now that we've allocated minimum and maximum sizes to everyone (the strips), distribute the extra space
        /// as according to the Row/Column styles.
        ///</devdoc>
        private int DistributeStyles(int cellBorderWidth, IList styles, Strip[] strips, int maxSize, bool dontHonorConstraint) {
            int usedSpace = 0;
            float desiredScaleSpace = 0;
            //first, allocate the minimum space required for each element

            float totalPercent = 0;
            float totalPercentAllocatedSpace = 0;
            float totalAbsoluteAndAutoSizeAllocatedSpace = 0;
            bool hasAutoSizeColumn = false;

            // Step 1: iterate through the rows or columns, 
            //  - calculate the amount of space allocated
            //     - for autosize and fixed size columns
            //     - for percent size columns
            //  - sum up the total "%"s being used 
            //     - eg totalPercent = 22 + 22 + 22 = 66%. each column should take up 1/3 of the remaining space.
        	for(int i = 0; i < strips.Length; i++) {
                Strip strip = strips[i];
                if(i < styles.Count) {
                    TableLayoutStyle style = (TableLayoutStyle) styles[i];
                    switch(style.SizeType) {
                        case SizeType.Absolute:
                            totalAbsoluteAndAutoSizeAllocatedSpace += strip.MinSize;
                            // We gaurantee a strip will be exactly abs pixels
                            Debug.Assert((strip.MinSize == style.Size), "absolutely sized strip's size should be set before we call ApplyStyles");
                            break;
                        case SizeType.Percent:
                            totalPercent += style.Size;
                            totalPercentAllocatedSpace += strip.MinSize;
                            break;
                        default:
                            totalAbsoluteAndAutoSizeAllocatedSpace += strip.MinSize;
                            hasAutoSizeColumn = true;
                            Debug.Assert(style.SizeType == SizeType.AutoSize, "Unsupported SizeType.");
                            break;
                    }
                }
                else {
                     hasAutoSizeColumn = true;
                }
                strip.MaxSize += cellBorderWidth;
                strip.MinSize += cellBorderWidth;  //add the padding for the cell border

                strips[i] = strip;
                usedSpace += strip.MinSize;
            }

            int remainingSpace = maxSize - usedSpace;
            

            
            // Step 2: (ONLY if we have % style column)
            //   - distribute unused space for absolute/autosize columns to percentage columns
            //          - determine the extra space that is not being used for autosize and fixed columns
            //          - divide space amongst % style columns using ratio of %/total % * total extra space 
            if (totalPercent > 0) {
                
               
                if (!dontHonorConstraint) {
                    
                    if (totalPercentAllocatedSpace > maxSize - totalAbsoluteAndAutoSizeAllocatedSpace) {
                        // fixup for the case where we've actually allocated more space than we have.
                        // this can happen when the sum of the widths/heights of the controls are larger than the size of the 
                        // table (aka maxSize)

                        //Don't want negative size...
                        totalPercentAllocatedSpace = Math.Max(0, maxSize - totalAbsoluteAndAutoSizeAllocatedSpace);
                    }

                    if (remainingSpace > 0) {
                        // If there's space left over, then give it to the percentage columns/rows
                        totalPercentAllocatedSpace += remainingSpace;
                    }
                    
                    else if (remainingSpace < 0) {
                        // If there's not enough space, then remove space from the percentage columns.
                        // We do this by recalculating the space available.
                        totalPercentAllocatedSpace = maxSize - totalAbsoluteAndAutoSizeAllocatedSpace - (strips.Length * cellBorderWidth);
                        remainingSpace = 0;
                    }
                    
                    
                    // in this case the strips fill up the remaining space.
                    for (int i = 0; i < strips.Length; i++) {
                        Strip strip = strips[i];
                        SizeType sizeType = i < styles.Count ? ((TableLayoutStyle)styles[i]).SizeType : SizeType.AutoSize;
                        if (sizeType == SizeType.Percent) {
                            TableLayoutStyle style = (TableLayoutStyle)styles[i];

                            // cast to int / (take the floor) so we know we dont accidentally go over our limit.
                            // the rest will be distributed later.
                            int stripSize = (int)(style.Size * totalPercentAllocatedSpace / totalPercent);
                            usedSpace -= strip.MinSize; // back out the size we thought we were allocating before.
                            usedSpace += stripSize + cellBorderWidth;  // add in the new size we think we're going to use.
                            strip.MinSize = stripSize + cellBorderWidth;
                            strips[i] = strip;
                        }

                    }
                }
                else {
                    // the size of the item defines the size allocated to the percentage style columns.
                    // this supports [Ok][Cancel] in a 50% 50% column arrangement.  When one grows it pushes the whole table
                    // larger.
                    int maxPercentWidth = 0;
                    for (int i = 0; i < strips.Length; i++) {
                        Strip strip = strips[i];  
                        SizeType sizeType = i < styles.Count ? ((TableLayoutStyle)styles[i]).SizeType : SizeType.AutoSize;
                   
                   
                        // Performing the inverse calculation for GetPreferredSize:
                        //
                        //               stylePercent * totalWidth                      colWidth * totalPercent
                        //  colWidth =   -------------------------  --->   totalWidth = -----------------------
                        //                     totalPercent                                   stylePercent
                        //
                        // we'll take the max of the total widths as the one for our preferred size.
                        if (sizeType == SizeType.Percent) {
                            TableLayoutStyle style = (TableLayoutStyle)styles[i];

                            int totalWidth = (int)Math.Round(((strip.MinSize * totalPercent)/ style.Size));
                            maxPercentWidth = Math.Max(maxPercentWidth, totalWidth);
                            usedSpace -= strip.MinSize;
                        }
                    }
                    usedSpace += maxPercentWidth;
                }
                

            }
            remainingSpace = maxSize - usedSpace;



            // Step 3: add remaining space to autosize columns
            //  - usually we only do this if we're not in preferred size (remaingSpace would be < 0)
            //  - and there are no % style columns
            
            if(/*!dontHonorConstraint && */hasAutoSizeColumn && remainingSpace > 0) {
                float scaleAdjustment = 1.0f;
                if(remainingSpace < desiredScaleSpace) {
                    scaleAdjustment = remainingSpace / desiredScaleSpace;
                }
                remainingSpace -= (int) Math.Ceiling(desiredScaleSpace);
                
                for(int i = 0; i < strips.Length; i++) {                    
                    Strip strip = strips[i];
                    SizeType sizeType = i < styles.Count ? ((TableLayoutStyle)styles[i]).SizeType : SizeType.AutoSize;
                    if (sizeType == SizeType.AutoSize) {
                        int delta = Math.Min(strip.MaxSize - strip.MinSize, remainingSpace);
                        if(delta > 0) {
                            usedSpace += delta;
                            remainingSpace -= delta;
                            strip.MinSize += delta;
                            strips[i] = strip;
                        }
                    }
                }
            }
            Debug.Assert((dontHonorConstraint || (usedSpace == SumStrips(strips, 0, strips.Length))), "Error computing usedSpace.");
            return usedSpace;
        }
Exemplo n.º 40
0
        private static void ParseTrash()
        {
            var comic = new Comic()
            {
                Name = "Trash",
                Source = "http://www.mangareader.net/trash/"
            };

            using (var client = new WebClient())
            {
                for (int issueID = 1; issueID <= 26; issueID++)
                {
                    Issue issue = new Issue()
                    {
                        Name = "Trash #" + issueID,
                    };

                    int stripCount = 0;

                    // Gather issue information
                    {
                        string data = client.DownloadString(string.Format("http://www.mangareader.net/trash/{0}/", issueID));
                        var doc = new HtmlDocument();
                        doc.LoadHtml(data);

                        var node = doc.DocumentNode.SelectSingleNode("//div[@id=\"selectpage\"]");
                        issue.Cover = doc.DocumentNode.SelectSingleNode("//img[@id=\"img\"]")?.GetAttributeValue("src", null);

                        var text = Regex.Match(node.InnerText, "of (?<num>\\d+)$");
                        stripCount = int.Parse(text.Groups["num"].Value);
                    }

                    for (int stripID = 1; stripID <= stripCount; stripID++)
                    {
                        string url = string.Format("http://www.mangareader.net/trash/{0}/{1}", issueID, stripID);
                        Console.WriteLine(url);
                        string data = client.DownloadString(url);
                        var doc = new HtmlDocument();
                        doc.LoadHtml(data);

                        var strip = new Strip();
                        strip.Title = "Trash #" + issueID + " Page #" + stripID;

                        strip.Url = doc.DocumentNode.SelectSingleNode("//img[@id=\"img\"]")?.GetAttributeValue("src", null);
                        issue.Strips.Add(strip);
                    }

                    comic.Issues.Add(issue);
                }
            }
            using (var fs = File.Open("trash.xml", FileMode.Create, FileAccess.Write))
            {
                comic.Save(fs);
            }
        }