| 1 | /* fre:ac - free audio converter |
| 2 | * Copyright (C) 2001-2019 Robert Kausch <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License as |
| 6 | * published by the Free Software Foundation, either version 2 of |
| 7 | * the License, or (at your option) any later version. |
| 8 | * |
| 9 | * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR |
| 10 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 11 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ |
| 12 | |
| 13 | #include "dialog.h" |
| 14 | |
| 15 | /* Custom text widget to draw without erasing the background. |
| 16 | */ |
| 17 | class TransparentText : public Text |
| 18 | { |
| 19 | public: |
| 20 | TransparentText(const String &iText, const Point &iPos) : Text(iText, iPos) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | Int Paint(Int message) |
| 25 | { |
| 26 | if (!IsRegistered()) return Error(); |
| 27 | if (!IsVisible()) return Success(); |
| 28 | |
| 29 | if (text != NIL && message == SP_PAINT) |
| 30 | { |
| 31 | Rect rect = Rect(GetRealPosition(), GetRealSize()); |
| 32 | Surface *surface = GetDrawSurface(); |
| 33 | |
| 34 | surface->SetText(text, Rect::OverlapRect(Rect(rect.GetPosition(), Size(scaledTextSize.cx, Math::Round(scaledTextSize.cy * 1.2))), GetVisibleArea()), font); |
| 35 | } |
| 36 | |
| 37 | return Success(); |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | BoCA::LanguageNotifierDialog::LanguageNotifierDialog(Bool incomplete) |
| 42 | { |
| 43 | Config *config = Config::Get(); |
| 44 | |
| 45 | mainWnd = new GUI::Window("Help translate this project", Point(100, 100), Size(380, 350)); |
| 46 | mainWnd_titlebar = new Titlebar(TB_NONE); |
| 47 | divider = new Divider(39, OR_HORZ | OR_BOTTOM); |
| 48 | |
| 49 | mainWnd->Add(mainWnd_titlebar); |
| 50 | mainWnd->Add(divider); |
| 51 | |
| 52 | button_close = new Button("Close", Point(87, 29), Size()); |
| 53 | button_close->onAction.Connect(&LanguageNotifierDialog::Close, this); |
| 54 | button_close->SetOrientation(OR_LOWERRIGHT); |
| 55 | |
| 56 | mainWnd->Add(button_close); |
| 57 | |
| 58 | Directory dir(Utilities::GetBoCADirectory().Append("freac.extension.langnotify")); |
| 59 | |
| 60 | if (!dir.Exists()) dir = Utilities::GetBoCADirectory().Append("../freac/freac.extension.langnotify"); |
| 61 | |
| 62 | Bitmap bitmap = ImageLoader::Load(File(String(dir).Append("/langnotify.png"))); |
| 63 | |
| 64 | bitmap.SetBackgroundColor(Setup::BackgroundColor); |
| 65 | |
| 66 | image_background = new Image(bitmap, Point(0, 0), Size(192, 192)); |
| 67 | |
| 68 | mainWnd->Add(image_background); |
| 69 | |
| 70 | #ifdef __APPLE__ |
| 71 | String location = "freac.app/Contents/Resources"; |
| 72 | #else |
| 73 | String location = "the fre:ac directory"; |
| 74 | #endif |
| 75 | |
| 76 | #ifndef __WIN32__ |
| 77 | if (Directory(S::System::System::GetResourcesDirectory().Append("freac")).Exists()) location = Directory(S::System::System::GetResourcesDirectory().Append("freac")); |
| 78 | #endif |
| 79 | |
| 80 | if (!incomplete) text_info = new TransparentText(String("Your native language does not seem to be supported by fre:ac yet.\n\nDid you know you can easily create your own translation and share\nit with other users?\n\nPlease have a look at the Readme.lang file in the lang subfolder\nof ").Append(location).Append(" for instructions on how to create a\ntranslation and submit it to the fre:ac project.\n\nIf you have any questions, please contact [email protected]."), Point(7, 45)); |
| 81 | else text_info = new TransparentText(String("The translation for your native language seems to be incomplete.\n\nDid you know you can easily complete it and share the result with\nother users?\n\nPlease have a look at the Readme.lang file in the lang subfolder\nof ").Append(location).Append(" for instructions on how to edit a\ntranslation and submit it to the fre:ac project.\n\nIf you have any questions, please contact [email protected]."), Point(7, 45)); |
| 82 | |
| 83 | text_intro = new TransparentText("Please help translate this project!", Point(7, 12)); |
| 84 | text_intro->SetFont(Font(Font::Default, 12, Font::Bold, 0, text_intro->GetFont().GetColor())); |
| 85 | text_intro->SetX((Math::Max(text_intro->GetUnscaledTextWidth(), text_info->GetUnscaledTextWidth()) + 9 - text_intro->GetUnscaledTextWidth()) / 2); |
| 86 | |
| 87 | text_thanks = new TransparentText("Thank you very much!", Point(7, text_info->GetUnscaledTextHeight() + 58)); |
| 88 | text_thanks->SetFont(Font(Font::Default, 12, Font::Bold, 0, text_thanks->GetFont().GetColor())); |
| 89 | text_thanks->SetX((Math::Max(text_intro->GetUnscaledTextWidth(), text_info->GetUnscaledTextWidth()) + 9 - text_thanks->GetUnscaledTextWidth()) / 2); |
| 90 | |
| 91 | image_background->SetPosition(Point((Math::Max(text_intro->GetUnscaledTextWidth(), text_info->GetUnscaledTextWidth()) - 178) / 2, (text_info->GetUnscaledTextHeight() - 94) / 2)); |
| 92 | |
| 93 | mainWnd->Add(text_intro); |
| 94 | mainWnd->Add(text_info); |
| 95 | mainWnd->Add(text_thanks); |
| 96 | |
| 97 | remind = config->GetIntValue("LanguageNotifier", "ShowAgain", True); |
| 98 | |
| 99 | check_remind = new CheckBox("Remind me later", Point(7, 27), Size(), &remind); |
| 100 | check_remind->SetOrientation(OR_LOWERLEFT); |
| 101 | check_remind->SetWidth(check_remind->GetUnscaledTextWidth() + 23); |
| 102 | |
| 103 | mainWnd->Add(check_remind); |
| 104 | |
| 105 | Add(mainWnd); |
| 106 | |
| 107 | mainWnd->SetFlags(mainWnd->GetFlags() | WF_TOPMOST | WF_NOTASKBUTTON); |
| 108 | mainWnd->SetIcon(ImageLoader::Load("icons/freac.png")); |
| 109 | |
| 110 | #ifndef __WIN32__ |
| 111 | if (Directory(S::System::System::GetResourcesDirectory().Append("freac")).Exists()) mainWnd->SetIcon(ImageLoader::Load(S::System::System::GetResourcesDirectory().Append("freac/icons/freac.png"))); |
| 112 | #endif |
| 113 | |
| 114 | Rect workArea = Screen::GetActiveScreenWorkArea(); |
| 115 | Float scaleFactor = Surface().GetSurfaceDPI() / 96.0; |
| 116 | |
| 117 | Size wndSize = Size(Math::Max(text_intro->GetUnscaledTextWidth(), text_info->GetUnscaledTextWidth()) + 21, text_info->GetUnscaledTextHeight() + 165); |
| 118 | Point wndPos = workArea.GetPosition() + Point((workArea.GetWidth() - Math::Round(wndSize.cx * scaleFactor)) / 2, |
| 119 | (workArea.GetHeight() - Math::Round(wndSize.cy * scaleFactor)) / 2); |
| 120 | |
| 121 | mainWnd->SetMetrics(wndPos, wndSize); |
| 122 | } |
| 123 | |
| 124 | BoCA::LanguageNotifierDialog::~LanguageNotifierDialog() |
| 125 | { |
| 126 | DeleteObject(mainWnd); |
| 127 | DeleteObject(mainWnd_titlebar); |
| 128 | |
| 129 | DeleteObject(divider); |
| 130 | |
| 131 | DeleteObject(button_close); |
| 132 | |
| 133 | DeleteObject(text_intro); |
| 134 | DeleteObject(text_info); |
| 135 | DeleteObject(text_thanks); |
| 136 | |
| 137 | DeleteObject(image_background); |
| 138 | |
| 139 | DeleteObject(check_remind); |
| 140 | } |
| 141 | |
| 142 | const Error &BoCA::LanguageNotifierDialog::ShowDialog() |
| 143 | { |
| 144 | mainWnd->Show(); |
| 145 | |
| 146 | return error; |
| 147 | } |
| 148 | |
| 149 | Void BoCA::LanguageNotifierDialog::Close() |
| 150 | { |
| 151 | Config *config = Config::Get(); |
| 152 | |
| 153 | mainWnd->Close(); |
| 154 | |
| 155 | config->SetIntValue("LanguageNotifier", "ShowAgain", remind); |
| 156 | } |