コード例 #1
0
ファイル: tabs.cs プロジェクト: zhangyong550126140/UIWidgets
        public override void paint(Canvas canvas, Size size)
        {
            this._needsPaint = false;
            this._painter    = this._painter ?? this.indicator.createBoxPainter(this.markNeedsPaint);

            if (this.controller.indexIsChanging)
            {
                Rect targetRect = this.indicatorRect(size, this.controller.index);
                this._currentRect = Rect.lerp(targetRect, this._currentRect ?? targetRect,
                                              TabsUtils._indexChangeProgress(this.controller));
            }
            else
            {
                int   currentIndex = this.controller.index;
                Rect  previous     = currentIndex > 0 ? this.indicatorRect(size, currentIndex - 1) : null;
                Rect  middle       = this.indicatorRect(size, currentIndex);
                Rect  next         = currentIndex < this.maxTabIndex ? this.indicatorRect(size, currentIndex + 1) : null;
                float index        = this.controller.index;
                float value        = this.controller.animation.value;
                if (value == index - 1.0f)
                {
                    this._currentRect = previous ?? middle;
                }
                else if (value == index + 1.0f)
                {
                    this._currentRect = next ?? middle;
                }
                else if (value == index)
                {
                    this._currentRect = middle;
                }
                else if (value < index)
                {
                    this._currentRect = previous == null ? middle : Rect.lerp(middle, previous, index - value);
                }
                else
                {
                    this._currentRect = next == null ? middle : Rect.lerp(middle, next, value - index);
                }
            }

            D.assert(this._currentRect != null);

            ImageConfiguration configuration = new ImageConfiguration(
                size: this._currentRect.size
                );

            this._painter.paint(canvas, this._currentRect.topLeft, configuration);
        }
コード例 #2
0
ファイル: switch.cs プロジェクト: JC-ut0/CubeGame
        public override void paint(PaintingContext context, Offset offset)
        {
            Canvas canvas = context.canvas;

            bool  isEnabled    = this.onChanged != null;
            float currentValue = this.position.value;

            float visualPosition = currentValue;

            Color trackColor = isEnabled
                ? Color.lerp(this.inactiveTrackColor, this.activeTrackColor, currentValue)
                : this.inactiveTrackColor;

            Color thumbColor = isEnabled
                ? Color.lerp(this.inactiveColor, this.activeColor, currentValue)
                : this.inactiveColor;

            ImageProvider thumbImage = isEnabled
                ? (currentValue < 0.5 ? this.inactiveThumbImage : this.activeThumbImage)
                : this.inactiveThumbImage;

            // Paint the track
            Paint paint = new Paint {
                color = trackColor
            };
            float trackHorizontalPadding = Constants.kRadialReactionRadius - Switch._kTrackRadius;
            Rect  trackRect = Rect.fromLTWH(
                offset.dx + trackHorizontalPadding,
                offset.dy + (this.size.height - Switch._kTrackHeight) / 2.0f,
                this.size.width - 2.0f * trackHorizontalPadding,
                Switch._kTrackHeight
                );
            RRect trackRRect = RRect.fromRectAndRadius(trackRect, Radius.circular(Switch._kTrackRadius));

            canvas.drawRRect(trackRRect, paint);

            Offset thumbPosition = new Offset(
                Constants.kRadialReactionRadius + visualPosition * this._trackInnerLength,
                this.size.height / 2.0f
                );

            this.paintRadialReaction(canvas, offset, thumbPosition);

            try {
                this._isPainting = true;
                BoxPainter thumbPainter;
                if (this._cachedThumbPainter == null || thumbColor != this._cachedThumbColor ||
                    thumbImage != this._cachedThumbImage)
                {
                    this._cachedThumbColor   = thumbColor;
                    this._cachedThumbImage   = thumbImage;
                    this._cachedThumbPainter = this._createDefaultThumbDecoration(thumbColor, thumbImage)
                                               .createBoxPainter(this._handleDecorationChanged);
                }

                thumbPainter = this._cachedThumbPainter;

                float inset  = 1.0f - (currentValue - 0.5f).abs() * 2.0f;
                float radius = Switch._kThumbRadius - inset;
                thumbPainter.paint(
                    canvas,
                    thumbPosition + offset - new Offset(radius, radius),
                    this.configuration.copyWith(size: Size.fromRadius(radius))
                    );
            }
            finally {
                this._isPainting = false;
            }
        }
