Exemple #1
0
 void UndoButtonClick(object sender, EventArgs e)
 {
     if (UndoStack.ToArray().Length > 0)
     {
         Byte[] b = UndoStack.Pop();
         using (MemoryStream ms = new MemoryStream(b, true))
         {
             BinaryFormatter bf = new BinaryFormatter();
             BrailleScreen   bs = ((BrailleScreen)bf.Deserialize(ms));
             LoadedScreen = null;
             LoadedScreen = new BrailleScreen(bs.Width, bs.Height);
             for (UInt16 i = 0; i < bs.Width; i++)
             {
                 for (UInt16 x = 0; x < bs.Height; x++)
                 {
                     LoadedScreen[i, x] = bs[i, x];
                 }
             }
         }
     }
     WidthNumber.Value  = (decimal)LoadedScreen.Width;
     HeightNumber.Value = (decimal)LoadedScreen.Height;
     RedrawGrid();
     RedrawElements(sender, e);
 }
        public static String[] RenderBrailleToTextFile(String StartPath, String EndPath, Boolean EchoOff = false)
        {
            BinaryFormatter bf = new BinaryFormatter();

            String[] x = new String[0];
            try
            {
                // CondVox("Loading screen instance...", EchoOff);
                FileStream    fs = new FileStream(StartPath, FileMode.Open);
                BrailleScreen bs = ((BrailleScreen)bf.Deserialize(fs));
                fs.Close();
                CondWait(500, EchoOff);
                x = RenderBrailleToTextFile(bs, EndPath, EchoOff);
            }
            catch (FileNotFoundException e)
            {
                CondVox(Localization.Get("error_objectnotfound") + StartPath, EchoOff, MessageBoxIcon.Exclamation);
                CondThrow(e, EchoOff);
            }
            catch (Exception e)
            {
                CondVox(Localization.Get("error_objectloadfail"), EchoOff, MessageBoxIcon.Error);
                CondVox(e, EchoOff);
                CondThrow(e, EchoOff);
            }
            return(x);
        }
Exemple #3
0
        public static void RenderBrailleToTextFile(String StartPath, String EndPath, Boolean EchoOff = false)
        {
            BinaryFormatter bf = new BinaryFormatter();

            try
            {
                CondVox("Loading screen instance...", EchoOff);
                FileStream    fs = new FileStream(StartPath, FileMode.Open);
                BrailleScreen bs = ((BrailleScreen)bf.Deserialize(fs));
                fs.Close();
                CondWait(500, EchoOff);
                RenderBrailleToTextFile(bs, EndPath, EchoOff);
            }
            catch (FileNotFoundException e)
            {
                CondVox("Unable to find given object file: " + StartPath, EchoOff);
                CondThrow(e, EchoOff);
            }
            catch (Exception e)
            {
                CondVox("Oh noes! Looks like something is wrong with the file!", EchoOff);
                CondVox(e, EchoOff);
                CondThrow(e, EchoOff);
            }
        }
