public IBrush LoadLinearBrush(AGS.API.Point point1, AGS.API.Point point2, AGS.API.Color color1, AGS.API.Color color2) { var paint = AndroidBrush.CreateTextPaint(); LinearGradient gradient = new LinearGradient (point1.X, point1.Y, point2.X, point2.Y, color1.Convert(), color2.Convert(), Shader.TileMode.Clamp); paint.SetShader(gradient); return new AndroidBrush (paint); }
public void SetProperties(AGS.API.SizeF baseSize, string text = null, ITextConfig config = null, int? maxWidth = null, int caretPosition = 0, bool renderCaret = false, bool? cropText = null) { bool changeNeeded = (text != null && text != _text) || (config != null && config != _config) || (maxWidth != null && maxWidth.Value != _maxWidth) || !baseSize.Equals(_baseSize) || _caretPosition != caretPosition || _renderCaret != renderCaret || (cropText != null && cropText.Value != _cropText); if (!changeNeeded) return; _text = text; if (config != null && config != _config) { _config = config; _spaceWidth = measureSpace(); } if (maxWidth != null) _maxWidth = maxWidth.Value; if (cropText != null) _cropText = cropText.Value; _baseSize = baseSize; _caretPosition = caretPosition; _renderCaret = renderCaret; drawToBitmap(); }
public void Tick (IViewport viewport, AGS.API.Size roomSize, AGS.API.Size virtualResoution, bool resetPosition) { IObject target = Target == null ? null : Target(); if (!Enabled || target == null) return; setScale(target, viewport, resetPosition); //todo: Allow control over which point in the target to follow float targetX = target.X;//target.CenterPoint == null ? target.X : target.CenterPoint.X; float targetY = target.Y;//target.CenterPoint == null ? target.Y : target.CenterPoint.Y; float maxResolutionX = virtualResoution.Width / viewport.ScaleX; float maxResolutionY = virtualResoution.Height / viewport.ScaleY; targetX = getTargetPos(targetX, roomSize.Width, maxResolutionX); targetY = getTargetPos(targetY, roomSize.Height, maxResolutionY); if (resetPosition) { viewport.X = targetX; viewport.Y = targetY; return; } float newX = getPos (viewport.X, targetX, StartSpeedX, 0.1f, ref _speedX); float newY = getPos (viewport.Y, targetY, StartSpeedY, 0.1f, ref _speedY); viewport.X = clamp(newX, roomSize.Width, maxResolutionX); viewport.Y = clamp(newY, roomSize.Height, maxResolutionY); }
public static DesktopBrush Solid(AGS.API.Color color) { DesktopBrush brush = new DesktopBrush (new SolidBrush (color.Convert())); brush.Type = BrushType.Solid; brush.Color = color; return brush; }
private void UpdateFromView(AGS.Types.View view) { if (view == null) { udLoop.Enabled = false; udFrame.Enabled = false; chkAnimate.Enabled = false; chkAnimate.Checked = false; StopTimer(); previewPanel.Invalidate(); } else { udLoop.Enabled = true; udFrame.Enabled = true; chkAnimate.Enabled = true; udLoop.Minimum = 0; udLoop.Maximum = (view.Loops.Count == 0) ? 0 : view.Loops.Count - 1; udFrame.Minimum = 0; udFrame.Maximum = 99; udDelay.Minimum = 1; udDelay.Maximum = 100; udLoop_ValueChanged(null, null); } }
public static string GetScriptText(AGS.Types.Script script) { if (script.FileName == "GlobalScript.asc" && !Regex.IsMatch(script.Text, @"function\s+dialog_request\s*\(")) { return script.Text + Environment.NewLine + "function dialog_request(int param) {" + Environment.NewLine + "}"; } return script.Text; }
public static AndroidBrush Solid(AGS.API.Color color) { TextPaint paint = CreateTextPaint(); paint.Color = color.Convert(); AndroidBrush brush = new AndroidBrush (paint); brush.Type = BrushType.Solid; brush.Color = color; return brush; }
public void ExportTranslation(AGS.Types.Translation translation) { using (JsonWriter output = JsonWriter.Create(InExportFolder(TRANSLATION_FILENAME, translation.Name))) { //output.ObfuscateKeys = true; //output.ObfuscateValues = true; WriteTranslationJson(output, translation); } }
public void WriteCustomPropertiesJson(JsonWriter output, string key, AGS.Types.CustomProperties customProperties) { using (output.BeginObject(key)) { foreach (AGS.Types.CustomProperty property in customProperties.PropertyValues.Values) { output.WriteValue(property.Name, property.Value); } } }
public AGSInput(GameWindow game, AGS.API.Size virtualResolution, IGameState state, IAGSRoomTransitions roomTransitions, IGameWindowSize windowSize) { _windowSize = windowSize; this._roomTransitions = roomTransitions; this._virtualWidth = virtualResolution.Width; this._virtualHeight = virtualResolution.Height; this._state = state; this._keysDown = new AGSConcurrentHashSet<Key>(); this._game = game; this._originalOSCursor = _game.Cursor; MouseDown = new AGSEvent<AGS.API.MouseButtonEventArgs>(); MouseUp = new AGSEvent<AGS.API.MouseButtonEventArgs>(); MouseMove = new AGSEvent<MousePositionEventArgs>(); KeyDown = new AGSEvent<KeyboardEventArgs>(); KeyUp = new AGSEvent<KeyboardEventArgs>(); game.MouseDown += async (sender, e) => { if (isInputBlocked()) return; var button = convert(e.Button); if (button == AGS.API.MouseButton.Left) LeftMouseButtonDown = true; else if (button == AGS.API.MouseButton.Right) RightMouseButtonDown = true; await MouseDown.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y))); }; game.MouseUp += async (sender, e) => { if (isInputBlocked()) return; var button = convert(e.Button); if (button == AGS.API.MouseButton.Left) LeftMouseButtonDown = false; else if (button == AGS.API.MouseButton.Right) RightMouseButtonDown = false; await MouseUp.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y))); }; game.MouseMove += async (sender, e) => { if (isInputBlocked()) return; await MouseMove.InvokeAsync(sender, new MousePositionEventArgs(convertX(e.X), convertY(e.Y))); }; game.KeyDown += async (sender, e) => { Key key = convert(e.Key); _keysDown.Add(key); if (isInputBlocked()) return; await KeyDown.InvokeAsync(sender, new KeyboardEventArgs(key)); }; game.KeyUp += async (sender, e) => { Key key = convert(e.Key); _keysDown.Remove(key); if (isInputBlocked()) return; await KeyUp.InvokeAsync(sender, new KeyboardEventArgs(key)); }; }
public IMask CreateMask(IGameFactory factory, string path, bool transparentMeansMasked = false, AGS.API.Color? debugDrawColor = null, string saveMaskToFile = null, string id = null) { Bitmap debugMask = null; FastBitmap debugMaskFast = null; if (saveMaskToFile != null || debugDrawColor != null) { debugMask = new Bitmap (Width, Height); debugMaskFast = new FastBitmap (debugMask, ImageLockMode.WriteOnly, true); } bool[][] mask = new bool[Width][]; System.Drawing.Color drawColor = debugDrawColor != null ? debugDrawColor.Value.Convert() : System.Drawing.Color.Black; using (FastBitmap bitmapData = new FastBitmap (_bitmap, ImageLockMode.ReadOnly)) { for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { var pixelColor = bitmapData.GetPixel(x, y); bool masked = pixelColor.A == 255; if (transparentMeansMasked) masked = !masked; if (mask[x] == null) mask[x] = new bool[Height]; mask[x][Height - y - 1] = masked; if (debugMask != null) { debugMaskFast.SetPixel(x, y, masked ? drawColor : System.Drawing.Color.Transparent); } } } } if (debugMask != null) debugMaskFast.Dispose(); //Save the duplicate if (saveMaskToFile != null) debugMask.Save (saveMaskToFile); IObject debugDraw = null; if (debugDrawColor != null) { debugDraw = factory.Object.GetObject(id ?? path ?? "Mask Drawable"); debugDraw.Image = factory.Graphics.LoadImage(new DesktopBitmap(debugMask, _graphics), null, path); debugDraw.Anchor = new AGS.API.PointF (); } return new AGSMask (mask, debugDraw); }
public static bool AreDialogScriptsCached(AGS.Types.IAGSEditor editor) { foreach (AGS.Types.Dialog dialog in editor.CurrentGame.Dialogs) { if (String.IsNullOrEmpty(dialog.CachedConvertedScript)) { return false; } } return true; }
public AGSGameSettings(string title, AGS.API.Size virtualResolution, WindowState windowState = WindowState.Maximized, AGS.API.Size? windowSize = null, VsyncMode vsync = VsyncMode.Adaptive, bool preserveAspectRatio = true, WindowBorder windowBorder = WindowBorder.Resizable) { Title = title; VirtualResolution = virtualResolution; WindowState = windowState; WindowSize = windowSize.HasValue ? windowSize.Value : virtualResolution; Vsync = vsync; PreserveAspectRatio = preserveAspectRatio; WindowBorder = windowBorder; }
public void DrawText(string text, ITextConfig config, AGS.API.SizeF textSize, AGS.API.SizeF baseSize, int maxWidth, int height, float xOffset) { _height = height; _text = text; _config = config; _maxWidth = maxWidth; IFont font = _config.Font; IBrush outlineBrush = _config.OutlineBrush; float left = xOffset + _config.AlignX(textSize.Width, baseSize); float top = _config.AlignY(_bitmap.Height, textSize.Height, baseSize); float centerX = left + _config.OutlineWidth / 2f; float centerY = top + _config.OutlineWidth / 2f; float right = left + _config.OutlineWidth; float bottom = top + _config.OutlineWidth; var gfx = _gfx; if (_config.OutlineWidth > 0f) { drawString(gfx, outlineBrush, left, top); drawString(gfx, outlineBrush, centerX, top); drawString(gfx, outlineBrush, right, top); drawString(gfx, outlineBrush, left, centerY); drawString(gfx, outlineBrush, right, centerY); drawString(gfx, outlineBrush, left, bottom); drawString(gfx, outlineBrush, centerX, bottom); drawString(gfx, outlineBrush, right, bottom); } if (_config.ShadowBrush != null) { drawString(gfx, _config.ShadowBrush, centerX + _config.ShadowOffsetX, centerY + _config.ShadowOffsetY); } drawString(gfx, _config.Brush, centerX, centerY); //This should be a better way to render the outline (DrawPath renders the outline, and FillPath renders the text) //but for some reason some lines are missing when we render like that, at least on the mac /*if (_outlineWidth > 0f) { GraphicsPath path = new GraphicsPath (); Pen outlinePen = new Pen (_outlineBrush, _outlineWidth) { LineJoin = LineJoin.Round }; path.AddString(_text, _font.FontFamily, (int)_font.Style, _font.Size, new Point (), new StringFormat ()); //gfx.ScaleTransform(1.3f, 1.35f); gfx.DrawPath(outlinePen, path); gfx.FillPath(_brush, path); } else gfx.DrawString (_text, _font, _brush, 0f, 0f);*/ }
public IBrush LoadLinearBrush(AGS.API.Color[] linearColors, IBlend blend, IColorBlend interpolationColors, ITransformMatrix transform, AGS.API.WrapMode wrapMode, bool gammaCorrection) { LinearGradientBrush g = new LinearGradientBrush (new System.Drawing.Point (), new System.Drawing.Point (), System.Drawing.Color.White, System.Drawing.Color.White); g.Blend = blend.Convert(); g.GammaCorrection = gammaCorrection; g.InterpolationColors = interpolationColors.Convert(); g.LinearColors = linearColors.Convert(); g.Transform = transform.Convert(); g.WrapMode = wrapMode.Convert(); return new DesktopBrush(g); }
public ViewEditor(AGS.Types.View viewToEdit) { _guiController = Factory.GUIController; _guiController.OnPropertyObjectChanged += new GUIController.PropertyObjectChangedHandler(GUIController_OnPropertyObjectChanged); _viewUpdateHandler = new AGS.Types.View.ViewUpdatedHandler(View_ViewUpdated); viewToEdit.ViewUpdated += _viewUpdateHandler; InitializeComponent(); _editingView = viewToEdit; InitializeControls(); viewPreview.DynamicUpdates = true; chkShowPreview.Checked = Factory.AGSEditor.Preferences.ShowViewPreviewByDefault; UpdateWhetherPreviewIsShown(); }
private void AddSpritesFromFolder(AGS.Types.ISpriteFolder folder, List<AGS.Types.Sprite> list) { foreach (AGS.Types.Sprite sprite in folder.Sprites) { while (list.Count <= sprite.Number) { list.Add(null); } list[sprite.Number] = sprite; } foreach (AGS.Types.ISpriteFolder subfolder in folder.SubFolders) { AddSpritesFromFolder(subfolder, list); } }
public IBrush LoadPathsGradientBrush(AGS.API.Color centerColor, AGS.API.PointF centerPoint, IBlend blend, AGS.API.PointF focusScales, AGS.API.Color[] surroundColors, IColorBlend interpolationColors, ITransformMatrix transform, AGS.API.WrapMode wrapMode) { PathGradientBrush g = new PathGradientBrush (new System.Drawing.Point[]{ }); g.Blend = blend.Convert(); g.CenterColor = centerColor.Convert(); g.CenterPoint = centerPoint.Convert(); g.FocusScales = focusScales.Convert(); g.SurroundColors = surroundColors.Convert(); g.InterpolationColors = interpolationColors.Convert(); g.Transform = transform.Convert(); g.WrapMode = wrapMode.Convert(); return new DesktopBrush(g); }
public ExporterPlugin(AGS.Types.IAGSEditor editor) { this.editor = editor; settingsPane = new SettingsPanel(this); settingsPane.contentDocument = new AGS.Types.ContentDocument(settingsPane, "RHF Export Settings", this); editor.AddComponent(this); editor.GUIController.AddMenu(this, MENU_ID, MENU_TITLE, editor.GUIController.FileMenuID); AGS.Types.MenuCommands mainMenuCommands = new AGS.Types.MenuCommands(MENU_ID); mainMenuCommands.Commands.Add(new AGS.Types.MenuCommand(COMMAND_EXPORT_ID, COMMAND_EXPORT_TITLE)); mainMenuCommands.Commands.Add(new AGS.Types.MenuCommand(COMMAND_EXPORT_ROOM_ID, COMMAND_EXPORT_ROOM_TITLE)); mainMenuCommands.Commands.Add(new AGS.Types.MenuCommand(COMMAND_SETTINGS_ID, COMMAND_SETTINGS_TITLE)); editor.GUIController.AddMenuItems(this, mainMenuCommands); }
public void MakeTransparent(AGS.API.Color color) { global::Android.Graphics.Color c = new global::Android.Graphics.Color(color.R, color.G, color.B, color.A); global::Android.Graphics.Color transparent = global::Android.Graphics.Color.Transparent; using (FastBitmap fastBitmap = new FastBitmap (_bitmap)) { for (int x = 0; x < _bitmap.Width; x++) { for (int y = 0; y < _bitmap.Height; y++) { if (fastBitmap.GetPixel(x, y) == c) fastBitmap.SetPixel(x, y, c); } } } }
public void WriteCharacterJson(JsonWriter output, string key, AGS.Types.Character character) { using (output.BeginObject(key)) { output.WriteValue("scriptName", character.ScriptName); output.WriteValue("room", character.StartingRoom); output.WriteValue("clickable", character.Clickable); output.WriteValue("x", character.StartX); output.WriteValue("y", character.StartY); output.WriteValue("name", character.RealName); output.WriteValue("speechColor", character.SpeechColor); output.WriteValue("animationDelay", character.AnimationDelay); output.WriteValue("normalView", character.NormalView); WriteCustomPropertiesJson(output, "properties", character.Properties); WriteInteractionsJson(output, "interactions", character.Interactions); } }
public void WriteTranslationJson(JsonWriter output, string key, AGS.Types.Translation translation) { using (output.BeginObject(key)) { output.WriteValue("game", GetCurrentGameGuid()); output.WriteValue("normalFont", translation.NormalFont); output.WriteValue("speechFont", translation.SpeechFont); using (output.BeginObject("translatedLines")) { foreach (KeyValuePair<string, string> line in translation.TranslatedLines) { if (!String.IsNullOrEmpty(line.Value)) { output.WriteValue(line.Key, line.Value); } } } } }
public void WriteDialogJson(JsonWriter output, string key, AGS.Types.Dialog dialog) { if (dialog == null) { output.WriteNull(key); return; } using (output.BeginObject(key)) { output.WriteValue("scriptName", dialog.Name); output.WriteValue("showTextParser", dialog.ShowTextParser); using (output.BeginArray("options")) { foreach (AGS.Types.DialogOption option in dialog.Options) { WriteDialogOptionJson(output, option); } } } }
public void DrawText(string text, ITextConfig config, AGS.API.SizeF textSize, AGS.API.SizeF baseSize, int maxWidth, int height, float xOffset) { //_height = height; todo: support height _text = text; _config = config; _maxWidth = maxWidth; TextPaint paint = getPaint(_config.Brush); float left = xOffset + _config.AlignX(textSize.Width, baseSize); float top = _config.AlignY(_bitmap.Height, textSize.Height, baseSize); float centerX = left + _config.OutlineWidth / 2f; float centerY = top + _config.OutlineWidth / 2f; float right = left + _config.OutlineWidth; float bottom = top + _config.OutlineWidth; var canvas = _canvas; if (_config.OutlineWidth > 0f) { TextPaint outlinePaint = getPaint(_config.OutlineBrush); drawString(canvas, outlinePaint, left, top); drawString(canvas, outlinePaint, centerX, top); drawString(canvas, outlinePaint, right, top); drawString(canvas, outlinePaint, left, centerY); drawString(canvas, outlinePaint, right, centerY); drawString(canvas, outlinePaint, left, bottom); drawString(canvas, outlinePaint, centerX, bottom); drawString(canvas, outlinePaint, right, bottom); } if (_config.ShadowBrush != null) { TextPaint shadowPaint = getPaint(_config.ShadowBrush); drawString(canvas, shadowPaint, centerX + _config.ShadowOffsetX, centerY + _config.ShadowOffsetY); } drawString(canvas, paint, centerX, centerY); }
private string GetNodeID(AGS.Types.Font item) { return "Fnt" + item.ID; }
private void ShowOrAddPane(AGS.Types.Font chosenFont) { ContentDocument document; if (!_documents.TryGetValue(chosenFont, out document) || document.Control.IsDisposed) { Dictionary<string, object> list = new Dictionary<string, object>(); list.Add(chosenFont.Name + " (Font " + chosenFont.ID + ")", chosenFont); document = new ContentDocument(new FontEditor(chosenFont), chosenFont.WindowTitle, this, ICON_KEY, list); _documents[chosenFont] = document; document.SelectedPropertyGridObject = chosenFont; } document.TreeNodeID = GetNodeID(chosenFont); _guiController.AddOrShowPane(document); _guiController.ShowCuppit("The Font Editor allows you to import fonts into your game. Windows TTF fonts are supported, as are SCI fonts which can be created with Radiant FontEdit.", "Fonts introduction"); }
private void ShowOrAddPane(AGS.Types.Font chosenFont) { if (!_documents.ContainsKey(chosenFont)) { Dictionary<string, object> list = new Dictionary<string, object>(); list.Add(chosenFont.Name + " (Font " + chosenFont.ID + ")", chosenFont); _documents.Add(chosenFont, new ContentDocument(new FontEditor(chosenFont), chosenFont.WindowTitle, this, list)); _documents[chosenFont].SelectedPropertyGridObject = chosenFont; } _guiController.AddOrShowPane(_documents[chosenFont]); _guiController.ShowCuppit("The Font Editor allows you to import fonts into your game. Windows TTF fonts are supported, as are SCI fonts which can be created with Radiant FontEdit.", "Fonts introduction"); }
private void EnsureViewHasAtLeast4LoopsAndAFrameInLeftRightLoops(AGS.Types.View view) { bool viewModified = false; while (view.Loops.Count < 4) { view.Loops.Add(new ViewLoop(view.Loops.Count)); viewModified = true; } if (view.Loops[1].Frames.Count < 1) { view.Loops[1].Frames.Add(new ViewFrame(0)); } if (view.Loops[2].Frames.Count < 1) { view.Loops[2].Frames.Add(new ViewFrame(0)); } if (viewModified) { view.NotifyClientsOfUpdate(); } }
private void ExportSpriteFolder( AGS.Types.ISpriteFolder folder, ImageSheet toMaskSheet, List<ImageSheet> completeImageSheets, bool alpha, bool topLevel) { if (toMaskSheet == null) { toMaskSheet = new ImageSheet(settings.MaxImageSheetWidth, settings.MaxImageSheetHeight, 0, 0); if (!alpha) { toMaskSheet.ClearColor = HacksAndKludges.GetTransparencyColor(); toMaskSheet.MakeTransparent = true; } foreach (AGS.Types.Sprite sprite in folder.Sprites) { if ((alpha && !sprite.AlphaChannel) || (!alpha && sprite.AlphaChannel)) { continue; } if (sprite.Width > settings.MaxImageSheetWidth || sprite.Height > settings.MaxImageSheetHeight) { throw new Exception("Sprite #" + sprite.Number + " is bigger than the maximum image sheet size"); } SpriteImageSheetEntry entry; if (alpha) { entry = new SpriteImageSheetEntry(editor, sprite, Color.Transparent); } else { entry = new SpriteImageSheetEntry(editor, sprite, HacksAndKludges.GetTransparencyColor()); } if (!toMaskSheet.AddEntry(entry)) { if (!toMaskSheet.IsEmpty) { completeImageSheets.Add(toMaskSheet); } toMaskSheet = new ImageSheet(settings.MaxImageSheetWidth, settings.MaxImageSheetHeight, 0, 0); } } } else { object maskSnapshot = toMaskSheet.Snapshot(); foreach (AGS.Types.Sprite sprite in folder.Sprites) { if ((alpha && !sprite.AlphaChannel) || (!alpha && sprite.AlphaChannel)) { continue; } if (sprite.Width > settings.MaxImageSheetWidth || sprite.Height > settings.MaxImageSheetHeight) { throw new Exception("Sprite #" + sprite.Number + " is bigger than the maximum image sheet size"); } SpriteImageSheetEntry entry; if (alpha) { entry = new SpriteImageSheetEntry(editor, sprite, Color.Transparent); } else { entry = new SpriteImageSheetEntry(editor, sprite, HacksAndKludges.GetTransparencyColor()); } if (!toMaskSheet.AddEntry(entry)) { toMaskSheet.RestoreSnapshot(maskSnapshot); ExportSpriteFolder(folder, null, completeImageSheets, alpha, true); return; } } } int insert = completeImageSheets.Count; foreach (AGS.Types.SpriteFolder subfolder in folder.SubFolders) { ExportSpriteFolder(subfolder, toMaskSheet, completeImageSheets, alpha, false); } if (topLevel && !toMaskSheet.IsEmpty) { completeImageSheets.Insert(insert, toMaskSheet); } }
public SpriteImageSheetEntry(AGS.Types.IAGSEditor editor, AGS.Types.Sprite sprite, Color bgColor) { TheSprite = sprite; bitmap = editor.GetSpriteImage(TheSprite.Number); Trim(bgColor); }