Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Recoil

Pages: 1 ... 3 4 [5] 6
61
DotNet / Re: [VB.NET] Gradient Rectangle
« on: May 15, 2016, 07:50:12 pm »
Took me a few hours to figure out what was going on.  Nothing I did worked for changing what I was wanting, to get the gradient to draw on the rectangles in the correct location.  I moved my button's position, the gradients still drew in the exact same spot!

So then I did this, which somewhat broke down what I was doing wrong:

        v0.Position.X = My.ControlBounds.X
        v0.Position.Y = My.ControlBounds.Y

        v1.Position.X = My.ControlBounds.X + My.ControlBounds.Size.Width
        v1.Position.Y = My.ControlBounds.Y

        v2.Position.X = My.ControlBounds.X + My.ControlBounds.Size.Width
        v2.Position.Y = My.ControlBounds.Y + My.ControlBounds.Size.Height

        v3.Position.X = My.ControlBounds.X
        v3.Position.Y = My.ControlBounds.Y + My.ControlBounds.Size.Height

 

Everything is drawing like intended now.

62
DotNet / Re: [VB.NET] Gradient Rectangle
« on: May 15, 2016, 05:20:52 pm »
Okay, so I simplified this issue because nothing it was doing was making any sense.  Originally I was drawing 5 buttons...4 along the top of my render window, one on the right side.

So I removed all of them but one, and changed the colors that I was using to 4 different colors so I could get a better idea of what this is doing.  This worked for 1 button.  I drew the second button, but nothing happened...when I rendered the third one, an inverted gradient rectangle with the new colors was drawn underneath buttons 2 and 3.  So I am close, to something...I just don't know what.

In my button class I am drawing a normal grey rectangle shape.  All that is working, and when I use multiple instances of my button, it displays them all at the top like it is supposed to.



On that button class I am wanting to make it gradient instead.  So now I am doing this:
        Dim col1 As New SFML.Graphics.Color(255, 0, 0, 255) ' red
        Dim col2 As New SFML.Graphics.Color(0, 0, 255, 255) ' blue
        Dim col3 As New SFML.Graphics.Color(255, 255, 0, 255) ' yellow
        Dim col4 As New SFML.Graphics.Color(0, 255, 0, 255) ' green

        Dim v0 As Vertex = New Vertex(New Vector2f(Me.Location.X, Me.Location.X), col1)
        Dim v1 As Vertex = New Vertex(New Vector2f(Me.Size.Width, Me.Location.X), col2)
        Dim v2 As Vertex = New Vertex(New Vector2f(Me.Size.Width, Me.Size.Height), col3)
        Dim v3 As Vertex = New Vertex(New Vector2f(Me.Location.X, Me.Size.Height), col4)

        target.Draw({v0, v1, v2, v3}, PrimitiveType.Quads)
 

Now when I draw 1 button, here are my results:


However, when I draw all 4 buttons at the top, this is my results:


As you can see, the locations and sizes of the buttons are correct because it is still drawing the grey rectangle shapes in their respective locations.  What I am not understanding is why I am not able to draw the gradient where it is supposed to be on each of the individual buttons.

Does anything look "off" with the vertex locations I am drawing the gradient in my button class?

63
DotNet / Re: [VB.NET] Gradient Rectangle
« on: May 15, 2016, 03:05:48 pm »
The API documents are not very helpful when you don't understand C++.  I found this link also which kinda explains the same thing, and gave me a better idea of the vertices: http://en.sfml-dev.org/forums/index.php?topic=6750.0

So here is how I have them setup, but this is apparently wrong as well:
        Dim v1 As Vertex = New Vertex(New Vector2f(Me.Location.X, Me.Location.X), col1)
        Dim v2 As Vertex = New Vertex(New Vector2f(Me.Size.Width, Me.Location.X), col1)
        Dim v3 As Vertex = New Vertex(New Vector2f(Me.Size.Width, Me.Size.Height), col2)
        Dim v4 As Vertex = New Vertex(New Vector2f(Me.Location.X, Me.Size.Height), col2)
 

Here is the only way I have been able to draw them:
        target.Draw({v1, v2, v3, v4}, PrimitiveType.Quads)
 

