コード例 #1
0
ファイル: HTTPCast.cs プロジェクト: 2max968/Kritzelv2
 public static void StartCasting(int port, InkControl ink, string password)
 {
     if (server != null && server.Active)
     {
         return;
     }
     HTTPCast.ink = ink;
     Log.SetConsoleHandler();
     server = new HttpServer(port);
     server.RegisterMethod("", mIndex);
     server.RegisterMethod("image", mImage);
     server.RegisterMethod("cast.html", mCast);
     server.RegisterMethod("index.html", mLogin);
     server.RegisterMethod("click", mClick);
     server.RegisterMethod("favicon.ico", mIcon);
     server.RegisterMethod("version", mVersion);
     server.Start();
 }
コード例 #2
0
 public void Click(InkControl control, float x, float y)
 {
     x = Util.PointToMm(x);
     y = Util.PointToMm(y);
     foreach (var line in lines)
     {
         if (line is Forms.IClickable)
         {
             var clickable = (Forms.IClickable)line;
             var bounds    = clickable.GetClickableBounds();
             if (x >= bounds.Left && y >= bounds.Top &&
                 x <= bounds.Right && y <= bounds.Bottom)
             {
                 clickable.Click(control);
             }
         }
     }
 }
コード例 #3
0
        public void OnShow(InkControl control)
        {
            if (OriginalPage != null && BackgroundImage == null)
            {
                string      path = TmpManager.GetTmpDir() + "\\render.pdf";
                PdfDocument doc  = new PdfDocument();
                doc.Pages.Add(OriginalPage);
                doc.Save(path);
                Bitmap[] bmp = MupdfSharp.PageRenderer.Render(path, 50, 0);
                BackgroundImage = new Renderer.Image(bmp[0]);

                loaderThread = new Thread(delegate()
                {
                    Bitmap[] bmp2 = MupdfSharp.PageRenderer.Render(path, PDFImporter.PAGETHEIGHTPIXEL, 0);
                    BackgroundImage.Dispose();
                    BackgroundImage = new Renderer.Image(bmp2[0]);
                    control.RefreshPage();
                });
                loaderThread.Start();
            }
        }
コード例 #4
0
        public MainWindow()
        {
            InitializeComponent();
            inkControl1      = new InkControl();
            inkControl1.Dock = DockStyle.Fill;
            pnInkControlContainer.Controls.Add(inkControl1);
            this.Icon           = Program.WindowIcon;
            panelTop.Height     = Util.GetGUISize();
            panelSide.Width     = Util.GetGUISize();
            MainWindow.Instance = this;
            Util.SetAllButtonSizes(panelTop, Util.GetGUISize());
            Util.SetAllButtonSizes(panelSide, Util.GetGUISize());
            icoFullscreen       = ResManager.LoadIcon("fullscreen.svg", Util.GetGUISize());
            icoFullscreenEnd    = ResManager.LoadIcon("fullscreenEnd.svg", Util.GetGUISize());
            btnFullscreen.Image = icoFullscreen;
            btnFullscreen.Text  = "";
            tmAutosave.Interval = Configuration.AutosaveInterval * 1000;

            btnFile.BackgroundImage = ResManager.LoadIcon("hamburger.svg", Util.GetGUISize());

            btnPageDown.Image   = ResManager.LoadIcon("gui/down.svg", Util.GetGUISize());
            btnPageUp.Image     = ResManager.LoadIcon("gui/up.svg", Util.GetGUISize());
            btnPageSelect.Image = ResManager.LoadIcon("gui/select.svg", Util.GetGUISize());
            btnPageSelect.Text  = btnPageUp.Text = btnPageDown.Text = "";
            btnShift.Image      = ResManager.LoadIcon("actions/transMove.svg", Util.GetGUISize());
            btnScale.Image      = ResManager.LoadIcon("actions/transScale.svg", Util.GetGUISize());
            btnRot.Image        = ResManager.LoadIcon("actions/transRotate.svg", Util.GetGUISize());
            btnBack.Image       = ResManager.LoadIcon("actions/undo.svg", Util.GetGUISize());
            btnForward.Image    = ResManager.LoadIcon("actions/redo.svg", Util.GetGUISize());
            btnDeletePage.Image = ResManager.LoadIcon("actions/delete.svg", Util.GetGUISize());
            btnDeletePage.Text  = "";
            btnCopy.Image       = ResManager.LoadIcon("actions/copy.svg", Util.GetGUISize());
            btnCopy.Text        = "";
            btnPaste.Image      = ResManager.LoadIcon("actions/paste.svg", Util.GetGUISize());
            btnPaste.Text       = "";
            btnCut.Image        = ResManager.LoadIcon("actions/cut.svg", Util.GetGUISize());
            btnCut.Text         = "";
            btnShift.Click     += TransformButton_Click;
            btnScale.Click     += TransformButton_Click;
            btnRot.Click       += TransformButton_Click;
            btnScale.Tag        = btnShift.Tag = btnRot.Tag = true;
            setCbColor(btnShift, btnScale, btnRot);
            panelSide.Dock              = Configuration.LeftHanded ? DockStyle.Right : DockStyle.Left;
            btnResetRotation.Image      = ResManager.LoadIcon("actions/resetRotation.svg", Util.GetGUISize());
            btnMatchWindow.Image        = ResManager.LoadIcon("actions/matchScreen.svg", Util.GetGUISize());
            btnResetTransform.Image     = ResManager.LoadIcon("actions/resetPosScale.svg", Util.GetGUISize());
            btnLayout.Image             = ResManager.LoadIcon("layout.svg", Util.GetGUISize());
            btnResetTransform.Text      = btnResetRotation.Text = btnMatchWindow.Text = "";
            btnFormType.BackgroundImage = Line.BitmapStrk;

            bool restore = false;

            if (Program.RestoreData)
            {
                restore = Dialogues.MsgBox.ShowYesNo("System.restoreData?");
            }

            if (restore)
            {
                doc.LoadDocument(null, new MessageLog());
                inkControl1.LoadPage(doc.Pages[0]);
                inkControl1.Thicknes = Configuration.PenCurrentSize;
            }
            else if (Environment.GetCommandLineArgs().Length <= 1)
            {
                doc.Pages.Add(new KPage(doc));
                doc.SetCurrentStateAsSaved();
                inkControl1.LoadPage(doc.Pages[0]);
                inkControl1.Thicknes = Configuration.PenCurrentSize;
            }
            else
            {
                string filename = Environment.GetCommandLineArgs()[1];
                if (!File.Exists(filename))
                {
                    MessageBox.Show("Cant open file '{0}'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    doc.LoadDocument(filename, new MessageLog());
                    inkControl1.LoadPage(doc.Pages[0]);
                    inkControl1.Thicknes = Configuration.PenSizeMin;
                }
            }

            sizeButtons = new Button[Configuration.PenSizeNum];
            for (int i = 0; i < Configuration.PenSizeNum; i++)
            {
                float  size    = Configuration.PenSizeMin + i * (Configuration.PenSizeMax - Configuration.PenSizeMin) / (float)(Configuration.PenSizeNum - 1);
                Button btnSize = new Button();
                btnSize.FlatStyle = FlatStyle.Flat;
                btnSize.FlatAppearance.BorderSize = 0;
                btnSize.Size   = new Size(Util.GetGUISize(), Util.GetGUISize());
                btnSize.Dock   = DockStyle.Right;
                btnSize.Tag    = size;
                btnSize.Click += BtnSize_Click;
                pnSizes.Controls.Add(btnSize);
                sizeButtons[i] = btnSize;
                Bitmap bmp = new Bitmap(Util.GetGUISize(), Util.GetGUISize());
                float  rad = (float)sizeButtons[i].Tag;
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.FillEllipse(Brushes.Black, new RectangleF(
                                      Util.GetGUISize() / 2 - rad, Util.GetGUISize() / 2 - rad,
                                      rad * 2, rad * 2));
                }
                btnSize.Image = bmp;
            }
            pnSizes.Width   = Configuration.PenSizeNum * Util.GetGUISize();
            pnSizes.Visible = Configuration.CalculateSplinesDuringDrawing;

            this.Shown += MainWindow_Shown;
            inkControl1.SelectionChanged += InkControl1_SelectionChanged;
            inkControl1.PageLoaded       += InkControl1_PageLoaded;
            inkControl1.LineAdded        += InkControl1_LineAdded;
            Style.StyleChanged           += Style_StyleChanged;
            Style_StyleChanged(null, Style.Default);

            colorPicker1.SetColor += ColorPicker1_SetColor;

            foreach (Control control in Controls)
            {
                if (control is Button)
                {
                    control.Text = Language.GetText(control.Text);
                }
            }
            foreach (ToolStripItem item in ctxMovePage.Items)
            {
                item.Text = Language.GetText(item.Text);
            }

            this.KeyPreview = true;
            HistoryManager.RegisterHistoryButtons(btnBack, btnForward);
        }
