Check Fake Focus

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Check Fake Focus

      Hi guys,

      In the last chapter about the C# editor, there's a section on input handling. In it, I find the following method:

      Source Code

      1. void CheckFakeFocus()
      2. {
      3. System.Drawing.Point position = Cursor.Position;
      4. System.Drawing.Point relativeToForm = m_displayPanel.PointToClient(position);
      5. m_fakeFocus = (relativeToForm.X >= 0 && relativeToForm.Y >= 0 &&
      6. relativeToForm.X < m_displayPanel.Width && relativeToForm.Y < m_displayPanel.Width);
      7. if (m_fakeFocus)
      8. {
      9. m_mouseDownPosition = position;
      10. }
      11. }
      Display All

      Which is used as:

      Source Code

      1. public bool PreFilterMessage(ref Message m)
      2. {
      3. // Intercept messages only if they occur for the EditorForm
      4. // or its display panel.
      5. if (m.Msg == WM_LBUTTONDOWN || m.Msg == WM_RBUTTONDOWN || m.Msg == WM_MBUTTONDOWN)
      6. CheckFakeFocus();
      7. if (m.HWnd == m_displayPanel.Handle || (m_fakeFocus && (m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP)))
      8. {
      9. switch (m.Msg)
      10. {
      Display All

      I was just wondering what the purpose is of this fake focus check? It seems to just check if the mouse cursor is inside the display panel, and then it sets the position to the real position? How exactly does this affect anything?

      Thanks!
      Cheers and beers from Belgium!
    • Without having implemented it myself as yet, I think the answer is in the method signature and comment.

      Source Code

      1. public bool PreFilterMessage(ref Message m)
      2. {
      3. // Intercept messages only if they occur for the EditorForm
      4. // or its display panel.


      Fakefocus appears to be a mouse over focus which isn't really focus; when the cursor is over a panel it has fake focus but not actual focus.
      The actual focus is given to actors with the PickActor() call in the switch statement.
      It's also an optimisation because panels that don't have fake focus (mouse over) wont consume messages (hence the name prefiltermessage()).

      Cheers.
    • Hello - yes that is indeed the reason. It was a little tricky to get keyboard messages to be received by the right UI entity, whether that was input fields in the component editor or the scene window.

      Maybe there's a better way to do that - at the time I wrote this code I would say my C# was still going through some n00bness.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • Thank you both for clarifying, I understand its purpose now!
      Just going to share an early screenshot of my editor-in-progress for fun, I'd imagine as author you'd be curious to see how other people are applying what they learn from the book :)

      Of course this is all still cleary a very early WIP, but proper progress is being made!

      [IMG:http://imageshack.us/a/img855/8528/r50a.th.png]
      Cheers and beers from Belgium!

      The post was edited 1 time, last by L0d3man ().

    • Look at that!

      Trees with shadows and everything. Now all you need is a killer ATV to drive around in.....
      Mr.Mike
      Author, Programmer, Brewer, Patriot