示例#1
0
        public void Draw()
        {
            //先生成文本
            int fontHeight = 32;

            switch (FontSize)
            {
            case XingKongScreen.XFontSize.Normal:
                fontHeight = 32;
                break;

            case XingKongScreen.XFontSize.Large:
                fontHeight = 48;
                break;

            case XingKongScreen.XFontSize.ExtraLarge:
                fontHeight = 64;
                break;

            default:
                break;
            }
            int fontWidth = XingKongScreen.MeasureStringWidth(Text, FontSize);
            int fontLeft  = 10;

            switch (TextAlign)
            {
            case XingKongScreen.TextAlign.Left:
                fontLeft = 10 + left;
                break;

            case XingKongScreen.TextAlign.Center:
                fontLeft = (Width - fontWidth) / 2 + Left + TextXoffset;
                break;

            case XingKongScreen.TextAlign.Right:
                fontLeft = Width - fontWidth - 10;
                break;

            default:
                break;
            }
            int fontTop = (Height - fontHeight) / 2 + Top + TextYoffset;

            XingKongLabel ltemp = new XingKongLabel();

            ltemp.Text     = Text;
            ltemp.Left     = (short)fontLeft;
            ltemp.Top      = (short)fontTop;
            ltemp.FontSize = FontSize;

            //计算矩形位置
            Point p1 = new Point(Left, Top);
            Point p2 = new Point(Left + Width, Top + Height);

            object asyncLockObj = XingKongScreen.AsyncLockObj;

            lock (asyncLockObj)
            {
                if (isChecked)
                {
                    XingKongScreen.SetColor(XingKongScreen.XColor.Gray);
                    XingKongScreen.FillSquare(p1, p2);

                    //设置文字为白色,背景为黑色
                    XingKongScreen.SetColor(XingKongScreen.XColor.White, XingKongScreen.XColor.Gray);
                    ltemp.Draw();

                    //恢复默认调色板
                    XingKongScreen.SetColor();
                }
                else
                {
                    XingKongScreen.SetColor(XingKongScreen.XColor.White);
                    XingKongScreen.FillSquare(p1, p2);
                    XingKongScreen.SetColor();
                    //先画文本
                    ltemp.Draw();
                    //再画矩形
                    XingKongScreen.DrawSquare(p1, p2);
                }
            }

            NeedDraw = false;
        }
        public DialogResult Show()
        {
            canExit = false;

            int[] widths = new int[3];
            widths[0] = XingKongScreen.MeasureStringWidth(Caption, lbCaption.FontSize);
            widths[1] = XingKongScreen.MeasureStringWidth(Title, lbTitle.FontSize);
            widths[2] = 128 * 2 + 40;

            int maxWidth = widths[0];

            foreach (int w in widths)
            {
                if (w > maxWidth)
                {
                    maxWidth = w;
                }
            }

            int actWidth  = maxWidth + 150;
            int actHeight = actWidth * 3 / 4;
            int left      = (800 - actWidth) / 2;
            int top       = (600 - actHeight) / 2;

            lbCaption.Left = (short)(20 + left);
            lbCaption.Top  = (short)(20 + top);

            Point pLeftTopOfBox     = new Point(left, top);
            Point pRightButtomOfBox = new Point(left + actWidth, top + actHeight);

            XingKongScreen.SetColor(XingKongScreen.XColor.White);
            XingKongScreen.FillSquare(pLeftTopOfBox, pRightButtomOfBox);
            XingKongScreen.SetColor();
            XingKongScreen.DrawSquare(pLeftTopOfBox, pRightButtomOfBox);

            int lbCaptionFontHeight = getFontHeightPixel(lbCaption.FontSize);
            int lbTitleFontHeight   = getFontHeightPixel(lbTitle.FontSize);

            XingKongScreen.DrawLine(new Point(left, 40 + top + lbCaptionFontHeight), new Point(left + actWidth, 40 + top + lbTitleFontHeight));

            lbTitle.Top  = (short)((actHeight / 5) + 40 + top + lbCaptionFontHeight);
            lbTitle.Left = (short)(((actWidth - XingKongScreen.MeasureStringWidth(lbTitle.Text, lbTitle.FontSize)) / 2) + left);

            int btOkFontHeight     = getFontHeightPixel(btOk.FontSize);
            int btCancelFontHeight = getFontHeightPixel(btCancel.FontSize);

            if (DialogStyle == Style.OkCancel)
            {
                btOk.Left = (actWidth - widths[2]) / 2 + left;
                btOk.Top  = (short)((actHeight * 3 / 5) + top + btCancelFontHeight);

                btCancel.Left = btOk.Left + btOk.Width + 40;
                btCancel.Top  = btOk.Top;

                btOk.Draw();
                btCancel.Draw();
            }
            else
            {
                btOk.Left = (actWidth - btOk.Width) / 2 + left;
                btOk.Top  = (short)((actHeight * 3 / 5) + top + btCancelFontHeight);
                btOk.Draw();
            }


            lbCaption.Draw();
            lbTitle.Draw();
            XingKongScreen.FreshScreen();

            if (btOk.IsChecked)
            {
                result = DialogResult.OK;
            }
            else
            {
                result = DialogResult.Cancel;
            }

            keyboard             = XingKongScreen.GetKeyboard();
            keyboard.KeyPressed += Keyboard_KeyPressed;
            while (!canExit)
            {
                Thread.Sleep(10);
            }
            keyboard.KeyPressed -= Keyboard_KeyPressed;
            return(result);
        }