1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "base/string_utilities.h"
#include "mforms/app.h"
#include "about_box.h"
#include "wb_context.h"
using namespace wb;
#ifdef __APPLE__
#define ABOUT_NORMAL_FONT "Helvetica Neue"
#define ABOUT_FONT_SIZE 11
#elif defined(_WIN32)
#define ABOUT_NORMAL_FONT "Tahoma"
#define ABOUT_FONT_SIZE 10
#else
#define ABOUT_NORMAL_FONT "Tahoma"
#define ABOUT_FONT_SIZE 10
#endif
//--------------------------------------------------------------------------------------------------
// The following helpers are just temporary. They will be replaced by a cairo context class.
static void delete_surface(cairo_surface_t* surface)
{
if (surface != NULL)
cairo_surface_destroy(surface);
}
//--------------------------------------------------------------------------------------------------
static int image_width(cairo_surface_t* image)
{
if (image != NULL)
return cairo_image_surface_get_width(image);
return 0;
}
//--------------------------------------------------------------------------------------------------
static int image_height(cairo_surface_t* image)
{
if (image != NULL)
return cairo_image_surface_get_height(image);
return 0;
}
//--------------------------------------------------------------------------------------------------
AboutBox::AboutBox(const std::string &edition)
: Popup(mforms::PopupPlain), _edition(edition)
{
base::Size size;
_scale_factor = mforms::App::get()->backing_scale_factor();
if (_scale_factor > 1)
{
_back_image = mforms::Utilities::load_icon("MySQL-WB-about-screen@2x.png");
size = base::Size(image_width(_back_image) / _scale_factor, image_height(_back_image) / _scale_factor);
}
else
{
_back_image = mforms::Utilities::load_icon("MySQL-WB-about-screen.png");
size = base::Size(image_width(_back_image), image_height(_back_image));
}
set_size((int)size.width, (int)size.height);
base::Rect bounds = mforms::App::get()->get_application_bounds();
// On OS X the vertical screen coordinate points up.
int left = (int)(bounds.left() + (bounds.width() - size.width) / 2);
#ifdef __APPLE__
int top = (int)(bounds.top() - (bounds.height() - size.height) / 2);
#else
int top = (int)(bounds.top() + (bounds.height() - size.height) / 2);
#endif
show(left, top);
}
//--------------------------------------------------------------------------------------------------
AboutBox::~AboutBox()
{
delete_surface(_back_image);
}
//--------------------------------------------------------------------------------------------------
#define TEXT_BASE_LINE 125
#define BUILD_TEXT_OFFSET 107
#define RELEASE_TYPE_OFFSET 365 // Right border.
void AboutBox::repaint(cairo_t *cr, int x, int y, int w, int h)
{
cairo_scale(cr, 1 / _scale_factor, 1 / _scale_factor);
cairo_set_source_surface(cr, _back_image, 0, 0);
cairo_paint(cr);
cairo_identity_matrix(cr);
std::string version = base::strfmt(_("Version %i.%i.%i build %i %s (%i bits)"), APP_MAJOR_NUMBER, APP_MINOR_NUMBER,
APP_RELEASE_NUMBER, APP_BUILD_NUMBER, APP_RELEASE_TYPE,
(int)sizeof(void*)*8);
cairo_select_font_face(cr, ABOUT_NORMAL_FONT, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, ABOUT_FONT_SIZE);
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_move_to(cr, BUILD_TEXT_OFFSET, TEXT_BASE_LINE);
cairo_show_text(cr, version.c_str());
cairo_text_extents_t extents;
cairo_text_extents(cr, _edition.c_str(), &extents);
cairo_move_to(cr, RELEASE_TYPE_OFFSET - extents.width, TEXT_BASE_LINE);
cairo_show_text(cr, _edition.c_str());
cairo_stroke(cr);
}
//--------------------------------------------------------------------------------------------------
static AboutBox *singleton = NULL;
bool AboutBox::mouse_up(mforms::MouseButton button, int x, int y)
{
singleton->set_modal_result(1);
return false;
}
//--------------------------------------------------------------------------------------------------
void AboutBox::closed()
{
delete singleton;
singleton = NULL;
}
//--------------------------------------------------------------------------------------------------
void AboutBox::show_about(const std::string &edition)
{
if (singleton != NULL)
return;
singleton = new AboutBox(edition);
singleton->on_close()->connect(boost::bind(&AboutBox::closed));
}
//--------------------------------------------------------------------------------------------------
|