Re: [Lazarus] TMouseButton
Kjow schreef: Hi all, I need to create an advanced function that manages mouse events, so I need to know when/which a button is pressed and so, when no button is pressed. I saw that in TMouseButton (row 142 of Controls unit) there isn't mbNone, so I simply edited that row: TMouseButton = (mbNone, mbLeft, mbRight, mbMiddle, mbExtra1, mbExtra2); Now I can see when no buttons are pressed; I simply manage it with MouseButtonPressed:=Button; //OnMouseDown MouseButtonPressed:=mbNone; //OnMouseUp Now the question: there is a better way to do this whitout modify the Lazarus source code? It is a bug/missing feature or this is a feature? What about: type TMouseButtons = set of TMouseButton; // if it doesn't exist yet var MouseButtonPressed: TMouseButtons; MouseButtonPressed:=MouseButtonPressed + Button; //OnMouseDown Your mbNone becomes: MouseButtonPressed:=[]; Vincent -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TMouseButton
07.04.2010 21:46, Kjow wrote: I saw that in TMouseButton (row 142 of Controls unit) there isn't mbNone, so I simply edited that row: TMouseButton = (mbNone, mbLeft, mbRight, mbMiddle, mbExtra1, mbExtra2); Now I can see when no buttons are pressed; I simply manage it with You miss that it is possible to press 2 buttons at the moment. That's why LCL uses a set to define what is pressed and what is not. As result you don't need mbNone. Just use [] to indicate that no button is pressed. Best regards, Paul Ishenin. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TMouseButton
On 07/04/2010 14:46, Kjow wrote: Hi all, I need to create an advanced function that manages mouse events, so I need to know when/which a button is pressed and so, when no button is pressed. I saw that in TMouseButton (row 142 of Controls unit) there isn't mbNone, so I simply edited that row: TMouseButton = (mbNone, mbLeft, mbRight, mbMiddle, mbExtra1, mbExtra2); Now I can see when no buttons are pressed; I simply manage it with MouseButtonPressed:=Button; //OnMouseDown MouseButtonPressed:=mbNone; //OnMouseUp Now the question: there is a better way to do this whitout modify the Lazarus source code? It is a bug/missing feature or this is a feature? I wouldn't recommend that change. Some units define const Foo = Array [TMouseButton] of String = (list of names for values); Those will break, because the count of the enum changed. Create a set type TMouseButtons = set of TMouseButton ; var MouseButtonPressed: TMouseButtons; MouseButtonPressed := []; MouseButtonPressed := [mbLeft]; MouseButtonPressed := [mbLeft, mbRight]; and so on -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TMouseButton
2010/4/7 Paul Ishenin webpi...@mail.ru: As result you don't need mbNone. Just use [] to indicate that no button is pressed. 2010/4/7 Martin laza...@mfriebe.de: I wouldn't recommend that change. Some units define const Foo = Array [TMouseButton] of String = (list of names for values); Those will break, because the count of the enum changed. Create a set type TMouseButtons = set of TMouseButton ; var MouseButtonPressed: TMouseButtons; MouseButtonPressed := []; MouseButtonPressed := [mbLeft]; MouseButtonPressed := [mbLeft, mbRight]; and so on Oh! Thank you both very much! I searched for this, but nothing found! :-) Best regards, Kjow -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TMouseButton
2010/4/7 Kjow antispamm...@gmail.com: As result you don't need mbNone. Just use [] to indicate that no button is pressed. 2010/4/7 Martin laza...@mfriebe.de: Create a set Other question... how to pass/read [] vaule to/in a function? e.g. function ButtonPress(Button: TMouseButton): string; begin case Button of []: Result:='Nothing Pressed'; //e.g. mbLeft: Result:='mbLeft'; mbRight: Result:='mbRight'; mbMiddle: Result:='mbMiddle'; end; end; and somewhere: showmessage(ButtonPress([])); // [] - e.g. Thanks, Kjow -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TMouseButton
2010/4/7 Vincent Snijders vsnijd...@vodafonevast.nl: What about: type TMouseButtons = set of TMouseButton; // if it doesn't exist yet var MouseButtonPressed: TMouseButtons; MouseButtonPressed:=MouseButtonPressed + Button; //OnMouseDown Your mbNone becomes: MouseButtonPressed:=[]; Vincent Thank you Vincent, I tried, but MouseButtonPressed:=[]; returns: Error: Incompatible types: got Empty Set expected TMouseButton and I don't know how to add Button to MouseButtonPressed... Thanks, Kjow -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TMouseButton
2010/4/7 Kjow antispamm...@gmail.com: 2010/4/7 Kjow antispamm...@gmail.com: Error: Incompatible types: got Empty Set expected TMouseButton Whops, I've mistyped, it works! But how to read the values from a function? e.g. function ButtonPress(Button: TMouseButtons): string; begin case Button of ...: Result:= 'you pressed' ; end; end; Ok, today is not my day :) I'm sorry for this flooding :( with if mbLeft in Button then Result:='left'; I can manage the buttons, but what for nothing? e.g. if [] in Button then Result:='nothing'; Thanks, Kjow -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TMouseButton
On 07/04/2010 15:35, Kjow wrote: 2010/4/7 Kjowantispamm...@gmail.com: Error: Incompatible types: got Empty Set expected TMouseButton Whops, I've mistyped, it works! But how to read the values from a function? e.g. function ButtonPress(Button: TMouseButtons): string; begin case Button of ...: Result:= 'you pressed' ; end; end; Case will not work. but mbleft, or mbLeft + any other button if mbLeft in Buttons then xxx; for only mbLeft, no other button: if Buttons = [mbLeft] then xxx; to add / remove ... Buttons := Buttons + mbLeft; Include(Buttons, mbLeft); Buttons := Buttons - mbLeft; Exclude(Buttons, mbLeft); -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TMouseButton
2010/4/7 Martin laza...@mfriebe.de: Case will not work. but mbleft, or mbLeft + any other button if mbLeft in Buttons then xxx; for only mbLeft, no other button: if Buttons = [mbLeft] then xxx; to add / remove ... Buttons := Buttons + mbLeft; Include(Buttons, mbLeft); Buttons := Buttons - mbLeft; Exclude(Buttons, mbLeft); Thank you! Now I understood that for 'nothing' I need to do: if Button=[] then Result:='nothing'; And if I want a combination I need to provide any case e.g. if Buttons = [mbLeft,mbRight] then xxx Thank you very much to all, you are great :) Best Regards, Kjow -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TMouseButton
Zitat von Kjow antispamm...@gmail.com: 2010/4/7 Kjow antispamm...@gmail.com: Error: Incompatible types: got Empty Set expected TMouseButton Whops, I've mistyped, it works! But how to read the values from a function? e.g. function ButtonPress(Button: TMouseButtons): string; begin case Button of ...: Result:= 'you pressed' ; end; end; The mouse buttons are combined in TShiftState. For example: OnMouseDown gets the Shift parameter, which contains the pressed mouse buttons and the pressed modifier keys. There is already a function to convert TShiftState into a string in unit LCLProc: procedure TMainForm.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin writeln('TMainForm.FormMouseDown ',dbgs(Shift)); // when only the right mouse button is pressed // it will write: [ssRight] end; Mattias -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus