public void ViewPic(Color bcolor, Brush fontbrush) { InfoPicture infoPic = App.Pictures[No]; if (base.Width >= 1) { try { int w; if (infoPic.W <= base.Width) { w = infoPic.W; } else { w = base.Width; } int height = (infoPic.H * w) / infoPic.W; base.Height = height + 40; Bitmap bg = new Bitmap(base.Width, base.Height); Graphics graphics = Graphics.FromImage(bg); graphics.Clear(bcolor); Bitmap img = Utility.GetBitmap(App.PictureImages[No], App.Pictures[No], false); graphics.DrawImage( img, new Rectangle(0, 20, w, height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel ); graphics.DrawString( No.ToString() + "--SIZE:" + infoPic.W.ToString() + "x" + infoPic.H.ToString(), new Font(main.Form.Font.Name, main.Form.Font.Size), fontbrush, (PointF) new Point(10, base.Height - 20) ); base.Image = bg; img.Dispose(); } catch (Exception exception) { MessageBox.Show(exception.Message); } } }
private void convertPictures() { for (int i = 0; i < m_app.Pictures.Count; i++) { label3.Visible = true; if (m_app.Pictures[i].IsPotrait != (m_app.IsPotrait ? 1 : 0)) { label3.Text = "Converting resource file:".Translate() + i.ToString() + "/" + m_app.Pictures.Count.ToString(); Application.DoEvents(); m_app.PictureImages[i] = cropPicture(i); InfoPicture pictureInfo = m_app.Pictures[i]; pictureInfo.IsPotrait = (byte)(m_app.IsPotrait ? 1 : 0); m_app.Pictures[i] = pictureInfo; } } }
public unsafe byte GuiCurveRef(ref InfoObject obj, byte ID) { byte qyt = 0; byte[] buffer = new byte[4]; ushort[] numArray = new ushort[4]; ushort[] numArray2 = new ushort[4]; ushort[] numArray3 = new ushort[4]; ushort[] numArray4 = new ushort[4]; uint address = 0; InfoPicture pic = new InfoPicture(); InfoCurveParam *curve_paramPtr; fixed(byte *px = &m_guiApp.CustomData[obj.AttributeStart]) curve_paramPtr = (InfoCurveParam *)px; InfoCurveChannelParam *[] curve_channel_paramPtrArray = new InfoCurveChannelParam *[4]; short x = 0; short num11 = 0; if (curve_paramPtr->ChannelCount <= 4) { byte num3; for (num3 = 0; num3 < curve_paramPtr->ChannelCount; num3++) { curve_channel_paramPtrArray[num3] = (InfoCurveChannelParam *)((((uint)curve_paramPtr) + sizeof(InfoCurveParam)) + (sizeof(InfoCurveChannelParam) * num3)); } byte num2 = 0; num3 = 0; while (num3 < curve_paramPtr->ChannelCount) { buffer[num3] = 1; numArray[num3] = curve_channel_paramPtrArray[num3]->BufNext; numArray3[num3] = curve_channel_paramPtrArray[num3]->DotLen; numArray4[num3] = numArray3[num3]; if (numArray3[num3] > 0) { num2 = (byte)(num2 + 1); } num3 = (byte)(num3 + 1); } if (num2 == 0) { CurveRefBack(ref obj, ID); } else { if (curve_paramPtr->BackType == 0) { qyt = 5; pic = m_runScreen.ReadInfoPicture(curve_paramPtr->PicID); address = pic.DataStart + m_guiApp.App.PictureImageStart; if (pic.IsPotrait == 1) { address += (uint)((((obj.Panel.Y + 1) * pic.W) - obj.Panel.X) * 2); } else { address += (uint)(((obj.Panel.Y * pic.W) + obj.Panel.X) * 2); } } else if (curve_paramPtr->BackType == 2) { qyt = 5; pic = m_runScreen.ReadInfoPicture(curve_paramPtr->PicID); address = pic.DataStart + m_guiApp.App.PictureImageStart; } else { x = (short)obj.Panel.X; num11 = (short)(x + curve_paramPtr->GridX); } for (short i = (short)obj.Panel.X; i <= obj.Panel.EndX; i = (short)(i + qyt)) { short endx = (short)((i + 5) - 1); if (endx > obj.Panel.EndX) { endx = (short)obj.Panel.EndX; } if (curve_paramPtr->BackType == 0) { if (pic.IsPotrait == 1) { address -= (uint)(qyt * 2); } m_runScreen.LCD_AreaSet((ushort)i, obj.Panel.Y, (ushort)endx, obj.Panel.EndY); m_runScreen.SendDataOffset(address, (ushort)(pic.W << 1), curve_paramPtr->Height, (byte)((endx - i) + 1)); if (pic.IsPotrait == 0) { address += (uint)(qyt * 2); } } else if (curve_paramPtr->BackType == 2) { if (pic.IsPotrait == 1) { address -= (uint)(qyt * 2); } m_runScreen.LCD_AreaSet((ushort)i, obj.Panel.Y, (ushort)endx, obj.Panel.EndY); m_runScreen.SendDataOffset(address, (ushort)(pic.W << 1), curve_paramPtr->Height, (byte)((endx - i) + 1)); if (pic.IsPotrait == 0) { address += (uint)(qyt * 2); } } else { short endy; short y; if (curve_paramPtr->GridX > 0) { ushort num14; ushort num15; if (i == x) { m_runScreen.LCD_AreaSet((ushort)i, obj.Panel.Y, (ushort)i, obj.Panel.EndY); m_runScreen.LCD_WR_POINT(curve_paramPtr->Height, curve_paramPtr->Griclr); num14 = (ushort)(i + 1); } else { num14 = (ushort)i; } if ((num14 + 5) >= num11) { num15 = (ushort)(num11 - 1); x = num11; num11 = (short)(num11 + curve_paramPtr->GridX); } else { num15 = (ushort)((num14 + 5) - 1); } qyt = (byte)((num15 - i) + 1); if ((i + qyt) > obj.Panel.EndX) { num15 = (ushort)endx; qyt = (byte)((endx - i) + 1); } if (curve_paramPtr->GridY > 0) { endy = (short)obj.Panel.EndY; while (endy > obj.Panel.Y) { y = (short)((endy - curve_paramPtr->GridY) + 1); if (y < obj.Panel.Y) { y = (short)obj.Panel.Y; } m_runScreen.LCD_AreaSet(num14, (ushort)y, num15, (ushort)endy); m_runScreen.LCD_WR_POINT((uint)(((num15 - num14) + 1) * (endy - y)), curve_paramPtr->BackColor); m_runScreen.LCD_WR_POINT((uint)((num15 - num14) + 1), curve_paramPtr->Griclr); endy = (short)(endy - curve_paramPtr->GridY); } } else { address = (uint)(curve_paramPtr->Height * ((num15 - num14) + 1)); m_runScreen.LCD_AreaSet(num14, obj.Panel.Y, num15, obj.Panel.EndY); m_runScreen.LCD_WR_POINT(address, curve_paramPtr->BackColor); } } else if (curve_paramPtr->GridY > 0) { for (endy = (short)obj.Panel.EndY; endy > obj.Panel.Y; endy = (short)(endy - curve_paramPtr->GridY)) { y = (short)((endy - curve_paramPtr->GridY) + 1); if (y < obj.Panel.Y) { y = (short)obj.Panel.Y; } m_runScreen.LCD_AreaSet((ushort)i, (ushort)y, (ushort)endx, (ushort)endy); qyt = (byte)((endx - i) + 1); m_runScreen.LCD_WR_POINT((uint)(qyt * (endy - y)), curve_paramPtr->BackColor); m_runScreen.LCD_WR_POINT(qyt, curve_paramPtr->Griclr); } } else { qyt = (byte)((endx - i) + 1); address = (uint)(curve_paramPtr->Height * ((endx - i) + 1)); m_runScreen.LCD_AreaSet((ushort)i, obj.Panel.Y, (ushort)endx, obj.Panel.EndY); m_runScreen.LCD_WR_POINT(address, curve_paramPtr->BackColor); } } num3 = 0; while (num3 < curve_paramPtr->ChannelCount) { if (numArray4[num3] > 0) { for (num2 = 0; num2 < qyt; num2 = (byte)(num2 + 1)) { byte num6; if (numArray[num3] == curve_channel_paramPtrArray[num3]->Begin) { numArray[num3] = (ushort)curve_channel_paramPtrArray[num3]->End; } else { numArray[num3] = (ushort)(numArray[num3] - 1); } if (numArray[num3] == curve_channel_paramPtrArray[num3]->Begin) { numArray2[num3] = (ushort)curve_channel_paramPtrArray[num3]->End; } else { numArray2[num3] = (ushort)(numArray[num3] - 1); } byte num5 = m_guiApp.CustomData[numArray[num3]]; byte num4 = m_guiApp.CustomData[numArray2[num3]]; if (buffer[num3] > 0) { num4 = num5; buffer[num3] = 0; } if (numArray4[num3] == 1) { num4 = num5; } if (num5 > num4) { num6 = (byte)((num5 - num4) + 1); m_runScreen.LCD_AreaSet((ushort)(i + num2), (ushort)(obj.Panel.EndY - num5), (ushort)(i + num2), (ushort)(obj.Panel.EndY - num4)); m_runScreen.LCD_WR_POINT(num6, curve_channel_paramPtrArray[num3]->Penclr); } else { num6 = (byte)((num4 - num5) + 1); m_runScreen.LCD_AreaSet((ushort)(i + num2), (ushort)(obj.Panel.EndY - num4), (ushort)(i + num2), (ushort)(obj.Panel.EndY - num5)); m_runScreen.LCD_WR_POINT(num6, curve_channel_paramPtrArray[num3]->Penclr); } numArray4[num3] = (ushort)(numArray4[num3] - 1); if (numArray4[num3] == 0) { break; } } } num3 = (byte)(num3 + 1); } } for (num3 = 0; num3 < curve_paramPtr->ChannelCount; num3 = (byte)(num3 + 1)) { if (curve_channel_paramPtrArray[num3]->DotLen == curve_paramPtr->Width) { curve_channel_paramPtrArray[num3]->BufFree = (ushort)((curve_paramPtr->BufLen - curve_paramPtr->Width) - (curve_channel_paramPtrArray[num3]->DotLen - numArray3[num3])); } } } curve_paramPtr->RefFlag = 0; } return(0); }
public unsafe byte GuiCurveRef(ref InfoObject obj, byte ID) { byte qyt = 0; byte[] buffer = new byte[4]; ushort[] numArray = new ushort[4]; ushort[] numArray2 = new ushort[4]; ushort[] numArray3 = new ushort[4]; ushort[] numArray4 = new ushort[4]; uint address = 0; InfoPicture pic = new InfoPicture(); InfoCurveParam* curve_paramPtr; fixed(byte* px = &m_guiApp.CustomData[obj.AttributeStart]) curve_paramPtr = (InfoCurveParam*)px; InfoCurveChannelParam*[] curve_channel_paramPtrArray = new InfoCurveChannelParam*[4]; short x = 0; short num11 = 0; if (curve_paramPtr->ChannelCount <= 4) { byte num3; for (num3 = 0; num3 < curve_paramPtr->ChannelCount; num3++) curve_channel_paramPtrArray[num3] = (InfoCurveChannelParam*)((((uint)curve_paramPtr) + sizeof(InfoCurveParam)) + (sizeof(InfoCurveChannelParam) * num3)); byte num2 = 0; num3 = 0; while (num3 < curve_paramPtr->ChannelCount) { buffer[num3] = 1; numArray[num3] = curve_channel_paramPtrArray[num3]->BufNext; numArray3[num3] = curve_channel_paramPtrArray[num3]->DotLen; numArray4[num3] = numArray3[num3]; if (numArray3[num3] > 0) { num2 = (byte)(num2 + 1); } num3 = (byte)(num3 + 1); } if (num2 == 0) { CurveRefBack(ref obj, ID); } else { if (curve_paramPtr->BackType == 0) { qyt = 5; pic = m_runScreen.ReadInfoPicture(curve_paramPtr->PicID); address = pic.DataStart + m_guiApp.App.PictureImageStart; if (pic.IsPotrait == 1) address += (uint)((((obj.Panel.Y + 1) * pic.W) - obj.Panel.X) * 2); else address += (uint)(((obj.Panel.Y * pic.W) + obj.Panel.X) * 2); } else if (curve_paramPtr->BackType == 2) { qyt = 5; pic = m_runScreen.ReadInfoPicture(curve_paramPtr->PicID); address = pic.DataStart + m_guiApp.App.PictureImageStart; } else { x = (short)obj.Panel.X; num11 = (short)(x + curve_paramPtr->GridX); } for (short i = (short)obj.Panel.X; i <= obj.Panel.EndX; i = (short)(i + qyt)) { short endx = (short)((i + 5) - 1); if (endx > obj.Panel.EndX) { endx = (short)obj.Panel.EndX; } if (curve_paramPtr->BackType == 0) { if (pic.IsPotrait == 1) address -= (uint)(qyt * 2); m_runScreen.LCD_AreaSet((ushort)i, obj.Panel.Y, (ushort)endx, obj.Panel.EndY); m_runScreen.SendDataOffset(address, (ushort)(pic.W << 1), curve_paramPtr->Height, (byte)((endx - i) + 1)); if (pic.IsPotrait == 0) address += (uint)(qyt * 2); } else if (curve_paramPtr->BackType == 2) { if (pic.IsPotrait == 1) address -= (uint)(qyt * 2); m_runScreen.LCD_AreaSet((ushort)i, obj.Panel.Y, (ushort)endx, obj.Panel.EndY); m_runScreen.SendDataOffset(address, (ushort)(pic.W << 1), curve_paramPtr->Height, (byte)((endx - i) + 1)); if (pic.IsPotrait == 0) address += (uint)(qyt * 2); } else { short endy; short y; if (curve_paramPtr->GridX > 0) { ushort num14; ushort num15; if (i == x) { m_runScreen.LCD_AreaSet((ushort)i, obj.Panel.Y, (ushort)i, obj.Panel.EndY); m_runScreen.LCD_WR_POINT(curve_paramPtr->Height, curve_paramPtr->Griclr); num14 = (ushort)(i + 1); } else num14 = (ushort)i; if ((num14 + 5) >= num11) { num15 = (ushort)(num11 - 1); x = num11; num11 = (short)(num11 + curve_paramPtr->GridX); } else num15 = (ushort)((num14 + 5) - 1); qyt = (byte)((num15 - i) + 1); if ((i + qyt) > obj.Panel.EndX) { num15 = (ushort)endx; qyt = (byte)((endx - i) + 1); } if (curve_paramPtr->GridY > 0) { endy = (short)obj.Panel.EndY; while (endy > obj.Panel.Y) { y = (short)((endy - curve_paramPtr->GridY) + 1); if (y < obj.Panel.Y) { y = (short)obj.Panel.Y; } m_runScreen.LCD_AreaSet(num14, (ushort)y, num15, (ushort)endy); m_runScreen.LCD_WR_POINT((uint)(((num15 - num14) + 1) * (endy - y)), curve_paramPtr->BackColor); m_runScreen.LCD_WR_POINT((uint)((num15 - num14) + 1), curve_paramPtr->Griclr); endy = (short)(endy - curve_paramPtr->GridY); } } else { address = (uint)(curve_paramPtr->Height * ((num15 - num14) + 1)); m_runScreen.LCD_AreaSet(num14, obj.Panel.Y, num15, obj.Panel.EndY); m_runScreen.LCD_WR_POINT(address, curve_paramPtr->BackColor); } } else if (curve_paramPtr->GridY > 0) { for (endy = (short)obj.Panel.EndY; endy > obj.Panel.Y; endy = (short)(endy - curve_paramPtr->GridY)) { y = (short)((endy - curve_paramPtr->GridY) + 1); if (y < obj.Panel.Y) { y = (short)obj.Panel.Y; } m_runScreen.LCD_AreaSet((ushort)i, (ushort)y, (ushort)endx, (ushort)endy); qyt = (byte)((endx - i) + 1); m_runScreen.LCD_WR_POINT((uint)(qyt * (endy - y)), curve_paramPtr->BackColor); m_runScreen.LCD_WR_POINT(qyt, curve_paramPtr->Griclr); } } else { qyt = (byte)((endx - i) + 1); address = (uint)(curve_paramPtr->Height * ((endx - i) + 1)); m_runScreen.LCD_AreaSet((ushort)i, obj.Panel.Y, (ushort)endx, obj.Panel.EndY); m_runScreen.LCD_WR_POINT(address, curve_paramPtr->BackColor); } } num3 = 0; while (num3 < curve_paramPtr->ChannelCount) { if (numArray4[num3] > 0) { for (num2 = 0; num2 < qyt; num2 = (byte)(num2 + 1)) { byte num6; if (numArray[num3] == curve_channel_paramPtrArray[num3]->Begin) numArray[num3] = (ushort)curve_channel_paramPtrArray[num3]->End; else numArray[num3] = (ushort)(numArray[num3] - 1); if (numArray[num3] == curve_channel_paramPtrArray[num3]->Begin) numArray2[num3] = (ushort)curve_channel_paramPtrArray[num3]->End; else numArray2[num3] = (ushort)(numArray[num3] - 1); byte num5 = m_guiApp.CustomData[numArray[num3]]; byte num4 = m_guiApp.CustomData[numArray2[num3]]; if (buffer[num3] > 0) { num4 = num5; buffer[num3] = 0; } if (numArray4[num3] == 1) num4 = num5; if (num5 > num4) { num6 = (byte)((num5 - num4) + 1); m_runScreen.LCD_AreaSet((ushort)(i + num2), (ushort)(obj.Panel.EndY - num5), (ushort)(i + num2), (ushort)(obj.Panel.EndY - num4)); m_runScreen.LCD_WR_POINT(num6, curve_channel_paramPtrArray[num3]->Penclr); } else { num6 = (byte)((num4 - num5) + 1); m_runScreen.LCD_AreaSet((ushort)(i + num2), (ushort)(obj.Panel.EndY - num4), (ushort)(i + num2), (ushort)(obj.Panel.EndY - num5)); m_runScreen.LCD_WR_POINT(num6, curve_channel_paramPtrArray[num3]->Penclr); } numArray4[num3] = (ushort)(numArray4[num3] - 1); if (numArray4[num3] == 0) break; } } num3 = (byte)(num3 + 1); } } for (num3 = 0; num3 < curve_paramPtr->ChannelCount; num3 = (byte)(num3 + 1)) { if (curve_channel_paramPtrArray[num3]->DotLen == curve_paramPtr->Width) { curve_channel_paramPtrArray[num3]->BufFree = (ushort)((curve_paramPtr->BufLen - curve_paramPtr->Width) - (curve_channel_paramPtrArray[num3]->DotLen - numArray3[num3])); } } } curve_paramPtr->RefFlag = 0; } return 0; }
private bool addPicture(int index) { Bitmap bm = new Bitmap(1, 1); int errors = 0; int loaded = 0; OpenFileDialog op = new OpenFileDialog { Multiselect = (index == 0xffff) ? true : false, Filter = "All files|*.*".Translate() }; Utility.SetInitialPath(op, "pic"); if (op.ShowDialog() != DialogResult.OK) { return(false); } Utility.SavePath(op, "pic"); InfoPicture infoPicture = new InfoPicture(); base.Visible = true; int numPicture = 1; foreach (string filename in op.FileNames) { label1.Text = "Converting Pictures".Translate() + numPicture.ToString(); numPicture++; Application.DoEvents(); bm = new Bitmap(1, 1); if (openPicture(ref bm, filename)) { ++loaded; byte[] buffer = new byte[bm.Width * bm.Height * 2]; int idx = 0; for (int iY = 0; iY < bm.Height; iY++) { ushort num; int iX; infoPicture.IsPotrait = (byte)(m_app.IsPotrait ? 1 : 0); if (m_app.IsPotrait) { for (iX = bm.Width - 1; iX >= 0; --iX) { if (bm.GetPixel(iX, iY).A == 0) { buffer[idx] = (byte)(HmiOptions.ColorTransparent % 0x100); buffer[idx + 1] = 0; } else { num = Utility.Get16Color(bm.GetPixel(iX, iY)); buffer[idx] = (byte)(num % 0x100); buffer[idx + 1] = (byte)(num / 0x100); if (buffer[idx] == HmiOptions.ColorTransparent && buffer[idx + 1] == 0) { buffer[idx] = (byte)HmiOptions.ColorTransparentReplace; } } idx += 2; } } else { for (iX = 0; iX < bm.Width; iX++) { if (bm.GetPixel(iX, iY).A == 0) { buffer[idx] = (byte)(HmiOptions.ColorTransparent % 0x100); buffer[idx + 1] = 0; } else { num = Utility.Get16Color(bm.GetPixel(iX, iY)); buffer[idx] = (byte)(num % 0x100); buffer[idx + 1] = (byte)(num / 0x100); if (buffer[idx] == HmiOptions.ColorTransparent && buffer[idx + 1] == 0) { buffer[idx] = (byte)HmiOptions.ColorTransparentReplace; } } idx += 2; } } } infoPicture.H = (ushort)bm.Height; infoPicture.Size = (uint)buffer.Length; infoPicture.W = (ushort)bm.Width; infoPicture.IsOne = 1; infoPicture.ShowTime = 0; infoPicture.SizeZi = infoPicture.Size; if (index == 0xffff) { m_app.Pictures.Add(infoPicture); m_app.PictureImages.Add(buffer); } else { if (index >= m_app.Pictures.Count) { return(false); } m_app.Pictures.Insert(index, infoPicture); m_app.PictureImages.Insert(index, buffer); } } else { errors++; } if (bm != null) { bm.Dispose(); } } if (errors == 0) { MessageBox.Show(string.Concat("Import successfully ".Translate(), loaded, " pieces".Translate())); } else { MessageBox.Show(string.Concat("Import successfully ".Translate(), loaded, " pieces, ERROR ".Translate(), errors)); } return(true); }
private bool addPicture(int index) { Bitmap bm = new Bitmap(1, 1); int errors = 0; int loaded = 0; OpenFileDialog op = new OpenFileDialog { Multiselect = (index == 0xffff) ? true : false, Filter = "All files|*.*".Translate() }; Utility.SetInitialPath(op, "pic"); if (op.ShowDialog() != DialogResult.OK) return false; Utility.SavePath(op, "pic"); InfoPicture infoPicture = new InfoPicture(); base.Visible = true; int numPicture = 1; foreach (string filename in op.FileNames) { label1.Text = "Converting Pictures".Translate() + numPicture.ToString(); numPicture++; Application.DoEvents(); bm = new Bitmap(1, 1); if (openPicture(ref bm, filename)) { ++loaded; byte[] buffer = new byte[bm.Width * bm.Height * 2]; int idx = 0; for (int iY = 0; iY < bm.Height; iY++) { ushort num; int iX; infoPicture.IsPotrait = (byte)(m_app.IsPotrait ? 1 : 0); if (m_app.IsPotrait) for (iX = bm.Width - 1; iX >= 0; --iX) { if (bm.GetPixel(iX, iY).A == 0) { buffer[idx] = (byte)(HmiOptions.ColorTransparent % 0x100); buffer[idx + 1] = 0; } else { num = Utility.Get16Color(bm.GetPixel(iX, iY)); buffer[idx] = (byte)(num % 0x100); buffer[idx + 1] = (byte)(num / 0x100); if (buffer[idx] == HmiOptions.ColorTransparent && buffer[idx + 1] == 0) buffer[idx] = (byte)HmiOptions.ColorTransparentReplace; } idx += 2; } else for (iX = 0; iX < bm.Width; iX++) { if (bm.GetPixel(iX, iY).A == 0) { buffer[idx] = (byte) (HmiOptions.ColorTransparent % 0x100); buffer[idx + 1] = 0; } else { num = Utility.Get16Color(bm.GetPixel(iX, iY)); buffer[idx] = (byte) (num % 0x100); buffer[idx + 1] = (byte) (num / 0x100); if (buffer[idx] == HmiOptions.ColorTransparent && buffer[idx + 1] == 0) buffer[idx] = (byte) HmiOptions.ColorTransparentReplace; } idx += 2; } } infoPicture.H = (ushort) bm.Height; infoPicture.Size = (uint) buffer.Length; infoPicture.W = (ushort) bm.Width; infoPicture.IsOne = 1; infoPicture.ShowTime = 0; infoPicture.SizeZi = infoPicture.Size; if (index == 0xffff) { m_app.Pictures.Add(infoPicture); m_app.PictureImages.Add(buffer); } else { if (index >= m_app.Pictures.Count) return false; m_app.Pictures.Insert(index, infoPicture); m_app.PictureImages.Insert(index, buffer); } } else errors++; if (bm != null) bm.Dispose(); } if (errors == 0) MessageBox.Show(string.Concat("Import successfully ".Translate(), loaded, " pieces".Translate())); else MessageBox.Show(string.Concat("Import successfully ".Translate(), loaded, " pieces, ERROR ".Translate(), errors)); return true; }
public bool SaveToFile(string binPath, bool compile, RichTextBox textCompile) { SaveToFileData data = new SaveToFileData(); StreamWriter writer = new StreamWriter(binPath); InfoApp infoApp = new InfoApp(); try { if (!prepareToSave(ref infoApp, compile, textCompile, data)) { textCompile.AddRichTextString( string.Concat( "Compile failure!".Translate(), " ", Errors, " Errors,".Translate(), " ", Warnings, " Warnings,".Translate() ), Color.Red); writer.Close(); writer.Dispose(); return(false); } infoApp.VersionMajor = HmiOptions.VersionMajor; infoApp.VersionMinor = HmiOptions.VersionMinor; infoApp.FileType = Utility.FileType(compile); byte[] buffer = Utility.ToBytes(infoApp); writer.BaseStream.Write(buffer, 0, HmiOptions.InfoAppSize); int idx; if (compile) { // Fill zeros to 4K boundary buffer = new byte[0x1000 - HmiOptions.InfoAppSize]; for (idx = 0; idx < buffer.Length; idx++) { buffer[idx] = 0; } writer.BaseStream.Write(buffer, 0, buffer.Length); } for (idx = 0; idx < Pictures.Count; idx++) { writer.BaseStream.Write(PictureImages[idx], 0, PictureImages[idx].Length); } for (idx = 0; idx < Fonts.Count; idx++) { writer.BaseStream.Write(FontImages[idx], 0, FontImages[idx].Length); } if (compile) { // Compile : int imgSize = (getPictureImagesSize() + getFontImagesSize()) % 0x1000; if (imgSize != 0) { buffer = new byte[0x1000 - imgSize]; for (idx = 0; idx < buffer.Length; idx++) { buffer[idx] = 0; } writer.BaseStream.Write(buffer, 0, buffer.Length); } } for (idx = 0; idx < data.m_infoStrings.Count; idx++) { writer.BaseStream.Write(data.m_stringDatas[idx], 0, data.m_stringDatas[idx].Length); } if (compile) { StreamReader reader = new StreamReader(Path.Combine(Application.StartupPath, "fwc.bin")); buffer = new byte[reader.BaseStream.Length]; reader.BaseStream.Position = 0L; reader.BaseStream.Read(buffer, 0, buffer.Length); writer.BaseStream.Write(buffer, 0, buffer.Length); reader.Close(); } for (idx = 0; idx < data.m_infoPages.Count; idx++) { buffer = Utility.ToBytes(data.m_infoPages[idx]); writer.BaseStream.Write(buffer, 0, HmiOptions.InfoPageSize); } for (idx = 0; idx < data.m_infoObjects.Count; idx++) { buffer = Utility.ToBytes(data.m_infoObjects[idx]); writer.BaseStream.Write(buffer, 0, HmiOptions.InfoObjectSize); } uint dataStart = 0; for (idx = 0; idx < infoApp.PictureCount; idx++) { InfoPicture picture = Pictures[idx]; picture.DataStart = dataStart; buffer = Utility.ToBytes(picture); writer.BaseStream.Write(buffer, 0, HmiOptions.InfoPictureSize); dataStart += (uint)PictureImages[idx].Length; } for (idx = 0; idx < infoApp.StringCount; idx++) { buffer = Utility.ToBytes(data.m_infoStrings[idx]); writer.BaseStream.Write(buffer, 0, HmiOptions.InfoStringSize); } dataStart = 0; for (idx = 0; idx < infoApp.FontCount; idx++) { InfoFont font = Fonts[idx]; font.DataOffset = dataStart; buffer = Utility.ToBytes(font); writer.BaseStream.Write(buffer, 0, HmiOptions.InfoFontSize); dataStart += (uint)FontImages[idx].Length; } writer.Close(); writer.Dispose(); textCompile.AddRichTextString( string.Concat( "Compile Success!".Translate(), " ", Errors, " Errors,".Translate(), " ", Warnings, " Warnings, FileSize:".Translate(), infoApp.FontDataStart ), Color.Black); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(false); }