June 26, 2016
On 06/26/2016 12:10 AM, TheDGuy wrote:
> On Saturday, 25 June 2016 at 21:57:35 UTC, TheDGuy wrote:
>> But i want to flash (e.g. change the CSS class) the buttons one by one
>> and not all at the sime time? How am i going to do that?
>
> Okay, i tried it with a new private int-variable which contains the
> current index of the for-loop, like this:
>
>     private void letButtonsFlash(){
>         foreach(Button btn;bArr){
>             btn.setSensitive(false);
>         }
>         for(int i = 0; i < level; i++){
>             index = i; //index is public
>             Button currentButton = bArr[rndButtonBlink[i]];
>             ListG list = currentButton.getStyleContext().listClasses();
>             string CSSClassName = to!string(cast(char*)list.next().data);
>             currentButton.getStyleContext().addClass(CSSClassName ~
> "-flash");
>             Timeout t = new Timeout(&timeout_delay,1,false);
>         }
>
>         foreach(Button btn;bArr){
>             btn.setSensitive(true);
>         }
>     }
>     bool timeout_delay(){
>         Button currentButton = bArr[rndButtonBlink[index]];
>         ListG list = currentButton.getStyleContext().listClasses();
>         string CSSClassName = to!string(cast(char*)list.next().data);
>         currentButton.getStyleContext().removeClass(CSSClassName ~
> "-flash");
>         return false;
>     }
>
> But now the strange thing happens, that the first button lights up as
> expected but the second button remains at its "flash color" and doesn't
> go back to normal color, i don't understand why this happens? Any ideas?

You should probably increment the index in the timeout_delay function.

-- 
Mike Wey
June 26, 2016
On Sunday, 26 June 2016 at 12:30:22 UTC, Mike Wey wrote:
>
> You should probably increment the index in the timeout_delay function.

This leads to a Range violation exception...
June 26, 2016
On 06/26/2016 05:03 PM, TheDGuy wrote:
> On Sunday, 26 June 2016 at 12:30:22 UTC, Mike Wey wrote:
>>
>> You should probably increment the index in the timeout_delay function.
>
> This leads to a Range violation exception...

How about this:

private void letButtonsFlash(){
    foreach(Button btn;bArr){
        btn.setSensitive(false);
    }
    for(int i = 0; i < level; i++){
        Button currentButton = bArr[rndButtonBlink[i]];
        ListG list = currentButton.getStyleContext().listClasses();
        string CSSClassName = to!string(cast(char*)list.next().data);
        currentButton.getStyleContext().addClass(CSSClassName ~ "-flash");
    }
    Timeout t = new Timeout(&timeout_delay,1,false);
}

bool timeout_delay(){
    for(int i = 0; i < level; i++){
        Button currentButton = bArr[rndButtonBlink[i]];
        ListG list = currentButton.getStyleContext().listClasses();
        string CSSClassName = to!string(cast(char*)list.next().data);
        currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash");
    }
    foreach(Button btn;bArr){
        btn.setSensitive(true);
    }
    return false;
}

Sets all the buttons to the flash color and after an timeout removes the flash color from all the buttons.

-- 
Mike Wey
June 26, 2016
On Sunday, 26 June 2016 at 16:29:52 UTC, Mike Wey wrote:
>
> How about this:
>
> private void letButtonsFlash(){
>     foreach(Button btn;bArr){
>         btn.setSensitive(false);
>     }
>     for(int i = 0; i < level; i++){
>         Button currentButton = bArr[rndButtonBlink[i]];
>         ListG list = currentButton.getStyleContext().listClasses();
>         string CSSClassName = to!string(cast(char*)list.next().data);
>         currentButton.getStyleContext().addClass(CSSClassName ~ "-flash");
>     }
>     Timeout t = new Timeout(&timeout_delay,1,false);
> }
>
> bool timeout_delay(){
>     for(int i = 0; i < level; i++){
>         Button currentButton = bArr[rndButtonBlink[i]];
>         ListG list = currentButton.getStyleContext().listClasses();
>         string CSSClassName = to!string(cast(char*)list.next().data);
>         currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash");
>     }
>     foreach(Button btn;bArr){
>         btn.setSensitive(true);
>     }
>     return false;
> }
>
> Sets all the buttons to the flash color and after an timeout removes the flash color from all the buttons.

Thanks for your answer,

but as i said before, i want to flash each button on it's own (the game is kinda like 'Simon Says').
June 29, 2016
On Sunday, 26 June 2016 at 21:06:58 UTC, TheDGuy wrote:
>
> Thanks for your answer,
>
> but as i said before, i want to flash each button on it's own (the game is kinda like 'Simon Says').

I tried to debug a little and what i don't understand is, that i get two times 'blue' on the console, even though yellow and blue lit up but yellow stayed at the flash color:

    private void letButtonsFlash(){
        foreach(Button btn;bArr){
            btn.setSensitive(false);
        }
        for(int i = 0; i < level; i++){
            index = i;
            Button currentButton = bArr[rndButtonBlink[i]]; //Array holds randomized Buttons
            ListG list = currentButton.getStyleContext().listClasses();
            string CSSClassName = to!string(cast(char*)list.next().data);
            currentButton.getStyleContext().addClass(CSSClassName ~ "-flash");
            Timeout t = new Timeout(() => this.timeout_delay(currentButton),1,false);
        }

        foreach(Button btn;bArr){
            btn.setSensitive(true);
        }
    }
    bool timeout_delay(Button currentButton){
        ListG list = currentButton.getStyleContext().listClasses();
        string CSSClassName = to!string(cast(char*)list.next().data);
        writeln(CSSClassName); //try to debug
        currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash");
        return false;
    }

The reason for the problem that buttons are flashing simultaneously might be, that the Timeout is running in an extra thread and therefore another Timeout is created by the mainthread in the for-loop even though the last one hasn't finished yet.

But what i don't understand is why the last button doesn't go back to the normal CSSClass and that the first button has two timeouts (according to my console debug text)?

It would be very much appreciated if someone who has GTKD installed can try my code:

http://pastebin.com/h0Nx1mL6


June 30, 2016
On Wednesday, 29 June 2016 at 10:41:21 UTC, TheDGuy wrote:
> I tried to debug a little and what i don't understand is, that i get two times 'blue' on the console, even though yellow and blue lit up but yellow stayed at the flash color:
>
>     private void letButtonsFlash(){
>         foreach(Button btn;bArr){
>             btn.setSensitive(false);
>         }
>         for(int i = 0; i < level; i++){
>             index = i;
>             Button currentButton = bArr[rndButtonBlink[i]]; //Array holds randomized Buttons
>             ListG list = currentButton.getStyleContext().listClasses();
>             string CSSClassName = to!string(cast(char*)list.next().data);
>             currentButton.getStyleContext().addClass(CSSClassName ~ "-flash");
>             Timeout t = new Timeout(() => this.timeout_delay(currentButton),1,false);
>         }
>
>         foreach(Button btn;bArr){
>             btn.setSensitive(true);
>         }
>     }
>     bool timeout_delay(Button currentButton){
>         ListG list = currentButton.getStyleContext().listClasses();
>         string CSSClassName = to!string(cast(char*)list.next().data);
>         writeln(CSSClassName); //try to debug
>         currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash");
>         return false;
>     }
>
> The reason for the problem that buttons are flashing simultaneously might be, that the Timeout is running in an extra thread and therefore another Timeout is created by the mainthread in the for-loop even though the last one hasn't finished yet.
>
> But what i don't understand is why the last button doesn't go back to the normal CSSClass and that the first button has two timeouts (according to my console debug text)?
>
> It would be very much appreciated if someone who has GTKD installed can try my code:
>
> http://pastebin.com/h0Nx1mL6

Okay, i am quite sure now that this is some kind of bug:

https://picload.org/image/rrrgwpgi/gtkd_timeout.png

    private void letButtonsFlash(){
        foreach(Button btn;bArr){
            btn.setSensitive(false);
        }
        for(int i = 0; i < level; i++){
            index = i;
            Button currentButton = bArr[rndButtonBlink[i]]; //Array holds randomized Buttons
            ListG list = currentButton.getStyleContext().listClasses();
            string CSSClassName = to!string(cast(char*)list.next().data);
            currentButton.getStyleContext().addClass(CSSClassName ~ "-flash");
            writeln("Creating Timeout for : " ~ CSSClassName);
            Timeout t = new Timeout(() => this.timeout_delay(currentButton),1,false);
        }

        foreach(Button btn;bArr){
            btn.setSensitive(true);
        }
    }
    bool timeout_delay(Button currentButton){
        ListG list = currentButton.getStyleContext().listClasses();
        string CSSClassName = to!string(cast(char*)list.next().data);
        currentButton.getStyleContext().removeClass(CSSClassName ~ "-flash");
        writeln("Removing flash CSS color for: " ~ CSSClassName);
        return false;
    }
June 30, 2016
On 06/30/2016 08:53 AM, TheDGuy wrote:
> On Wednesday, 29 June 2016 at 10:41:21 UTC, TheDGuy wrote:
>> I tried to debug a little and what i don't understand is, that i get
>> two times 'blue' on the console, even though yellow and blue lit up
>> but yellow stayed at the flash color:
>>
>>     private void letButtonsFlash(){
>>         foreach(Button btn;bArr){
>>             btn.setSensitive(false);
>>         }
>>         for(int i = 0; i < level; i++){
>>             index = i;
>>             Button currentButton = bArr[rndButtonBlink[i]]; //Array
>> holds randomized Buttons
>>             ListG list = currentButton.getStyleContext().listClasses();
>>             string CSSClassName = to!string(cast(char*)list.next().data);
>>             currentButton.getStyleContext().addClass(CSSClassName ~
>> "-flash");
>>             Timeout t = new Timeout(() =>
>> this.timeout_delay(currentButton),1,false);
>>         }
>>
>>         foreach(Button btn;bArr){
>>             btn.setSensitive(true);
>>         }
>>     }
>>     bool timeout_delay(Button currentButton){
>>         ListG list = currentButton.getStyleContext().listClasses();
>>         string CSSClassName = to!string(cast(char*)list.next().data);
>>         writeln(CSSClassName); //try to debug
>>         currentButton.getStyleContext().removeClass(CSSClassName ~
>> "-flash");
>>         return false;
>>     }
>>
>> The reason for the problem that buttons are flashing simultaneously
>> might be, that the Timeout is running in an extra thread and therefore
>> another Timeout is created by the mainthread in the for-loop even
>> though the last one hasn't finished yet.
>>
>> But what i don't understand is why the last button doesn't go back to
>> the normal CSSClass and that the first button has two timeouts
>> (according to my console debug text)?
>>
>> It would be very much appreciated if someone who has GTKD installed
>> can try my code:
>>
>> http://pastebin.com/h0Nx1mL6
>
> Okay, i am quite sure now that this is some kind of bug:
>
> https://picload.org/image/rrrgwpgi/gtkd_timeout.png
>
>     private void letButtonsFlash(){
>         foreach(Button btn;bArr){
>             btn.setSensitive(false);
>         }
>         for(int i = 0; i < level; i++){
>             index = i;
>             Button currentButton = bArr[rndButtonBlink[i]]; //Array
> holds randomized Buttons
>             ListG list = currentButton.getStyleContext().listClasses();
>             string CSSClassName = to!string(cast(char*)list.next().data);
>             currentButton.getStyleContext().addClass(CSSClassName ~
> "-flash");
>             writeln("Creating Timeout for : " ~ CSSClassName);
>             Timeout t = new Timeout(() =>
> this.timeout_delay(currentButton),1,false);
>         }
>
>         foreach(Button btn;bArr){
>             btn.setSensitive(true);
>         }
>     }
>     bool timeout_delay(Button currentButton){
>         ListG list = currentButton.getStyleContext().listClasses();
>         string CSSClassName = to!string(cast(char*)list.next().data);
>         currentButton.getStyleContext().removeClass(CSSClassName ~
> "-flash");
>         writeln("Removing flash CSS color for: " ~ CSSClassName);
>         return false;
>     }

Is the complete source available some ware?

-- 
Mike Wey
June 30, 2016
On Thursday, 30 June 2016 at 20:11:17 UTC, Mike Wey wrote:
> Is the complete source available some ware?

Yes, here: http://pastebin.com/h0Nx1mL6


1 2
Next ›   Last »