public async override void OnTick() { baseHandledOnTick = false; base.OnTick(); if (!baseHandledOnTick) { if (String.IsNullOrEmpty(Settings.SceneName) || titleParameters == null) { return; } await Connection.SetTitleAsync(GraphicsTools.WrapStringToFitImage(Settings.SceneName, titleParameters)); if (!String.IsNullOrEmpty(Settings.SceneName) && !isFetchingScreenshot) { // Run in task due to possible long wait times _ = Task.Run(() => { try { isFetchingScreenshot = true; _ = DrawSceneBorder(); } catch (Exception ex) { Logger.Instance.LogMessage(TracingLevel.ERROR, $"SmartSceneSwitcherAction OnTick Exception: {ex}"); } finally { isFetchingScreenshot = false; } }); } } }
public MatchImageResult MatchImageFlipUpDown(Mat viewportMat, RECT viewportRect, Vec4f exRectRate, string exName, double threshold) { var exRectMat = viewportMat.GetChildMatByRectRate(exRectRate); var exImgMat = ConfigMgr.GetInstance().GetPCRExImg(exName, viewportMat, viewportRect); var exRectFlipMat = new Mat(); var exImgFlipMat = new Mat(); Cv2.Flip(exRectMat, exRectFlipMat, FlipMode.XY); Cv2.Flip(exImgMat, exImgFlipMat, FlipMode.XY); var flipMatchRes = GraphicsTools.GetInstance().MatchImage(exRectFlipMat, exImgFlipMat, threshold); var flipMatchedRect = flipMatchRes.MatchedRect; var rectWidth = exRectMat.Width; var rectHeight = exRectMat.Height; var matchRes = new MatchImageResult() { Success = flipMatchRes.Success, MatchedRect = new RECT() { x1 = rectWidth - flipMatchedRect.x2, y1 = rectHeight - flipMatchedRect.y2, x2 = rectWidth - flipMatchedRect.x1, y2 = rectHeight - flipMatchedRect.y1, } }; return(matchRes); }
private void pictureZXDisplay_MouseMove(object sender, MouseEventArgs e) { if (e.X < 0 || e.Y < 0) { return; } string numberFormat = this.hexNumbersToolStripMenuItem.Checked ? "#{0:X2}" : "{0}"; int Xcoor = (e.X + 1) / 2; int Ycoor = (e.Y + 1) / 2; if (!isSpriteViewType()) { ushort screenAdress = GraphicsTools.getScreenAdress(Xcoor, Ycoor); textBoxScreenAddress.Text = String.Format(numberFormat, screenAdress); ushort attributeAdress = GraphicsTools.getAttributeAdress(Xcoor, Ycoor); textBoxAttributeAddress.Text = String.Format(numberFormat, attributeAdress); if (this.hexNumbersToolStripMenuItem.Checked) { textBoxXCoorYCoor.Text = String.Format("#{0:X2}; #{1:X2}", Xcoor, Ycoor); textBoxBytesAtAdress.Text = String.Format("#{0:X2}", _spectrum.ReadMemory(screenAdress)); } else { textBoxXCoorYCoor.Text = String.Format("{0}; {1}", Xcoor, Ycoor); textBoxBytesAtAdress.Text = String.Format("{0}", _spectrum.ReadMemory(screenAdress)); } for (ushort memValue = (ushort)(screenAdress + 1); memValue < screenAdress + 5; memValue++) { textBoxBytesAtAdress.Text += "; " + String.Format(numberFormat, _spectrum.ReadMemory(memValue)); } } else if (comboDisplayType.SelectedIndex == 1) //only Sprite View for now...ToDo other view types, e.g. Jetpac type { int zoomFactor = (int)numericUpDownZoomFactor.Value; ushort addressPointer = Convert.ToUInt16(numericUpDownActualAddress.Value); int addressUnderCursorBase = addressPointer + (Convert.ToByte(comboSpriteWidth.SelectedItem) / 8) * (Ycoor) + (Xcoor / 8); //ToDo: zooming will crash this ! ushort addressUnderCursor = Convert.ToUInt16(addressUnderCursorBase > 0xFFFF ? addressUnderCursorBase - 0xFFFF: addressUnderCursorBase); //Sprite address textBoxSpriteAddress.Text = String.Format("#{0:X2}({1})", addressUnderCursor, addressUnderCursor); //Bytes at address textBoxSpriteBytes.Text = String.Format("#{0:X2}", _spectrum.ReadMemory(addressUnderCursor)); for (ushort memValue = (ushort)(addressUnderCursor + 1); memValue < addressUnderCursor + 5; memValue++) { textBoxSpriteBytes.Text += "; " + String.Format("#{0:X2}", _spectrum.ReadMemory(memValue)); } } if (comboDisplayType.SelectedIndex == 0 && _mouseSelectionArea != null) //for ScreenView only - update selection area if is cropping { _mouseSelectionArea.MouseMove(ref pictureZXDisplay, e); } }
/// <summary> /// Screen View type /// </summary> public void setZXScreenView() { if (_spectrum == null || m_instance == null) { return; } pictureZXDisplay.Width = ZX_SCREEN_WIDTH; pictureZXDisplay.Height = ZX_SCREEN_HEIGHT; bmpZXMonochromatic = new Bitmap(ZX_SCREEN_WIDTH / 2, ZX_SCREEN_HEIGHT / 2); ushort screenPointer = (ushort)numericUpDownActualAddress.Value; //Screen View for (int segments = 0; segments < 3; segments++) { for (int eightLines = 0; eightLines < 8; eightLines++) { //Cycle: Fill 8 lines in one segment for (int linesInSegment = 0; linesInSegment < 64; linesInSegment += 8) { // Cycle: all attributes in 1 line for (int attributes = 0; attributes < 32; attributes++) { byte blockByte = _spectrum.ReadMemory(screenPointer++); BitArray spriteBits = GraphicsTools.getAttributePixels(blockByte, m_instance.checkBoxMirror.Checked); if (spriteBits == null) { return; } // Cycle: fill 8 pixels for 1 attribute for (int pixels = 0; pixels < 8; pixels++) { if (spriteBits[pixels]) { bmpZXMonochromatic.SetPixel(pixels + (attributes * 8), linesInSegment + eightLines + (segments * 64), Color.Black); } else { bmpZXMonochromatic.SetPixel(pixels + (attributes * 8), linesInSegment + eightLines + (segments * 64), Color.White); } } } } } } // 3 segments of the ZX Screen //Size newSize = new Size((int)(pictureZXDisplay.Width), (int)(pictureZXDisplay.Height)); /*pictureZXDisplay.Image = bmpZXMonochromatic; * pictureZXDisplay.Width = ZX_SCREEN_WIDTH; * pictureZXDisplay.Height = ZX_SCREEN_HEIGHT;*/ Image resizedImage = bmpZXMonochromatic.GetThumbnailImage(ZX_SCREEN_WIDTH, ZX_SCREEN_HEIGHT, null, IntPtr.Zero); pictureZXDisplay.Image = resizedImage; pictureZXDisplay.SizeMode = PictureBoxSizeMode.StretchImage; }
private void ClearRandomChests() { foreach (GameObject go in _mChestList.Values) { GraphicsTools.ManualDestroyObject(go, false); } _mChestList.Clear(); }
/// <summary> /// /// </summary> /// <param name="viewportMat"></param> /// <param name="viewportRect"></param> /// <param name="exRectRate">采样区域</param> /// <param name="exName"></param> /// <returns></returns> public MatchImageResult MatchImage(Mat viewportMat, RECT viewportRect, Vec4f exRectRate, string exName, double threshold) { var exRectMat = viewportMat.GetChildMatByRectRate(exRectRate); var exImgMat = ConfigMgr.GetInstance().GetPCRExImg(exName, viewportMat, viewportRect); var matchRes = GraphicsTools.GetInstance().MatchImage(exRectMat, exImgMat, threshold); return(matchRes); }
private void MovePixels(byte i_mode) //0 => move left; 1 => move right { if (comboDisplayType.SelectedIndex == 1) //Sprite view only for now { //move pixels left int bytesToMoveLeft = (this.bitmapGridSpriteView.getGridWidth() / 8) * this.bitmapGridSpriteView.getGridHeight(); ushort screenPointer = (ushort)numericUpDownActualAddress.Value; //moving right to left int maxScreenByteToMove = (this.bitmapGridSpriteView.getGridWidth() / 8) * this.bitmapGridSpriteView.getGridHeight(); int spriteViewWidthInTokens = this.bitmapGridSpriteView.getGridWidth() / 8; bool isLastTokenInLine = false; for (int pixelPointer = 0; pixelPointer < maxScreenByteToMove; pixelPointer++) { bool setZeroBit; if (screenPointer <= 0xFFFF && this.bitmapGridSpriteView.getGridWidth() > 8) { setZeroBit = GraphicsTools.IsBitSet(_spectrum.ReadMemory((ushort)(screenPointer + 1)), 7); } else { setZeroBit = false; } isLastTokenInLine = ((pixelPointer + 1) % spriteViewWidthInTokens == 0); isLastTokenInLine = isLastTokenInLine && spriteViewWidthInTokens != 1 && pixelPointer != 0 && pixelPointer != maxScreenByteToMove; if (i_mode == 0) { byte actByte = (byte)(_spectrum.ReadMemory(screenPointer) << 1); //set bit 0(most right) if there is a sprite view bitmap size more than 8 pixels(continous scrolling) if (isLastTokenInLine == false && screenPointer + 1 <= 0xFFFF) { if (setZeroBit) { actByte |= 0x01; } } //move left _spectrum.WriteMemory(screenPointer, actByte); } else { //move right _spectrum.WriteMemory(screenPointer, (byte)(_spectrum.ReadMemory(screenPointer) >> 1)); } screenPointer++; //move to next byte } } else { Locator.Resolve <IUserMessage>().Info("This feature implemented only for Sprite view...Todo!"); } //Refresh setZXImage(); }
/// <inheritdoc/> public void DrawPixel(int x, int y, Color color) { var nativeColor = GraphicsTools.GetNativeColor(pixelFormat, color); SetPixel(x, y, nativeColor); if (autoUpdate) { Update(); } }
/// <inheritdoc/> public void DrawPixel(int x, int y, byte red, byte green, byte blue) { var nativeColor = GraphicsTools.GetNativeColor(pixelFormat, red, green, blue); SetPixel(x, y, nativeColor); if (autoUpdate) { Update(); } }
private async Task InitDisplayAsync() { // Allocate buffers var bytesPerPixel = GraphicsTools.GetBitsPerPixel(pixelFormat) / 8; displayBuffer = new byte[Width * Height * bytesPerPixel]; // displayBuffer = new byte[Width * Height * 3]; // Hardware Reset resetPin.Write(GpioPinValue.High); await Task.Delay(500); resetPin.Write(GpioPinValue.Low); await Task.Delay(500); resetPin.Write(GpioPinValue.High); await Task.Delay(500); // Which display type? switch (displayType) { case ST7735DisplayType.B: await InitDisplayBAsync(); break; case ST7735DisplayType.R: case ST7735DisplayType.RBlack: case ST7735DisplayType.RGreen: case ST7735DisplayType.RGreen144: case ST7735DisplayType.RRed: await InitDisplayRAsync(); break; default: throw new InvalidOperationException(string.Format(Strings.UnknownDisplayType, displayType)); } // Breathe await Task.Delay(10); // If the orientation is not portrait we need to update orientation if (orientation != DisplayOrientations.Portrait) { // Set orientation, do not flip // Note, this also reverts to RAM mode when done SetOrientation(false); } // Set address window to full size of the display // Note, this also reverts to RAM mode when done SetAddressWindow(0, 0, (byte)(width - 1), (byte)(height - 1)); }
public void DestroyRandomChest(int chestID) { GameObject go = null; if (_mChestList.TryGetValue(chestID, out go)) { GraphicsTools.ManualDestroyObject(go, false); _mChestList.Remove(chestID); } // Globals.Instance.MGUIManager.GetGUIWindow<GUIMain>().UpdateCopyChestShow(_mChestList.Count); }
public void setBitmapBits(IDebuggable i_spectrum, ushort i_startAddress) { int gridBytes = X_BIT_COUNT / 8 * Y_BIT_COUNT; _gridBits = new BitArray[gridBytes]; for (int counter = 0; counter < gridBytes; counter++) { byte blockByte = i_spectrum.ReadMemory(i_startAddress++); _gridBits[counter] = GraphicsTools.getAttributePixels(blockByte, false); } }
protected virtual void InitIndicator() { if (null == _IndicatorEffect) { _IndicatorEffect = GraphicsTools.ManualCreateObject("TempArtist/Prefab/Particle/S_Point", "Indicator", true); } // if (null == _mRoute) // { // _mRoute = GraphicsTools.ManualCreateObject("Common/Route", "Route"); // } }
private void TmrPage_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (String.IsNullOrEmpty(currentPageInitialColor)) { Logger.Instance.LogMessage(TracingLevel.WARN, "TmrPage: No alert color, reverting to default"); currentPageInitialColor = DEFAULT_ALERT_COLOR; } Color shadeColor = GraphicsTools.GenerateColorShades(currentPageInitialColor, alertStage, Constants.ALERT_TOTAL_SHADES); FlashStatusChanged?.Invoke(this, new FlashStatusEventArgs(shadeColor, pageMessage)); alertStage = (alertStage + 1) % Constants.ALERT_TOTAL_SHADES; }
//ContextMenuExportBitmap private void SaveBitmapAs(ImageFormat i_imgFormat) { string fileName = @"image_export."; int zoomFactor = Convert.ToByte(numericUpDownZoomFactor.Value); int bitmapWidth = this.bitmapGridSpriteView.getGridWidth() * zoomFactor; int bitmapHeight = this.bitmapGridSpriteView.getGridHeight() * zoomFactor; if (i_imgFormat == null) { byte[] arrSprite = GraphicsTools.GetBytesFromBitmap(this.bitmapGridSpriteView); SaveScreenBytes(arrSprite, this.bitmapGridSpriteView.getGridWidth() / 8, this.bitmapGridSpriteView.getGridHeight()); return; } else { if (i_imgFormat == ImageFormat.Png) { fileName += "png"; } else if (i_imgFormat == ImageFormat.Jpeg) { fileName += "jpg"; } else if (i_imgFormat == ImageFormat.Bmp) { fileName += "bmp"; } else { Locator.Resolve <IUserMessage>().Error("Invalid format to save!"); return; } } string filePath = Path.Combine(Utils.GetAppFolder(), fileName); if (File.Exists(filePath)) { File.Delete(filePath); } //save cropped bitmap Bitmap bmp = pictureZXDisplay.Image as Bitmap; Bitmap cloneBitmap = bmp.Clone(new Rectangle(0, 0, bitmapWidth, bitmapHeight), bmp.PixelFormat); cloneBitmap.Save(filePath, i_imgFormat); Locator.Resolve <IUserMessage>().Info(String.Format("File '{0}' saved to root app directory!", fileName)); }
protected virtual GameObject CreateRandomChest(int chestID) { GameObject go = GraphicsTools.ManualCreateObject("TempArtist/Prefab/Build/m_other_box", "Chest" + chestID.ToString(), true); ChestTrigger trigger = go.AddComponent <ChestTrigger>() as ChestTrigger; trigger.ChestID = chestID; int index = Random.Range(0, _mChestPosList.Length); go.transform.position = _mChestPosList[index]; _mChestList.Add(chestID, go); // Globals.Instance.MGUIManager.GetGUIWindow<GUIMain>().UpdateCopyChestShow(_mChestList.Count); return(go); }
protected virtual void ClearIndicator() { if (null != _IndicatorEffect) { GraphicsTools.ManualDestroyObject(_IndicatorEffect, true); _IndicatorEffect = null; } // if (null != _mRoute) // { // GraphicsTools.ManualDestroyObject(_mRoute); // _mRoute = null; // } }
private void TmrPage_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (autoStopPage > 0 && (DateTime.Now - pageStartTime).TotalSeconds > autoStopPage) { Logger.Instance.LogMessage(TracingLevel.INFO, $"Auto stopping page after {(DateTime.Now - pageStartTime).TotalSeconds} seconds"); isPaging = false; pageMessage = null; return; } using (Bitmap img = Tools.GenerateGenericKeyImage(out Graphics graphics)) { int height = img.Height; int width = img.Width; // Background var bgBrush = new SolidBrush(GraphicsTools.GenerateColorShades(Settings.AlertColor, alertStage, Constants.ALERT_TOTAL_SHADES)); graphics.FillRectangle(bgBrush, 0, 0, width, height); if (String.IsNullOrEmpty(pageMessage)) { Connection.SetImageAsync(img); } else { using (Font font = new Font("Verdana", 26, FontStyle.Bold, GraphicsUnit.Pixel)) { var fgBrush = Brushes.White; SizeF stringSize = graphics.MeasureString(pageMessage, font); float stringPos = 0; float stringHeight = Math.Abs((height - stringSize.Height)) / 2; if (stringSize.Width < width) { stringPos = Math.Abs((width - stringSize.Width)) / 2; } else // Move to multi line { stringHeight = 0; pageMessage = Tools.SplitStringToFit(pageMessage, new BarRaider.SdTools.Wrappers.TitleParameters(font.FontFamily, font.Style, font.Size, Color.White, true, BarRaider.SdTools.Wrappers.TitleVerticalAlignment.Top), imageWidthPixels: width); } graphics.DrawString(pageMessage, font, fgBrush, new PointF(stringPos, stringHeight)); Connection.SetImageAsync(img); } } alertStage = (alertStage + 1) % Constants.ALERT_TOTAL_SHADES; graphics.Dispose(); } }
public void ShowZoomedSelectionArea() { if (_mouseSelectionArea == null) { return; } //show selected area preview int width = _mouseSelectionArea.getCroppedArea().Width / 2; int height = _mouseSelectionArea.getCroppedArea().Height / 2; Bitmap croppedArea = GraphicsTools.GetBitmapCroppedArea(bmpZXMonochromatic, new Point(_mouseSelectionArea.getCroppedArea().X / 2, _mouseSelectionArea.getCroppedArea().Y / 2), new Size(width, height)); pictureZoomedArea.Image = croppedArea; }
private void ClearScreen(Color col) { var color = (ushort)GraphicsTools.GetNativeColor(pixelFormat, col); var high = (byte)(color >> 8); var low = (byte)color; var index = 0; displayBuffer[index++] = high; displayBuffer[index++] = low; displayBuffer[index++] = high; displayBuffer[index++] = low; displayBuffer[index++] = high; displayBuffer[index++] = low; displayBuffer[index++] = high; displayBuffer[index++] = low; displayBuffer[index++] = high; displayBuffer[index++] = low; displayBuffer[index++] = high; displayBuffer[index++] = low; displayBuffer[index++] = high; displayBuffer[index++] = low; displayBuffer[index++] = high; displayBuffer[index++] = low; Array.Copy(displayBuffer, 0, displayBuffer, 16, 16); Array.Copy(displayBuffer, 0, displayBuffer, 32, 32); Array.Copy(displayBuffer, 0, displayBuffer, 64, 64); Array.Copy(displayBuffer, 0, displayBuffer, 128, 128); Array.Copy(displayBuffer, 0, displayBuffer, 256, 256); index = 512; var line = 0; var Half = Height / 2; while (++line < Half - 1) { Array.Copy(displayBuffer, 0, displayBuffer, index, 256); index += 256; } Array.Copy(displayBuffer, 0, displayBuffer, index, displayBuffer.Length / 2); if (autoUpdate) { Update(); } }
private Image getTileViewImage() { byte spriteWidth = Convert.ToByte(comboSpriteWidth.SelectedItem); //byte spriteHeight; ushort screenPointer = (ushort)numericUpDownActualAddress.Value; if (_spectrum == null || m_instance == null) { return(null); } Bitmap bmpSpriteView = new Bitmap(spriteWidth, ZX_SCREEN_HEIGHT); for (int YPointerShift = 0; YPointerShift < ZX_SCREEN_HEIGHT; YPointerShift += 8) { for (int XPointerShift = 0; XPointerShift < spriteWidth; XPointerShift += 8) { //draw one tile for (int line = 0; line < 8; line++) { BitArray spriteBits = GraphicsTools.getAttributePixels(_spectrum.ReadMemory(screenPointer++), m_instance.checkBoxMirror.Checked); if (spriteBits == null) { return(null); } // Cycle: fill 8 pixels for 1 attribute for (int pixelBit = 7; pixelBit > -1; pixelBit--) { if (spriteBits[pixelBit]) { bmpSpriteView.SetPixel(pixelBit + XPointerShift, line + YPointerShift, Color.Black); } else { bmpSpriteView.SetPixel(pixelBit + XPointerShift, line + YPointerShift, Color.White); } } } } } byte spriteZoomFactor = Convert.ToByte(numericUpDownZoomFactor.Value); Image resizedImage = bmpSpriteView.GetThumbnailImage(spriteWidth * spriteZoomFactor, (spriteWidth * spriteZoomFactor * bmpSpriteView.Height) / bmpSpriteView.Width, null, IntPtr.Zero); return(resizedImage); }
private void TmrPage_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (autoStopSeconds > 0 && (DateTime.Now - pageStartTime).TotalSeconds > autoStopSeconds) { Logger.Instance.LogMessage(TracingLevel.INFO, $"Auto stopping page after {(DateTime.Now - pageStartTime).TotalSeconds} seconds"); StopFlashAndReset(); connection.SwitchProfileAsync(null); return; } if (String.IsNullOrEmpty(currentPageInitialColor)) { Logger.Instance.LogMessage(TracingLevel.WARN, "TmrPage: No alert color, reverting to default"); currentPageInitialColor = DEFAULT_ALERT_COLOR; } Color shadeColor = GraphicsTools.GenerateColorShades(currentPageInitialColor, alertStage, Constants.ALERT_TOTAL_SHADES); FlashStatusChanged?.Invoke(this, new FlashStatusEventArgs(shadeColor, pageMessage)); alertStage = (alertStage + 1) % Constants.ALERT_TOTAL_SHADES; }
private void TmrPage_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { Bitmap img = Tools.GenerateKeyImage(deviceType, out Graphics graphics); int height = Tools.GetKeyDefaultHeight(deviceType); int width = Tools.GetKeyDefaultWidth(deviceType); // Background var bgBrush = new SolidBrush(GraphicsTools.GenerateColorShades(Settings.AlertColor, alertStage, Constants.ALERT_TOTAL_SHADES)); graphics.FillRectangle(bgBrush, 0, 0, width, height); if (String.IsNullOrEmpty(pageMessage)) { Connection.SetImageAsync(img); } else { var font = new Font("Verdana", 11, FontStyle.Bold); var fgBrush = Brushes.White; SizeF stringSize = graphics.MeasureString(pageMessage, font); float stringPos = 0; float stringHeight = Math.Abs((height - stringSize.Height)) / 2; if (stringSize.Width < width) { stringPos = Math.Abs((width - stringSize.Width)) / 2; } else // Move to multi line { stringHeight = 0; pageMessage = pageMessage.Replace(" ", "\n"); } graphics.DrawString(pageMessage, font, fgBrush, new PointF(stringPos, stringHeight)); Connection.SetImageAsync(img); } alertStage = (alertStage + 1) % Constants.ALERT_TOTAL_SHADES; graphics.Dispose(); }
private void bitmapGridSpriteView_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { int clickedPixel = bitmapGridSpriteView.getClickedPixel(e); int temp = (int)numericUpDownActualAddress.Value + clickedPixel / 8; if (temp > 0xFFFF) { temp -= 0xFFFF; } UInt16 bitToToggleAddress = Convert.ToUInt16(temp); if (bitToToggleAddress < 0x4000) { return; //cannot change ROM } byte memValue = _spectrum.ReadMemory(bitToToggleAddress); memValue = (byte)GraphicsTools.ToggleBit(memValue, clickedPixel % 8); _spectrum.WriteMemory(Convert.ToUInt16(bitToToggleAddress), memValue); setZXImage(); //refresh } }
private void DrawCollider() { if (null != _mDrawGameObj) { DestroyImmediate(_mDrawGameObj); _mDrawGameObj = null; } if (!isDraw) { return; } switch (colliderStyle) { case ColliderStyle.BOX: { // Gizmos.DrawWireCube(center, boxSize); break; } case ColliderStyle.SPHERE: { _mDrawGameObj = GraphicsTools.DrawDottedCircle(center, radius, 6, lineWidth, lineWidth); // Gizmos.DrawWireSphere(center, radius); break; } case ColliderStyle.MESH: { break; } } _mDrawGameObj.transform.parent = gameObject.transform; _mDrawGameObj.transform.localPosition += new Vector3(0.0f, 0.0f, 0.0f); }
private void buttonExportSelectionArea_Click(object sender, EventArgs e) { //export selection area to picture or bytes if (_mouseSelectionArea == null || _mouseSelectionArea.isSelected() == false) { return; } int width = _mouseSelectionArea.getCroppedArea().Width / 2; int height = _mouseSelectionArea.getCroppedArea().Height / 2; Bitmap croppedArea = GraphicsTools.GetBitmapCroppedArea(bmpZXMonochromatic, new Point(_mouseSelectionArea.getCroppedArea().X / 2, _mouseSelectionArea.getCroppedArea().Y / 2), new Size(width, height)); if (croppedArea == null) { Locator.Resolve <IUserMessage>().Warning("Could not get cropped area...nothing done!"); return; } byte[] arrScreenBytes = GraphicsTools.GetBytesFromBitmap(croppedArea); SaveScreenBytes(arrScreenBytes, width, height); //croppedArea.Save(@"image_export_cropped.bmp"); }
public void DestroyChest(GameObject go) { chestObjs.Remove(go); GraphicsTools.ManualDestroyObject(go, false); }
protected virtual void OnBattleEnd_impl(GameData.BattleGameData.BattleResult battleResult) { // Resume the camera Globals.Instance.MSceneManager.mMainCamera.transform.position = _mCurrentCamPos; Globals.Instance.MSceneManager.mMainCamera.transform.forward = _mCurrentCamForward; // resume trigger battle, and close Input SetEnabled(true); SetFingerEventActive(true); _mIsPermitRequestBattle = true; // Clear ReinforcementData Globals.Instance.MGameDataManager.MActorData.RemoveReinforcementData(); Vector3 monsterPos = Vector3.zero; switch (battleResult.BattleWinResult) { // Actor win case GameData.BattleGameData.EBattleWinResult.ACTOR_WIN: { // Destroy the guide DestroyGuideArrows(_mFightingMonsterFleet); // Destroy the failed Fleet according to BattleResult monsterPos = _mFightingMonsterFleet.Position; _mMonsterFleetList.Remove(_mFightingMonsterFleet); Globals.Instance.MPlayerManager.RemoveMonsterFleet(_mFightingMonsterFleet); _mFightingMonsterFleet = null; // Create a random chest if (battleResult.ChestID != -1) { GameObject go = CreateRandomChest(battleResult.ChestID); go.transform.position = monsterPos; } // Single Drap information OnceBattleFinish(); break; } // Dogfall case GameData.BattleGameData.EBattleWinResult.DOGFALL: { // Destroy the guide DestroyGuideArrows(_mFightingMonsterFleet); // Destroy the failed Fleet according to BattleResult monsterPos = _mFightingMonsterFleet.Position; _mMonsterFleetList.Remove(_mFightingMonsterFleet); Globals.Instance.MPlayerManager.RemoveMonsterFleet(_mFightingMonsterFleet); _mFightingMonsterFleet = null; // Create a random chest if (battleResult.ChestID != -1) { GameObject go = CreateRandomChest(battleResult.ChestID); go.transform.position = monsterPos; } break; } // Monster win case GameData.BattleGameData.EBattleWinResult.MONSTER_WIN: { // tzz added // move the warship by monster collider bounds to avoid the fight immedately again // Vector3 t_monsterSize = _mFightingMonsterFleet.m_battleTrigger.GetComponent <Collider>().bounds.size; // increase some distance t_monsterSize.x += 50; // get the own actor ship position Vector3 t_ownPos = Vector3.zero; foreach (WarshipL ws in _mActorFleet._mWarshipList) { t_ownPos = ws.U3DGameObject.transform.position; break; } // monster(Enemy) position Vector3 t_monsterPos = _mFightingMonsterFleet.m_copyStatusGameObject.transform.position; // actor direct back position Vector3 t_direclyBackPos = t_monsterPos + ((t_ownPos - t_monsterPos).normalized * t_monsterSize.x); Vector2[] t_restPos = { new Vector2(t_direclyBackPos.x, t_direclyBackPos.z), new Vector2(t_monsterPos.x + t_monsterSize.x, t_monsterPos.z), new Vector2(t_monsterPos.x - t_monsterSize.x, t_monsterPos.z), new Vector2(t_monsterPos.x, t_monsterPos.z + t_monsterSize.x), new Vector2(t_monsterPos.x, t_monsterPos.z - t_monsterSize.x), }; foreach (Vector2 pos in t_restPos) { if (crossArea.Contains(pos)) { // rest position is in the cross Area // foreach (WarshipL ws in _mActorFleet._mWarshipList) { ws.ForceMoveTo(new Vector3(pos.x, t_ownPos.y, pos.y)); } break; } } Statistics.INSTANCE.CustomEventCall(Statistics.CustomEventType.FailedCopyBattle, "CopyID", Globals.Instance.MGameDataManager.MCurrentCopyData.MCopyBasicData.CopyID); break; } } // Flush ship life Dictionary <long, GirlData> dictWarshipData = Globals.Instance.MGameDataManager.MActorData.GetWarshipDataList(); List <GameData.BattleGameData.WarshipBattleEndCurrLife> listWarshipLife = GameStatusManager.Instance.MBattleStatus.MBattleResult.ListWarshipBattleEndCurrLife; foreach (GameData.BattleGameData.WarshipBattleEndCurrLife warshipLife in listWarshipLife) { if (dictWarshipData.ContainsKey(warshipLife.ShipID)) { dictWarshipData[warshipLife.ShipID].PropertyData.Life = warshipLife.ShipCurrLife; } } // Globals.Instance.MGameDataManager.MActorData.NotifyWarshipUpdate(); Debug.Log("copystatas"); Globals.Instance.M3DItemManager.PlayBattleEffect(battleResult, delegate(){ Globals.Instance.MGUIManager.CreateWindow <GUISingleDrop>(delegate(GUISingleDrop gui) { gui.UpdateData(); }); }); if (battleResult.IsFinalBattle) { _mIsFinalBattle = true; GameObject go = GraphicsTools.ManualCreateObject("TempArtist/Prefab/Particle/S_LeaveCopy", "LeaveTrigger", false); float y = go.transform.position.y; LeaveCopyTrigger trigger = go.AddComponent <LeaveCopyTrigger>() as LeaveCopyTrigger; go.transform.position = new Vector3(monsterPos.x, y, monsterPos.z); go.transform.localScale = Vector3.one; mLeaveTrigger = go.transform.position; // DisplayCopyDrops(); } }
private async void DrawKey(CovidCountryStats stats) { const int ICON_STARTING_X = 3; const int TEXT_PADDING_Y = 3; const int TEXT_PADDING_X = 40; const int ICON_SIZE_PIXELS = 35; const int COUNTRY_NAME_PADDING_Y = 10; if (stats == null) { return; } if ((DateTime.Now - lastStageChange).TotalSeconds >= STAGE_CHANGE_SECONDS) { lastStageChange = DateTime.Now; currentStage = (currentStage + 1) % TOTAL_STAGES; } if (!long.TryParse(stats.Deaths, out long deaths) || !long.TryParse(stats.Cases, out long allCases)) { Logger.Instance.LogMessage(TracingLevel.WARN, $"CoronavirusCountryStatsAction > Could not convert deaths/all cases to integer Deaths: {stats.Deaths} Case: {stats.Cases}"); return; } // Get the recovery rate as a percentage double recoveryRate = (1 - ((double)deaths / (double)allCases)) * 100; using (Bitmap img = Tools.GenerateGenericKeyImage(out Graphics graphics)) { graphics.PageUnit = GraphicsUnit.Pixel; int height = img.Height; int width = img.Width; float heightPosition = 10; string text; if (settings.ShowFlag && stats.Info != null && !String.IsNullOrEmpty(stats.Info.FlagURL)) { using (Bitmap flag = FetchImage(stats.Info.FlagURL)) { if (flag != null) { float opacity = flagOpacity / 100f; using (Image opacityFlag = GraphicsTools.CreateOpacityImage(flag, opacity)) { graphics.DrawImage(opacityFlag, 0, 0, img.Width, img.Height); } } } } var font = new Font("Verdana", 23, FontStyle.Bold, GraphicsUnit.Pixel); var fontRecoveryTitle = new Font("Verdana", 20, FontStyle.Bold, GraphicsUnit.Pixel); var fontRecovery = new Font("Verdana", 30, FontStyle.Bold, GraphicsUnit.Pixel); Bitmap icon; float stringWidth = graphics.GetTextCenter(stats.Name, width, font, 0); heightPosition = graphics.DrawAndMeasureString(stats.Name, font, Brushes.White, new PointF(stringWidth, heightPosition)); heightPosition += COUNTRY_NAME_PADDING_Y; float widthPosition = 0; switch (currentStage) { case 0: // All Cases /* * using (icon = IconChar.Ambulance.ToBitmap(height, Color.Gray)) * { * text = $"{Utils.FormatNumber(allCases)}\n({stats.TodayCases})"; * widthPosition = Utils.CenterText(text, width, font, graphics); * using (Image opacityIcon = Utils.SetImageOpacity(icon, 0.5f)) * { * graphics.DrawImage(opacityIcon, new PointF(0, COUNTRY_NAME_PADDING_Y)); * } * heightPosition = Utils.DrawStringOnGraphics(graphics, text, font, Brushes.Orange, new PointF(widthPosition, heightPosition + TEXT_PADDING_Y)); * } */ using (icon = IconChar.Ambulance.ToBitmap(ICON_SIZE_PIXELS, Color.Orange)) { text = $"{Tools.FormatNumber(allCases)}"; widthPosition = graphics.GetTextCenter(text, width, font); widthPosition -= ((ICON_SIZE_PIXELS + ICON_STARTING_X) / 2); // Add room for the icon graphics.DrawImage(icon, new PointF(widthPosition, (int)heightPosition)); heightPosition = graphics.DrawAndMeasureString(text, font, Brushes.Orange, new PointF(widthPosition + ICON_SIZE_PIXELS + ICON_STARTING_X, heightPosition + TEXT_PADDING_Y)); text = $"({stats.TodayCases})"; widthPosition = graphics.GetTextCenter(text, width, font); heightPosition = graphics.DrawAndMeasureString(text, font, Brushes.Orange, new PointF(widthPosition, heightPosition)); } break; case 1: // Deaths using (icon = IconChar.SkullCrossbones.ToBitmap(ICON_SIZE_PIXELS, Color.Red)) { text = $"{Tools.FormatNumber(deaths)}"; widthPosition = graphics.GetTextCenter(text, width, font); widthPosition -= ((ICON_SIZE_PIXELS + ICON_STARTING_X) / 2); // Add room for the icon graphics.DrawImage(icon, new PointF(widthPosition, (int)heightPosition)); heightPosition = graphics.DrawAndMeasureString(text, font, Brushes.Red, new PointF(widthPosition + ICON_SIZE_PIXELS + ICON_STARTING_X, heightPosition + TEXT_PADDING_Y)); text = $"({ stats.TodayDeaths})"; widthPosition = graphics.GetTextCenter(text, width, font); heightPosition = graphics.DrawAndMeasureString(text, font, Brushes.Red, new PointF(widthPosition, heightPosition)); } break; case 2: // Recovery text = "Recovered:"; widthPosition = graphics.GetTextCenter(text, width, font, 3); heightPosition = graphics.DrawAndMeasureString(text, fontRecoveryTitle, Brushes.Green, new PointF(widthPosition, heightPosition)); // Put percentage exactly in middle text = $"{(int)recoveryRate}%"; widthPosition = graphics.GetTextCenter(text, width, fontRecovery, ICON_STARTING_X); graphics.DrawAndMeasureString(text, fontRecovery, Brushes.Green, new PointF(widthPosition, heightPosition)); break; } await Connection.SetImageAsync(img); graphics.Dispose(); } }
private void btnOpenFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Text Document File(*.txt)|*.txt|All File(*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { try { // enable button findpath va button save image this.btnFindPath.Enabled = true; this.btnSaveImage.Enabled = true; // reset control values this.cboFrom.Items.Clear(); this.cboTo.Items.Clear(); this.lvMatrix.Items.Clear(); this.lvMatrix.Columns.Clear(); this.txtResult.Clear(); this.picGraphics.Image = null; // Matrix m = new Matrix(); // this.FileName = ofd.FileName; this.Adjacent = m.LoadFile(this.FileName, this.lvMatrix, this.cboFrom, this.cboTo); this.cboFrom.SelectedIndex = 0; this.cboTo.SelectedIndex = 1; this.Vertices = m.Vertices; this.g = new GraphicsTools(this.picGraphics.Width, this.picGraphics.Height);// khoi tao graphics tool // lay danh sach toa do cac dinh this.lstPointVertices = new Vector2D(this.Vertices, this.picGraphics.Width - frmMain.PicturePadding, this.picGraphics.Height - frmMain.PicturePadding).getRandomPoint(); // tao bitmap do thi voi danh sach ke va danh sach toa cac dinh this.picGraphics.Image = this.g.CreateGraphics(this.Adjacent, this.lstPointVertices); } catch (Exception EX) { MessageBox.Show(EX.Message, "Error"); } } ofd.Dispose(); }
public override void Initialize() { // Get the FingerEvent Component, Register FingerEventListener Globals.Instance.MFingerEvent.Add3DEventListener(this); SetFingerEventActive(true); mFormerCameraPos = Globals.Instance.MSceneManager.mMainCamera.transform.position; mFormerCameraEular = Globals.Instance.MSceneManager.mMainCamera.transform.eulerAngles; // find the right dock position // GameObject port = GameObject.Find("Scene/m_other_Wharf"); if (port == null) { throw new System.Exception("GameObject.Find(\"Scene/m_other_Wharf\") == null"); } Transform cameraPos = port.transform.Find("CameraPostion"); Globals.Instance.MSceneManager.mMainCamera.transform.position = cameraPos.position; Globals.Instance.MSceneManager.mMainCamera.transform.eulerAngles = cameraPos.eulerAngles; // find the right dock warship position // mPlayerDockPos.Clear(); int index = 1; while (index < 10) { Transform pos = port.transform.Find("postion0" + index); if (pos == null) { break; } mPlayerDockPos.Insert(0, pos.position); index++; } // open the GUIPlayerDock // GUIRadarScan.Show(); bool playerDockState = GameStatusManager.Instance.EnterPKBattleByPlayerDock; //Globals.Instance.MGUIManager.CreateWindow<GUIPlayerDock>(delegate(GUIPlayerDock gui){ // // if(playerDockState){ // ShowPlayerWarship(mCurrPageIndex); // }else{ // NetSender.Instance.RequestPlayerDock(); // } //}); // create the selected player effect // if (mSelectedEffect == null) { mSelectedEffect = GraphicsTools.ManualCreateObject("TempArtist/Prefab/Particle/S_Point", "Indicator", true);; mSelectedEffect.SetActiveRecursively(false); } }