public ServerFastestSelectionButton(bool isSelected) : base()
        {
            const int    constButtonHeight = 61;
            const int    constImgHeight    = 24;
            const string title             = "Fastest server";

            Title = "";

            // flag icon
            var flagView = new NSImageView();

            flagView.Frame = new CGRect(20, (constButtonHeight - constImgHeight) / 2, constImgHeight, constImgHeight);
            flagView.Image = NSImage.ImageNamed("iconAutomaticServerSelection");
            AddSubview(flagView);

            // title
            __Title       = UIUtils.NewLabel(title);
            __Title.Frame = new CGRect(49, flagView.Frame.Y + 3, 200, 18);
            __Title.Font  = UIUtils.GetSystemFontOfSize(14.0f, NSFontWeight.Semibold);
            __Title.SizeToFit();
            AddSubview(__Title);

            // image
            __Image        = new NSImageView();
            __Image.Frame  = new CGRect(__Title.Frame.X + __Title.Frame.Width, flagView.Frame.Y, 25, 25);
            __Image.Image  = NSImage.ImageNamed("iconSelected");
            __Image.Hidden = true;
            AddSubview(__Image);

            IsSelected = isSelected;
        }
예제 #2
0
        public NetworkActionButton(NetworkAction networkAction,
                                   ViewModelNetworksSettings networksSettingsModel,
                                   float width) : base()
        {
            NetworkAction         = networkAction;
            NetworksSettingsModel = networksSettingsModel;
            const int constButtonHeight = 35;
            const int constImgHeight    = 16;

            Bordered = false;
            Title    = "";
            Frame    = new CGRect(0, 0, width, constButtonHeight);

            // wifi icon
            var wifiIconView = new NSImageView();

            wifiIconView.Frame = new CGRect(20, (constButtonHeight - constImgHeight) / 2, constImgHeight, constImgHeight);
            wifiIconView.Image = NSImage.ImageNamed("iconWiFiSmallBlue");
            AddSubview(wifiIconView);

            // title
            __Title           = UIUtils.NewLabel(networkAction.Network.SSID);
            __Title.Frame     = new CGRect(49, wifiIconView.Frame.Y, width / 2, 18);
            __Title.TextColor = NSColor.FromRgb(38, 57, 77);
            AddSubview(__Title);

            WiFiActionTypeEnum action = networkAction.Action;

            if (action == WiFiActionTypeEnum.Default)
            {
                action = networksSettingsModel.NetworkActions.DefaultActionType;
            }

            System.nfloat xpos = __Title.Frame.Width + __Title.Frame.X + 20;

            //action
            __PopUpButton          = new NSPopUpButton();
            __PopUpButton.Bordered = false;
            __PopUpButton.Frame    = new CGRect(xpos, (constButtonHeight - 24) / 2, width - xpos - 10, 24);
            AddSubview(__PopUpButton);

            networkAction.PropertyChanged += NetworkAction_PropertyChanged;
            NetworksSettingsModel.NetworkActions.PropertyChanged += NetworkActions_PropertyChanged;

            CreatePopupButtonElements();
        }
예제 #3
0
        public ServerSelectionButton(ServerLocation serverLocation) : base()
        {
            ServerLocation = serverLocation;

            const int constButtonHeight = 61;
            const int constFlagHeight   = 24;

            Bordered = false;
            Title    = "";
            Frame    = new CGRect(0, 0, 320, constButtonHeight);

            // flag icon
            var flagView = new NSImageView();

            flagView.Frame = new CGRect(20, (constButtonHeight - constFlagHeight) / 2, constFlagHeight, constFlagHeight);
            flagView.Image = GuiHelpers.CountryCodeToImage.GetCountryFlag(serverLocation.CountryCode);
            AddSubview(flagView);

            // server name
            __ServerName       = UIUtils.NewLabel(serverLocation.Name);
            __ServerName.Frame = new CGRect(49, flagView.Frame.Y + 1, 200, 18);
            __ServerName.Font  = UIUtils.GetSystemFontOfSize(14.0f, NSFontWeight.Semibold);
            __ServerName.SizeToFit();
            AddSubview(__ServerName);

            // check if server name is too long
            const int maxXforSelectedIcon    = 218;
            nfloat    serverNameOverlapWidth = (__ServerName.Frame.X + __ServerName.Frame.Width) - maxXforSelectedIcon;

            if (serverNameOverlapWidth > 0)
            {
                CGRect oldFrame = __ServerName.Frame;
                __ServerName.Frame = new CGRect(oldFrame.X, oldFrame.Y, oldFrame.Width - serverNameOverlapWidth, oldFrame.Height);
            }

            // selected server image
            __selectedServerImage        = new NSImageView();
            __selectedServerImage.Frame  = new CGRect(__ServerName.Frame.X + __ServerName.Frame.Width, flagView.Frame.Y - 2, 25, 25);
            __selectedServerImage.Image  = NSImage.ImageNamed("iconSelected");
            __selectedServerImage.Hidden = !ServerLocation.IsSelected;
            AddSubview(__selectedServerImage);

            // ping status image
            __pingStatusImage        = new NSImageView();
            __pingStatusImage.Frame  = new CGRect(238, flagView.Frame.Y, 24, 24);
            __pingStatusImage.Hidden = true;
            AddSubview(__pingStatusImage);
            UpdatePingStatusImage();

            // ping timeout info
            __PingView           = UIUtils.NewLabel(GetPingTimeString(ServerLocation.PingTime));
            __PingView.Alignment = NSTextAlignment.Left;
            __PingView.Font      = UIUtils.GetSystemFontOfSize(12.0f);
            __PingView.Frame     = new CGRect(260, flagView.Frame.Y + 4, 60, 18);
            __PingView.TextColor = NSColor.FromRgb(180, 193, 204);
            if (ServerLocation.PingTime == 0)
            {
                __PingView.Hidden = true;
            }
            __PingView.SizeToFit();
            AddSubview(__PingView);

            // "disabled layer" visible only if button is disabled
            __DisabledLayer       = new ColorView();
            __DisabledLayer.Frame = new CGRect(Frame.X, Frame.Y, Frame.Width, Frame.Height - 1);
            var bgClr = Colors.WindowBackground;

            __DisabledLayer.BackgroundColor = Colors.IsDarkMode ? new CGColor(bgClr.RedComponent, bgClr.GreenComponent, bgClr.BlueComponent, 0.6f) : new CGColor(1.0f, 0.6f);
            __DisabledLayer.Hidden          = true;
            AddSubview(__DisabledLayer);
        }