コード例 #5
0
        public static async Task <int> StartCasting(string host, string castID, InkControl control)
        {
            WebCast.host    = host;
            WebCast.castId  = castID;
            WebCast.control = control;

            client = new WebClient();
            client.UploadDataCompleted += (object s, UploadDataCompletedEventArgs e) =>
            {
                error          = e.Error;
                uploadFinished = true;
            };
            client.DownloadDataCompleted += (object s, DownloadDataCompletedEventArgs e) =>
            {
                error = e.Error;
                if (error == null)
                {
                    downloadedData = e.Result;
                }
                else
                {
                    downloadedData = new byte[] { (byte)'e', (byte)'r', (byte)'r', (byte)'o', (byte)'r' }
                };
                downloadFinished = true;
            };
            //client.BaseAddress = new Uri($"{host}");
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            //client.DefaultRequestHeaders.Accept.Clear();
            //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("image/bmp"));
            try
            {
                string uri = $"{host}Create/{castID}";
                Program.MainLog.Add(MessageType.MSG, "Connecting to '{0}'", uri);
                //var response = await client.GetAsync(uri);
                //string text = await response.Content.ReadAsStringAsync();
                string text = client.DownloadString(new Uri(uri));

                Program.MainLog.Add(MessageType.MSG, $"Response from Server: '{text}'");
                if (!text.StartsWith("OK"))
                {
                    return(1);
                }
            }
            catch (WebException wex)
            {
                if (wex.Status == WebExceptionStatus.TrustFailure)
                {
                    Program.MainLog.Add(wex);
                    if (Dialogues.MsgBox.ShowYesNo("Cast.web.trust"))
                    {
                        Program.MainLog.Add(MessageType.WARN, "Ignoring future Https certificate errors");
                        ServicePointManager.ServerCertificateValidationCallback =
                            new System.Net.Security.RemoteCertificateValidationCallback(delegate
                        {
                            return(true);
                        });
                        return(await StartCasting(host, castID, control));
                    }
                }
                return(2);
            }
            catch (Exception ex)
            {
                Program.MainLog.Add(ex);
                return(2);
            }
            IsCasting = true;
            BackgroundLoop();
            return(0);
        }