Exemple #1
0
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            double x = 100;
            double currTemp;

            int width = 0;
            int height = 0;

            base.OnExposeEvent(args);
            this.ParentWindow.GetSize(out width, out height);
            this._x = (width - MainWidth) / 2;

            this._weatherService.GetWeather();

            var current = this._weatherService.GetCurrentCondition();
            var forecast = this._weatherService.GetForecast();

            if(current == null || forecast == null)
            {
                return true;
            }

            using (var g = Gdk.CairoHelper.Create(args.Window))
            {
                g.SetSourceRGBA(0, 0, 0, 0.9);
                this.DrawRoundedRectangle(g, 0, 0, this.WidthRequest, this.HeightRequest, CBaseControl.CornerRadius);
                g.FillPreserve();

                g.SetSourceRGB(1, 1, 1);
                g.SelectFontFace("Tahoma", FontSlant.Normal, FontWeight.Normal);
                g.SetFontSize(16);

                double.TryParse(current.temp, out currTemp);
                var dto = new RegionDto();
                dto.X = 10;
                dto.Y = 0;
                dto.Width = 100;
                dto.Height = 100;
                dto.Max = current.temp.FtoC();
                dto.Min = string.Empty;
                dto.WeatherCode = current.code;
                dto.WeekDay = string.Empty;
                dto.Trend = currTemp - this._lastTemp;
                this.DrawWeatherRegion(g, dto);

                this._lastTemp = currTemp;
                int cnt = 2;
                foreach(var forest in forecast.ToArray())
                {
                    dto.X = x;
                    dto.Y = 0;
                    dto.Width = 100;
                    dto.Height = 100;
                    dto.Max = forest.high.FtoC();
                    dto.Min = forest.low.FtoC();
                    dto.WeatherCode = forest.code;
                    dto.WeekDay = forest.day;
                    dto.Trend = null;
                    this.DrawWeatherRegion(g, dto);
                    if(--cnt == 0)
                    {
                        x += 250;
                    }
                    else
                    {
                        x += 110;
                    }
                }
                g.SetSourceRGBA(0, 0, 0, 1);
            }

            return true;
        }
Exemple #2
0
        private void DrawWeatherRegion(Context g, RegionDto dto)
        {
            string trendIcon = string.Empty;
            g.SetSourceRGB(1, 1, 1);

            double halfWidth = dto.Width / 2.0;

            TextExtents extDay;

            if (string.IsNullOrEmpty(dto.WeekDay))
            {
                extDay = g.TextExtents("test");
            }
            else
            {
                extDay = g.TextExtents(dto.WeekDay);
            }

            var t_x = dto.X + halfWidth - (extDay.Width / 2);
            var t_y = dto.Y + extDay.Height + padding;

            this.DrawTextAt(g, t_x, t_y, dto.WeekDay);

            //drawe day temp
            var extMax = g.TextExtents(dto.Max);
            var extMin = g.TextExtents(dto.Min);

            t_y = t_y + extDay.Height + padding + 2;

            t_x = dto.X + halfWidth - (extMax.Width / 2);
            this.DrawTextAt(g, t_x, t_y, dto.Max);

            if (dto.Trend.HasValue)
            {
                if (dto.Trend.Value > 0)
                {
                    trendIcon = "up.png";
                }
                else
                    if (dto.Trend < 0)
                {
                    trendIcon = "dwn.png";
                }
                if (!string.IsNullOrEmpty(trendIcon))
                {
                    string pathToImg = global::System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("Icons/{0}", trendIcon));
                    ImageSurface image_surface = new ImageSurface(pathToImg);
                    this.DrawSurfaceAt(g, image_surface, t_x - extMax.Width / 2, t_y - extMax.Height);
                }
            }

            t_x = dto.X + halfWidth - imageWidth / 2;
            DrawWeatherCode(g, dto.WeatherCode, t_x, t_y);

            g.SetSourceRGB(0.7, 0.7, 0.7);
            t_x = dto.X + halfWidth - (extMin.Width / 2);
            t_y += 68 + extMax.Height / 2;
            this.DrawTextAt(g, t_x, t_y, dto.Min);
        }