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

Author Topic: How do I make a Windows ContextMenu inside an SFML application? (.net)  (Read 5029 times)

0 Members and 1 Guest are viewing this topic.

ggggggggggggggg

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Email
The only tutorials I've seen are for a Windows form application. I was wondering if it was possible to use a Context Menu without a Windows form. If not I'll be forced to make it myself but I obviously want to see if I can use a premade one before I make my own.

I know how to actually make a Context Menu but I don't know how to use ContextMenu.Show. It takes a System.Windows.Forms.Control parameter which makes me believe it's not possible outside of a Windows form.
« Last Edit: September 24, 2015, 07:08:36 am by asusralis »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: How do I make a Windows ContextMenu inside an SFML application? (.net)
« Reply #1 on: September 24, 2015, 10:38:16 am »
I think what you're looking for is NativeWindow and it's AssignHandle() member. This should allow you to wrap SFML's window and make it accessible for C# stuff (untested).

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: How do I make a Windows ContextMenu inside an SFML application? (.net)
« Reply #2 on: September 24, 2015, 02:06:40 pm »
So if I understand correctly you want to draw SFML in a window and then when you right click utilize a native context menu?

If so just embed SFML within a Windows Form and when you use ContextMenu.Show(...) pass the form that SFML is embedded in as the control reference.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

ggggggggggggggg

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Email
Re: How do I make a Windows ContextMenu inside an SFML application? (.net)
« Reply #3 on: October 20, 2015, 05:38:25 am »
I'm not sure how to wrap SFML's window or embed SFML into a Form. Do you mean to make a Form project and ignore the actual Form? Because I've been trying this but I'm not sure what to pass.

For the life of me I can't figure this out. Sadly there is next to nothing on the internet that has much on this (or NativeWindow). When you mean intercept the control do you mean SFML takes the info passed and uses it itself? How is the contextmenu/button/whatever form object is actually drawn?

Is this something that isn't supposed to happen? I.e is it better to just make my own UI system in SFML or it common for an application to use its own render window but use form elements?
« Last Edit: October 20, 2015, 05:40:45 am by asusralis »

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: How do I make a Windows ContextMenu inside an SFML application? (.net)
« Reply #4 on: October 20, 2015, 07:11:24 pm »
Context menu is not related to the graphics, it's windows control, so it is not related to SFML and depends on windows platform.
You are need to implement your own context menu by using RectangleShape and Text objects.

ggggggggggggggg

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Email
Re: How do I make a Windows ContextMenu inside an SFML application? (.net)
« Reply #5 on: October 21, 2015, 06:37:46 pm »
Right. But I do want to use the Window's context menu. That's what I'm trying to figure out how to do. The two people who replied to me pushed me in the right direction but I'm not actually sure how to do it. There's next to none on the web about this.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: How do I make a Windows ContextMenu inside an SFML application? (.net)
« Reply #6 on: October 22, 2015, 06:58:00 pm »
Quote
I'm not sure how to wrap SFML's window or embed SFML into a Form. Do you mean to make a Form project and ignore the actual Form? Because I've been trying this but I'm not sure what to pass.

If you read the documentation or search around (I already posted multiple examples of this in the .Net forum) it is already well explained.

Quote
Sadly there is next to nothing on the internet that has much on this

Really?

Quote
How is the contextmenu/button/whatever form object is actually drawn?

In WinForms every single control is an actual window that the OS has created and embedded within another window. Whether SFML creates a window itself or uses an existing window the graphics initialization part is the same (creating an opengl context with the handle of whatever window it is using). So to embed SFML in a WinForms project all you do is pass the handle of the control to the constructor. Then the OpenGL rendering takes over for drawing that window's contents (or control as it is also a window).

And really, if you want to integrate WinForms with SFML it is best to already know how WinForms works so I won't be explaining that here. But I just took 5 minutes and wrote the following example (exactly how I already explained to do it) which shows opening a native context menu. The code should be self explanatory and give you enough to get started.

(click to show/hide)

(click to show/hide)
« Last Edit: October 22, 2015, 07:07:40 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

ggggggggggggggg

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Email
Re: How do I make a Windows ContextMenu inside an SFML application? (.net)
« Reply #7 on: October 23, 2015, 10:52:49 am »
Although I don't see why the hostility (and see why people usually talk ill about these forums...) I thank you for the help. Now to make all of this work by myself!
« Last Edit: October 23, 2015, 11:01:34 am by asusralis »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: How do I make a Windows ContextMenu inside an SFML application? (.net)
« Reply #8 on: October 23, 2015, 03:06:21 pm »
Although I don't see why the hostility (and see why people usually talk ill about these forums...)

 ??? I would honestly love to hear what you thought was hostile about my reply.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor