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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 Eran Ifrah
// file name : cl_aui_notebook_art.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// 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; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "clAuiMainNotebookTabArt.h"
#include "editor_config.h"
#include <wx/dcgraph.h>
#include "plugin_general_wxcp.h"
#include <wx/dcmemory.h>
#include <editor_config.h>
#include "globals.h"
#include "cl_command_event.h"
#include "plugin.h"
#include "event_notifier.h"
#include <wx/stc/stc.h>
#include "ieditor.h"
#include "clNotebookTheme.h"
#include <wx/xrc/xmlres.h>
static const wxDouble X_RADIUS = 6.0;
static const wxDouble X_DIAMETER = 2 * X_RADIUS;
#ifdef __WXMAC__
#include <wx/osx/private.h>
#define TAB_HEIGHT_SPACER 10
#define TAB_Y_OFFSET 2
#define TEXT_Y_SPACER 0
#define BMP_Y_SPACER 0
#elif defined(__WXMSW__)
#define TAB_HEIGHT_SPACER 10
#define TAB_Y_OFFSET 0
#define TEXT_Y_SPACER -2
#define BMP_Y_SPACER 0
#else // GTK/FreeBSD
#define TAB_Y_OFFSET 0
#define TEXT_Y_SPACER 0
#define BMP_Y_SPACER 0
#endif
static int x_button_height = 16;
clAuiMainNotebookTabArt::clAuiMainNotebookTabArt(IManager* manager)
: m_manager(manager)
, m_tabRadius(0.0)
{
#ifdef __WXMSW__
m_tabRadius = 1.0;
#elif defined(__WXGTK__)
m_tabRadius = 1.0;
#else
m_tabRadius = 0.0;
#endif
// Default buttons
m_bmpClose = wxXmlResource::Get()->LoadBitmap("tab_x_close");
m_bmpCloseHover = wxXmlResource::Get()->LoadBitmap("tab_x_close_hover");
m_bmpClosePressed = wxXmlResource::Get()->LoadBitmap("tab_x_close_pressed");
x_button_height = m_bmpClose.GetHeight();
}
clAuiMainNotebookTabArt::~clAuiMainNotebookTabArt() {}
void clAuiMainNotebookTabArt::DrawBackground(wxDC& dc, wxWindow* wnd, const wxRect& rect)
{
wxUnusedVar(wnd);
#ifdef __WXGTK__
wxDC& gdc = dc;
#else
wxGCDC gdc;
if(!DrawingUtils::GetGCDC(dc, gdc)) return;
#endif
DoSetColours();
gdc.SetPen(m_activeTabPenColour);
wxBrush brush = DrawingUtils::GetStippleBrush();
brush.SetColour(m_bgColour);
gdc.SetBrush(brush);
gdc.GradientFillLinear(rect, m_bgColour, m_bgColour, wxSOUTH);
wxPoint ptBottomLeft = rect.GetBottomLeft();
wxPoint ptBottomRight = rect.GetBottomRight();
gdc.SetPen(m_activeTabBgColour);
gdc.DrawLine(ptBottomLeft, ptBottomRight);
ptBottomLeft.y -= 1;
ptBottomRight.y -= 1;
gdc.SetPen(m_activeTabPenColour);
gdc.DrawLine(ptBottomLeft, ptBottomRight);
}
void clAuiMainNotebookTabArt::DrawTab(wxDC& dc,
wxWindow* wnd,
const wxAuiNotebookPage& page,
const wxRect& in_rect,
int close_button_state,
wxRect* out_tab_rect,
wxRect* out_button_rect,
int* x_extent)
{
if(in_rect.GetHeight() == 0) return; // Tabs are not visible
int curx = 0;
wxGCDC gdc;
if(!DrawingUtils::GetGCDC(dc, gdc)) return;
wxColour penColour = page.active ? m_activeTabPenColour : m_penColour;
wxGraphicsPath path = gdc.GetGraphicsContext()->CreatePath();
gdc.SetPen(penColour);
wxSize sz = GetTabSize(gdc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent);
wxRect rr(in_rect.GetTopLeft(), sz);
rr.y += TAB_Y_OFFSET;
rr.width += 1;
#if 0
if(page.active) {
rr.y -= 2;
rr.height += 2;
}
#endif
#ifndef __WXGTK__
rr.height += 4;
#endif
/// the tab start position (x)
curx = rr.x + 7;
// Set clipping region
int clip_width = rr.width;
if(rr.x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - rr.x;
gdc.SetClippingRegion(rr.x, rr.y, clip_width, rr.height);
gdc.SetBrush(m_bgColour);
gdc.SetPen(penColour);
if(page.active) {
gdc.SetBrush(m_activeTabBgColour);
path.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, m_tabRadius);
gdc.GetGraphicsContext()->FillPath(path);
gdc.GetGraphicsContext()->StrokePath(path);
} else {
wxGraphicsPath outerPath = gdc.GetGraphicsContext()->CreatePath();
gdc.SetPen(penColour);
outerPath.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, m_tabRadius);
gdc.GetGraphicsContext()->StrokePath(outerPath);
gdc.SetPen(m_innerPenColour);
path.AddRoundedRectangle(rr.x + 1, rr.y + 1, rr.width - 3, rr.height - 2, m_tabRadius);
gdc.GetGraphicsContext()->StrokePath(path);
gdc.SetBrush(m_tabBgColour);
gdc.GetGraphicsContext()->StrokePath(path);
gdc.GetGraphicsContext()->FillPath(path);
gdc.SetPen(penColour);
}
if(!page.active) {
// Draw 2 lines at the bottom rect
// one with the background colour of the active tab and the second
// with the active tab pen colour
wxPoint p1, p2;
p1 = in_rect.GetBottomLeft();
p1.x -= 1;
p2 = in_rect.GetBottomRight();
gdc.SetPen(m_activeTabBgColour);
gdc.DrawLine(p1, p2);
p1.y -= 1;
p2.y -= 1;
gdc.SetPen(m_activeTabPenColour);
gdc.DrawLine(p1, p2);
} else {
wxPoint p1, p2;
p1 = in_rect.GetBottomLeft();
p2 = in_rect.GetBottomRight();
gdc.SetPen(m_activeTabBgColour);
gdc.DrawLine(p1, p2);
gdc.DrawPoint(p1);
gdc.DrawPoint(p1);
p1.x += 1;
gdc.DrawPoint(p1);
gdc.DrawPoint(p1);
p1.x -= 1;
gdc.DrawPoint(p1);
gdc.DrawPoint(p1);
}
wxString caption = page.caption;
if(caption.IsEmpty()) {
caption = "Tp";
}
wxFont fnt = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
gdc.SetFont(fnt);
wxSize ext = gdc.GetTextExtent(caption);
if(caption == "Tp") caption.Clear();
/// Draw the bitmap
if(page.bitmap.IsOk()) {
int bmpy = (rr.y + (rr.height - page.bitmap.GetHeight()) / 2) - TAB_Y_OFFSET + BMP_Y_SPACER;
gdc.GetGraphicsContext()->DrawBitmap(page.bitmap, curx, bmpy, page.bitmap.GetWidth(), page.bitmap.GetHeight());
curx += page.bitmap.GetWidth();
curx += 3;
}
/// Draw the text
wxColour textColour = page.active ? m_activeTabTextColour : m_tabTextColour;
gdc.SetTextForeground(textColour);
wxDouble textYOffCorrd = (rr.y + (rr.height - ext.y) / 2) - TAB_Y_OFFSET + TEXT_Y_SPACER;
gdc.GetGraphicsContext()->DrawText(page.caption, curx, textYOffCorrd);
// advance the X offset
curx += ext.x;
curx += 3;
/// Draw the X button on the tab
if(close_button_state != wxAUI_BUTTON_STATE_HIDDEN) {
curx += 1;
wxBitmap xBmp = m_bmpClose;
switch(close_button_state) {
case wxAUI_BUTTON_STATE_HOVER:
xBmp = m_bmpCloseHover;
break;
case wxAUI_BUTTON_STATE_PRESSED:
xBmp = m_bmpClosePressed;
break;
}
int btny = (rr.y + (rr.height - x_button_height) / 2) - TAB_Y_OFFSET + BMP_Y_SPACER;
gdc.GetGraphicsContext()->DrawBitmap(xBmp, curx, btny, x_button_height, x_button_height);
*out_button_rect = wxRect(curx, btny, x_button_height, x_button_height);
curx += x_button_height;
}
*out_tab_rect = rr;
gdc.DestroyClippingRegion();
}
wxSize clAuiMainNotebookTabArt::GetTabSize(wxDC& dc,
wxWindow* WXUNUSED(wnd),
const wxString& caption,
const wxBitmap& bitmap,
bool active,
int close_button_state,
int* x_extent)
{
static wxCoord measured_texty(wxNOT_FOUND);
wxCoord measured_textx;
wxCoord tmp;
wxFont f = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
// if(active) {
// f.SetWeight(wxFONTWEIGHT_BOLD);
// }
dc.SetFont(f);
dc.GetTextExtent(caption, &measured_textx, &tmp);
// do it once
if(measured_texty == wxNOT_FOUND) dc.GetTextExtent(wxT("ABCDEFXj"), &tmp, &measured_texty);
// add padding around the text
wxCoord tab_width = measured_textx;
wxCoord tab_height = measured_texty;
#ifdef __WXGTK__
tab_height = TAB_CTRL_HEIGHT;
#endif
if(tab_height < 16) tab_height = 16;
// if the close button is showing, add space for it
if(close_button_state != wxAUI_BUTTON_STATE_HIDDEN) tab_width += X_DIAMETER + 3;
// if there's a bitmap, add space for it
// NOTE: we only support 16 pixels bitmap (or smaller)
// so there is no need to adjust the tab height!
#ifndef __WXGTK__
tab_height += TAB_HEIGHT_SPACER;
#endif
if(bitmap.IsOk()) {
tab_width += bitmap.GetWidth();
tab_width += 3; // right side bitmap padding
}
// add padding
#ifdef __WXMAC__
tab_width += 16;
#else
tab_width += 16;
#endif
if(m_flags & wxAUI_NB_TAB_FIXED_WIDTH) {
tab_width = 80;
}
*x_extent = tab_width;
return wxSize(tab_width, tab_height);
}
void clAuiMainNotebookTabArt::DoSetColours()
{
// Set the colours
// based on the selected book theme
if(!m_bgColour.IsOk()) {
DoInitializeColoursFromTheme();
}
// If we have an active editor, update the colours, if not - keep the old ones
IEditor* editor = m_manager->GetActiveEditor();
SetLightColours();
// We use the colour theme based on the active editor
if(editor) {
// Change lightness ranges between 0-200
// 0 would be completely black, 200 completely white an ialpha of 100 returns the same colour.
m_activeTabBgColour = editor->GetCtrl()->StyleGetBackground(0);
if(DrawingUtils::IsDark(m_activeTabBgColour)) {
SetDarkColours();
}
}
}
void clAuiMainNotebookTabArt::DoInitializeColoursFromTheme()
{
clNotebookTheme theme = clNotebookTheme::GetTheme(clNotebookTheme::kDefault);
m_activeTabPenColour = theme.GetActiveTabPenColour();
m_tabBgColour = theme.GetTabBgColour().ChangeLightness(150);
m_penColour = m_activeTabPenColour.ChangeLightness(130);
m_innerPenColour = m_tabBgColour.ChangeLightness(150);
m_bgColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
m_activeTabTextColour = theme.GetActiveTabTextColour();
m_tabTextColour = theme.GetTabTextColour();
m_activeTabBgColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
}
void clAuiMainNotebookTabArt::SetDarkColours()
{
// Change lightness ranges between 0-200
// 0 would be completely black, 200 completely white an ialpha of 100 returns the same colour.
clColourPalette colours = DrawingUtils::GetColourPalette();
// Adjust the button colours
m_bmpClose = wxXmlResource::Get()->LoadBitmap("tab_x_close_dark");
m_bmpCloseHover = wxXmlResource::Get()->LoadBitmap("tab_x_close_dark_hover");
m_bmpClosePressed = wxXmlResource::Get()->LoadBitmap("tab_x_close_dark_pressed");
// adjust some colours
m_activeTabTextColour = *wxWHITE;
m_tabTextColour = m_activeTabTextColour.ChangeLightness(70);
m_activeTabBgColour = wxColour("rgb(85, 85, 85)").ChangeLightness(110);
#if 0
m_activeTabPenColour = m_activeTabBgColour;
#else
m_activeTabPenColour = m_activeTabBgColour.ChangeLightness(30);
#endif
m_tabBgColour = wxColour("rgb(60, 60, 60)");
m_bgColour = colours.bgColour.ChangeLightness(70);
m_penColour = m_bgColour.ChangeLightness(80);
m_innerPenColour = m_penColour.ChangeLightness(120);
}
void clAuiMainNotebookTabArt::SetLightColours()
{
// Change lightness ranges between 0-200
// 0 would be completely black, 200 completely white an ialpha of 100 returns the same colour.
// Adjust the button colours
m_bmpClose = wxXmlResource::Get()->LoadBitmap("tab_x_close");
m_bmpCloseHover = wxXmlResource::Get()->LoadBitmap("tab_x_close_hover");
m_bmpClosePressed = wxXmlResource::Get()->LoadBitmap("tab_x_close_pressed");
// adjust some colours
m_activeTabTextColour = *wxBLACK;
m_tabTextColour = m_activeTabTextColour.ChangeLightness(130);
m_activeTabBgColour = wxColour("rgb(246, 246, 246)");
// The active pen colour is a bit more lighter than the active tab bg colour
m_activeTabPenColour = wxColour("rgb(170, 170, 170)");
m_tabBgColour = wxColour("rgb(230, 230, 230)");
#if defined(__WXMSW__) || defined(__WXGTK__)
m_bgColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
#else
m_bgColour = wxColour("rgb(240, 240, 240)");
#endif
m_penColour = wxColour("rgb(190, 190, 190)");
m_innerPenColour = *wxWHITE;
}
|