IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PureBasic Discussion :

plantage si mouseclick


Sujet :

PureBasic

  1. #1
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    40
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Mars 2006
    Messages : 40
    Points : 31
    Points
    31
    Par défaut plantage si mouseclick
    Bonjour !

    Alors, une petite question pour les debuggers confirmés: J'ai un petit programme qui ouvre un écran dans une fenêtre. Tout se passe bien pendant qq secondes, puis... si on clique (gauche) la fenêtre devient blanche et plante.

    Est ce que cela vient de mon code ? de PB 4.31 64bits ? Windows 7 64 ?
    Si qqun reprend ce code, avez vous un plantage identique ?
    Le fichier chargé est zippé et joint (mouse.bmp)

    Merci pour toute info !
    Sam

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    Global imgMousePointer.l
     
    Macro DebugTxt
      StartDrawing(ScreenOutput())
      DrawText(0,0,"x " + Str(MouseX()) + " - y " + Str(MouseY()))
      StopDrawing()
    EndMacro
     
    ;- Init DirectX
    If InitSprite()=0 Or InitMouse()=0 Or InitKeyboard()=0
      MessageRequester("Erreur","Impossible d'initialiser DirectX")
      End
    EndIf
     
    ;- Main loop
    If OpenWindow(0, 0, 0, 800,600, "3D iso viewer", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
      OpenWindowedScreen(WindowID(0),0,0,800,600,1,0,0)
     
      imgMousePointer = LoadSprite(#PB_Any,"mouse.bmp",0)
      TransparentSpriteColor(imgMousePointer, RGB(255, 0, 255))
      DisplayTransparentSprite(imgMousePointer,500,440)
     
      Repeat
        ExamineKeyboard() : ExamineMouse() : ClearScreen($0)
        DisplayTransparentSprite(imgMousePointer,MouseX(),MouseY())
        DebugTxt
        FlipBuffers()
      Until KeyboardPushed(#PB_Key_Escape)
    EndIf
    Fichiers attachés Fichiers attachés

  2. #2
    Responsable Purebasic

    Avatar de comtois
    Inscrit en
    Avril 2003
    Messages
    1 262
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 1 262
    Points : 9 981
    Points
    9 981
    Billets dans le blog
    8
    Par défaut
    il faut traiter tous les événements dans la file d'attente à chaque tour de ta boucle principale.

    Ajoute ça dans ton code, juste après ton Repeat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
        While WindowEvent()
        wend
    Vous souhaitez participer à la rubrique PureBasic (tutoriels, FAQ, sources) ? Contactez-moi par MP.

  3. #3
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    40
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Mars 2006
    Messages : 40
    Points : 31
    Points
    31
    Par défaut
    Ok, c'était parfait comme réponse, merci !

    Maintenant que les évènements sont pris en compte, j'essaie de ne prendre en compte qu'un seul clic de souris à la fois. Sur le programe suivant, tant que le bouton gauche (ou droit) est enfoncé, l'action continue.
    Je souhaiterais uniquement réaliser mon action une fois uniquement, au moment ou le clic de la souris est relâché par exemple.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
     
    #ScreenWidth = 800
    #ScreenHeight = 600
    #ScrollSpeed=5
    #TailleMapX=256
    #TailleMapY=256
    #TailleTileX = 32
    #TailleTileY = 32
    #Offset = -16
    #Levelling = 5
     
    Structure World
      X.i
      Y.i
      Z.i
    EndStructure
     
    Global Dim Map.World(#TailleMapX*#TailleMapY)
    Global imgMousePointer.i
     
    Declare Max(nb1.l,nb2.l)
    Declare InitMap()
    Declare DrawMap()
    Declare UpdateMouse()
     
    Macro DebugTxt()
      StartDrawing(ScreenOutput())
      DrawText(0,0,"x " + Str(MouseX()) + " - y " + Str(MouseY()))
      DrawText(0,20,"x1 " + Str(MouseX() - (MouseX() % #TailleTileX)) + " y1 " +  Str(MouseY() - (MouseY() % #TailleTileY)))
      StopDrawing()
    EndMacro
    Procedure.l Minimum(nb1.l, nb2.l)
      If nb1<nb2
        Resultat.l = nb1
      Else
        Resultat.l = nb2
      EndIf
      ProcedureReturn Resultat
    EndProcedure 
    Procedure.l Maximum(nb1.l, nb2.l)
      If nb1>nb2
        Resultat.l = nb1
      Else
        Resultat.l = nb2
      EndIf
      ProcedureReturn Resultat
    EndProcedure
     
    ;- Init Resources
    If InitSprite()=0 Or InitMouse()=0 Or InitKeyboard()=0
      MessageRequester("Erreur","Impossible d'initialiser DirectX")
      End
    EndIf
     
    ;- Main loop
    If OpenWindow(0, 0, 0, 800,600, "3D iso viewer", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
      OpenWindowedScreen(WindowID(0),0,0,#ScreenWidth+1,#ScreenHeight+1,1,0,0)
     
      imgMousePointer = LoadSprite(#PB_Any,"mouse.bmp",0)
      TransparentSpriteColor(imgMousePointer, RGB(255, 0, 255))
      DisplayTransparentSprite(imgMousePointer,500,440)
     
      InitMap()
      Repeat
        While WindowEvent()
        Wend
        ExamineKeyboard() : ExamineMouse() : ClearScreen($0)
        DrawMap()
        UpdateMouse()
        DebugTxt()
        FlipBuffers()
      Until KeyboardPushed(#PB_Key_Escape)
    EndIf
     
    Procedure InitMap()
    a=0
      For j=0 To #ScreenHeight Step #TailleTileY
        For i=0 To #ScreenWidth Step #TailleTileX
          Map(a)\X = i
          Map(a)\Y = j
          Map(a)\z = 0
          a+1      
        Next i
      Next j
    EndProcedure
     
    Procedure DrawMap()
      StartDrawing(ScreenOutput())
      For i =0 To #TailleMapX*#TailleMapY
        Plot(Map(i)\X,Map(i)\Y + Map(i)\z,$FF00FF)
      Next i
      StopDrawing()
    EndProcedure
     
    Procedure UpdateMouse()
      DisplayTransparentSprite(imgMousePointer,MouseX(),MouseY())
     
    ; calculate map(i) current position under mouse
        tmp1=(MouseX() - (MouseX() % #TailleTileX))/#TailleTileX
        tmp2=(MouseY() - (MouseY() % #TailleTileY))/#TailleTileY
        tmp3=(tmp2 * ((#ScreenWidth/#TailleTileX)+1) + tmp1)
     
      If MouseButton(#PB_MouseButton_Left)
        StartDrawing(ScreenOutput())
          DrawText(0,40,"LEFT")
          DrawText(0,60,Str(tmp1) + " " + Str(tmp2) + " " + Str(tmp3))
          map(tmp3)\z + #Levelling
        StopDrawing()
      EndIf 
      If MouseButton(#PB_MouseButton_Middle)
        StartDrawing(ScreenOutput())
          DrawText(40,40,"MIDDLE")
          DrawText(0,60,Str(tmp1) + " " + Str(tmp2) + " " + Str(tmp3))
        StopDrawing()
      EndIf 
      If MouseButton(#PB_MouseButton_Right)
        StartDrawing(ScreenOutput())
          DrawText(100,40,"RIGHT")
          DrawText(0,60,Str(tmp1) + " " + Str(tmp2) + " " + Str(tmp3))
          map(tmp3)\z - #Levelling
        StopDrawing()
      EndIf 
     
    ;   point1X = Minimum((MouseX()-#offset) - ((MouseX()-#offset) % #TailleTileX),800)
    ;   point2X = Minimum((MouseX()-#offset) - ((MouseX()-#offset) % #TailleTileX) + #TailleTileX,800) 
    ;   point1Y = Minimum((MouseY()-#offset) - ((MouseY()-#offset) % #TailleTileY),600)
    ;   point2Y = Minimum((MouseY()-#offset) - ((MouseY()-#offset) % #TailleTileY) + #TailleTileY,600)
    ;   isoX1 = point1X - point1Y
    ;   isoX2 = point2X - point2Y
    ;   isoY1 = (point1X+point1Y)/2
    ;   isoY2 = (point2X+point2Y)/2
    ;   
    ;   StartDrawing(ScreenOutput())
    ;     Plot(point1X,point1Y,$FFFFFF)
    ;     Plot(point2X,point2Y,$FFFFFF)
    ;     Plot(point1X,point2Y,$FFFFFF)
    ;     Plot(point2X,point1Y,$FFFFFF)
    ;  StopDrawing()
     
      point1X = Map(tmp3)\X
      point1Y = Map(tmp3)\Y + Map(tmp3)\z
      point2X = Map(tmp3+1)\X
      point2Y = Map(tmp3+1)\Y + Map(tmp3+1)\z
      point3X = Map(tmp3+(#ScreenWidth/#TailleTileX)+1)\X
      point3Y = Map(tmp3+(#ScreenWidth/#TailleTileX)+1)\Y+Map(tmp3+(#ScreenWidth/#TailleTileX)+1)\z
      point4X = Map(tmp3+(#ScreenWidth/#TailleTileX)+2)\X
      point4Y =Map(tmp3+(#ScreenWidth/#TailleTileX)+2)\Y+Map(tmp3+(#ScreenWidth/#TailleTileX)+2)\z
     
       StartDrawing(ScreenOutput())
         LineXY(point1X,point1Y,point2X,point2Y,$FFFFFF)
         LineXY(point1X,point1Y,point3X,point3Y,$FFFFFF)
         LineXY(point3X,point3Y,point4X,point4Y,$FFFFFF)
         LineXY(point2X,point2Y,point4X,point4Y,$FFFFFF)
      StopDrawing()
    EndProcedure
    J'ai balayé mes tentatives dans ce code, mais j'ai essayé de définir un mouserelease.b qui vaut 1 ou 0, l'initialiser à 1 et le mettre à 0 quand on passe dans la boucle ou la souris est testée. ce n'était pas très optimal ni ne fonctionnait. Une idée ?

    Merci !

  4. #4
    Responsable Purebasic

    Avatar de comtois
    Inscrit en
    Avril 2003
    Messages
    1 262
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 1 262
    Points : 9 981
    Points
    9 981
    Billets dans le blog
    8
    Par défaut
    Si tu as une fenêtre, tu peux aussi essayer d'utiliser windowMouseX() et WindowMouseY() qui utilise l'API plutôt qu'un examineMouse() qui utilise directx, et tu peux tester ton bouton ainsi :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
    InitSprite()
    OpenWindow(0, 0, 0, 400, 200, "Souris", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    OpenWindowedScreen(WindowID(0), 0, 0, 400, 200, 0, 0, 0)
     
    Repeat
     
      Repeat
        Event = WindowEvent()
     
        If Event = #WM_CLOSE
          End
        EndIf
     
        If Event = #WM_LBUTTONDOWN
            SetWindowTitle(0, "Bouton gauche appuyé")
     
        ElseIf Event = #WM_LBUTTONUP
            SetWindowTitle(0, "Bouton gauche relaché")
            StartDrawing(ScreenOutput())
              Box(WindowMouseX(0), WindowMouseY(0), 4, 4,  #Red)
            StopDrawing()
     
        ElseIf Event = #WM_RBUTTONDOWN
            SetWindowTitle(0, "Bouton droit appuyé")
     
        ElseIf Event = #WM_RBUTTONUP
            SetWindowTitle(0, "Bouton droit relaché")
     
        EndIf
      Until Event = 0
     
      FlipBuffers()
     
    ForEver
    Dans l'exemple ci-dessus je trace un carré rouge à l'écran où se trouve la souris , uniquement quand tu relâches le bouton gauche.
    Vous souhaitez participer à la rubrique PureBasic (tutoriels, FAQ, sources) ? Contactez-moi par MP.

  5. #5
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    40
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Mars 2006
    Messages : 40
    Points : 31
    Points
    31
    Par défaut
    Bien bien, de très bon conseil j'imagine. Néanmoins, il faut la version complète pour avoir accès à l'API de Windows. Ce n'est pas (encore) mon cas.

    Je vais donc essayer d'autres choses.

  6. #6
    Responsable Purebasic

    Avatar de comtois
    Inscrit en
    Avril 2003
    Messages
    1 262
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 1 262
    Points : 9 981
    Points
    9 981
    Billets dans le blog
    8
    Par défaut
    euh, il n'y a pas d'api direct là ,seulement des commandes PureBasic, ça devrait fonctionner chez toi ?

    Effectivement tu n'as pas les résidents avec la version démo, il doit te manquer les constantes de ce type #WM_RBUTTONDOWN , mais tu peux les définir en faisant une recherche sur google, tu trouveras la valeur

    Mais je reconnais que ça peut devenir fastidieux. donc pour rester dans l'esprit de ce que tu utilises, peut-être un truc de ce genre (pas testé)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    If ExamineMouse()
      If MouseButton(#PB_MouseButton_Left)
        MemoireBoutonGauche = #True
      ElseIf MemoireBoutonGauche
        ;Mettre une procédure ou ce que tu veux ici
        Debug "action unique quand le bouton gauche de la souris est relâché"
        MemoireBoutonGauche = #False
      EndIf  
    EndIf
    Vous souhaitez participer à la rubrique PureBasic (tutoriels, FAQ, sources) ? Contactez-moi par MP.

  7. #7
    Responsable Purebasic

    Avatar de comtois
    Inscrit en
    Avril 2003
    Messages
    1 262
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 1 262
    Points : 9 981
    Points
    9 981
    Billets dans le blog
    8
    Par défaut
    j'ai refais le premier code sans les constantes, ça devrait aussi fonctionner chez toi avec la version démo ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
    InitSprite()
    OpenWindow(0, 0, 0, 400, 200, "Souris", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    OpenWindowedScreen(WindowID(0), 0, 0, 400, 200, 0, 0, 0)
     
    Repeat
     
      Repeat
        Event = WindowEvent()
     
        If Event = #PB_Event_CloseWindow
          End
        EndIf
     
        If Event = 513
            SetWindowTitle(0, "Bouton gauche appuyé")
     
        ElseIf Event = 514
            SetWindowTitle(0, "Bouton gauche relaché")
            StartDrawing(ScreenOutput())
              Box(WindowMouseX(0), WindowMouseY(0), 4, 4,  #Red)
            StopDrawing()
     
        ElseIf Event = 516
            SetWindowTitle(0, "Bouton droit appuyé")
     
        ElseIf Event = 517
            SetWindowTitle(0, "Bouton droit relaché")
     
        EndIf
      Until Event = 0
     
      FlipBuffers()
     
    ForEver
    Vous souhaitez participer à la rubrique PureBasic (tutoriels, FAQ, sources) ? Contactez-moi par MP.

  8. #8
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    40
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Mars 2006
    Messages : 40
    Points : 31
    Points
    31
    Par défaut
    Effectivement, cela fonctionne mieux sans les constantes (au passage, #RED est une constante).
    Du coup, avec ce bout de code, j'ai même l'impression qu'on peut gérer l'action au moment du clic et non de son relâchement. C'est tip top.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
     
    InitSprite()
    OpenWindow(0, 0, 0, 400, 200, "Souris", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    OpenWindowedScreen(WindowID(0), 0, 0, 400, 200, 0, 0, 0)
     
    Repeat
     
      Repeat
        Event = WindowEvent()
     
        If Event = #PB_Event_CloseWindow
          End
        EndIf
     
        If Event = 513
            SetWindowTitle(0, "Bouton gauche appuyé")
            StartDrawing(ScreenOutput())
              Box(WindowMouseX(0), WindowMouseY(0), 4, 4,  $FF0000)
            StopDrawing()
     
        ElseIf Event = 514
            SetWindowTitle(0, "Bouton gauche relaché")
     
     
        ElseIf Event = 516
            SetWindowTitle(0, "Bouton droit appuyé")
            StartDrawing(ScreenOutput())
              Box(WindowMouseX(0), WindowMouseY(0), 4, 4,  $00000FF)
            StopDrawing()
     
        ElseIf Event = 517
            SetWindowTitle(0, "Bouton droit relaché")
     
        EndIf
      Until Event = 0
     
      FlipBuffers()
     
    ForEver
    Encore une victoire de comtois.

  9. #9
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    40
    Détails du profil
    Informations personnelles :
    Âge : 44

    Informations forums :
    Inscription : Mars 2006
    Messages : 40
    Points : 31
    Points
    31
    Par défaut
    Après inclusion dans le code d'origine, cela fonctionne pile poil.
    Après un bref regard sur l'aide MSDN, j'ai compris pourquoi je ne pouvais pas cliquer à toute vitesse: il faut également gérer le double clic:
    Du coup, il faut tester l'Event 513 & 515 (WM_LBUTTONDOWN et WM_LBUTTONDBLCLK) pour le clic gauche et 516 & 518 pour le clic droit.

    C'est fou comment c'est simple parfois...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
     
    #ScreenWidth = 800
    #ScreenHeight = 600
    #ScrollSpeed=5
    #TailleMapX=256
    #TailleMapY=256
    #TailleTileX = 32
    #TailleTileY = 32
    #Offset = -16
    #Levelling = 5
     
    Structure World
      X.i
      Y.i
      Z.i
    EndStructure
     
    Global Dim Map.World(#TailleMapX*#TailleMapY)
    Global imgMousePointer.i
    Global Event
     
    Declare Max(nb1.l,nb2.l)
    Declare InitMap()
    Declare DrawMap()
    Declare UpdateMouse()
     
    Macro DebugTxt()
      StartDrawing(ScreenOutput())
      DrawText(0,0,"x " + Str(MouseX()) + " - y " + Str(MouseY()))
      DrawText(0,15,"x1 " + Str(MouseX() - (MouseX() % #TailleTileX)) + " y1 " +  Str(MouseY() - (MouseY() % #TailleTileY)))
      StopDrawing()
    EndMacro
    Procedure.l Minimum(nb1.l, nb2.l)
      If nb1<nb2
        Resultat.l = nb1
      Else
        Resultat.l = nb2
      EndIf
      ProcedureReturn Resultat
    EndProcedure 
    Procedure.l Maximum(nb1.l, nb2.l)
      If nb1>nb2
        Resultat.l = nb1
      Else
        Resultat.l = nb2
      EndIf
      ProcedureReturn Resultat
    EndProcedure
     
    ;- Init Resources
    If InitSprite()=0 Or InitMouse()=0 Or InitKeyboard()=0
      MessageRequester("Erreur","Impossible d'initialiser DirectX")
      End
    EndIf
     
    ;- Main loop
    If OpenWindow(0, 0, 0, 800,600, "3D iso viewer", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
      OpenWindowedScreen(WindowID(0),0,0,#ScreenWidth+1,#ScreenHeight+1,1,0,0)
     
      imgMousePointer = LoadSprite(#PB_Any,"mouse.bmp",0)
      TransparentSpriteColor(imgMousePointer, RGB(255, 0, 255))
      DisplayTransparentSprite(imgMousePointer,500,440)
     
      InitMap()
     
    ;  Repeat
    ;    While WindowEvent()
    ;    Wend
      Repeat
        Event = WindowEvent()
        ExamineKeyboard()
        ExamineMouse()
        ClearScreen($0)
        DrawMap()
        UpdateMouse()
        DebugTxt()
        FlipBuffers()
      Until KeyboardPushed(#PB_Key_Escape)
    EndIf
     
    Procedure InitMap()
    a=0
      For j=0 To #ScreenHeight Step #TailleTileY
        For i=0 To #ScreenWidth Step #TailleTileX
          Map(a)\X = i
          Map(a)\Y = j
          Map(a)\z = 0
          a+1      
        Next i
      Next j
    EndProcedure
     
    Procedure DrawMap()
      StartDrawing(ScreenOutput())
      For i =0 To #TailleMapX*#TailleMapY
        Plot(Map(i)\X,Map(i)\Y + Map(i)\z,$FF00FF)
      Next i
      StopDrawing()
    EndProcedure
     
    Procedure UpdateMouse()
      DisplayTransparentSprite(imgMousePointer,MouseX(),MouseY())
     
    ; calculate map(i) current position under mouse
        tmp1=(MouseX() - (MouseX() % #TailleTileX))/#TailleTileX
        tmp2=(MouseY() - (MouseY() % #TailleTileY))/#TailleTileY
        tmp3=(tmp2 * ((#ScreenWidth/#TailleTileX)+1) + tmp1)
     
      If MouseButton(#PB_Any)=0
        DrawText(0,60,"PB_Key_All")
      EndIf
     
      If Event = 513 Or Event = 515 ;MouseButton(#PB_MouseButton_Left) And MouseFlag=0
        StartDrawing(ScreenOutput())
          DrawText(0,30,"LEFT")
          DrawText(0,45,Str(tmp1) + " " + Str(tmp2) + " " + Str(tmp3))
          map(tmp3)\z + #Levelling
        StopDrawing()
      EndIf 
      If MouseButton(#PB_MouseButton_Middle) And MouseFlag=0
        StartDrawing(ScreenOutput())
          DrawText(40,30,"MIDDLE")
          DrawText(0,45,Str(tmp1) + " " + Str(tmp2) + " " + Str(tmp3))
        StopDrawing()
      EndIf 
      If Event = 516 Or Event = 518 ;MouseButton(#PB_MouseButton_Right) And MouseFlag=0
        StartDrawing(ScreenOutput())
          DrawText(100,30,"RIGHT")
          DrawText(0,45,Str(tmp1) + " " + Str(tmp2) + " " + Str(tmp3))
          map(tmp3)\z - #Levelling
        StopDrawing()
      EndIf 
     
      point1X = Map(tmp3)\X
      point1Y = Map(tmp3)\Y + Map(tmp3)\z
      point2X = Map(tmp3+1)\X
      point2Y = Map(tmp3+1)\Y + Map(tmp3+1)\z
      point3X = Map(tmp3+(#ScreenWidth/#TailleTileX)+1)\X
      point3Y = Map(tmp3+(#ScreenWidth/#TailleTileX)+1)\Y+Map(tmp3+(#ScreenWidth/#TailleTileX)+1)\z
      point4X = Map(tmp3+(#ScreenWidth/#TailleTileX)+2)\X
      point4Y =Map(tmp3+(#ScreenWidth/#TailleTileX)+2)\Y+Map(tmp3+(#ScreenWidth/#TailleTileX)+2)\z
     
       StartDrawing(ScreenOutput())
         LineXY(point1X,point1Y,point2X,point2Y,$FFFFFF)
         LineXY(point1X,point1Y,point3X,point3Y,$FFFFFF)
         LineXY(point3X,point3Y,point4X,point4Y,$FFFFFF)
         LineXY(point2X,point2Y,point4X,point4Y,$FFFFFF)
      StopDrawing()
    EndProcedure

  10. #10
    Responsable Purebasic

    Avatar de comtois
    Inscrit en
    Avril 2003
    Messages
    1 262
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 1 262
    Points : 9 981
    Points
    9 981
    Billets dans le blog
    8
    Par défaut
    Tu devrais définir les constantes dans ton code, c'est quand même plus compréhensible de lire #WM_LBUTTONDOWN plutôt que 513

    Ajoute les constantes que tu utilises au début de ton code.
    Si un jour tu passes à la version complète , tu pourras les supprimer (elles sont déjà incluses dans les fichiers résidents y compris #Red comme tu l'as constaté. C'est aussi une constante issue des fichiers de déclaration pour Windows).

    Vous souhaitez participer à la rubrique PureBasic (tutoriels, FAQ, sources) ? Contactez-moi par MP.

Discussions similaires

  1. Plantage IIS ...
    Par rgarnier dans le forum XMLRAD
    Réponses: 20
    Dernier message: 28/10/2003, 10h54
  2. Plantage de Delphi 7
    Par Andry dans le forum EDI
    Réponses: 3
    Dernier message: 04/09/2003, 16h36
  3. Réponses: 7
    Dernier message: 20/08/2003, 10h33
  4. plantage a la deconnexion du client
    Par travail dans le forum 4D
    Réponses: 3
    Dernier message: 05/06/2003, 13h39
  5. [Kylix] Plantage IDE Kylix3/Mandrake 9.0
    Par OmicroN dans le forum EDI
    Réponses: 3
    Dernier message: 28/01/2003, 23h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo