Shaped Window with mouse area problem

New to FreeBASIC? Post your questions here.
Forgotten Coder
Posts: 4
Joined: Jan 12, 2019 12:23

Shaped Window with mouse area problem

Postby Forgotten Coder » Jan 13, 2019 23:24

Hi everyone

There are many gui's like Windows, Linux flavors, etc. But what if we want to make a new one ? Where to start ? Well i started by trying to make a colored window with a bar on top. So far so good. But problems started when i tried to use the mouse ...

The problem is i can't fix the mouse position inside top area when i am pressing a button. If i move it "violently" up, down, left, right it will go off the limits of top bar ...:(

Here is my code. Any ideas ? Making experiments with this for hours. I am using Windows 7.

Code: Select all

#include "fbgfx.bi"
Using fb

Dim e As EVENT

Dim As Integer x, y, pressed, buttons, wx, wy
Dim As Any Ptr img

Screen 20, 32,, GFX_SHAPED_WINDOW

img=imagecreate(1024,768)

Line img, (0, 0)-(1024, 768), RGBA(96, 96, 96,255), BF
Line img, (0, 0)-(1024, 40), RGBA(64, 64, 64,200), BF

put (0,0), img

pressed = 0

Do
   
    screenLock()
    if (ScreenEvent(@e)) then
       
      if e.type = EVENT_MOUSE_BUTTON_PRESS then
        pressed=1
      end if 
     
      if e.type = EVENT_MOUSE_BUTTON_RELEASE then
        pressed = 0
      end if
     
      'check if mouse is in top area
      if pressed=1 then
        if (e.x>=0 and e.x<=1024 and e.y>=0 and e.y<=40) then
          'move window 
          ScreenControl GET_WINDOW_POS, wx, wy
          ScreenControl SET_WINDOW_POS, wx + e.dx, wy + e.dy
        end if
      end if   
     
   end if
   
   screenunLock()   
   
   'Sleep 1
   
Loop While Not MultiKey(1)


badidea
Posts: 1144
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Shaped Window with mouse area problem

Postby badidea » Jan 13, 2019 23:43

May I suggest the name: YaGUI = Yet another Graphical User Interface.
Making a good GUI with all the features is a lot of work.

I cannot move the window at all here (on linux).
oyster
Posts: 157
Joined: Oct 11, 2005 10:46

Re: Shaped Window with mouse area problem

Postby oyster » Jan 14, 2019 1:35

it seems that fltk supports shaped window
leopardpm
Posts: 1775
Joined: Feb 28, 2009 20:58

Re: Shaped Window with mouse area problem

Postby leopardpm » Jan 14, 2019 2:24

hmmm... i see the problem, but don't know the fix.

I modified your code so that you don't loose the window when you move mouse violently.... but it still doesn't track the mouse fast enough for some reason... this will work for you though:

Code: Select all

#include "fbgfx.bi"
Using fb

Dim e As EVENT

Dim As Integer x, y, pressed, buttons, wx, wy
Dim As Any Ptr img

Screen 20, 32,, GFX_SHAPED_WINDOW

img=imagecreate(1024,768)

Line img, (0, 0)-(1024, 768), RGBA(96, 96, 96,255), BF
Line img, (0, 0)-(1024, 40), RGBA(64, 64, 64,200), BF

put (0,0), img

pressed = 0
dim as integer windowgrab = 0
Do
   
   
    if (ScreenEvent(@e)) then
       
      if e.type = EVENT_MOUSE_BUTTON_PRESS then
        pressed=1
        if (e.x>=0 and e.x<=1024 and e.y>=0 and e.y<=40) then
            windowgrab = 1
        end if
      end if 
     
      if e.type = EVENT_MOUSE_BUTTON_RELEASE then
        pressed = 0
        windowgrab = 0
      end if
     
      'check if mouse is in top area
      if windowgrab=1 then
          'move window
          screenLock()
          ScreenControl GET_WINDOW_POS, wx, wy
          ScreenControl SET_WINDOW_POS, wx + e.dx, wy + e.dy
          screenunLock()
      end if   
     
   end if
   
     
   
   'Sleep 1
   
Loop While Not MultiKey(1)


Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests