1

Topic: need some explanation

mh... i really dont understand the following code:

                int PrevColor = *paColors[i];
                int Color = 0;
                for(int s = 0; s < 3; s++)
                {
                    CUIRect Text;
                    RightView.HSplitTop(19.0f, &Button, &RightView);
                    Button.VSplitLeft(30.0f, 0, &Button);
                    Button.VSplitLeft(70.0f, &Text, &Button);
                    Button.VSplitRight(5.0f, &Button, 0);
                    Button.HSplitTop(4.0f, 0, &Button);

                    float k = ((PrevColor>>((2-s)*8))&0xff)  / 255.0f;
                    k = DoScrollbarH(&s_aColorSlider[i][s], &Button, k);
                    Color <<= 8;
                    Color += clamp((int)(k*255), 0, 255);
                    UI()->DoLabel(&Text, paLabels[s], 15.0f, -1);

                }

could somebody explain it line-by-line?

(its in menus_settings.cpp, CMenus::RenderSettingsPlayer(), around line 200)

2

Re: need some explanation

Don't try to understand every part of line code, line by line, just get its global sense. I doubt anybody can understand the whole Teeworlds code.
If you understand some english, it's basically easily readable: you print 3 scrollbars with labels, and all the button.xsplit are to place it. Labels and color sliders are stored in arrays, to allow the loop, and to avoid large amount of repetitive code.

Not Luck, Just Magic.

3

Re: need some explanation

Dune wrote:

Don't try to understand every part of line code, line by line, just get its global sense. I doubt anybody can understand the whole Teeworlds code.
If you understand some english, it's basically easily readable: you print 3 scrollbars with labels, and all the button.xsplit are to place it. Labels and color sliders are stored in arrays, to allow the loop, and to avoid large amount of repetitive code.

i got the global sense... but i really want to know what this specific part of the code means. smile

4

Re: need some explanation

Tell us which line(s) you don't understand.

Not Luck, Just Magic.

5

Re: need some explanation

                int PrevColor = *paColors[i];
                int Color = 0;
                for(int s = 0; s < 3; s++)
                {

i understood so far

                    CUIRect Text;
                    RightView.HSplitTop(19.0f, &Button, &RightView);
                    Button.VSplitLeft(30.0f, 0, &Button);
                    Button.VSplitLeft(70.0f, &Text, &Button);
                    Button.VSplitRight(5.0f, &Button, 0);
                    Button.HSplitTop(4.0f, 0, &Button);

some gui stuff i dont understand, how is ensured that it can only be some values? (since you cant make really dark colours with that gui)
and what are these VSplit... functions?

                    float k = ((PrevColor>>((2-s)*8))&0xff)  / 255.0f;
                    k = DoScrollbarH(&s_aColorSlider[i][s], &Button, k);
                    Color <<= 8;
                    Color += clamp((int)(k*255), 0, 255);
                    UI()->DoLabel(&Text, paLabels[s], 15.0f, -1);

the color is created

                }

6

Re: need some explanation

heinrich5991 wrote:

i understood so far

                    CUIRect Text;
                    RightView.HSplitTop(19.0f, &Button, &RightView);
                    Button.VSplitLeft(30.0f, 0, &Button);
                    Button.VSplitLeft(70.0f, &Text, &Button);
                    Button.VSplitRight(5.0f, &Button, 0);
                    Button.HSplitTop(4.0f, 0, &Button);

some gui stuff i dont understand, how is ensured that it can only be some values? (since you cant make really dark colours with that gui)
and what are these VSplit... functions?

VSplit means Vertical Split, and HSplit means Horizontal Split.
VSplitLeft means Vertical Split from the left, etc.
You just split the CUIRect var to 30 units from the left, and etc.

Not Luck, Just Magic.