What all that does is draw 3 varying sized rectangles (I at least got the shape down) on my render window.  This code is going in a control class, which is supposed to draw the rectangle the size/width/height of the control, in this case a button.  But this is drawing way outside of the bounds of the control.

64
DotNet / [VB.NET] Gradient Rectangle - [SOLVED]
« on: May 15, 2016, 03:26:29 am »
Currently I have a rectangle shape I am using for a control image.  It looks flat so I would like to make it gradient instead.  So far I have pieced together this, but I'm pretty certain that the coordinates are wrong for my rectangle...New Vector2f requires 2 coordinates:

Dim col1 As New SFML.Graphics.Color(102, 102, 255, 255)
        Dim col2 As New SFML.Graphics.Color(0, 0, 255, 255)

        Dim v1 As Vertex = New Vertex(New Vector2f(0, Me.Location.X), col1)
        Dim v2 As Vertex = New Vertex(New Vector2f(Me.Location.X, Me.Size.Width), col1)
        Dim v3 As Vertex = New Vertex(New Vector2f(Me.Location.Y, Me.Size.Height), col2)
        Dim v4 As Vertex = New Vertex(New Vector2f(Me.Location.Y + Me.Size.Height, Me.Size.Height), col2)

        Dim rectangle() As Vertex = {v1, v2, v3, v4}
 

I am unable to test that because I cannot do "target.Draw(rectangle())".  I tried inserting arbitrary values, but then VS says cannot convert the rectangle to drawable.

Hoping someone has an idea of how to draw a simple gradient rectangle.  Thanks.

65
DotNet / Re: [VB.NET] Mouse events for custom drawn gfx controls.
« on: May 13, 2016, 02:44:02 pm »
Maybe I should add additional code and clarify what I am trying to do?

Public WithEvents MyWindow As RenderWindow
 

Here are the 3 primary subs I am using for my mouse events.
Private Sub MyWindow_MouseButtonPressed(sender As Object, e As MouseButtonEventArgs) Handles MyWindow.MouseButtonPressed

    MyControlMouseDown(sender, e)

End Sub

Private Sub MyWindow_MouseButtonReleased(sender As Object, e As MouseButtonEventArgs) Handles MyWindow.MouseButtonReleased

    MyControlMouseUp(sender, e)

End Sub

Private Sub MyWindow_MouseMoved(sender As Object, e As MouseMoveEventArgs) Handles MyWindow.MouseMoved

    MyControlMouseMove(sender, e)

End Sub
 

When any of that ^ is done, I am sending the event through to my controls, then running the following:
Public Sub MyControlMouseUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)

    If MyButton.ControlRectangle.Contains(e.X, e.Y) Then

        MyButton.MouseUp(sender, e)

        ' Fire off events here that happen when the mouse button is up on this control.

    End If

End Sub
 

The above is like the middle man, and sends events through to other control events.  When a control, like my button, is sent a mouse up event, it stops drawing the button down gfx I have to show that the button is being hit.

Regardless if my buttons (drawn controls) are declared with events or not, I have to use this middleman procedure to pass events off to them, unless I want to try and fire everything off in the main mouse event subs...and with the amount of custom drawn controls I have, would be way too many to shove in there.

So I am looking for a better way to go about this, particularly being able to have the drawn objects (controls) be able to handle their own events.

66
DotNet / Re: [VB.NET] Mouse events for custom drawn gfx controls.
« on: May 12, 2016, 04:08:13 pm »
For anyone else who has ran across this post in their extensive SFML/VB.NET searches...

Public WithEvents MyWindow As RenderWindow
 

Public Sub Main_KeyPressed(ByVal sender As Object, ByVal e As SFML.Window.KeyEventArgs) Handles MyWindow.KeyPressed
       
    MsgBox("KeyPressed " & e.Code & " on Main...")

End Sub

Public Sub Main_MouseWheel(ByVal sender As Object, ByVal e As MouseWheelEventArgs) Handles MyWindow.MouseWheelMoved

    MsgBox("MouseWheelMoved " & e.Delta & " on Main...")

End Sub
 

Private Sub MyPicturebox_MouseHover(sender As Object, e As EventArgs) Handles MyPicturebox.MouseHover

    MyPicturebox.Focus()

End Sub
 

However, this is still not a solution for custom drawn control events.  But is getting me closer  ;D

67
DotNet / [VB.NET] Mouse events for custom drawn gfx controls.
« on: May 12, 2016, 03:02:35 pm »
Hey guys!  I ran into too many issues regarding lack of documentation for all of the SFML control libraries I found, so I set out to create my own that may work a bit easier for what I am doing.  I have created several generic controls that I would like to enhance and be able to throw in a dll and reuse with other projects. 

I am using a picturebox as my RenderWindow.  Currently I check the mouse events for that picturebox, and send them through to Rectangles that I have setup for the bounds of my drawn objects...this may sound simple, but it is often a very tedious way to get custom drawn controls from scratch to function properly, especially when I can have a dozen controls on the RenderWindow.  It would be so much easier if I could just set all the methods for the mouse events in the drawn object class itself, but I have tried adding handlers to these drawn controls with no effect when I try to use them.

Recently I found additional options for getting input in my application loop.

This can get mouse events specifically for my form:
        If WinForm.MouseButtons = (MouseButtons.Right) Then
            MsgBox("Right button pressed.")
        End If
 

This can get mouse events while the application is running, on my form or outside of it:
        If Mouse.IsButtonPressed(Mouse.Button.Right) Then
            MsgBox("Right button pressed.")
        End If
 

There is pretty much no way to determine if the mouse wheel is/has been scrolled though.  Regardless, these still are not proper ways to get my controls to function properly from the classes themselves.  Over the last few days I have been able to piece together a basic understanding of making the events work from my control classes, but with the SFML documentation in cpp, and very few examples in C# that will not port to VB.Net, I am stuck on making any progress.

I feel like I am very close to making these work as intended, so I am hoping fresh eyes may be able to point me in the right direction.

68
Graphics / Re: Clipping [VB.NET]
« on: June 19, 2015, 02:16:55 pm »
GameWindow.Draw(tmpLight, New RenderStates(BlendMode.Alpha))
 
That got me the ability to use BlendMode, but the effect is identical to GameWindow.Draw(tmpLight) because my image is a transparent png.

Thanks for the help.  I may have to look into another way to achieve this.

69
Graphics / Re: Clipping [VB.NET]
« on: June 19, 2015, 01:28:31 pm »
Thanks for the reply.  I have looked around but am unable to find an example in vb.net of how to apply blend mode.  The closest thing I can get is Blendmode.Add() but I am unable to use this on either the sprite or the circle.

I can find stuff in c++ but nothing for vb.net.  Would you know where an example may be located?

70
Graphics / Clipping [VB.NET]
« on: June 19, 2015, 12:22:42 pm »
I am able to draw a sprite to the screen and change the opacity values to look like night and day.  Not I am trying to achieve lighting effects for various sections of the screen that will not be affected by the dark overlay.  I'm trying to determine how I can clip the second sprite with the first CircleShape so I will have a start on a dynamic lighting effect.

Dim tmpLight As New CircleShape(300)
tmpLight.Texture = New Texture(LightGfx)
tmpLight.TextureRect = New IntRect(LightGfxInfo.Width / 2 - 150, LightGfxInfo.Height / 2 - 150, 300, 300)

tmpLight.FillColor = New SFML.Graphics.Color(255, 255, 255, 255) 'CurrLevel)
tmpLight.Position = New Vector2f(0, 0)
GameWindow.Draw(tmpLight)
 

Dim tmpSprite As Sprite
tmpSprite = New Sprite(NightGfx)
tmpSprite.TextureRect = New IntRect(0, 0, frmMainGame.GameScreen.Width, frmMainGame.GameScreen.Height)

tmpSprite.Color = New SFML.Graphics.Color(255, 255, 255, CurrLevel)
tmpSprite.Position = New Vector2f(0, 0)
GameWindow.Draw(tmpSprite)
 

I do not see any way that I am able to clip the Sprite by the CircleShape.  I would really appreciate a suggestion on a method to achieve this.

71
Graphics / Re: VB.NET - change alpha level on sprite?
« on: June 13, 2015, 02:49:09 am »
That's it...I can't believe I missed that -_-

