Ejemplo n.º 1
0
 /// <summary>
 /// 重绘前景方法
 /// </summary>
 /// <param name="paint">绘图对象</param>
 /// <param name="clipRect">裁剪区域</param>
 public override void OnPaintBackground(CPaint paint, RECT clipRect)
 {
     base.OnPaintBackground(paint, clipRect);
     lock (m_barrages)
     {
         int barragesSize = m_barrages.Count;
         for (int i = 0; i < barragesSize; i++)
         {
             Barrage brg  = m_barrages[i];
             FONT    font = brg.Font;
             RECT    rect = brg.Rect;
             String  str  = brg.Text;
             SIZE    size = paint.TextSize(str, font);
             rect.right  = rect.left + size.cx;
             rect.bottom = rect.top + size.cy;
             brg.Rect    = rect;
             long color = brg.Color;
             int  mode  = brg.Mode;
             if (mode == 1)
             {
                 int a = 0, r = 0, g = 0, b = 0;
                 COLOR.ToARGB(null, color, ref a, ref r, ref g, ref b);
                 a     = a * brg.Tick / 400;
                 color = COLOR.ARGB(a, r, g, b);
             }
             paint.DrawText(str, color, font, rect);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 启动弹幕
        /// </summary>
        /// <param name="barrage">弹幕参数</param>
        public void AddBarrage(Barrage barrage)
        {
            barrage.Color = m_sysColors[m_tick % 6];
            int width = Width, height = Height;

            if (width < 100)
            {
                width = 100;
            }
            if (height < 100)
            {
                height = 100;
            }
            int mode = barrage.Mode;

            if (mode == 0)
            {
                barrage.Rect = new RECT(width, m_rd.Next(0, height), width, 0);
            }
            lock (m_barrages)
            {
                m_barrages.Add(barrage);
            }
            m_tick++;
            Invalidate();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 秒表方法
 /// </summary>
 /// <param name="timerID">秒表ID</param>
 public override void OnTimer(int timerID)
 {
     base.OnTimer(timerID);
     if (m_timerID == timerID)
     {
         bool paint = false;
         lock (m_barrages)
         {
             int barragesSize = m_barrages.Count;
             if (barragesSize > 0)
             {
                 int width = Width, height = Height;
                 for (int i = 0; i < barragesSize; i++)
                 {
                     Barrage brg  = m_barrages[i];
                     int     mode = brg.Mode;
                     if (mode == 0 || mode == 2)
                     {
                         if (brg.Rect.right < 0)
                         {
                             m_barrages.Remove(brg);
                             i--;
                             barragesSize--;
                         }
                         else
                         {
                             brg.Calculate();
                         }
                         paint = true;
                     }
                     else if (mode == 1)
                     {
                         int tick = brg.Tick;
                         tick--;
                         if (tick <= 0)
                         {
                             m_barrages.Remove(brg);
                             i--;
                             barragesSize--;
                         }
                         else
                         {
                             brg.Tick = tick;
                         }
                         if (tick % 20 == 0)
                         {
                             paint = true;
                         }
                     }
                 }
             }
         }
         if (paint)
         {
             //Invalidate();
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加弹幕
        /// </summary>
        /// <param name="text">文字</param>
        /// <param name="mode">模式</param>
        /// <param name="speed">速度</param>
        public void AddBarrage(String text, int mode, int speed)
        {
            Barrage barrage = new Barrage();

            barrage.Text  = text;
            barrage.Speed = speed;
            barrage.Mode  = mode;
            m_barrageDiv.AddBarrage(barrage);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 启动弹幕
        /// </summary>
        /// <param name="barrage">弹幕参数</param>
        public void AddBarrage(Barrage barrage)
        {
            barrage.Color = m_sysColors[m_tick % 6];
            int width = Width, height = Height;

            if (width < 100)
            {
                width = 100;
            }
            if (height < 100)
            {
                height = 100;
            }
            int mode = barrage.Mode;

            if (mode == 0 || mode == 2)
            {
                if (mode == 2)
                {
                    INativeBase native  = Native;
                    ControlA    iAnswer = native.FindControl("txtAnswer");
                    POINT       mp      = MousePoint;
                    barrage.Rect = new RECT(width, m_rd.Next(iAnswer.Top, iAnswer.Bottom - 40), width, 0);
                }
                else
                {
                    barrage.Rect = new RECT(width, m_rd.Next(0, height), width, 0);
                }
            }
            else
            {
                int left = 0, top = 0;
                if (width > 200)
                {
                    left = m_rd.Next(0, width - 100);
                }
                if (height > 200)
                {
                    top = m_rd.Next(0, height - 100);
                }
                barrage.Rect = new RECT(left, top, left, 0);
            }
            lock (m_barrages)
            {
                m_barrages.Add(barrage);
            }
            m_tick++;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 提示
        /// </summary>
        /// <param name="var">变量</param>
        /// <returns>结果</returns>
        public double ADDBARRAGE(CVariable var)
        {
            String text = "";
            int    len  = var.m_parameters.Length;

            for (int i = 0; i < len; i++)
            {
                text += m_indicator.GetText(var.m_parameters[i]);
            }
            BarrageDiv barrageDiv = (m_xml as MainFrame).FindControl("divBarrage") as BarrageDiv;
            Barrage    barrage    = new Barrage();

            barrage.Text = text;
            barrage.Mode = 0;
            barrageDiv.AddBarrage(barrage);
            return(1);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 重绘前景方法
 /// </summary>
 /// <param name="paint">绘图对象</param>
 /// <param name="clipRect">裁剪区域</param>
 public override void OnPaintBackground(CPaint paint, RECT clipRect)
 {
     base.OnPaintBackground(paint, clipRect);
     lock (m_barrages)
     {
         int barragesSize = m_barrages.Count;
         for (int i = 0; i < barragesSize; i++)
         {
             Barrage brg  = m_barrages[i];
             FONT    font = brg.Font;
             RECT    rect = brg.Rect;
             String  str  = brg.Text;
             SIZE    size = paint.TextSize(str, font);
             rect.right  = rect.left + size.cx;
             rect.bottom = rect.top + size.cy;
             brg.Rect    = rect;
             long color = brg.Color;
             int  mode  = brg.Mode;
             if (mode == 1)
             {
                 int a = 0, r = 0, g = 0, b = 0;
                 COLOR.ToARGB(null, color, ref a, ref r, ref g, ref b);
                 a     = a * brg.Tick / 400;
                 color = COLOR.ARGB(a, r, g, b);
             }
             if (mode == 2)
             {
                 POINT[] points = new POINT[5];
                 int     mWidth = rect.right - rect.left, mHeight = rect.bottom - rect.top;
                 points[0] = new POINT(rect.left, rect.top + mHeight / 2 + 1);
                 points[1] = new POINT(rect.left + 20, rect.top);
                 points[2] = new POINT(rect.right, rect.top);
                 points[3] = new POINT(rect.right, rect.bottom);
                 points[4] = new POINT(rect.left + 20, rect.bottom);
                 RECT drawRect = new RECT(rect.left - 30, rect.top - 10, rect.right + 30, rect.bottom + 10);
                 paint.DrawImage("file='fire2.jpg' highcolor='150,150,150' lowcolor='0,0,0'", drawRect);
                 //paint.FillGradientPolygon(COLOR.ARGB(255, 120, 40), COLOR.ARGB(255, 80, 40), points, 90);
             }
             else
             {
                 paint.DrawText(str, color, font, rect);
             }
         }
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 清除弹幕
 /// </summary>
 public void ClearBarrages()
 {
     lock (m_barrages)
     {
         int barragesSize = m_barrages.Count;
         for (int i = 0; i < barragesSize; i++)
         {
             Barrage brg = m_barrages[i];
             if (brg.Mode == 1)
             {
                 m_barrages.Remove(brg);
                 barragesSize--;
                 i--;
             }
         }
         Invalidate();
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 启动弹幕
        /// </summary>
        /// <param name="barrage">弹幕参数</param>
        public void AddBarrage(Barrage barrage)
        {
            barrage.Color = m_sysColors[m_tick % 6];
            int width = Width, height = Height;

            if (width < 100)
            {
                width = 100;
            }
            if (height < 100)
            {
                height = 100;
            }
            int mode = barrage.Mode;

            if (mode == 0)
            {
                barrage.Rect = new RECT(width, m_rd.Next(0, height), width, 0);
            }
            else
            {
                int left = 0, top = 0;
                if (width > 200)
                {
                    left = m_rd.Next(0, width - 200);
                }
                if (height > 200)
                {
                    top = m_rd.Next(0, height - 200);
                }
                barrage.Rect = new RECT(left, top, left, 0);
            }
            lock (m_barrages)
            {
                m_barrages.Add(barrage);
            }
            m_tick++;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 重绘前景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public override void OnPaintBackground(CPaint paint, RECT clipRect)
        {
            int width = Width, height = Height;

            base.OnPaintBackground(paint, clipRect);
            lock (m_barrages)
            {
                int barragesSize = m_barrages.Count;
                int top          = 0;
                for (int i = 0; i < barragesSize; i++)
                {
                    Barrage brg  = m_barrages[i];
                    FONT    font = brg.Font;
                    RECT    rect = brg.Rect;
                    String  str  = brg.Text;
                    SIZE    size = paint.TextSize(str, font);
                    int     mode = brg.Mode;
                    if (mode == 1)
                    {
                        rect.left = 0;
                        rect.top  = top + (50 - size.cy) / 2;
                    }
                    rect.right  = rect.left + size.cx;
                    rect.bottom = rect.top + size.cy;
                    brg.Rect    = rect;
                    long color = brg.Color;
                    paint.FillRect(COLOR.ARGB(50, 50, 50), rect);
                    paint.DrawRect(COLOR.ARGB(212, 158, 45), 1, 0, rect);
                    paint.DrawText(str, color, font, rect);
                    if (mode == 1)
                    {
                        top += 50;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 调用主线程返方法
        /// </summary>
        /// <param name="sender">调用者</param>
        /// <param name="args">参数</param>
        public void Invoke(object sender, object args)
        {
            CMessage message = args as CMessage;

            if (message != null)
            {
                if (message.m_serviceID == ChatService.SERVICEID_CHAT)
                {
                    if (message.m_functionID == ChatService.FUNCTIONID_SENDALL)
                    {
                        ChatData chatData = new ChatData();
                        ChatService.GetChatData(chatData, message.m_body, message.m_bodyLength);
                        CIndicator indicator = CFunctionEx.CreateIndicator2("", chatData, this);
                        indicator.Clear();
                        indicator.Dispose();
                    }
                    else if (message.m_functionID == ChatService.FUNCTIONID_GETHOSTS)
                    {
                        List <ChatHostInfo> datas = new List <ChatHostInfo>();
                        int type = 0;
                        ChatService.GetHostInfos(datas, ref type, message.m_body, message.m_bodyLength);
                        if (type != 2)
                        {
                            int datasSize = datas.Count;
                            for (int i = 0; i < datasSize; i++)
                            {
                                ChatHostInfo   hostInfo    = datas[i];
                                List <GridRow> rows        = m_gridHosts.m_rows;
                                int            rowsSize    = rows.Count;
                                bool           containsRow = false;
                                for (int j = 0; j < rowsSize; j++)
                                {
                                    GridRow oldRow = rows[j];
                                    if (oldRow.GetCell("colP1").GetString() == hostInfo.m_ip && oldRow.GetCell("colP2").GetInt() == hostInfo.m_serverPort)
                                    {
                                        containsRow = true;
                                    }
                                }
                                if (!containsRow)
                                {
                                    if (hostInfo.m_type == 1)
                                    {
                                        String      key = hostInfo.m_ip + ":" + hostInfo.m_serverPort;
                                        ChatService newServerService = DataCenter.GetClientChatService(key);
                                        if (newServerService == null)
                                        {
                                            newServerService            = new ChatService();
                                            newServerService.ServerIP   = hostInfo.m_ip;
                                            newServerService.ServerPort = hostInfo.m_serverPort;
                                            newServerService.ToServer   = true;
                                            BaseService.AddService(newServerService);
                                            DataCenter.AddClientChatService(key, newServerService);
                                        }
                                    }
                                    else
                                    {
                                        GridRow row = new GridRow();
                                        m_gridHosts.AddRow(row);
                                        row.AddCell("colP1", new GridStringCell(hostInfo.m_ip));
                                        row.AddCell("colP2", new GridIntCell(hostInfo.m_serverPort));
                                        if (hostInfo.m_type == 1)
                                        {
                                            row.AddCell("colP3", new GridStringCell("--"));
                                            row.AddCell("colP4", new GridStringCell("--"));
                                        }
                                        else
                                        {
                                            row.AddCell("colP3", new GridStringCell(hostInfo.m_userID));
                                            row.AddCell("colP4", new GridStringCell(hostInfo.m_userName));
                                        }
                                        row.AddCell("colP5", new GridStringCell(hostInfo.m_type == 1 ? "服务器" : "客户端"));
                                    }
                                }
                            }
                        }
                        else
                        {
                            Dictionary <String, String> removeHosts = new Dictionary <String, String>();
                            foreach (ChatHostInfo hostInfo in datas)
                            {
                                removeHosts[hostInfo.ToString()] = "";
                            }
                            List <GridRow> rows     = m_gridHosts.m_rows;
                            int            rowsSize = rows.Count;
                            if (rowsSize > 0)
                            {
                                for (int i = 0; i < rowsSize; i++)
                                {
                                    GridRow row = rows[i];
                                    String  key = row.GetCell("colP1").GetString() + ":" + row.GetCell("colP2").GetString();
                                    if (removeHosts.ContainsKey(key))
                                    {
                                        m_gridHosts.RemoveRow(row);
                                        i--;
                                        rowsSize--;
                                    }
                                }
                            }
                        }
                        SetHostGridRowVisible();
                    }
                    else if (message.m_functionID == ChatService.FUNCTIONID_SEND)
                    {
                        ChatData chatData = new ChatData();
                        ChatService.GetChatData(chatData, message.m_body, message.m_bodyLength);
                        CIndicator indicator = CFunctionEx.CreateIndicator2("", chatData, this);
                        indicator.Clear();
                        indicator.Dispose();
                    }
                }
            }
            String newStr = args as String;

            if (newStr != null)
            {
                if (newStr == "showchat")
                {
                    FlashWindow(m_mainForm.Handle, true);
                    SetForegroundWindow(m_mainForm.Handle);
                }
                else if (newStr == "shake")
                {
                    m_mainForm.Play();
                }
                else if (newStr.StartsWith("how:"))
                {
                    String  text    = newStr.Substring(4);
                    Barrage barrage = new Barrage();
                    barrage.Text = text;
                    barrage.Mode = 1;
                    m_barrageForm.BarrageDiv.AddBarrage(barrage);
                }
                else
                {
                    TextBoxA txtReceive = GetTextBox("txtReceive");
                    txtReceive.Text += newStr;
                    txtReceive.Invalidate();
                    if (txtReceive.VScrollBar != null && txtReceive.VScrollBar.Visible)
                    {
                        txtReceive.VScrollBar.ScrollToEnd();
                        txtReceive.Update();
                        txtReceive.Invalidate();
                    }
                }
            }
        }