Page 1 of 1

problem with releasemouse + openwindowscreen

Posted: Sat Nov 13, 2004 3:02 pm
by patrick88
hi,

This application opens a window with a graphic screen inside. I thus have a graphic cursor which is trotted with the mouse.

but the mouse hesitates much to return in the graphic screen.
would you have an idea to arrange that?
or a better solution...

thanks

patrick88

Code: Select all

;- déclaration constante
#WINDOW_DEPLACED = 161

Enumeration
  #WIN_MAIN
  #GDT_STATUSBAR
  #GDT_STATUSBAR_COORDX
  #GDT_STATUSBAR_COORDY
EndEnumeration

;- déclaration structure
Structure STRU_INFO_WINDOW
  ;relatif à la fenêtre principale
  main_x.w
  main_y.w
  main_width.w
  main_height.w
  main_flag.l
  main_version.s
  
  ;relatif à la zone de dessin
  draw_x.w
  draw_y.w
  draw_width.w
  draw_height.w
  draw_AutoStretch.l
  draw_RightOffset.w
  draw_BottomOffset.w
  draw_TopOffset.w
  
  etat.w
EndStructure

;- déclaration variable
Global INFO_WINMAIN.STRU_INFO_WINDOW
Global a_qui_est_la_souris.b

Procedure initialisation()
  ;relatif à la fenêtre principale
  INFO_WINMAIN\main_x = 50
  INFO_WINMAIN\main_y = 50
  INFO_WINMAIN\main_width = 600
  INFO_WINMAIN\main_height = 350
  INFO_WINMAIN\main_flag = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
  INFO_WINMAIN\main_version = "Draw-01-00"
  
  ;relatif à la zone de dessin
  INFO_WINMAIN\draw_x = 25
  INFO_WINMAIN\draw_y = 25
  INFO_WINMAIN\draw_RightOffset = 25
  INFO_WINMAIN\draw_BottomOffset = 25
  INFO_WINMAIN\draw_TopOffset = 4
  INFO_WINMAIN\draw_width = INFO_WINMAIN\main_width - INFO_WINMAIN\draw_x-INFO_WINMAIN\draw_RightOffset
  INFO_WINMAIN\draw_height = INFO_WINMAIN\main_height - INFO_WINMAIN\draw_y-INFO_WINMAIN\draw_BottomOffset
  INFO_WINMAIN\draw_AutoStretch = 1
  
  If InitSprite() = 0 Or InitKeyboard()=0 Or InitMouse()  = 0
    MessageRequester( "Erreur" , "Impossible d'initialiser DirectX 7 Ou plus" , 0 )
    End
  ElseIf OpenWindow(#WIN_MAIN,INFO_WINMAIN\main_x,INFO_WINMAIN\main_y,INFO_WINMAIN\main_width,INFO_WINMAIN\main_height,INFO_WINMAIN\main_flag,INFO_WINMAIN\main_version) = 0
    MessageRequester( "Erreur", "Impossible d'ouvrir la fenêtre")
    End
  EndIf
  If OpenWindowedScreen( WindowID(#WIN_MAIN), INFO_WINMAIN\draw_x,INFO_WINMAIN\draw_y,INFO_WINMAIN\draw_width,INFO_WINMAIN\draw_height, INFO_WINMAIN\draw_AutoStretch, INFO_WINMAIN\draw_RightOffset, INFO_WINMAIN\draw_BottomOffset ) = 0
    MessageRequester( "Erreur" , "Impossible d'ouvrir l'écran " , 0 )
    End
  EndIf
  If CreateStatusBar(#GDT_STATUSBAR, WindowID(#WIN_MAIN))
    AddStatusBarField(80)
    AddStatusBarField(80)
  EndIf
  
  a_qui_est_la_souris=0
  INFO_WINMAIN\etat = 0
EndProcedure

initialisation()
Repeat
  ClearScreen(255,255,255)
  
  result = ExamineMouse()
  
  If INFO_WINMAIN\etat = 0
    INFO_WINMAIN\etat =1
    MouseLocate(INFO_WINMAIN\draw_width/2,INFO_WINMAIN\draw_height/2)
  EndIf
  mx.w = MouseX() : my.w = MouseY()
  
  If StartDrawing(ScreenOutput())
    FrontColor(255,0,0)
    LineXY(0,my,INFO_WINMAIN\draw_width,my)
    LineXY(mx,0,mx,INFO_WINMAIN\draw_height)
    StopDrawing()
  EndIf
  
  StatusBarText(#GDT_STATUSBAR, 0, "X:"+Str(mx))
  StatusBarText(#GDT_STATUSBAR, 1, "Y:"+Str(my))
  
  wmx = WindowMouseX() : wmy = WindowMouseY()
  
  ReleaseMouse(0)
  If wmx <= INFO_WINMAIN\draw_x+5 Or wmx >=INFO_WINMAIN\draw_width + INFO_WINMAIN\draw_x Or wmy <= INFO_WINMAIN\draw_y+5 Or wmy >=INFO_WINMAIN\draw_height + INFO_WINMAIN\draw_y
    ReleaseMouse(1)
  Else
    ReleaseMouse(0)
  EndIf

  
  ;- gestion des évenement windows
  Select WindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #WM_LBUTTONDOWN
      ; If  a_qui_est_la_souris = 1
        ; a_qui_est_la_souris = ReleaseMouse(0)
        ; INFO_WINMAIN\etat =0
      ; EndIf
      
      ;-Gadgets
    Case #PB_Event_Gadget
      Select EventGadgetID()
        
      EndSelect
      
    Default
      
  EndSelect
  
  FlipBuffers()
  
  Delay(1)
Until Quit>0
End 

Posted: Mon Nov 15, 2004 6:54 pm
by patrick88
another solution, with use of createimage... ending of problem with releasemouse()

modif of :

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Image example file
;
;    (c) 2001 - Fantaisie Software
;
; ------------------------------------------------------------
;
;
; Some 2D graphics functions...
;

Procedure Create_Image()

If CreateImage(0, 500, 300)
  
  StartDrawing(ImageOutput())
  
  For k=0 To 500
    FrontColor(k,0, k)  ; a rainbow, from black to pink
    Line(0, k, 300, 0)
  Next
  
  DrawingMode(1)
  Locate(40, 50)
  FrontColor(255,255,255) ; print the text to white !
  DrawText("An image created easely...")
  
  StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
  
EndIf
  
;CopyImage(0, 1)
;ResizeImage(1, 100, 100)
  
;GrabImage(0, 2, 100, 60, 150, 40)
EndProcedure

Procedure WindowCallback(WindowID, Message, lParam, wParam)
  If Message = #WM_PAINT
    StartDrawing(WindowOutput())
    DrawImage(UseImage(0), 0, 0)
    ;DrawImage(UseImage(1), 320, 80)
    ;DrawImage(UseImage(2), 320, 200)
    StopDrawing()
  EndIf
  
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure


If OpenWindow(0, 100, 100, 500, 300, #PB_Window_SystemMenu, "PureBasic - Image")
  
  Create_Image()
  
  SetWindowCallback(@WindowCallback())
  
  Repeat
    EventID = WaitWindowEvent()
    StartDrawing(WindowOutput())
      DrawImage(UseImage(0), 0, 0)
    StopDrawing()
    
    StartDrawing(WindowOutput())
      FrontColor(255,255,255)
      LineXY(0,WindowMouseY(),500,WindowMouseY())
      LineXY(WindowMouseX(),0,WindowMouseX(),300)
    StopDrawing()
  Until EventID = #PB_EventCloseWindow  ; If the user has pressed on the close button
  
EndIf

End   ; All the opened windows are closed automatically by PureBasic