Exemple #1
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            var gctx = UIGraphics.GetCurrentContext();

            if (needclear)
            {
                gctx.ClearRect(rect);
                gctx.SetStrokeColor(UIColor.Green.CGColor);
                gctx.SetLineWidth(2);
                gctx.StrokeRect(rect);
                needclear = false;
                return;
            }

            gctx.SetStrokeColor(UIColor.Green.CGColor);
            gctx.SetLineWidth(2);
            gctx.StrokeRect(rect);

            if (WBData != null)
            {
                var xRate = rect.Size.Width / 9600;
                var yRate = rect.Size.Height / 4800;

                UIColor.Clear.SetFill();
                UIColor.Black.SetStroke();

                int currentMin = GetMinute(CurrentSecond);
                if (previousMin != currentMin)
                {
                    previousMin    = currentMin;
                    currentEventTs = -1;
                }

                if (WBData.WBLines != null && WBData.WBLines.Count > 0)
                {
                    foreach (WBLine line in WBData.WBLines)
                    {
                        WBLineStyle linestyle = WBLineStyle.Create(line.Color);
                        linestyle.Color.SetStroke();
                        gctx.SetLineWidth(linestyle.Width);
                        gctx.MoveTo(line.X0 * xRate, line.Y0 * yRate);
                        gctx.AddLineToPoint(line.X1 * xRate, line.Y1 * yRate);
                        gctx.StrokePath();
                    }
                }

                if (WBData.WBEvents != null && WBData.WBEvents.Count > 0)
                {
                    Hashtable group = GroupWBEventsBySecond(WBData.WBEvents);

                    int endMilliseconds = CurrentSecond * 1000 % 60000;
                    int ix;
                    for (ix = currentEventTs; ix <= endMilliseconds; ix++)
                    {
                        List <WBEvent> wbevents = group[(uint)ix] as List <WBEvent>;

                        if (wbevents == null)
                        {
                            continue;
                        }

                        foreach (WBEvent wbevent in wbevents)
                        {
                            if (wbevent.X >= 0)
                            {
                                if (lastPoint == null)
                                {
                                    lastPoint = wbevent;
                                }
                                else
                                {
                                    currentLineStyle.Color.SetStroke();
                                    gctx.SetLineWidth(currentLineStyle.Width);

                                    gctx.MoveTo(lastPoint.X * xRate, lastPoint.Y * yRate);
                                    gctx.AddLineToPoint(wbevent.X * xRate, wbevent.Y * yRate);
                                    gctx.StrokePath();
                                    lastPoint = wbevent;
                                }
                            }
                            else
                            {
                                switch (wbevent.X)
                                {
                                case -100:     //Pen Up
                                    currentLineStyle.Color = UIColor.Black;
                                    lastPoint = null;
                                    break;

                                case -200:     //Clear event
                                    gctx.ClearRect(rect);
                                    lastPoint = null;
                                    break;

                                default:
                                    currentLineStyle = WBLineStyle.Create(wbevent.X);
                                    break;
                                }
                                lastPoint = null;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void DrawWhiteBoard(string group, int currenttime, bool forcerefresh, COLDataSource ds)
        {
            bool drawLines  = true;
            int  currentMin = Helper.GetMinute(currenttime * 1000);

            if (previousMin == currentMin && forcerefresh == false)
            {
                // Whiteboard data is based on minute, not second.
                // Only draw when in different minute, or user changed the slider manually.
                drawLines = false;
            }
            else
            {
                forcerefresh   = false;
                previousMin    = currentMin;
                currentEventTs = -1;
            }

            WBData wbdata = ds.GetWhiteBoardData(DataType.WB_1, currenttime);

            if (wbdata == null)
            {
                return;
            }

            if (drawLines && wbdata.WBLines != null && wbdata.WBLines.Count > 0)
            {
                //JavaScriptSerializer jss = new JavaScriptSerializer();
                //List<BoardLine> list = new List<BoardLine>();
                foreach (WBLine line in wbdata.WBLines)
                {
                    WBLineStyle linestyle = Helper.GetLineStyle(line.UColor);
                    Clients.Group(group).broadcastDrawWBLine(linestyle.Color, linestyle.Width, line.X0, line.Y0, line.X1, line.Y1);
                    //list.Add(new BoardLine { Color = linestyle.Color, Width = linestyle.Width, X0 = line.X0, Y0 = line.Y0, X1 = line.X1, Y1 = line.Y1 });
                }
                Clients.Group(group).broadcastDrawWBLineFinished();
                //Clients.All.broadcastDrawWBLine(jss.Serialize(list));
            }

            if (wbdata.WBEvents != null && wbdata.WBEvents.Count > 0)
            {
                Hashtable htgroup = GroupWBEventsBySecond(wbdata.WBEvents);

                int endMilliseconds = currenttime * 1000 % 60000;
                int ix;
                //JavaScriptSerializer jss = new JavaScriptSerializer();
                //List<BoardLine> list = new List<BoardLine>();
                for (ix = currentEventTs; ix <= endMilliseconds; ix++)
                {
                    List <WBEvent> wbevents = htgroup[(uint)ix] as List <WBEvent>;

                    if (wbevents == null)
                    {
                        continue;
                    }

                    foreach (WBEvent wbevent in wbevents)
                    {
                        if (wbevent.X >= 0)
                        {
                            if (lastPoint == null)
                            {
                                lastPoint = wbevent;
                            }
                            else
                            {
                                //currentLineStyle.Color.SetStroke();
                                //gctx.SetLineWidth(currentLineStyle.Width);
                                //gctx.MoveTo(lastPoint.X * xRate, lastPoint.Y * yRate);
                                //gctx.AddLineToPoint(wbevent.X * xRate, wbevent.Y * yRate);
                                //gctx.StrokePath();
                                Clients.Group(group).broadcastDrawWBEvent(currentLineStyle.Color, currentLineStyle.Width, lastPoint.X, lastPoint.Y, wbevent.X, wbevent.Y);
                                //list.Add(new BoardLine { Color = currentLineStyle.Color, Width = currentLineStyle.Width, X0 = lastPoint.X, Y0 = lastPoint.Y, X1 = wbevent.X, Y1 = wbevent.Y });
                                lastPoint = wbevent;
                            }
                        }
                        else
                        {
                            switch (wbevent.X)
                            {
                            case -100:     //Pen Up
                                currentLineStyle.Color = -8;
                                lastPoint = null;
                                break;

                            case -200:     //Clear event
                                           //gctx.ClearRect(rect);
                                Clients.Group(group).broadcastClearReat();
                                lastPoint = null;
                                break;

                            default:
                                currentLineStyle = Helper.GetLineStyle(wbevent.X);
                                break;
                            }
                            lastPoint = null;
                        }
                    }
                }
                Clients.Group(group).broadcastDrawWBEventFinished();
                // Clients.All.broadcastDrawWBEvent(jss.Serialize(list));
                currentEventTs = ix;
            }
        }