Exemplo n.º 1
0
        public DrawBlock(List <DrawBlock> layer, DrawBlock top)
        {
            Layer = layer;
            Block = top.Block;
            Rect  = top.Rect;

            Above     = top;
            top.Below = this;
        }
Exemplo n.º 2
0
        public void Remove()
        {
            Layer.Remove(this);

            if (Below != null)
            {
                Below.Remove();
            }

            Above.Below = null;
            Above       = null;
        }
Exemplo n.º 3
0
        private void BlockRow_Paint(object sender, PaintEventArgs e)
        {
            if (DisplayBuffer == null)
            {
                DisplayBuffer = new Bitmap(Width, Height);
            }

            if (!Redraw)
            {
                e.Graphics.DrawImage(DisplayBuffer, 0, 0);
                return;
            }
            Redraw = false;

            // background
            Graphics buffer = Graphics.FromImage(DisplayBuffer);

            buffer.Clear(Color.White);
            //buffer.SmoothingMode = SmoothingMode.AntiAlias;


            // draw tick lines
            foreach (int mark in View.ScheduleSlider.SmallMarks)
            {
                buffer.DrawLine(SmallPen, mark, 0, mark, Height);
            }

            foreach (int mark in View.ScheduleSlider.BigMarks)
            {
                buffer.DrawLine(BigPen, mark, 0, mark, Height);
            }

            //buffer.DrawLine(RefPen, View.ScheduleSlider.RefMark, 0, View.ScheduleSlider.RefMark, Height);

            // setup vars
            Rectangle tempRect = new Rectangle();

            tempRect.Y      = 0;
            tempRect.Height = Height;

            StartTime     = View.GetStartTime().ToUniversalTime();
            EndTime       = View.GetEndTime().ToUniversalTime();
            TicksperPixel = View.ScheduleSlider.TicksperPixel;


            // draw higher plans
            BlockAreas.Clear();
            GoalAreas.Clear();


            Uplinks = View.Core.Trust.GetUnconfirmedUplinkIDs(UserID, View.ProjectID);

            // upnodes just used for scope calc now
            List <PlanNode> upnodes  = new List <PlanNode>();
            PlanNode        nextNode = Node;

            while (nextNode.Parent.GetType() == typeof(PlanNode))
            {
                nextNode = (PlanNode)nextNode.Parent;
                upnodes.Add(nextNode);
            }

            upnodes.Reverse();


            // draw plans for each node above in the current block layered on top of one another
            // if we want to change to loop doesnt inherit other loop member's plans, replace foreach uplinks with upnodes
            // not obvious behaviour

            int level = 0;

            //foreach (ulong uplink in Uplinks)
            foreach (PlanNode node in upnodes)
            {
                ulong uplink = node.Link.UserID;

                foreach (PlanBlock block in GetBlocks(uplink))
                {
                    // scope -1 everyone or current level 0 highest + scope is >= than current node
                    if ((block.Scope == -1 || (level + block.Scope >= upnodes.Count)) &&
                        BlockinRange(block, ref tempRect))
                    {
                        buffer.FillRectangle(GetMask(uplink, true), tempRect);
                        BlockAreas.Add(new BlockArea(tempRect, block, level, false));
                    }
                }

                level++;
            }

            // draw local plans
            List <List <DrawBlock> > layers = new List <List <DrawBlock> >();

            // arrange visible blocks
            foreach (PlanBlock block in GetBlocks(UserID))
            {
                if (BlockinRange(block, ref tempRect))
                {
                    AddDrawBlock(new DrawBlock(block, tempRect), layers);
                }
            }

            List <KeyValuePair <string, PointF> > StringList = new List <KeyValuePair <string, PointF> >();

            // draw blocks
            if (layers.Count > 0)
            {
                int y     = 2;
                int yStep = (Height - 2) / layers.Count;

                foreach (List <DrawBlock> list in layers)
                {
                    foreach (DrawBlock item in list)
                    {
                        if (item.Above == null)
                        {
                            item.Rect.Y      = y;
                            item.Rect.Height = yStep - 1;

                            DrawBlock down = item.Below;
                            while (down != null)
                            {
                                item.Rect.Height += yStep;
                                down              = down.Below;
                            }

                            BlockAreas.Add(new BlockArea(item.Rect, item.Block, level, true));

                            Rectangle fill = item.Rect;
                            fill.Height = Height - y;
                            buffer.FillRectangle(GetMask(UserID, true), fill);

                            if (item.Block == View.SelectedBlock)
                            {
                                buffer.DrawRectangle(SelectPen, item.Rect);
                            }

                            SizeF size = buffer.MeasureString(item.Block.Title, Tahoma);

                            if (size.Width < item.Rect.Width - 2 && size.Height < item.Rect.Height - 2)
                            {
                                StringList.Add(new KeyValuePair <string, PointF>(item.Block.Title,
                                                                                 new PointF(item.Rect.X + (item.Rect.Width - size.Width) / 2, item.Rect.Y + (item.Rect.Height - size.Height) / 2)));
                            }
                        }
                    }

                    y += yStep;
                }
            }

            // scan higher's goal lists for assigned goals to this id
            if (View.SelectedGoalID != 0)
            {
                // cache what to draw, look at how goals control get progress status
                // color goal bars solid red / blue / gray
                // cache strings, draw after goals

                //Uplinks.Add(Node.Link.DhtID); // add self to scan
                upnodes.Add(Node);

                foreach (PlanNode node in upnodes)
                {
                    ulong  userID = node.Link.UserID;
                    OpPlan upPlan = View.Plans.GetPlan(userID, true);

                    if (upPlan != null)
                    {
                        if (upPlan.GoalMap.ContainsKey(View.SelectedGoalID))
                        {
                            foreach (PlanGoal goal in upPlan.GoalMap[View.SelectedGoalID])
                            {
                                if (goal.Project == View.ProjectID && goal.Person == UserID)
                                {
                                    if (StartTime < goal.End && goal.End < EndTime)
                                    {
                                        int x = (int)((goal.End.Ticks - StartTime.Ticks) / TicksperPixel);

                                        int completed = 0, total = 0;
                                        View.Plans.GetEstimate(goal, ref completed, ref total);

                                        // draw divider line with little right triangles in top / bottom
                                        buffer.FillRectangle(WhiteBrush, new Rectangle(x - 4, 2, 2, Height - 4));

                                        if (total > 0)
                                        {
                                            int progress = completed * (Height - 4) / total;
                                            buffer.FillRectangle(GreenBrush, new Rectangle(x - 4, 2 + (Height - 4) - progress, 2, progress));
                                        }

                                        buffer.FillPolygon(GetMask(UserID, false), new Point[] {
                                            new Point(x - 6, 2),
                                            new Point(x, 2),
                                            new Point(x, Height - 2),
                                            new Point(x - 6, Height - 2),
                                            new Point(x - 2, Height - 2 - 5),
                                            new Point(x - 2, 2 + 5)
                                        });

                                        GoalAreas.Add(new BlockArea(new Rectangle(x - 6, 2, 6, Height - 4), goal));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // draw strings
            foreach (KeyValuePair <string, PointF> pair in StringList)
            {
                buffer.DrawString(pair.Key, Tahoma, blackBrush, pair.Value);
            }

            // draw selection
            if (Node.Selected)
            {
                if (View.PlanStructure.Focused)
                {
                    buffer.FillRectangle(Highlight, 0, 0, Width, 2);
                    buffer.FillRectangle(Highlight, 0, Height - 2, Width, 2);
                }

                else
                {
                    buffer.DrawLine(BlackPen, 1, 0, Width - 1, 0);
                    buffer.DrawLine(BlackPen, 0, Height - 1, Width, Height - 1);
                }
            }

            // Copy buffer to display
            e.Graphics.DrawImage(DisplayBuffer, 0, 0);
        }
Exemplo n.º 4
0
        private void AddDrawBlock(DrawBlock draw, List <List <DrawBlock> > layers)
        {
            bool conflict = false;

            List <DrawBlock> delete = new List <DrawBlock>();

            foreach (List <DrawBlock> layer in layers)
            {
                conflict = false;
                delete.Clear();

                foreach (DrawBlock item in layer)
                {
                    if (item.Rect.IntersectsWith(draw.Rect))
                    {
                        if (draw.Above != null) // signals block was already drawn, but this layer is full
                        {
                            return;
                        }

                        if (item.Above == null) // this is the main block for an item, cant draw here, create new layer
                        {
                            conflict = true;
                            break;
                        }
                        else // this item isnt the main so it can be deleted if there is a conflict
                        {
                            delete.Add(item);
                        }
                    }
                }

                if (!conflict)
                {
                    foreach (DrawBlock item in delete)
                    {
                        item.Remove();
                    }

                    if (draw.Above != null)
                    {
                        draw.Above.Below = draw;
                    }

                    draw.Layer = layer;
                    layer.Add(draw);

                    // draw same rect another layer down if there is room
                    DrawBlock next = new DrawBlock(draw.Block, draw.Rect);
                    next.Above = draw;
                    draw       = next;
                }
            }

            if (draw.Above != null) // signals block already is drawn in a layer
            {
                return;
            }

            // new layer
            List <DrawBlock> newLayer = new List <DrawBlock>();

            draw.Layer = newLayer;
            newLayer.Add(draw);

            // duplicate previous layer's blocks to this list
            if (layers.Count > 0)
            {
                foreach (DrawBlock topBlock in layers[layers.Count - 1])
                {
                    if (!topBlock.Rect.IntersectsWith(draw.Rect))
                    {
                        newLayer.Add(new DrawBlock(newLayer, topBlock));
                    }
                }
            }

            layers.Add(newLayer);
        }
Exemplo n.º 5
0
        public void Remove()
        {
            Layer.Remove(this);

            if (Below != null)
                Below.Remove();

            Above.Below = null;
            Above = null;
        }
Exemplo n.º 6
0
        public DrawBlock(List<DrawBlock> layer, DrawBlock top)
        {
            Layer = layer;
            Block = top.Block;
            Rect = top.Rect;

            Above = top;
            top.Below = this;
        }
Exemplo n.º 7
0
        private void AddDrawBlock(DrawBlock draw, List<List<DrawBlock>> layers)
        {
            bool conflict = false;

            List<DrawBlock> delete = new List<DrawBlock>();

            foreach (List<DrawBlock> layer in layers)
            {
                conflict = false;
                delete.Clear();

                foreach (DrawBlock item in layer)
                    if (item.Rect.IntersectsWith(draw.Rect))
                    {
                        if (draw.Above != null) // signals block was already drawn, but this layer is full
                            return;

                        if (item.Above == null) // this is the main block for an item, cant draw here, create new layer
                        {
                            conflict = true;
                            break;
                        }
                        else // this item isnt the main so it can be deleted if there is a conflict
                            delete.Add(item);

                    }

                if (!conflict)
                {
                    foreach (DrawBlock item in delete)
                        item.Remove();

                    if (draw.Above != null)
                        draw.Above.Below = draw;

                    draw.Layer = layer;
                    layer.Add(draw);

                    // draw same rect another layer down if there is room
                    DrawBlock next = new DrawBlock(draw.Block, draw.Rect);
                    next.Above = draw;
                    draw = next;
                }
            }

            if (draw.Above != null) // signals block already is drawn in a layer
                return;

            // new layer
            List<DrawBlock> newLayer = new List<DrawBlock>();
            draw.Layer = newLayer;
            newLayer.Add(draw);

            // duplicate previous layer's blocks to this list
            if (layers.Count > 0)
            {
                foreach (DrawBlock topBlock in layers[layers.Count - 1])
                    if (!topBlock.Rect.IntersectsWith(draw.Rect))
                        newLayer.Add(new DrawBlock(newLayer, topBlock));
            }

            layers.Add(newLayer);
        }