Thanks!

72
Graphics / VB.NET - change alpha level on sprite?
« on: June 13, 2015, 02:07:19 am »
So I have seen this: http://www.sfml-dev.org/tutorials/2.1/graphics-sprite.php

I am able to set my colors like this:
tmpSprite.Color = SFML.Graphics.Color.Green
 

I honestly do not understand how to be able to change it so I can have the 4 channel argb instead.  Does anyone have an idea?

Please let me know what other information would be helpful, in getting an idea...thanks.

73
Graphics / Re: Drawing buttons
« on: June 11, 2015, 03:12:46 pm »
I figured out how to make a custom class for this.  Because I need the images to change depending on if the mouse is over, down, or up I inherited a picturebox and tried to use those mouse events, but they will not work.  However, I can set the same boolean values that control the image outside of the class and they work.

Does anyone have an idea why the mouse events of the custom picturebox class will not work when it is drawn to the screen?

74
Graphics / Drawing buttons
« on: June 10, 2015, 04:08:52 pm »
I have been drawing text with rectangles for buttons as a temporary solution just to get something up and running.  The rectangles would be used to check the location of the mouse on mouse up, mouse down, and mouse over subs.  This worked but looked horrid...

I started working on creating buttons to replace that.  On the mouse events it checks if the location contains the mouse, then turns on a global variable. (Mouse Move Sub)
        If InBank Then

            If BankLeaveButtonLocation.Contains(e.Location) Then
                If BankLeaveMouseDownButton = False Then
                    BankLeaveMouseOverButton = True
                End If
            Else
                BankLeaveMouseOverButton = False
            End If
 

Then I have to declare the image for the button.
    ' Bank Leave Button
    Public BankLeaveButtonGfx As Texture
    Public BankLeaveButtonGfxInfo As GraphicInfo
    Public TempBankLeaveButtonBitmap As Bitmap
    Public BankLeaveButtonLocation As Rectangle
 

Then I have to initialize the button graphics with the rest of the graphics.
        ' Bank Leave Button
        BankLeaveButtonGfxInfo = New GraphicInfo
        If FileExist(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT) Then
            TempBankLeaveButtonBitmap = New Bitmap(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT)
            BankLeaveButtonGfxInfo.Width = TempBankLeaveButtonBitmap.Width
            BankLeaveButtonGfxInfo.Height = TempBankLeaveButtonBitmap.Height
            _transcolor = TempBankLeaveButtonBitmap.GetPixel(0, 0)

            _memStream = New MemoryStream()
            TempBankLeaveButtonBitmap.Save(_memStream, ImageFormat.Png)
            BankLeaveButtonGfx = New Texture(_memStream)
            _memStream.Dispose()
        End If
 

When the panel is drawing, then drawing the button, I have to check what the global variable is first and set the Y position.
        Dim BankLeaveButtonOffset As Integer = 0
        If BankLeaveMouseOverButton = True Then
            BankLeaveButtonOffset = MouseOverOffsetY
        ElseIf BankLeaveMouseDownButton = True Then
            BankLeaveButtonOffset = MouseDownOffsetY
        End If
 

Then draw the button in my render loop.
        ' Bank Leave Button Background
        Dim windowLeaveButtonSprite As Sprite = New Sprite(BankLeaveButtonGfx)
        windowLeaveButtonSprite.TextureRect = New IntRect(0, BankLeaveButtonOffset, TempBankLeaveButtonBitmap.Width, TempBankLeaveButtonBitmap.Height / 3)
        windowLeaveButtonSprite.Position = New Vector2f((windowSprite.Position.X + TempBankWindowBitmap.Width / 2) - (TempBankLeaveButtonBitmap.Width / 2), ((windowSprite.Position.Y + TempBankWindowBitmap.Height) - TempBankLeaveButtonBitmap.Height / 3) - 3)
        BankLeaveButtonLocation = New Rectangle(windowLeaveButtonSprite.Position.X, windowLeaveButtonSprite.Position.Y, windowLeaveButtonSprite.GetLocalBounds().Width, windowLeaveButtonSprite.GetLocalBounds().Height)
        GameWindow.Draw(windowLeaveButtonSprite)
 