Exemple #4
0
        void LoadButtonClick(object sender, EventArgs e)
        {
            Ofd.Title      = "Select object file to open";
            Ofd.DefaultExt = "o";
            Ofd.Filter     = Localization.Get("filter_o");
            DialogResult dr = Ofd.ShowDialog();

            if (dr == DialogResult.OK && File.Exists(Ofd.FileName))
            {
                BinaryFormatter bf = new BinaryFormatter();
                FileStream      fs = new FileStream(Ofd.FileName, FileMode.Open);
                BrailleScreen   bs = ((BrailleScreen)bf.Deserialize(fs));
                if (!(bs.Width > WidthNumber.Maximum || bs.Height > HeightNumber.Maximum))
                {
                    LoadedScreen = bs;
                }
                else
                {
                    MessageBox.Show(String.Format(Localization.Get("error_objecttoolarge"), HeightNumber.Maximum), "Braille Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                fs.Close();
                FileName.Text = Path.GetFileName(Ofd.FileName);
                UndoStack.Clear();
            }
            WidthNumber.Value  = (decimal)(LoadedScreen.Width);
            HeightNumber.Value = (decimal)(LoadedScreen.Height);
            RedrawElements(sender, e);
        }
        // static String BrailleReference = " A1B'K2L@CIF/MSP\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)=";
        // static Int32 StarterIndex = 0x2800;

        public static void Example(Boolean EchoOff = false)
        {
            RequestHandler.CondVox("Creating an example file...", EchoOff);
            StreamWriter  w = new StreamWriter("take your output.txt");
            BrailleScreen y = new BrailleScreen(16, 12);

            RequestHandler.CondWait(2000, EchoOff);
            y[0, 0]  = true;
            y[15, 0] = true;
            y[0, 8]  = true;
            y[15, 8] = true;
            RequestHandler.CondVox("bum, bum, be-dum, bum, bum, be-dum, bum...", EchoOff);
            RequestHandler.CondWait(3000, EchoOff);
            BrailleScreen x = new BrailleScreen(4, 4);

            x[0, 0] = true;
            x[3, 0] = true;
            x[0, 2] = true;
            x[3, 2] = true;
            BrailleScreen s = BrailleScreen.Merge(x, y, 6, 3);

            RequestHandler.CondVox("Rendering results...", EchoOff);
            RequestHandler.RenderBrailleToTextFile(s, w, false);
            w.Close();
            RequestHandler.CondWait(2000, EchoOff);
            RequestHandler.CondVox("Results saved to 'take your output.txt'.", EchoOff);
            RequestHandler.CondWait(1500, EchoOff);
        }
        public static void CompileBrailleFromImage(Bitmap Source, FileStream Target, Boolean EchoOff = false)
        {
            BrailleScreen bs = ConstructBrailleFromImage(Source, EchoOff);
            // CondVox("Braille screen built successfully.", EchoOff);
            // CondVox("Dumping screen to file...", EchoOff);
            // CondWait(500, EchoOff);
            BinaryFormatter bf = new BinaryFormatter();

            // CondVox("bum, bum, be-dum, bum, bum, be-dum, bum...", EchoOff);
            // CondWait(3500, EchoOff);
            bf.Serialize(Target, bs);
            CondVox(Localization.Get("ok_compiled"), EchoOff);
            // CondWait(500, EchoOff);
        }
Exemple #7
0
 public static void RenderBrailleToTextFile(BrailleScreen Source, String SavePath, Boolean EchoOff = false)
 {
     try
     {
         CondVox("Making target file...", EchoOff);
         StreamWriter s = new StreamWriter(SavePath);
         CondWait(500, EchoOff);
         RenderBrailleToTextFile(Source, s, EchoOff);
         s.Close();
     }
     catch (Exception e)
     {
         CondVox("We were unsuccessful in creating an output file.", EchoOff);
         CondThrow(e, EchoOff);
     }
 }
 public static String[] RenderBrailleToTextFile(BrailleScreen Source, String SavePath, Boolean EchoOff = false)
 {
     String[] x = new String[0];
     try
     {
         // CondVox("Making target file...", EchoOff);
         StreamWriter s = new StreamWriter(SavePath);
         CondWait(500, EchoOff);
         x = RenderBrailleToTextFile(Source, s, EchoOff);
         s.Close();
     }
     catch (Exception e)
     {
         CondVox(Localization.Get("error_renderdumpfail"), EchoOff, MessageBoxIcon.Error);
         CondThrow(e, EchoOff);
     }
     return(x);
 }
Exemple #9
0
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            this.SizeChanged          += RedrawElements;
            this.Shown                += PoppedUp;
            ScaleNumber.ValueChanged  += RedrawElements;
            WidthNumber.ValueChanged  += IncreaseScreenHorizontally;
            HeightNumber.ValueChanged += IncreaseScreenVertically;
            LoadButton.Text            = Localization.Get("ui_loadbutton");
            SaveButton.Text            = Localization.Get("ui_savebutton");
            RenderButton.Text          = Localization.Get("ui_renderbutton");
            UndoButton.Text            = Localization.Get("ui_undo");
            FileName.Text              = Localization.Get("ui_nofile");
            label2.Text                = Localization.Get("ui_width");
            label3.Text                = Localization.Get("ui_height");
            FillRadioBox.Text          = Localization.Get("ui_fill");
            ClearRadioBox.Text         = Localization.Get("ui_clear");

            LoadedScreen = new BrailleScreen(4, 4);

            DefaultRenderButtonX     = RenderButton.Location.X;
            DefaultRenderButtonY     = RenderButton.Location.Y;
            DefaultDrawingAreaWidth  = DrawingArea.Width;
            DefaultDrawingAreaHeight = DrawingArea.Height;
            HeightNumber.Maximum     = (decimal)(DefaultDrawingAreaHeight - (DefaultDrawingAreaHeight % 4));
            WidthNumber.Maximum      = HeightNumber.Maximum;
            DefaultDrawingAreaY      = DrawingArea.Location.Y;
            DefaultDrawingAreaX      = DrawingArea.Location.X;
            DefaultFormWidth         = this.Width;
            DefaultFormHeight        = this.Height;

            DrawingArea.MouseDown += MouseClicked;
            DrawingArea.MouseUp   += MouseReleased;
            DrawingArea.MouseMove += MouseDrag;

            FillRadioBox.Checked = true;

            // RedrawGrid();
        }
        public static void Main(string[] args)
        {
            try
            {
                BrailleScreen s = new BrailleScreen(4, 4);
            }
            catch (Exception)
            {
                Console.WriteLine("No 'DotGraphics.Screens' library connected!");
                Environment.Exit(-1);
            }
            List <String> Arguments = new List <string>();

            foreach (String i in args)
            {
                Arguments.Add(i);
            }

            Process(args.Length, Arguments, false);
        }
Exemple #11
0
 public static void RenderBrailleToTextFile(BrailleScreen Source, StreamWriter Target, Boolean EchoOff = false)
 {
     try
     {
         CondVox("Rendering image to text file...", EchoOff);
         String[] Container = new String[Source.Height / 4];
         Source.Render(ref Container);
         foreach (String x in Container)
         {
             Target.WriteLine(x);
         }
         CondWait(500, EchoOff);
         CondVox("Render complete!", EchoOff);
     }
     catch (Exception e)
     {
         CondVox("Error occured while trying to render an image to file.", EchoOff);
         CondVox(e, EchoOff);
         CondThrow(e, EchoOff);
     }
 }
 public static String[] RenderBrailleToTextFile(BrailleScreen Source, StreamWriter Target, Boolean EchoOff = false)
 {
     String[] Container = new String[Source.Height / 4];
     try
     {
         Source.Render(ref Container);
         foreach (String x in Container)
         {
             Target.WriteLine(x);
         }
         CondWait(500, EchoOff);
         CondVox(Localization.Get("ok_render"), EchoOff);
         return(Container);
     }
     catch (Exception e)
     {
         CondVox(Localization.Get("error_renderfail"), EchoOff, MessageBoxIcon.Error);
         CondVox(e, EchoOff, MessageBoxIcon.Error);
         CondThrow(e, EchoOff);
     }
     return(Container);
 }
Exemple #13
0
        void IncreaseScreenVertically(object sender, EventArgs e)
        {
            PushScreen();
            HeightNumber.Value = Math.Ceiling(HeightNumber.Value / 4) * 4;

            if (HeightNumber.Value > LoadedScreen.Height)
            {
                BrailleScreen x = new BrailleScreen(LoadedScreen.Width, ((UInt16)(HeightNumber.Value)));
                LoadedScreen = BrailleScreen.Merge(LoadedScreen, x);
            }
            else if (HeightNumber.Value < LoadedScreen.Height)
            {
                for (UInt16 y = ((UInt16)(HeightNumber.Value)); y < LoadedScreen.Height; y++)
                {
                    for (UInt16 x = 0; x < LoadedScreen.Width; x++)
                    {
                        if (LoadedScreen[x, y])
                        {
                            HeightNumber.Value = ((decimal)(LoadedScreen.Height));
                            return;
                        }
                    }
                }
                BrailleScreen bs = new BrailleScreen(LoadedScreen.Width, ((UInt16)HeightNumber.Value));
                for (UInt16 y = 0; y < bs.Height; y++)
                {
                    for (UInt16 x = 0; x < bs.Width; x++)
                    {
                        bs[x, y] = LoadedScreen[x, y];
                    }
                }
                LoadedScreen = bs;
            }
            RedrawElements(sender, e);

            HeightNumber.Value = ((decimal)(LoadedScreen.Height));
        }
Exemple #14
0
        void IncreaseScreenHorizontally(object sender, EventArgs e)
        {
            PushScreen();
            WidthNumber.Value = Math.Min(Math.Ceiling(WidthNumber.Value / 2) * 2, 1024);

            if (WidthNumber.Value > LoadedScreen.Width)
            {
                BrailleScreen x = new BrailleScreen(((UInt16)(WidthNumber.Value)), LoadedScreen.Height);
                LoadedScreen = BrailleScreen.Merge(LoadedScreen, x);
            }
            else if (WidthNumber.Value < LoadedScreen.Width)
            {
                for (UInt16 x = ((UInt16)(WidthNumber.Value)); x < LoadedScreen.Width; x++)
                {
                    for (UInt16 y = 0; y < LoadedScreen.Height; y++)
                    {
                        if (LoadedScreen[x, y])
                        {
                            WidthNumber.Value = ((decimal)(LoadedScreen.Width));
                            return;
                        }
                    }
                }
                BrailleScreen bs = new BrailleScreen((UInt16)(WidthNumber.Value), LoadedScreen.Height);
                for (UInt16 x = 0; x < WidthNumber.Value; x++)
                {
                    for (UInt16 y = 0; y < bs.Height; y++)
                    {
                        bs[x, y] = LoadedScreen[x, y];
                    }
                }
                LoadedScreen = bs;
            }
            RedrawElements(sender, e);

            WidthNumber.Value = ((decimal)(LoadedScreen.Width));
        }
        public static BrailleScreen ConstructBrailleFromImage(Bitmap Source, Boolean EchoOff = true)
        {
            // CondVox("Validating image...", EchoOff);
            if (CondAssert(((Source.Width % 2) == 0 && (Source.Height % 4) == 0), Localization.Get("error_imageaspectratio"), EchoOff))
            {
                return(new BrailleScreen(2, 4));
            }
            if (CondAssert(((Source.Width >= 0 && Source.Width < 65536) || (Source.Height >= 0 && Source.Height < 65536)), Localization.Get("error_imagetoolarge"), EchoOff))
            {
                return(new BrailleScreen(2, 4));
            }
            // CondVox("Copying data to braille screen...", EchoOff);
            BrailleScreen bs = new BrailleScreen((UInt16)(Source.Width), (UInt16)(Source.Height));

            for (UInt16 i = 0; i < bs.Height; i++)
            {
                for (UInt16 x = 0; x < bs.Width; x++)
                {
                    bs[x, i] = (Source.GetPixel(x, i).A != 0);
                }
            }

            return(bs);
        }
Exemple #16
0
        public static BrailleScreen ConstructBrailleFromImage(Bitmap Source, Boolean EchoOff = true)
        {
            CondVox("Validating image...", EchoOff);
            if (CondAssert(((Source.Width % 2) == 0 && (Source.Height % 4) == 0), "Image does not fit in following parameters: width is not multiple of 2 & height is not multiple of 4.", EchoOff))
            {
                return(new BrailleScreen(2, 4));
            }
            if (CondAssert(((Source.Width >= 0 && Source.Width < 65536) || (Source.Height >= 0 && Source.Height < 65536)), "Image size is too large: width and height should be less than 65536.", EchoOff))
            {
                return(new BrailleScreen(2, 4));
            }
            CondVox("Copying data to braille screen...", EchoOff);
            BrailleScreen bs = new BrailleScreen((UInt16)(Source.Width), (UInt16)(Source.Height));

            for (UInt16 i = 0; i < bs.Height; i++)
            {
                for (UInt16 x = 0; x < bs.Width; x++)
                {
                    bs[x, i] = (Source.GetPixel(x, i).A != 0);
                }
            }

            return(bs);
        }