GUI In Cosmos: Help in C# - c#

I have been using Cosmos in Microsoft Visual C# 2008 to make primitive, TUI, operating systems. I wonder how to make a GUI in Cosmos. I know that it's possible, but I just want to know how to make it. Constructive criticism appreciated, insults not! Please reply with code (and comments in the code), because I am an absolute beginner, with only some knowledge of basic c# commands. Thanks!

I do not know what milestone your using, but I think this might work for you. You need this class level variable:
Cosmos.Hardware.VGAScreen screen;
And in your Init method:
screen = new Cosmos.Hardware.VGAScreen();
screen.SetMode300x200x8();
screen.Clear(0);
//done init vga screen
After that last comment, in your code, you can use this to set the color of a pixel:
screen.SetPixel300x200x8(uint x, uint y, uint color);
The color parameter is the color of the pixel in 256 color format (numbers 0 through 255). That's all you need to make a GUI. You need lots of math skills to make shapes, though.

There are also GUI API's with function's to make shapes.
Search on Google/YouTube or visit the discussion page on Cosmos' Codeplex page:
http://cosmos.codeplex.com/discussions

This is for 2020 Because this is a VERY good way todo this in cosmos. (USING CGS)
using System;
using System.Drawing;
using Cosmos.System.Graphics;
using Sys = Cosmos.System;
namespace Graphics
{
public class Kernel : Sys.Kernel
{
Canvas canvas;
protected override void BeforeRun()
{
canvas = FullScreenCanvas.GetFullScreenCanvas();
canvas.Clear(Color.Black);
}
protected override void Run()
{
Pen pen = new Pen(Color.White);
// DRAW stuff see https://www.gocosmos.org/docs/cosmos-graphic-subsystem/
}
}
}

Related

Setting up a UI slider to control post processing effects?

As the title says, I'm trying to set up a UI slider so the player can adjust some of the post processing settings (specifically the exposure and temperature) while the game is running.
To bring you up to speed:
I'm using version one of the post processing stack, as found here:
https://assetstore.unity.com/packages/essentials/post-processing-stack-83912
I'm very new to C#; I'm at the "Frankenstein" stage of learning how to code (following tutorials and modifying what works until it breaks or does what I'm trying to accomplish).
I figure my best shot is to try to adapt what I learned from this tutorial on creating an audio volume slider: https://www.youtube.com/watch?v=YOaYQrN1oYQ&t=122s
This is the code I've cobbled together so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BrightnessSlider : MonoBehaviour {
public void SetBrightness (float brightness)
{
Debug.Log(brightness);
}
}
Specific issues I'm having at specific points in the tutorial:
2:07 For the function of the slider, the tutorial sets up a dynamic float that matches the custom method (SetVolume) they specify. When I try setting up my own function with a custom method (SetBrightness), I can't find it. I'm also not sure if I need to set a different object instead of the canvas for this step.
3:47 In the tutorial they expose a parameter for the volume so that it can be manipulated through script, but I don't know what the equivalent of that would be for post processing.
For the record, I was able to follow this tutorial to create my own audio slider and got it working with no problems.
One last thing: I opened up the script for the post processing profile and found the variable type I think I'd need or would at least be somewhat relevant: ColorGradingModel, but I honestly have no idea what to do with this information.
Update July 09, 2018


I've since been looking over #Nol's code and had someone else look at it and help me out with it. At the moment, the slider's functionality(not sure if that's the correct terminology but that's what I've been sticking with) is set up through the On Value Changed field in the inspector , but it's not actually driving/changing the brightness values. I had someone else (who's far more qualified than I am) look at it with me. It seems like it should work the way they've set it up, but something is getting lost in translation between the method and the slider.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEngine.UI;
public class BrightnessSlider : MonoBehaviour
{
public Slider slider;
public PostProcessingProfile Default;
private ColorGradingModel cgm;
private void Start()
{
//I haven't been able to get this to not return some sort of error,
//and I'm not even sure of its usefulness.
//I've been keeping it commented out for the most part.
Default.profile.TryGetSettings(out cgm);
}
public void SetBrightness(float brightness)
{
ColorGradingModel.Settings settings = cgm.settings;
settings.basic.postExposure = brightness;
cgm.settings = settings;
Debug.Log("Brightness is: " + brightness); //For testing purposes
}
}
It seems like you have the core of what you need to know for changing your settings down. That's good.
You'll need a few simple changes:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing; //How you'll access PPV (Post Processing Volume) models and settings
public class BrightnessSlider : MonoBehaviour {
PostProcessingVolume ppv; //You can make this public to set in inspector
ColorGradingModel cgm; //can use ppv.profile.TryGetSettings(out cgm) in Start()
public void SetBrightness (float brightness)
{
cg.[setting you want to change].value = brightness;
}
}

implement an interface Xamarin forms pcl with c#

I just downloaded the plugin XamJam.Screen and I have to implement it, the problem is that it is an interface.
That said, I've never implemented interfaces in c # programming, and I wonder if anyone can advise me how to implement it, I tried but without success, the following code:
namespace Fimap.WebPart
{
public partial class HomePage : ContentView
{
public HomePage()
{
InitializeComponent();
Screen xyz = new getScreen();
var w = xyz.Size.Width;
}
public class getScreen : Screen
{
public ScreenSize Size
{
get
{
return Size;
}
}
}
}
}
the problem is that size 0 me back around.
My goal is to take the width and height of the device.
You do not need to implement the interface yourself. If you installed the package through NUGET, you only need to call
var size = Plugin.XamJam.Screen.CrossScreen.Current.Size;
you can access the width and height of the screen with size.Width and size.Height
Please visit the project github home page and checkout the additional disclaimers on how the library works, provided by the author.
As you can see, the library is of limited use. There is probably a better way to achieve what ever it is that you are trying to do. Consider researching your actual use case / problem further.

Fast screen capture using DirectX in Java (Re-writing from existing code in C# to Java)

My aim is to capture the screen using DirectX in Java.
I have found the project fully detailed and explained here in C# .
Unfortunately, I do not have any knowledge in C sharp. I don't know if I can ask here a re-writing code above mentioned from C# to Java to those who handle both language, but I guess the final result would interest a lot of people.
Anyway, I thank those in advance who would be kind enough to help me with this. Even if I never tried, I know that a C# -> Java conversion software (or any other language) is not advised, explaining my question of re-writing.
Please find on below the code concerned:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SlimDX.Direct3D9;
namespace KMPP
{
public class DxScreenCapture
{
Device d;
public DxScreenCapture()
{
PresentParameters present_params = new PresentParameters();
present_params.Windowed = true;
present_params.SwapEffect = SwapEffect.Discard;
d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
}
public Surface CaptureScreen()
{
Surface s = Surface.CreateOffscreenPlain(d, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
d.GetFrontBufferData(0, s);
return s;
}
}
}
PS:Since Surface s is here a DirectX type of image, it would be interesting for me then to convert it into PNG then.
Java isn't C#
C# is totally different to java. C# can use DirectX but java cannot use it because DirectX was unavailable on all platforms. Instead you can use the Robot class present in java.awt package. Here's how to get the image.
Doing it with a robot
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
Robot r = new Robot();
BufferedImage s = r.createScreenCapture(new Rectangle(ss));
It returns a BufferedImage which contains the screenshot.

SFML with C#, startup trouble

I want to use SFML with C# .NET. I've had to get SFML 2.0 since 1.6 apparently had some issues with AMD graphics cards. The issue is that the constructor of SFML.Window.Window enters an infinite loop.
My code:
using SFML;
using SFML.Window;
using SFML.Graphics;
namespace SFML
{
class Program
{
static void Main(string[] args)
{
SFML.Window.Window window = new SFML.Window.Window(new VideoMode(800, 600), "Test widow");
}
}
}
It seems like nobody else on the internet has this issue, and I've tried it on another computer with the same result. Any help will be extremely appreciated.
Not sure you're creating the Window appropriately. Look at the examples from the Github source. If you're doing OpenGL, you'd use RenderWindow for instantiating your window object:
https://github.com/SFML/SFML.Net/blob/master/examples/opengl/OpenGL.cs
For 2D windows:
https://github.com/SFML/SFML.Net/blob/master/examples/window/Window.cs
Also note the inclusion of Tao bindings in those examples.

VMR9 vs EVR : How to use ImageCompositor with EVR?

I've coded a PixelShader compiler/tester that works live on the Image or Video source that is playing using DirectShow.Net + VMR9.
And it was all good until I decided to give it a go as a real video player, and started adjusting every bit of it to work as it should (titles,etc).
Then I found out that video is very pixelated (badly interpolated) on Windows7 with ATI gpus. The solution was to go with EVR. And I did it. Aside with some glitches with background flickering and resize slowness that I'll try to solve with a custom presenter it all looked good.
BUT...
I lost the ability to apply pixel shading to the output video because there is no SetImageCompositor method on the EVR FilterConfig interface.
This is the EVR interface:
[SuppressUnmanagedCodeSecurity]
[Guid("83E91E85-82C1-4ea7-801D-85DC50B75086")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IEVRFilterConfig
{
void GetNumberOfStreams(out int pdwMaxStreams);
void SetNumberOfStreams(int dwMaxStreams);
}
This is the VMR9 interface:
[Guid("5a804648-4f66-4867-9c43-4f5c822cf1b8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[SuppressUnmanagedCodeSecurity]
public interface IVMRFilterConfig9
{
int GetNumberOfStreams(out int pdwMaxStreams);
int GetRenderingMode(out VMR9Mode Mode);
int GetRenderingPrefs(out VMR9RenderPrefs pdwRenderFlags);
int SetImageCompositor(IVMRImageCompositor9 lpVMRImgCompositor);
int SetNumberOfStreams(int dwMaxStreams);
int SetRenderingMode(VMR9Mode Mode);
int SetRenderingPrefs(VMR9RenderPrefs dwRenderFlags);
}
I have been using this approach with a custom image compositor to apply pixel shaders:
IVMRFilterConfig9 filterConfig = (IVMRFilterConfig9)vmr9;
// frameManager is my custom class implementing IVMRImageCompositor9
hr = filterConfig.SetImageCompositor(frameManager);
DsError.ThrowExceptionForHR(hr);
Now I cannot...
Using: VS2010, C#, DirectShow.NET, Mediafoundation.NET, Managed DX9.
What is the solution to this problem? Any guidelines on how to do it with EVR?
Thank you very much!
Since nobody had suggestions I dig up a little and think I have found out what could be the solution:
http://msdn.microsoft.com/en-us/library/bb530107(v=vs.85).aspx
This should be now done in the custom presenter...

Categories