Then I dispose of the TempBitmap along with the rest of the TempBitmaps...All that is just drawing 1 button, and only list 1 event that it changes.

However, I have to have several buttons drawn on the screen at various times.  Ideally I should create a class, but I am lost on what I will need to do to accomplish this with what I am doing to draw them now.  Can someone help me figure out what to do?

75
Graphics / Re: VB.NET Transparent RenderWindow
« on: May 27, 2015, 01:21:01 pm »
I have tried going about this a different way, and I am calling the following in my render loop:

Public Sub DrawTempWindow()
       
        If Not InGame Then Exit Sub
       
        Dim e As New PaintEventArgs(frmMainGame.Panel1.CreateGraphics(), frmMainGame.Panel1.Bounds)

        Dim tempImage = New Bitmap(frmMainGame.GameScreen.Width, frmMainGame.GameScreen.Height, PixelFormat.Format24bppRgb)
        Dim memoryGraphics As Graphics = Graphics.FromImage(tempImage)
        Dim screenPos As Point = frmMainGame.GameScreen.PointToScreen(New Point(0, 0))
        memoryGraphics.CopyFromScreen(screenPos.X, screenPos.Y, 0, 0, frmMainGame.GameScreen.Size)

        Dim destRect As New Rectangle(0, 0, frmMainGame.Panel1.Width, frmMainGame.Panel1.Height)
        Dim srcRect As New Rectangle(frmMainGame.GameScreen.Location.X, frmMainGame.GameScreen.Location.Y, frmMainGame.Panel1.Width, frmMainGame.Panel1.Height)

        e.Graphics.DrawImage(tempImage, destRect, srcRect, GraphicsUnit.Pixel)

        tempImage.Dispose()
        memoryGraphics.Dispose()

        Dim attributes As New ImageAttributes

        Dim matrixElements As Single()() = { _
        New Single() {1.0F, 0.0F, 0.0F, 0.0F, 0.0F}, _
        New Single() {0.0F, 1.0F, 0.0F, 0.0F, 0.0F}, _
        New Single() {0.0F, 0.0F, 1.0F, 0.0F, 0.0F}, _
        New Single() {0.0F, 0.0F, 0.0F, CSng(0.4), 0.0F}, _
        New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}

        Dim matrix As ColorMatrix
        matrix = New ColorMatrix(matrixElements)
        attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default,
        ColorAdjustType.Bitmap)

        Dim bitmap As Bitmap = New Bitmap(frmMainGame.Panel1.Width, frmMainGame.Panel1.Height, PixelFormat.Format24bppRgb)
        Dim g As Graphics = Graphics.FromImage(bitmap)
        Dim brush As Brush = New SolidBrush(frmMainGame.Panel1.BackColor)
        g.FillRectangle(brush, New RectangleF(0, 0, frmMainGame.Panel1.Width, frmMainGame.Panel1.Height))
        brush.Dispose()

        e.Graphics.DrawImage(bitmap, _
        New Rectangle(0, 0, frmMainGame.Panel1.Width, frmMainGame.Panel1.Height), _
        0, 0, frmMainGame.Panel1.Width, frmMainGame.Panel1.Height, GraphicsUnit.Pixel, attributes)

        bitmap.Dispose()
        g.Dispose()
        brush.Dispose()

    End Sub
 

This shows an almost working transparent panel.  The location of my picturebox (GameScreen) and panel1 are both (208, 0), and my panel1 is 200x200 size.  This displays offset, so it is getting the image 208 pixels to the right of my panel1.  When I set [srcRect As New Rectangle(frmMainGame.GameScreen.Location.X - 208,...] it displays what is under the form, but if I only set it halfway, it will display an offset of 104 pixels, and also show 2 sections on my panel1 where it is picking up the panel1 when it takes the initial image.

I have tried turning the visibility off, getting the image, then turning panel1 visibility back on, then drawing the image, but I get the same results.

Alternatively I have also searched on how to use panel1 as a RenderWindow, then Draw() the image the same way as I do sprites, but I can find nothing on rendering an entire image, or converting the bitmap that is drawn with e.graphics to a texture.

Pages: 1 ... 3 4 [5] 6
anything