コード例 #3
0
    public byte GenerateVoxel(int x, int y, int z)
    {
        /* IMMUTABLE PASS */
        //if(y==0) return 1;
        //return 0;

        // If outside world, return air.
        //IsVoxelInWorld(pos)
        if (y < 0 || y >= VoxelData.ChunkHeight)
        {
            return(0);
        }

        // If bottom block of chunk, return bedrock.
        if (y == 0)
        {
            return(1);
        }

        /* BIOME SELECTION PASS*/

        int   solidGroundHeight   = 42;
        float sumOfHeights        = 0f;
        int   count               = 0;
        float strongestHeight     = 0f;
        float strongestWeight     = 0f;
        int   strongestBiomeIndex = 0;

        for (int i = 0; i < biomes.Length; i++)
        {
            float weight = Noise.Get2DPerlin(x, z, biomes[i].offset, biomes[i].scale);

            // Get the height of the terrain (for the current biome) and multiply it by its weight.
            float height = biomes[i].terrainHeight * Noise.Get2DPerlin(x, z, 0, biomes[i].terrainScale) * weight;

            // Keep track of which weight is strongest.
            if (weight > strongestWeight)
            {
                strongestWeight     = weight;
                strongestBiomeIndex = i;
                strongestHeight     = height;
            }

            // If the height value is greater 0 add it to the sum of heights.
            if (height > 0)
            {
                sumOfHeights += height;
                count++;
            }
        }

        // Set biome to the one with the strongest weight.
        BiomeAttributes biome = biomes[strongestBiomeIndex];

        // Get the average of the heights.
        sumOfHeights /= count;

        sumOfHeights = sumOfHeights * 3 / 4 + strongestHeight * 1 / 4;

        int terrainHeight = (int)(sumOfHeights + solidGroundHeight);

        //terrainHeight = (int)(sumOfHeights/4 + solidGroundHeight);

        //BiomeAttributes biome = biomes[index];

        /* BASIC TERRAIN PASS */

        byte voxelValue = 0;

        if (y == terrainHeight)
        {
            voxelValue = biome.surfaceBlock;
        }
        else if (y < terrainHeight && y > terrainHeight - 4)
        {
            voxelValue = biome.subSurfaceBlock;
        }
        else if (y > terrainHeight)
        {
            return(0);
        }
        else
        {
            voxelValue = 2;
        }

        /* SECOND PASS */

        if (voxelValue == 2)
        {
            foreach (Lode lode in biome.lodes)
            {
                if (y > lode.minHeight && y < lode.maxHeight)
                {
                    if (Noise.Get3DPerlin(x, y, z, lode.noiseOffset, lode.scale, lode.threshold))
                    {
                        voxelValue = lode.blockID;
                    }
                }
            }
        }

        /* TREE PASS */
        //if(false)
        if (y == terrainHeight && biome.placeMajorFlora)
        {
            if (Noise.Get2DPerlin(x, z, 0, biome.majorFloraZoneScale) > biome.majorFloraZoneThreshold)
            {
                //voxelValue = 6;
                if (Noise.Get2DPerlin(x, z, 0, biome.majorFloraPlacementScale) > biome.majorFloraPlacementThreshold)
                {
                    //voxelValue = 12;
                    lock (modifications)
                    {
                        //Structure.GenerateMajorFlora(this, biome.majorFloraIndex, x, y, z, biome.minHeight, biome.maxHeight);

                        switch (biome.majorFloraIndex)
                        {
                        //default:
                        case 0: {
                            voxelValue = 10;

                            int height = (int)(biome.maxHeight * Noise.Get2DPerlin(x, z, 250f, 3f));

                            if (height < biome.minHeight)
                            {
                                height = biome.minHeight;
                            }

                            //height = 50;

                            int baseY = y + height - 2;
                            new BoxPainter(this, x - 2, baseY, z - 2, 4, 0, 4, 11);
                            new BoxPainter(this, x - 2, baseY + 1, z - 2, 4, 0, 4, 11);
                            new BoxPainter(this, x - 1, baseY + 2, z - 1, 2, 0, 2, 11);
                            new BoxPainter(this, x - 1, baseY + 3, z - 1, 2, 0, 2, 11, 1);
                            BoxPainter trunk = new BoxPainter(this, x, y + 1, z, 0, height - 1, 0, 6);
                            //BoxPainter MainLeaves = new BoxPainter(this, x-1, y+height, z-1, 3, 4, 3, 11);
                        } break;

                        case 1: {
                            int height = (int)(biome.maxHeight * Noise.Get2DPerlin(x, z, 23456f, 2f));

                            if (height < biome.minHeight)
                            {
                                height = biome.minHeight;
                            }

                            BoxPainter trunk = new BoxPainter(this, x, y, z, 0, height, 0, 12);
                        } break;
                        }
                    }
                }
            }
        }

        return(voxelValue);
    }