Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Apr 28, 2017

Add DrawFilledRectangle()

@ghost ghost closed this Apr 28, 2017
@fanoI fanoI reopened this Apr 29, 2017
@fanoI
Copy link
Contributor

fanoI commented Apr 29, 2017

Now I see that the code not compiled but do you have tried it on your machine before creating the PR?

I suggest you a more simpler approach instead to draw rectangles one inside the other it will be better to use DrawLine you can draw a simple draw horizontal lines until the rectangle has been filled.
If you want to test your modifications there is a Canvas TestRunner that you can use.

Thank you for the help!

@valentinbreiz
Copy link
Member

valentinbreiz commented Apr 29, 2017

I tried to compil cosmos with #628 and and Cosmos does not build.
And I tried to correct errors but @DjAlEx234 DrawFilledRectangle() does not work :/

@fanoI
Copy link
Contributor

fanoI commented Apr 29, 2017

There is obviously no hurry :-)
Let @DjAlEx234 correct its code when he wants...

@ghost
Copy link
Author

ghost commented Apr 29, 2017

where is the test runner?

@fanoI
Copy link
Contributor

fanoI commented Apr 29, 2017

The graphic TestRunner is here: https://github.com/CosmosOS/Cosmos/blob/master/Tests/GraphicTest/Kernel.cs

to enable it comment the other test and leave only it from here: https://github.com/CosmosOS/Cosmos/blob/master/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs

you simply execute tests use the TestRunner project (the text mode one, the graphic based does not show Cosmos' console so no GUI seen!).

@@ -230,6 +230,29 @@ public void DrawRectangle(Pen pen, int x, int y, int width, int height)
DrawLine(pen, xc, yc, xd, yd);
}

public void DrawFilledRectangle(Pen pen, int x_start, int y_start, int width, int height)
{
for (int i; i != width; i++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be int i = 0

}
}

public void DrawSquare(Pen pen, int x, int y, int sideslength)
Copy link
Member

@jp2masa jp2masa Apr 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to have DrawSquare nor DrawFilledSquare, as it can be done using DrawRectangle and DrawFilledRectangle.

@jp2masa jp2masa requested a review from fanoI April 30, 2017 00:34
Copy link
Contributor

@fanoI fanoI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have decided that DrawSquare / DrawFilledSquare are in the end not needed.

Only a thing can you add to the CGS demo the Drawing of a filled rectangle?

@fanoI
Copy link
Contributor

fanoI commented Apr 30, 2017

Another thing the methods that could be overriden by a driver that has these "shapes" in hardware should be done virtual so DrawLine(), DrawRectangle() and DrawFilledRectangle() must be all virtual so as all the methods requested in #603.

Thank you!

@ghost
Copy link
Author

ghost commented Apr 30, 2017

What do you mean by virtual?

@fanoI
Copy link
Contributor

fanoI commented Apr 30, 2017

Add virtual modifier to the method for example:

 public virtual void DrawLine(Pen pen, int x1, int y1, int x2, int y2)

Bochs not having the capacity to draw lines in hardware will use this software implementation but a more powerful GPU (VmWare has already some emulated "hardware" capabilities) will override this method to implement its version of DrawLine() but it cannot do it if DrawLine() is not declared virtual in the Canvas abstract class.

@ghost
Copy link
Author

ghost commented Apr 30, 2017

So can I make a copy of every drawX void and make it virtual?

@fanoI
Copy link
Contributor

fanoI commented Apr 30, 2017

No you not have to copy anything the methods: DrawLine(), DrawRectangle() and DrawFilledRectangle() must have the virtual modifier nothing else have to be changed.
The method Clear() is one example, in that case the Bochs driver ovverides it too because there is a more performant way to do it: https://github.com/CosmosOS/Cosmos/blob/master/source/Cosmos.System/Graphics/VBEScreen.cs#L99

The other methods in the more "shapes" issue should be virtual too maybe some very advanced GPU gives the possibility to draw triangles in hardware so it can be overridden too.

