| 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 "donorbox.h" |
| 14 | #include "../dialog.h" |
| 15 | |
| 16 | using namespace smooth::IO; |
| 17 | |
| 18 | static PaymentMethod *MethodDonorboxFactory() |
| 19 | { |
| 20 | return new MethodDonorbox(); |
| 21 | } |
| 22 | |
| 23 | Bool methodDonorboxRegistered = DonateDialog::RegisterPaymentMethod(&MethodDonorboxFactory); |
| 24 | |
| 25 | BoCA::MethodDonorbox::MethodDonorbox() : PaymentMethod("donorbox") |
| 26 | { |
| 27 | layer = NIL; |
| 28 | |
| 29 | /* Load Donorbox logo. |
| 30 | */ |
| 31 | Directory dir(Utilities::GetBoCADirectory().Append("freac.extension.donate")); |
| 32 | |
| 33 | if (!dir.Exists()) dir = Utilities::GetBoCADirectory().Append("../freac/freac.extension.donate"); |
| 34 | |
| 35 | logo = ImageLoader::Load(String(dir).Append("/donorbox/logo.png")); |
| 36 | } |
| 37 | |
| 38 | BoCA::MethodDonorbox::~MethodDonorbox() |
| 39 | { |
| 40 | if (layer != NIL) Object::DeleteObject(layer); |
| 41 | } |
| 42 | |
| 43 | Layer *BoCA::MethodDonorbox::GetLayer() |
| 44 | { |
| 45 | if (layer == NIL) layer = new LayerDonorbox(); |
| 46 | |
| 47 | return layer; |
| 48 | } |
| 49 | |
| 50 | BoCA::LayerDonorbox::LayerDonorbox() |
| 51 | { |
| 52 | I18n *i18n = I18n::Get(); |
| 53 | |
| 54 | i18n->SetContext("Extensions::Donate::Donorbox"); |
| 55 | |
| 56 | text_donate = new Text(i18n->TranslateString("Donorbox enables quick and simple donations by credit card. Click this\nbutton to make a donation with Donorbox:"), Point(7, 4)); |
| 57 | |
| 58 | Add(text_donate); |
| 59 | |
| 60 | Directory dir(Utilities::GetBoCADirectory().Append("freac.extension.donate")); |
| 61 | |
| 62 | if (!dir.Exists()) dir = Utilities::GetBoCADirectory().Append("../freac/freac.extension.donate"); |
| 63 | |
| 64 | link_donate = new Hyperlink(ImageLoader::Load(String(dir).Append("/donorbox/button.png")), String("https://donorbox.org/the-freac-project-").Append(i18n->TranslateString("usd")), Point(0, text_donate->GetUnscaledTextHeight() + 20), Size(166, 40)); |
| 65 | |
| 66 | image_box = new Image(ImageLoader::Load(String(dir).Append("/donorbox/box.png")), link_donate->GetPosition() + Point(30, 10), Size(19, 19)); |
| 67 | text_box = new Text(i18n->TranslateString("Donate"), link_donate->GetPosition() + Point(60, 10)); |
| 68 | |
| 69 | Font font = text_box->GetFont(); |
| 70 | |
| 71 | font.SetColor(Color(255, 255, 255)); |
| 72 | font.SetWeight(Font::Bold); |
| 73 | font.SetSize(10); |
| 74 | |
| 75 | text_box->SetFont(font); |
| 76 | text_box->SetBackgroundColor(Color(45, 129, 197)); |
| 77 | text_box->SetY(link_donate->GetY() + (link_donate->GetHeight() - 3 - text_box->GetUnscaledTextHeight()) / 2); |
| 78 | |
| 79 | Add(link_donate); |
| 80 | |
| 81 | Add(image_box); |
| 82 | Add(text_box); |
| 83 | |
| 84 | onChangeSize.Connect(&LayerDonorbox::OnChangeSize, this); |
| 85 | |
| 86 | SetSize(Size(text_donate->GetUnscaledTextWidth() + 15, text_donate->GetUnscaledTextHeight() + 76)); |
| 87 | } |
| 88 | |
| 89 | BoCA::LayerDonorbox::~LayerDonorbox() |
| 90 | { |
| 91 | DeleteObject(text_donate); |
| 92 | |
| 93 | DeleteObject(link_donate); |
| 94 | |
| 95 | DeleteObject(image_box); |
| 96 | DeleteObject(text_box); |
| 97 | } |
| 98 | |
| 99 | Void BoCA::LayerDonorbox::OnChangeSize(const Size &nSize) |
| 100 | { |
| 101 | link_donate->SetX(nSize.cx / 2 - 83); |
| 102 | |
| 103 | Int width = image_box->GetWidth() + text_box->GetUnscaledTextWidth() + 8; |
| 104 | |
| 105 | image_box->SetX((nSize.cx - width) / 2); |
| 106 | text_box->SetX(image_box->GetWidth() + 8 + (nSize.cx - width) / 2); |
| 107 | } |