@valentinbreiz
Copy link
Member

I'm writing the .DrawString method, here an exemple for the letter A:
canvas.DrawLine(pen, x, y + 1, x, y + 7);
canvas.DrawLine(pen, x + 4, y + 1, x + 4, y + 7);
canvas.DrawLine(pen, x + 1, y, x + 4, y);
canvas.DrawLine(pen, x + 1, y + 4, x + 4, y + 4);
There is a way to write this method well... faster ? x)

@jp2masa
Copy link
Member

jp2masa commented May 3, 2017

@valentinbreiz I don't know if we should have a DrawString method, it should be implemented by the graphics library, because fonts can be vectorial or use images for letters. The example you provided is vectorial, but it should be handled by the graphics library. We should provide methods for drawing vector images, like drawing lines, bézier curves... I don't know if we should handle drawing images, I think it should be implemented by a graphics library too.
@fanoI What do you think?

@fanoI
Copy link
Contributor

fanoI commented May 3, 2017

DrawString() and DrawImage() was in the list of "CGS New Features" but I've put them there I didn't had analyzed how much difficult they where... probably as you say they deserve intermediate libraries that will use CGS as a building block.
Probably to do DrawString() efficiently the solution is to have before DrawImage() and to create the string as bitmap / vectorial imagine in memory, so to Draw a String we need:

  1. Font support, makes sense in this age to support only TrueType that seems they have a sort of VM to be implemented to do correct rendering
  2. Create the "image" of the String in Memory
  3. C# DrawString class has Brushes, Styles a lot of things...
  4. Draw the String as an Image

So in the end I'd say for now let's continue with what is in #603 that are really more primitive graphic types we think of "how to DrawImages" and "how to DrawStrings" after.

@ghost
Copy link
Author

ghost commented May 4, 2017

can we add a project that writes letters from a library?

@fanoI
Copy link
Contributor

fanoI commented May 4, 2017

First a premise:
Text rendering is much complex issue then "pasting" some glyphs... Not just much complex, it is very complex: kerning, ligatures, spacing, bidirectional text, vowels, and much more...

Microsoft itself divides the problem in two parts DirectWrite and Direct2D / GDI+ (legacy), Direct2D is in some way the equivalent of our Canvas class.
https://en.wikipedia.org/wiki/DirectWrite

The OpenType format (successor of TrueType):
https://en.wikipedia.org/wiki/OpenType

In conclusion how to Draw Text in Cosmos needs more study and sure should affronted in a separated PR.

add stuff
Copy link
Member

@jp2masa jp2masa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canvas methods to draw elements on the screen should be virtual.

@@ -230,6 +230,22 @@ public void DrawRectangle(Pen pen, int x, int y, int width, int height)
DrawLine(pen, xc, yc, xd, yd);
}

public void DrawFilledRectangle(Pen pen, int x_start, int y_start, int width, int height)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be virtual.

}
}

public void DrawTriangle(Pen pen, int v1x, int v1y, int v2x, int v2y, int v3x, int v3y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be virtual.

@jp2masa jp2masa merged commit e75262f into CosmosOS:master May 23, 2017
@prepare
Copy link

prepare commented Jun 26, 2018

Hello @fanoI,

I want to introduce a pure C# framework that can

  1. Read OpenType font (.ttf, .otf)

  2. Layout a string the glyph-spans and layout each glyph. (with OpenType glyph layout)

  3. Render it to a Bitmap surface with grey-scale technique or with LCD-effect technique
    (subpixel rendering)

Here =>https://github.com/LayoutFarm/Typography


I think my lib can help your graphics system.

:)

@prepare
Copy link

prepare commented Jun 26, 2018

It is not only an advertisement. I want to help you too.

But I don't known much about Cosmos.

I need a time to learn your system first.

@fanoI
Copy link
Contributor

fanoI commented Jun 27, 2018

@prepare thank you for your help offer!
We have already bitmap supported so drawing text is really the next step of CGS.

PM me if you have requests on how Cosmos works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants