Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_LookAndFeel_V2.cpp 127KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. namespace LookAndFeelHelpers
  21. {
  22. static Colour createBaseColour (Colour buttonColour,
  23. bool hasKeyboardFocus,
  24. bool shouldDrawButtonAsHighlighted,
  25. bool shouldDrawButtonAsDown) noexcept
  26. {
  27. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  28. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  29. if (shouldDrawButtonAsDown) return baseColour.contrasting (0.2f);
  30. if (shouldDrawButtonAsHighlighted) return baseColour.contrasting (0.1f);
  31. return baseColour;
  32. }
  33. static TextLayout layoutTooltipText (const String& text, Colour colour) noexcept
  34. {
  35. const float tooltipFontSize = 13.0f;
  36. const int maxToolTipWidth = 400;
  37. AttributedString s;
  38. s.setJustification (Justification::centred);
  39. s.append (text, Font (tooltipFontSize, Font::bold), colour);
  40. TextLayout tl;
  41. tl.createLayoutWithBalancedLineLengths (s, (float) maxToolTipWidth);
  42. return tl;
  43. }
  44. }
  45. //==============================================================================
  46. LookAndFeel_V2::LookAndFeel_V2()
  47. {
  48. // initialise the standard set of colours..
  49. const uint32 textButtonColour = 0xffbbbbff;
  50. const uint32 textHighlightColour = 0x401111ee;
  51. const uint32 standardOutlineColour = 0xb2808080;
  52. static const uint32 standardColours[] =
  53. {
  54. TextButton::buttonColourId, textButtonColour,
  55. TextButton::buttonOnColourId, 0xff4444ff,
  56. TextButton::textColourOnId, 0xff000000,
  57. TextButton::textColourOffId, 0xff000000,
  58. ToggleButton::textColourId, 0xff000000,
  59. ToggleButton::tickColourId, 0xff000000,
  60. ToggleButton::tickDisabledColourId, 0xff808080,
  61. TextEditor::backgroundColourId, 0xffffffff,
  62. TextEditor::textColourId, 0xff000000,
  63. TextEditor::highlightColourId, textHighlightColour,
  64. TextEditor::highlightedTextColourId, 0xff000000,
  65. TextEditor::outlineColourId, 0x00000000,
  66. TextEditor::focusedOutlineColourId, textButtonColour,
  67. TextEditor::shadowColourId, 0x38000000,
  68. CaretComponent::caretColourId, 0xff000000,
  69. Label::backgroundColourId, 0x00000000,
  70. Label::textColourId, 0xff000000,
  71. Label::outlineColourId, 0x00000000,
  72. ScrollBar::backgroundColourId, 0x00000000,
  73. ScrollBar::thumbColourId, 0xffffffff,
  74. TreeView::linesColourId, 0x4c000000,
  75. TreeView::backgroundColourId, 0x00000000,
  76. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  77. TreeView::selectedItemBackgroundColourId, 0x00000000,
  78. TreeView::oddItemsColourId, 0x00000000,
  79. TreeView::evenItemsColourId, 0x00000000,
  80. PopupMenu::backgroundColourId, 0xffffffff,
  81. PopupMenu::textColourId, 0xff000000,
  82. PopupMenu::headerTextColourId, 0xff000000,
  83. PopupMenu::highlightedTextColourId, 0xffffffff,
  84. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  85. ComboBox::buttonColourId, 0xffbbbbff,
  86. ComboBox::outlineColourId, standardOutlineColour,
  87. ComboBox::textColourId, 0xff000000,
  88. ComboBox::backgroundColourId, 0xffffffff,
  89. ComboBox::arrowColourId, 0x99000000,
  90. ComboBox::focusedOutlineColourId, 0xffbbbbff,
  91. PropertyComponent::backgroundColourId, 0x66ffffff,
  92. PropertyComponent::labelTextColourId, 0xff000000,
  93. TextPropertyComponent::backgroundColourId, 0xffffffff,
  94. TextPropertyComponent::textColourId, 0xff000000,
  95. TextPropertyComponent::outlineColourId, standardOutlineColour,
  96. BooleanPropertyComponent::backgroundColourId, 0xffffffff,
  97. BooleanPropertyComponent::outlineColourId, standardOutlineColour,
  98. ListBox::backgroundColourId, 0xffffffff,
  99. ListBox::outlineColourId, standardOutlineColour,
  100. ListBox::textColourId, 0xff000000,
  101. Slider::backgroundColourId, 0x00000000,
  102. Slider::thumbColourId, textButtonColour,
  103. Slider::trackColourId, 0x7fffffff,
  104. Slider::rotarySliderFillColourId, 0x7f0000ff,
  105. Slider::rotarySliderOutlineColourId, 0x66000000,
  106. Slider::textBoxTextColourId, 0xff000000,
  107. Slider::textBoxBackgroundColourId, 0xffffffff,
  108. Slider::textBoxHighlightColourId, textHighlightColour,
  109. Slider::textBoxOutlineColourId, standardOutlineColour,
  110. ResizableWindow::backgroundColourId, 0xff777777,
  111. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  112. AlertWindow::backgroundColourId, 0xffededed,
  113. AlertWindow::textColourId, 0xff000000,
  114. AlertWindow::outlineColourId, 0xff666666,
  115. ProgressBar::backgroundColourId, 0xffeeeeee,
  116. ProgressBar::foregroundColourId, 0xffaaaaee,
  117. TooltipWindow::backgroundColourId, 0xffeeeebb,
  118. TooltipWindow::textColourId, 0xff000000,
  119. TooltipWindow::outlineColourId, 0x4c000000,
  120. TabbedComponent::backgroundColourId, 0x00000000,
  121. TabbedComponent::outlineColourId, 0xff777777,
  122. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  123. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  124. Toolbar::backgroundColourId, 0xfff6f8f9,
  125. Toolbar::separatorColourId, 0x4c000000,
  126. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  127. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  128. Toolbar::labelTextColourId, 0xff000000,
  129. Toolbar::editingModeOutlineColourId, 0xffff0000,
  130. DrawableButton::textColourId, 0xff000000,
  131. DrawableButton::textColourOnId, 0xff000000,
  132. DrawableButton::backgroundColourId, 0x00000000,
  133. DrawableButton::backgroundOnColourId, 0xaabbbbff,
  134. HyperlinkButton::textColourId, 0xcc1111ee,
  135. GroupComponent::outlineColourId, 0x66000000,
  136. GroupComponent::textColourId, 0xff000000,
  137. BubbleComponent::backgroundColourId, 0xeeeeeebb,
  138. BubbleComponent::outlineColourId, 0x77000000,
  139. TableHeaderComponent::textColourId, 0xff000000,
  140. TableHeaderComponent::backgroundColourId, 0xffe8ebf9,
  141. TableHeaderComponent::outlineColourId, 0x33000000,
  142. TableHeaderComponent::highlightColourId, 0x8899aadd,
  143. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  144. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  145. DirectoryContentsDisplayComponent::highlightedTextColourId, 0xff000000,
  146. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  147. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  148. 0x1004000, /*KeyboardComponentBase::upDownButtonBackgroundColourId*/ 0xffd3d3d3,
  149. 0x1004001, /*KeyboardComponentBase::upDownButtonArrowColourId*/ 0xff000000,
  150. 0x1005000, /*MidiKeyboardComponent::whiteNoteColourId*/ 0xffffffff,
  151. 0x1005001, /*MidiKeyboardComponent::blackNoteColourId*/ 0xff000000,
  152. 0x1005002, /*MidiKeyboardComponent::keySeparatorLineColourId*/ 0x66000000,
  153. 0x1005003, /*MidiKeyboardComponent::mouseOverKeyOverlayColourId*/ 0x80ffff00,
  154. 0x1005004, /*MidiKeyboardComponent::keyDownOverlayColourId*/ 0xffb6b600,
  155. 0x1005005, /*MidiKeyboardComponent::textLabelColourId*/ 0xff000000,
  156. 0x1005006, /*MidiKeyboardComponent::shadowColourId*/ 0x4c000000,
  157. 0x1006000, /*MPEKeyboardComponent::whiteNoteColourId*/ 0xff1a1c27,
  158. 0x1006001, /*MPEKeyboardComponent::blackNoteColourId*/ 0x99f1f1f1,
  159. 0x1006002, /*MPEKeyboardComponent::textLabelColourId*/ 0xfff1f1f1,
  160. 0x1006003, /*MPEKeyboardComponent::noteCircleFillColourId*/ 0x99ba00ff,
  161. 0x1006004, /*MPEKeyboardComponent::noteCircleOutlineColourId*/ 0xfff1f1f1,
  162. 0x1004500, /*CodeEditorComponent::backgroundColourId*/ 0xffffffff,
  163. 0x1004502, /*CodeEditorComponent::highlightColourId*/ textHighlightColour,
  164. 0x1004503, /*CodeEditorComponent::defaultTextColourId*/ 0xff000000,
  165. 0x1004504, /*CodeEditorComponent::lineNumberBackgroundId*/ 0x44999999,
  166. 0x1004505, /*CodeEditorComponent::lineNumberTextId*/ 0x44000000,
  167. 0x1007000, /*ColourSelector::backgroundColourId*/ 0xffe5e5e5,
  168. 0x1007001, /*ColourSelector::labelTextColourId*/ 0xff000000,
  169. 0x100ad00, /*KeyMappingEditorComponent::backgroundColourId*/ 0x00000000,
  170. 0x100ad01, /*KeyMappingEditorComponent::textColourId*/ 0xff000000,
  171. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  172. FileChooserDialogBox::titleTextColourId, 0xff000000,
  173. SidePanel::backgroundColour, 0xffffffff,
  174. SidePanel::titleTextColour, 0xff000000,
  175. SidePanel::shadowBaseColour, 0xff000000,
  176. SidePanel::dismissButtonNormalColour, textButtonColour,
  177. SidePanel::dismissButtonOverColour, textButtonColour,
  178. SidePanel::dismissButtonDownColour, 0xff4444ff,
  179. FileBrowserComponent::currentPathBoxBackgroundColourId, 0xffffffff,
  180. FileBrowserComponent::currentPathBoxTextColourId, 0xff000000,
  181. FileBrowserComponent::currentPathBoxArrowColourId, 0x99000000,
  182. FileBrowserComponent::filenameBoxBackgroundColourId, 0xffffffff,
  183. FileBrowserComponent::filenameBoxTextColourId, 0xff000000,
  184. };
  185. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  186. setColour ((int) standardColours [i], Colour ((uint32) standardColours [i + 1]));
  187. }
  188. LookAndFeel_V2::~LookAndFeel_V2() {}
  189. //==============================================================================
  190. void LookAndFeel_V2::drawButtonBackground (Graphics& g,
  191. Button& button,
  192. const Colour& backgroundColour,
  193. bool shouldDrawButtonAsHighlighted,
  194. bool shouldDrawButtonAsDown)
  195. {
  196. const int width = button.getWidth();
  197. const int height = button.getHeight();
  198. const float outlineThickness = button.isEnabled() ? ((shouldDrawButtonAsDown || shouldDrawButtonAsHighlighted) ? 1.2f : 0.7f) : 0.4f;
  199. const float halfThickness = outlineThickness * 0.5f;
  200. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  201. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  202. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  203. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  204. const Colour baseColour (LookAndFeelHelpers::createBaseColour (backgroundColour,
  205. button.hasKeyboardFocus (true),
  206. shouldDrawButtonAsHighlighted,
  207. shouldDrawButtonAsDown)
  208. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  209. drawGlassLozenge (g,
  210. indentL,
  211. indentT,
  212. (float) width - indentL - indentR,
  213. (float) height - indentT - indentB,
  214. baseColour, outlineThickness, -1.0f,
  215. button.isConnectedOnLeft(),
  216. button.isConnectedOnRight(),
  217. button.isConnectedOnTop(),
  218. button.isConnectedOnBottom());
  219. }
  220. Font LookAndFeel_V2::getTextButtonFont (TextButton&, int buttonHeight)
  221. {
  222. return Font (jmin (15.0f, (float) buttonHeight * 0.6f));
  223. }
  224. int LookAndFeel_V2::getTextButtonWidthToFitText (TextButton& b, int buttonHeight)
  225. {
  226. return getTextButtonFont (b, buttonHeight).getStringWidth (b.getButtonText()) + buttonHeight;
  227. }
  228. void LookAndFeel_V2::drawButtonText (Graphics& g, TextButton& button,
  229. bool /*shouldDrawButtonAsHighlighted*/, bool /*shouldDrawButtonAsDown*/)
  230. {
  231. Font font (getTextButtonFont (button, button.getHeight()));
  232. g.setFont (font);
  233. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  234. : TextButton::textColourOffId)
  235. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  236. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  237. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  238. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  239. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  240. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  241. const int textWidth = button.getWidth() - leftIndent - rightIndent;
  242. if (textWidth > 0)
  243. g.drawFittedText (button.getButtonText(),
  244. leftIndent, yIndent, textWidth, button.getHeight() - yIndent * 2,
  245. Justification::centred, 2);
  246. }
  247. void LookAndFeel_V2::drawTickBox (Graphics& g, Component& component,
  248. float x, float y, float w, float h,
  249. const bool ticked,
  250. const bool isEnabled,
  251. const bool shouldDrawButtonAsHighlighted,
  252. const bool shouldDrawButtonAsDown)
  253. {
  254. const float boxSize = w * 0.7f;
  255. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  256. LookAndFeelHelpers::createBaseColour (component.findColour (TextButton::buttonColourId)
  257. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  258. true, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown),
  259. isEnabled ? ((shouldDrawButtonAsDown || shouldDrawButtonAsHighlighted) ? 1.1f : 0.5f) : 0.3f);
  260. if (ticked)
  261. {
  262. Path tick;
  263. tick.startNewSubPath (1.5f, 3.0f);
  264. tick.lineTo (3.0f, 6.0f);
  265. tick.lineTo (6.0f, 0.0f);
  266. g.setColour (component.findColour (isEnabled ? ToggleButton::tickColourId
  267. : ToggleButton::tickDisabledColourId));
  268. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  269. .translated (x, y));
  270. g.strokePath (tick, PathStrokeType (2.5f), trans);
  271. }
  272. }
  273. void LookAndFeel_V2::drawToggleButton (Graphics& g, ToggleButton& button,
  274. bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
  275. {
  276. if (button.hasKeyboardFocus (true))
  277. {
  278. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  279. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  280. }
  281. float fontSize = jmin (15.0f, (float) button.getHeight() * 0.75f);
  282. const float tickWidth = fontSize * 1.1f;
  283. drawTickBox (g, button, 4.0f, ((float) button.getHeight() - tickWidth) * 0.5f,
  284. tickWidth, tickWidth,
  285. button.getToggleState(),
  286. button.isEnabled(),
  287. shouldDrawButtonAsHighlighted,
  288. shouldDrawButtonAsDown);
  289. g.setColour (button.findColour (ToggleButton::textColourId));
  290. g.setFont (fontSize);
  291. if (! button.isEnabled())
  292. g.setOpacity (0.5f);
  293. g.drawFittedText (button.getButtonText(),
  294. button.getLocalBounds().withTrimmedLeft (roundToInt (tickWidth) + 5)
  295. .withTrimmedRight (2),
  296. Justification::centredLeft, 10);
  297. }
  298. void LookAndFeel_V2::changeToggleButtonWidthToFitText (ToggleButton& button)
  299. {
  300. auto fontSize = jmin (15.0f, (float) button.getHeight() * 0.75f);
  301. auto tickWidth = fontSize * 1.1f;
  302. Font font (fontSize);
  303. button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 9,
  304. button.getHeight());
  305. }
  306. void LookAndFeel_V2::drawDrawableButton (Graphics& g, DrawableButton& button,
  307. bool /*shouldDrawButtonAsHighlighted*/, bool /*shouldDrawButtonAsDown*/)
  308. {
  309. bool toggleState = button.getToggleState();
  310. g.fillAll (button.findColour (toggleState ? DrawableButton::backgroundOnColourId
  311. : DrawableButton::backgroundColourId));
  312. const int textH = (button.getStyle() == DrawableButton::ImageAboveTextLabel)
  313. ? jmin (16, button.proportionOfHeight (0.25f))
  314. : 0;
  315. if (textH > 0)
  316. {
  317. g.setFont ((float) textH);
  318. g.setColour (button.findColour (toggleState ? DrawableButton::textColourOnId
  319. : DrawableButton::textColourId)
  320. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.4f));
  321. g.drawFittedText (button.getButtonText(),
  322. 2, button.getHeight() - textH - 1,
  323. button.getWidth() - 4, textH,
  324. Justification::centred, 1);
  325. }
  326. }
  327. //==============================================================================
  328. AlertWindow* LookAndFeel_V2::createAlertWindow (const String& title, const String& message,
  329. const String& button1, const String& button2, const String& button3,
  330. MessageBoxIconType iconType,
  331. int numButtons, Component* associatedComponent)
  332. {
  333. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  334. if (numButtons == 1)
  335. {
  336. aw->addButton (button1, 0,
  337. KeyPress (KeyPress::escapeKey),
  338. KeyPress (KeyPress::returnKey));
  339. }
  340. else
  341. {
  342. const KeyPress button1ShortCut ((int) CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  343. KeyPress button2ShortCut ((int) CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  344. if (button1ShortCut == button2ShortCut)
  345. button2ShortCut = KeyPress();
  346. if (numButtons == 2)
  347. {
  348. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey), button1ShortCut);
  349. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey), button2ShortCut);
  350. }
  351. else if (numButtons == 3)
  352. {
  353. aw->addButton (button1, 1, button1ShortCut);
  354. aw->addButton (button2, 2, button2ShortCut);
  355. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey));
  356. }
  357. }
  358. return aw;
  359. }
  360. void LookAndFeel_V2::drawAlertBox (Graphics& g, AlertWindow& alert,
  361. const Rectangle<int>& textArea, TextLayout& textLayout)
  362. {
  363. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  364. int iconSpaceUsed = 0;
  365. const int iconWidth = 80;
  366. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  367. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  368. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  369. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  370. iconSize, iconSize);
  371. if (alert.getAlertType() != MessageBoxIconType::NoIcon)
  372. {
  373. Path icon;
  374. uint32 colour;
  375. char character;
  376. if (alert.getAlertType() == MessageBoxIconType::WarningIcon)
  377. {
  378. colour = 0x55ff5555;
  379. character = '!';
  380. icon.addTriangle ((float) iconRect.getX() + (float) iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  381. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  382. (float) iconRect.getX(), (float) iconRect.getBottom());
  383. icon = icon.createPathWithRoundedCorners (5.0f);
  384. }
  385. else
  386. {
  387. colour = alert.getAlertType() == MessageBoxIconType::InfoIcon ? (uint32) 0x605555ff : (uint32) 0x40b69900;
  388. character = alert.getAlertType() == MessageBoxIconType::InfoIcon ? 'i' : '?';
  389. icon.addEllipse (iconRect.toFloat());
  390. }
  391. GlyphArrangement ga;
  392. ga.addFittedText (Font ((float) iconRect.getHeight() * 0.9f, Font::bold),
  393. String::charToString ((juce_wchar) (uint8) character),
  394. (float) iconRect.getX(), (float) iconRect.getY(),
  395. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  396. Justification::centred, false);
  397. ga.createPath (icon);
  398. icon.setUsingNonZeroWinding (false);
  399. g.setColour (Colour (colour));
  400. g.fillPath (icon);
  401. iconSpaceUsed = iconWidth;
  402. }
  403. g.setColour (alert.findColour (AlertWindow::textColourId));
  404. textLayout.draw (g, Rectangle<int> (textArea.getX() + iconSpaceUsed,
  405. textArea.getY(),
  406. textArea.getWidth() - iconSpaceUsed,
  407. textArea.getHeight()).toFloat());
  408. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  409. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  410. }
  411. int LookAndFeel_V2::getAlertBoxWindowFlags()
  412. {
  413. return ComponentPeer::windowAppearsOnTaskbar
  414. | ComponentPeer::windowHasDropShadow;
  415. }
  416. Array<int> LookAndFeel_V2::getWidthsForTextButtons (AlertWindow&, const Array<TextButton*>& buttons)
  417. {
  418. const int n = buttons.size();
  419. Array<int> buttonWidths;
  420. const int buttonHeight = getAlertWindowButtonHeight();
  421. for (int i = 0; i < n; ++i)
  422. buttonWidths.add (getTextButtonWidthToFitText (*buttons.getReference (i), buttonHeight));
  423. return buttonWidths;
  424. }
  425. int LookAndFeel_V2::getAlertWindowButtonHeight()
  426. {
  427. return 28;
  428. }
  429. Font LookAndFeel_V2::getAlertWindowTitleFont()
  430. {
  431. Font messageFont = getAlertWindowMessageFont();
  432. return messageFont.withHeight (messageFont.getHeight() * 1.1f).boldened();
  433. }
  434. Font LookAndFeel_V2::getAlertWindowMessageFont()
  435. {
  436. return Font (15.0f);
  437. }
  438. Font LookAndFeel_V2::getAlertWindowFont()
  439. {
  440. return Font (12.0f);
  441. }
  442. //==============================================================================
  443. void LookAndFeel_V2::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  444. int width, int height,
  445. double progress, const String& textToShow)
  446. {
  447. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  448. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  449. g.fillAll (background);
  450. if (progress >= 0.0f && progress < 1.0f)
  451. {
  452. drawGlassLozenge (g, 1.0f, 1.0f,
  453. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  454. (float) (height - 2),
  455. foreground,
  456. 0.5f, 0.0f,
  457. true, true, true, true);
  458. }
  459. else
  460. {
  461. // spinning bar..
  462. g.setColour (foreground);
  463. const int stripeWidth = height * 2;
  464. const int position = (int) (Time::getMillisecondCounter() / 15) % stripeWidth;
  465. Path p;
  466. for (float x = (float) (- position); x < (float) (width + stripeWidth); x += (float) stripeWidth)
  467. p.addQuadrilateral (x, 0.0f,
  468. x + (float) stripeWidth * 0.5f, 0.0f,
  469. x, (float) height,
  470. x - (float) stripeWidth * 0.5f, (float) height);
  471. Image im (Image::ARGB, width, height, true);
  472. {
  473. Graphics g2 (im);
  474. drawGlassLozenge (g2, 1.0f, 1.0f,
  475. (float) (width - 2),
  476. (float) (height - 2),
  477. foreground,
  478. 0.5f, 0.0f,
  479. true, true, true, true);
  480. }
  481. g.setTiledImageFill (im, 0, 0, 0.85f);
  482. g.fillPath (p);
  483. }
  484. if (textToShow.isNotEmpty())
  485. {
  486. g.setColour (Colour::contrasting (background, foreground));
  487. g.setFont ((float) height * 0.6f);
  488. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  489. }
  490. }
  491. void LookAndFeel_V2::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  492. {
  493. const float radius = (float) jmin (w, h) * 0.4f;
  494. const float thickness = radius * 0.15f;
  495. Path p;
  496. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  497. radius * 0.6f, thickness,
  498. thickness * 0.5f);
  499. const float cx = (float) x + (float) w * 0.5f;
  500. const float cy = (float) y + (float) h * 0.5f;
  501. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  502. for (uint32 i = 0; i < 12; ++i)
  503. {
  504. const uint32 n = (i + 12 - animationIndex) % 12;
  505. g.setColour (colour.withMultipliedAlpha ((float) (n + 1) / 12.0f));
  506. g.fillPath (p, AffineTransform::rotation ((float) i * (MathConstants<float>::pi / 6.0f))
  507. .translated (cx, cy));
  508. }
  509. }
  510. bool LookAndFeel_V2::isProgressBarOpaque (ProgressBar& progressBar)
  511. {
  512. return progressBar.findColour (ProgressBar::backgroundColourId).isOpaque();
  513. }
  514. bool LookAndFeel_V2::areScrollbarButtonsVisible()
  515. {
  516. return true;
  517. }
  518. void LookAndFeel_V2::drawScrollbarButton (Graphics& g, ScrollBar& scrollbar,
  519. int width, int height, int buttonDirection,
  520. bool /*isScrollbarVertical*/,
  521. bool /*shouldDrawButtonAsHighlighted*/,
  522. bool shouldDrawButtonAsDown)
  523. {
  524. Path p;
  525. const auto w = (float) width;
  526. const auto h = (float) height;
  527. if (buttonDirection == 0)
  528. p.addTriangle (w * 0.5f, h * 0.2f,
  529. w * 0.1f, h * 0.7f,
  530. w * 0.9f, h * 0.7f);
  531. else if (buttonDirection == 1)
  532. p.addTriangle (w * 0.8f, h * 0.5f,
  533. w * 0.3f, h * 0.1f,
  534. w * 0.3f, h * 0.9f);
  535. else if (buttonDirection == 2)
  536. p.addTriangle (w * 0.5f, h * 0.8f,
  537. w * 0.1f, h * 0.3f,
  538. w * 0.9f, h * 0.3f);
  539. else if (buttonDirection == 3)
  540. p.addTriangle (w * 0.2f, h * 0.5f,
  541. w * 0.7f, h * 0.1f,
  542. w * 0.7f, h * 0.9f);
  543. if (shouldDrawButtonAsDown)
  544. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  545. else
  546. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  547. g.fillPath (p);
  548. g.setColour (Colour (0x80000000));
  549. g.strokePath (p, PathStrokeType (0.5f));
  550. }
  551. void LookAndFeel_V2::drawScrollbar (Graphics& g,
  552. ScrollBar& scrollbar,
  553. int x, int y,
  554. int width, int height,
  555. bool isScrollbarVertical,
  556. int thumbStartPosition,
  557. int thumbSize,
  558. bool /*isMouseOver*/,
  559. bool /*isMouseDown*/)
  560. {
  561. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  562. Path slotPath, thumbPath;
  563. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  564. const float slotIndentx2 = slotIndent * 2.0f;
  565. const float thumbIndent = slotIndent + 1.0f;
  566. const float thumbIndentx2 = thumbIndent * 2.0f;
  567. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  568. if (isScrollbarVertical)
  569. {
  570. slotPath.addRoundedRectangle ((float) x + slotIndent,
  571. (float) y + slotIndent,
  572. (float) width - slotIndentx2,
  573. (float) height - slotIndentx2,
  574. ((float) width - slotIndentx2) * 0.5f);
  575. if (thumbSize > 0)
  576. thumbPath.addRoundedRectangle ((float) x + thumbIndent,
  577. (float) thumbStartPosition + thumbIndent,
  578. (float) width - thumbIndentx2,
  579. (float) thumbSize - thumbIndentx2,
  580. ((float) width - thumbIndentx2) * 0.5f);
  581. gx1 = (float) x;
  582. gx2 = (float) x + (float) width * 0.7f;
  583. }
  584. else
  585. {
  586. slotPath.addRoundedRectangle ((float) x + slotIndent,
  587. (float) y + slotIndent,
  588. (float) width - slotIndentx2,
  589. (float) height - slotIndentx2,
  590. ((float) height - slotIndentx2) * 0.5f);
  591. if (thumbSize > 0)
  592. thumbPath.addRoundedRectangle ((float) thumbStartPosition + thumbIndent,
  593. (float) y + thumbIndent,
  594. (float) thumbSize - thumbIndentx2,
  595. (float) height - thumbIndentx2,
  596. ((float) height - thumbIndentx2) * 0.5f);
  597. gy1 = (float) y;
  598. gy2 = (float) y + (float) height * 0.7f;
  599. }
  600. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  601. Colour trackColour1, trackColour2;
  602. if (scrollbar.isColourSpecified (ScrollBar::trackColourId)
  603. || isColourSpecified (ScrollBar::trackColourId))
  604. {
  605. trackColour1 = trackColour2 = scrollbar.findColour (ScrollBar::trackColourId);
  606. }
  607. else
  608. {
  609. trackColour1 = thumbColour.overlaidWith (Colour (0x44000000));
  610. trackColour2 = thumbColour.overlaidWith (Colour (0x19000000));
  611. }
  612. g.setGradientFill (ColourGradient (trackColour1, gx1, gy1,
  613. trackColour2, gx2, gy2, false));
  614. g.fillPath (slotPath);
  615. if (isScrollbarVertical)
  616. {
  617. gx1 = (float) x + (float) width * 0.6f;
  618. gx2 = (float) x + (float) width;
  619. }
  620. else
  621. {
  622. gy1 = (float) y + (float) height * 0.6f;
  623. gy2 = (float) y + (float) height;
  624. }
  625. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  626. Colour (0x19000000), gx2, gy2, false));
  627. g.fillPath (slotPath);
  628. g.setColour (thumbColour);
  629. g.fillPath (thumbPath);
  630. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  631. Colours::transparentBlack, gx2, gy2, false));
  632. {
  633. Graphics::ScopedSaveState ss (g);
  634. if (isScrollbarVertical)
  635. g.reduceClipRegion (x + width / 2, y, width, height);
  636. else
  637. g.reduceClipRegion (x, y + height / 2, width, height);
  638. g.fillPath (thumbPath);
  639. }
  640. g.setColour (Colour (0x4c000000));
  641. g.strokePath (thumbPath, PathStrokeType (0.4f));
  642. }
  643. ImageEffectFilter* LookAndFeel_V2::getScrollbarEffect()
  644. {
  645. return nullptr;
  646. }
  647. int LookAndFeel_V2::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  648. {
  649. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  650. }
  651. int LookAndFeel_V2::getDefaultScrollbarWidth()
  652. {
  653. return 18;
  654. }
  655. int LookAndFeel_V2::getScrollbarButtonSize (ScrollBar& scrollbar)
  656. {
  657. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  658. : scrollbar.getHeight());
  659. }
  660. //==============================================================================
  661. void LookAndFeel_V2::drawTreeviewPlusMinusBox (Graphics& g, const Rectangle<float>& area,
  662. Colour /*backgroundColour*/, bool isOpen, bool /*isMouseOver*/)
  663. {
  664. auto boxSize = roundToInt (jmin (16.0f, area.getWidth(), area.getHeight()) * 0.7f) | 1;
  665. auto x = ((int) area.getWidth() - boxSize) / 2 + (int) area.getX();
  666. auto y = ((int) area.getHeight() - boxSize) / 2 + (int) area.getY();
  667. Rectangle<float> boxArea ((float) x, (float) y, (float) boxSize, (float) boxSize);
  668. g.setColour (Colour (0xe5ffffff));
  669. g.fillRect (boxArea);
  670. g.setColour (Colour (0x80000000));
  671. g.drawRect (boxArea);
  672. auto size = (float) boxSize * 0.5f + 1.0f;
  673. auto centre = (float) (boxSize / 2);
  674. g.fillRect ((float) x + ((float) boxSize - size) * 0.5f, (float) y + centre, size, 1.0f);
  675. if (! isOpen)
  676. g.fillRect ((float) x + centre, (float) y + ((float) boxSize - size) * 0.5f, 1.0f, size);
  677. }
  678. bool LookAndFeel_V2::areLinesDrawnForTreeView (TreeView&)
  679. {
  680. return true;
  681. }
  682. int LookAndFeel_V2::getTreeViewIndentSize (TreeView&)
  683. {
  684. return 24;
  685. }
  686. //==============================================================================
  687. void LookAndFeel_V2::drawBubble (Graphics& g, BubbleComponent& comp,
  688. const Point<float>& tip, const Rectangle<float>& body)
  689. {
  690. Path p;
  691. p.addBubble (body.reduced (0.5f), body.getUnion (Rectangle<float> (tip.x, tip.y, 1.0f, 1.0f)),
  692. tip, 5.0f, jmin (15.0f, body.getWidth() * 0.2f, body.getHeight() * 0.2f));
  693. g.setColour (comp.findColour (BubbleComponent::backgroundColourId));
  694. g.fillPath (p);
  695. g.setColour (comp.findColour (BubbleComponent::outlineColourId));
  696. g.strokePath (p, PathStrokeType (1.0f));
  697. }
  698. //==============================================================================
  699. Font LookAndFeel_V2::getPopupMenuFont()
  700. {
  701. return Font (17.0f);
  702. }
  703. void LookAndFeel_V2::getIdealPopupMenuItemSize (const String& text, const bool isSeparator,
  704. int standardMenuItemHeight, int& idealWidth, int& idealHeight)
  705. {
  706. if (isSeparator)
  707. {
  708. idealWidth = 50;
  709. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  710. }
  711. else
  712. {
  713. Font font (getPopupMenuFont());
  714. if (standardMenuItemHeight > 0 && font.getHeight() > (float) standardMenuItemHeight / 1.3f)
  715. font.setHeight ((float) standardMenuItemHeight / 1.3f);
  716. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  717. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  718. }
  719. }
  720. void LookAndFeel_V2::getIdealPopupMenuItemSizeWithOptions (const String& text,
  721. bool isSeparator,
  722. int standardMenuItemHeight,
  723. int& idealWidth,
  724. int& idealHeight,
  725. const PopupMenu::Options&)
  726. {
  727. getIdealPopupMenuItemSize (text,
  728. isSeparator,
  729. standardMenuItemHeight,
  730. idealWidth,
  731. idealHeight);
  732. }
  733. void LookAndFeel_V2::drawPopupMenuBackground (Graphics& g, int width, int height)
  734. {
  735. auto background = findColour (PopupMenu::backgroundColourId);
  736. g.fillAll (background);
  737. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  738. for (int i = 0; i < height; i += 3)
  739. g.fillRect (0, i, width, 1);
  740. #if ! JUCE_MAC
  741. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  742. g.drawRect (0, 0, width, height);
  743. #endif
  744. }
  745. void LookAndFeel_V2::drawPopupMenuBackgroundWithOptions (Graphics& g,
  746. int width,
  747. int height,
  748. const PopupMenu::Options&)
  749. {
  750. drawPopupMenuBackground (g, width, height);
  751. }
  752. void LookAndFeel_V2::drawPopupMenuUpDownArrow (Graphics& g, int width, int height, bool isScrollUpArrow)
  753. {
  754. auto background = findColour (PopupMenu::backgroundColourId);
  755. g.setGradientFill (ColourGradient (background, 0.0f, (float) height * 0.5f,
  756. background.withAlpha (0.0f),
  757. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  758. false));
  759. g.fillRect (1, 1, width - 2, height - 2);
  760. auto hw = (float) width * 0.5f;
  761. auto arrowW = (float) height * 0.3f;
  762. auto y1 = (float) height * (isScrollUpArrow ? 0.6f : 0.3f);
  763. auto y2 = (float) height * (isScrollUpArrow ? 0.3f : 0.6f);
  764. Path p;
  765. p.addTriangle (hw - arrowW, y1,
  766. hw + arrowW, y1,
  767. hw, y2);
  768. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  769. g.fillPath (p);
  770. }
  771. void LookAndFeel_V2::drawPopupMenuUpDownArrowWithOptions (Graphics& g,
  772. int width, int height,
  773. bool isScrollUpArrow,
  774. const PopupMenu::Options&)
  775. {
  776. drawPopupMenuUpDownArrow (g, width, height, isScrollUpArrow);
  777. }
  778. void LookAndFeel_V2::drawPopupMenuItem (Graphics& g, const Rectangle<int>& area,
  779. const bool isSeparator, const bool isActive,
  780. const bool isHighlighted, const bool isTicked,
  781. const bool hasSubMenu, const String& text,
  782. const String& shortcutKeyText,
  783. const Drawable* icon, const Colour* const textColourToUse)
  784. {
  785. if (isSeparator)
  786. {
  787. auto r = area.reduced (5, 0);
  788. r.removeFromTop (r.getHeight() / 2 - 1);
  789. g.setColour (Colour (0x33000000));
  790. g.fillRect (r.removeFromTop (1));
  791. g.setColour (Colour (0x66ffffff));
  792. g.fillRect (r.removeFromTop (1));
  793. }
  794. else
  795. {
  796. auto textColour = findColour (PopupMenu::textColourId);
  797. if (textColourToUse != nullptr)
  798. textColour = *textColourToUse;
  799. auto r = area.reduced (1);
  800. if (isHighlighted)
  801. {
  802. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  803. g.fillRect (r);
  804. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  805. }
  806. else
  807. {
  808. g.setColour (textColour);
  809. }
  810. if (! isActive)
  811. g.setOpacity (0.3f);
  812. Font font (getPopupMenuFont());
  813. auto maxFontHeight = (float) area.getHeight() / 1.3f;
  814. if (font.getHeight() > maxFontHeight)
  815. font.setHeight (maxFontHeight);
  816. g.setFont (font);
  817. auto iconArea = r.removeFromLeft ((r.getHeight() * 5) / 4).reduced (3).toFloat();
  818. if (icon != nullptr)
  819. {
  820. icon->drawWithin (g, iconArea, RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f);
  821. }
  822. else if (isTicked)
  823. {
  824. auto tick = getTickShape (1.0f);
  825. g.fillPath (tick, tick.getTransformToScaleToFit (iconArea, true));
  826. }
  827. if (hasSubMenu)
  828. {
  829. auto arrowH = 0.6f * getPopupMenuFont().getAscent();
  830. auto x = (float) r.removeFromRight ((int) arrowH).getX();
  831. auto halfH = (float) r.getCentreY();
  832. Path p;
  833. p.addTriangle (x, halfH - arrowH * 0.5f,
  834. x, halfH + arrowH * 0.5f,
  835. x + arrowH * 0.6f, halfH);
  836. g.fillPath (p);
  837. }
  838. r.removeFromRight (3);
  839. g.drawFittedText (text, r, Justification::centredLeft, 1);
  840. if (shortcutKeyText.isNotEmpty())
  841. {
  842. Font f2 (font);
  843. f2.setHeight (f2.getHeight() * 0.75f);
  844. f2.setHorizontalScale (0.95f);
  845. g.setFont (f2);
  846. g.drawText (shortcutKeyText, r, Justification::centredRight, true);
  847. }
  848. }
  849. }
  850. void LookAndFeel_V2::drawPopupMenuItemWithOptions (Graphics& g, const Rectangle<int>& area,
  851. bool isHighlighted,
  852. const PopupMenu::Item& item,
  853. const PopupMenu::Options&)
  854. {
  855. const auto colour = item.colour != Colour() ? &item.colour : nullptr;
  856. const auto hasSubMenu = item.subMenu != nullptr
  857. && (item.itemID == 0 || item.subMenu->getNumItems() > 0);
  858. drawPopupMenuItem (g,
  859. area,
  860. item.isSeparator,
  861. item.isEnabled,
  862. isHighlighted,
  863. item.isTicked,
  864. hasSubMenu,
  865. item.text,
  866. item.shortcutKeyDescription,
  867. item.image.get(),
  868. colour);
  869. }
  870. void LookAndFeel_V2::drawPopupMenuSectionHeader (Graphics& g,
  871. const Rectangle<int>& area,
  872. const String& sectionName)
  873. {
  874. g.setFont (getPopupMenuFont().boldened());
  875. g.setColour (findColour (PopupMenu::headerTextColourId));
  876. g.drawFittedText (sectionName,
  877. area.getX() + 12, area.getY(), area.getWidth() - 16, (int) ((float) area.getHeight() * 0.8f),
  878. Justification::bottomLeft, 1);
  879. }
  880. void LookAndFeel_V2::drawPopupMenuSectionHeaderWithOptions (Graphics& g, const Rectangle<int>& area,
  881. const String& sectionName,
  882. const PopupMenu::Options&)
  883. {
  884. drawPopupMenuSectionHeader (g, area, sectionName);
  885. }
  886. //==============================================================================
  887. int LookAndFeel_V2::getMenuWindowFlags()
  888. {
  889. return ComponentPeer::windowHasDropShadow;
  890. }
  891. void LookAndFeel_V2::drawMenuBarBackground (Graphics& g, int width, int height, bool, MenuBarComponent& menuBar)
  892. {
  893. auto baseColour = LookAndFeelHelpers::createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId),
  894. false, false, false);
  895. if (menuBar.isEnabled())
  896. drawShinyButtonShape (g, -4.0f, 0.0f, (float) width + 8.0f, (float) height,
  897. 0.0f, baseColour, 0.4f, true, true, true, true);
  898. else
  899. g.fillAll (baseColour);
  900. }
  901. Font LookAndFeel_V2::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  902. {
  903. return Font ((float) menuBar.getHeight() * 0.7f);
  904. }
  905. int LookAndFeel_V2::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  906. {
  907. return getMenuBarFont (menuBar, itemIndex, itemText)
  908. .getStringWidth (itemText) + menuBar.getHeight();
  909. }
  910. void LookAndFeel_V2::drawMenuBarItem (Graphics& g, int width, int height,
  911. int itemIndex, const String& itemText,
  912. bool isMouseOverItem, bool isMenuOpen,
  913. bool /*isMouseOverBar*/, MenuBarComponent& menuBar)
  914. {
  915. if (! menuBar.isEnabled())
  916. {
  917. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  918. .withMultipliedAlpha (0.5f));
  919. }
  920. else if (isMenuOpen || isMouseOverItem)
  921. {
  922. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  923. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  924. }
  925. else
  926. {
  927. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  928. }
  929. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  930. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  931. }
  932. Component* LookAndFeel_V2::getParentComponentForMenuOptions (const PopupMenu::Options& options)
  933. {
  934. return options.getParentComponent();
  935. }
  936. void LookAndFeel_V2::preparePopupMenuWindow (Component&) {}
  937. bool LookAndFeel_V2::shouldPopupMenuScaleWithTargetComponent (const PopupMenu::Options&) { return true; }
  938. int LookAndFeel_V2::getPopupMenuBorderSize() { return 2; }
  939. int LookAndFeel_V2::getPopupMenuBorderSizeWithOptions (const PopupMenu::Options&)
  940. {
  941. return getPopupMenuBorderSize();
  942. }
  943. void LookAndFeel_V2::drawPopupMenuColumnSeparatorWithOptions (Graphics&,
  944. const Rectangle<int>&,
  945. const PopupMenu::Options&) {}
  946. int LookAndFeel_V2::getPopupMenuColumnSeparatorWidthWithOptions (const PopupMenu::Options&)
  947. {
  948. return 0;
  949. }
  950. //==============================================================================
  951. void LookAndFeel_V2::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/, TextEditor& textEditor)
  952. {
  953. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  954. }
  955. void LookAndFeel_V2::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  956. {
  957. if (textEditor.isEnabled())
  958. {
  959. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  960. {
  961. const int border = 2;
  962. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  963. g.drawRect (0, 0, width, height, border);
  964. g.setOpacity (1.0f);
  965. auto shadowColour = textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f);
  966. drawBevel (g, 0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  967. }
  968. else
  969. {
  970. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  971. g.drawRect (0, 0, width, height);
  972. g.setOpacity (1.0f);
  973. auto shadowColour = textEditor.findColour (TextEditor::shadowColourId);
  974. drawBevel (g, 0, 0, width, height + 2, 3, shadowColour, shadowColour);
  975. }
  976. }
  977. }
  978. CaretComponent* LookAndFeel_V2::createCaretComponent (Component* keyFocusOwner)
  979. {
  980. return new CaretComponent (keyFocusOwner);
  981. }
  982. //==============================================================================
  983. void LookAndFeel_V2::drawComboBox (Graphics& g, int width, int height, const bool isMouseButtonDown,
  984. int buttonX, int buttonY, int buttonW, int buttonH, ComboBox& box)
  985. {
  986. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  987. if (box.isEnabled() && box.hasKeyboardFocus (false))
  988. {
  989. g.setColour (box.findColour (ComboBox::focusedOutlineColourId));
  990. g.drawRect (0, 0, width, height, 2);
  991. }
  992. else
  993. {
  994. g.setColour (box.findColour (ComboBox::outlineColourId));
  995. g.drawRect (0, 0, width, height);
  996. }
  997. auto outlineThickness = box.isEnabled() ? (isMouseButtonDown ? 1.2f : 0.5f) : 0.3f;
  998. auto baseColour = LookAndFeelHelpers::createBaseColour (box.findColour (ComboBox::buttonColourId),
  999. box.hasKeyboardFocus (true),
  1000. false, isMouseButtonDown)
  1001. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f);
  1002. drawGlassLozenge (g,
  1003. (float) buttonX + outlineThickness, (float) buttonY + outlineThickness,
  1004. (float) buttonW - outlineThickness * 2.0f, (float) buttonH - outlineThickness * 2.0f,
  1005. baseColour, outlineThickness, -1.0f,
  1006. true, true, true, true);
  1007. if (box.isEnabled())
  1008. {
  1009. const float arrowX = 0.3f;
  1010. const float arrowH = 0.2f;
  1011. const auto x = (float) buttonX;
  1012. const auto y = (float) buttonY;
  1013. const auto w = (float) buttonW;
  1014. const auto h = (float) buttonH;
  1015. Path p;
  1016. p.addTriangle (x + w * 0.5f, y + h * (0.45f - arrowH),
  1017. x + w * (1.0f - arrowX), y + h * 0.45f,
  1018. x + w * arrowX, y + h * 0.45f);
  1019. p.addTriangle (x + w * 0.5f, y + h * (0.55f + arrowH),
  1020. x + w * (1.0f - arrowX), y + h * 0.55f,
  1021. x + w * arrowX, y + h * 0.55f);
  1022. g.setColour (box.findColour (ComboBox::arrowColourId));
  1023. g.fillPath (p);
  1024. }
  1025. }
  1026. Font LookAndFeel_V2::getComboBoxFont (ComboBox& box)
  1027. {
  1028. return Font (jmin (15.0f, (float) box.getHeight() * 0.85f));
  1029. }
  1030. Label* LookAndFeel_V2::createComboBoxTextBox (ComboBox&)
  1031. {
  1032. return new Label (String(), String());
  1033. }
  1034. void LookAndFeel_V2::positionComboBoxText (ComboBox& box, Label& label)
  1035. {
  1036. label.setBounds (1, 1,
  1037. box.getWidth() + 3 - box.getHeight(),
  1038. box.getHeight() - 2);
  1039. label.setFont (getComboBoxFont (box));
  1040. }
  1041. PopupMenu::Options LookAndFeel_V2::getOptionsForComboBoxPopupMenu (ComboBox& box, Label& label)
  1042. {
  1043. return PopupMenu::Options().withTargetComponent (&box)
  1044. .withItemThatMustBeVisible (box.getSelectedId())
  1045. .withInitiallySelectedItem (box.getSelectedId())
  1046. .withMinimumWidth (box.getWidth())
  1047. .withMaximumNumColumns (1)
  1048. .withStandardItemHeight (label.getHeight());
  1049. }
  1050. void LookAndFeel_V2::drawComboBoxTextWhenNothingSelected (Graphics& g, ComboBox& box, Label& label)
  1051. {
  1052. g.setColour (findColour (ComboBox::textColourId).withMultipliedAlpha (0.5f));
  1053. auto font = label.getLookAndFeel().getLabelFont (label);
  1054. g.setFont (font);
  1055. auto textArea = getLabelBorderSize (label).subtractedFrom (label.getLocalBounds());
  1056. g.drawFittedText (box.getTextWhenNothingSelected(), textArea, label.getJustificationType(),
  1057. jmax (1, (int) ((float) textArea.getHeight() / font.getHeight())),
  1058. label.getMinimumHorizontalScale());
  1059. }
  1060. //==============================================================================
  1061. Font LookAndFeel_V2::getLabelFont (Label& label)
  1062. {
  1063. return label.getFont();
  1064. }
  1065. void LookAndFeel_V2::drawLabel (Graphics& g, Label& label)
  1066. {
  1067. g.fillAll (label.findColour (Label::backgroundColourId));
  1068. if (! label.isBeingEdited())
  1069. {
  1070. auto alpha = label.isEnabled() ? 1.0f : 0.5f;
  1071. const Font font (getLabelFont (label));
  1072. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  1073. g.setFont (font);
  1074. auto textArea = getLabelBorderSize (label).subtractedFrom (label.getLocalBounds());
  1075. g.drawFittedText (label.getText(), textArea, label.getJustificationType(),
  1076. jmax (1, (int) ((float) textArea.getHeight() / font.getHeight())),
  1077. label.getMinimumHorizontalScale());
  1078. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  1079. }
  1080. else if (label.isEnabled())
  1081. {
  1082. g.setColour (label.findColour (Label::outlineColourId));
  1083. }
  1084. g.drawRect (label.getLocalBounds());
  1085. }
  1086. BorderSize<int> LookAndFeel_V2::getLabelBorderSize (Label& label)
  1087. {
  1088. return label.getBorderSize();
  1089. }
  1090. //==============================================================================
  1091. void LookAndFeel_V2::drawLinearSliderBackground (Graphics& g, int x, int y, int width, int height,
  1092. float /*sliderPos*/,
  1093. float /*minSliderPos*/,
  1094. float /*maxSliderPos*/,
  1095. const Slider::SliderStyle /*style*/, Slider& slider)
  1096. {
  1097. auto sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  1098. auto trackColour = slider.findColour (Slider::trackColourId);
  1099. auto gradCol1 = trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f));
  1100. auto gradCol2 = trackColour.overlaidWith (Colour (0x14000000));
  1101. Path indent;
  1102. if (slider.isHorizontal())
  1103. {
  1104. const float iy = (float) y + (float) height * 0.5f - sliderRadius * 0.5f;
  1105. const float ih = sliderRadius;
  1106. g.setGradientFill (ColourGradient::vertical (gradCol1, iy, gradCol2, iy + ih));
  1107. indent.addRoundedRectangle ((float) x - sliderRadius * 0.5f, iy,
  1108. (float) width + sliderRadius, ih,
  1109. 5.0f);
  1110. }
  1111. else
  1112. {
  1113. const float ix = (float) x + (float) width * 0.5f - sliderRadius * 0.5f;
  1114. const float iw = sliderRadius;
  1115. g.setGradientFill (ColourGradient::horizontal (gradCol1, ix, gradCol2, ix + iw));
  1116. indent.addRoundedRectangle (ix, (float) y - sliderRadius * 0.5f,
  1117. iw, (float) height + sliderRadius,
  1118. 5.0f);
  1119. }
  1120. g.fillPath (indent);
  1121. g.setColour (Colour (0x4c000000));
  1122. g.strokePath (indent, PathStrokeType (0.5f));
  1123. }
  1124. void LookAndFeel_V2::drawLinearSliderThumb (Graphics& g, int x, int y, int width, int height,
  1125. float sliderPos, float minSliderPos, float maxSliderPos,
  1126. const Slider::SliderStyle style, Slider& slider)
  1127. {
  1128. auto sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  1129. auto knobColour = LookAndFeelHelpers::createBaseColour (slider.findColour (Slider::thumbColourId),
  1130. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  1131. slider.isMouseOverOrDragging() && slider.isEnabled(),
  1132. slider.isMouseButtonDown() && slider.isEnabled());
  1133. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  1134. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  1135. {
  1136. float kx, ky;
  1137. if (style == Slider::LinearVertical)
  1138. {
  1139. kx = (float) x + (float) width * 0.5f;
  1140. ky = sliderPos;
  1141. }
  1142. else
  1143. {
  1144. kx = sliderPos;
  1145. ky = (float) y + (float) height * 0.5f;
  1146. }
  1147. drawGlassSphere (g,
  1148. kx - sliderRadius,
  1149. ky - sliderRadius,
  1150. sliderRadius * 2.0f,
  1151. knobColour, outlineThickness);
  1152. }
  1153. else
  1154. {
  1155. if (style == Slider::ThreeValueVertical)
  1156. {
  1157. drawGlassSphere (g, (float) x + (float) width * 0.5f - sliderRadius,
  1158. sliderPos - sliderRadius,
  1159. sliderRadius * 2.0f,
  1160. knobColour, outlineThickness);
  1161. }
  1162. else if (style == Slider::ThreeValueHorizontal)
  1163. {
  1164. drawGlassSphere (g,sliderPos - sliderRadius,
  1165. (float) y + (float) height * 0.5f - sliderRadius,
  1166. sliderRadius * 2.0f,
  1167. knobColour, outlineThickness);
  1168. }
  1169. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  1170. {
  1171. auto sr = jmin (sliderRadius, (float) width * 0.4f);
  1172. drawGlassPointer (g, jmax (0.0f, (float) x + (float) width * 0.5f - sliderRadius * 2.0f),
  1173. minSliderPos - sliderRadius,
  1174. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  1175. drawGlassPointer (g,
  1176. jmin ((float) x + (float) width - sliderRadius * 2.0f,
  1177. (float) x + (float) width * 0.5f),
  1178. maxSliderPos - sr,
  1179. sliderRadius * 2.0f,
  1180. knobColour,
  1181. outlineThickness,
  1182. 3);
  1183. }
  1184. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  1185. {
  1186. auto sr = jmin (sliderRadius, (float) height * 0.4f);
  1187. drawGlassPointer (g, minSliderPos - sr,
  1188. jmax (0.0f, (float) y + (float) height * 0.5f - sliderRadius * 2.0f),
  1189. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  1190. drawGlassPointer (g,
  1191. maxSliderPos - sliderRadius,
  1192. jmin ((float) y + (float) height - sliderRadius * 2.0f,
  1193. (float) y + (float) height * 0.5f),
  1194. sliderRadius * 2.0f,
  1195. knobColour,
  1196. outlineThickness,
  1197. 4);
  1198. }
  1199. }
  1200. }
  1201. void LookAndFeel_V2::drawLinearSlider (Graphics& g, int x, int y, int width, int height,
  1202. float sliderPos, float minSliderPos, float maxSliderPos,
  1203. const Slider::SliderStyle style, Slider& slider)
  1204. {
  1205. g.fillAll (slider.findColour (Slider::backgroundColourId));
  1206. if (style == Slider::LinearBar || style == Slider::LinearBarVertical)
  1207. {
  1208. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  1209. auto baseColour = LookAndFeelHelpers::createBaseColour (slider.findColour (Slider::thumbColourId)
  1210. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  1211. false, isMouseOver,
  1212. isMouseOver || slider.isMouseButtonDown());
  1213. drawShinyButtonShape (g,
  1214. (float) x,
  1215. style == Slider::LinearBarVertical ? sliderPos
  1216. : (float) y,
  1217. style == Slider::LinearBarVertical ? (float) width
  1218. : (sliderPos - (float) x),
  1219. style == Slider::LinearBarVertical ? ((float) height - sliderPos)
  1220. : (float) height, 0.0f,
  1221. baseColour,
  1222. slider.isEnabled() ? 0.9f : 0.3f,
  1223. true, true, true, true);
  1224. }
  1225. else
  1226. {
  1227. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  1228. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  1229. }
  1230. }
  1231. int LookAndFeel_V2::getSliderThumbRadius (Slider& slider)
  1232. {
  1233. return jmin (7,
  1234. slider.getHeight() / 2,
  1235. slider.getWidth() / 2) + 2;
  1236. }
  1237. void LookAndFeel_V2::drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos,
  1238. const float rotaryStartAngle, const float rotaryEndAngle, Slider& slider)
  1239. {
  1240. const float radius = jmin ((float) width * 0.5f, (float) height * 0.5f) - 2.0f;
  1241. const float centreX = (float) x + (float) width * 0.5f;
  1242. const float centreY = (float) y + (float) height * 0.5f;
  1243. const float rx = centreX - radius;
  1244. const float ry = centreY - radius;
  1245. const float rw = radius * 2.0f;
  1246. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  1247. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  1248. if (radius > 12.0f)
  1249. {
  1250. if (slider.isEnabled())
  1251. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  1252. else
  1253. g.setColour (Colour (0x80808080));
  1254. const float thickness = 0.7f;
  1255. {
  1256. Path filledArc;
  1257. filledArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, angle, thickness);
  1258. g.fillPath (filledArc);
  1259. }
  1260. {
  1261. const float innerRadius = radius * 0.2f;
  1262. Path p;
  1263. p.addTriangle (-innerRadius, 0.0f,
  1264. 0.0f, -radius * thickness * 1.1f,
  1265. innerRadius, 0.0f);
  1266. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  1267. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  1268. }
  1269. if (slider.isEnabled())
  1270. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  1271. else
  1272. g.setColour (Colour (0x80808080));
  1273. Path outlineArc;
  1274. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  1275. outlineArc.closeSubPath();
  1276. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  1277. }
  1278. else
  1279. {
  1280. if (slider.isEnabled())
  1281. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  1282. else
  1283. g.setColour (Colour (0x80808080));
  1284. Path p;
  1285. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  1286. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  1287. p.addLineSegment (Line<float> (0.0f, 0.0f, 0.0f, -radius), rw * 0.2f);
  1288. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  1289. }
  1290. }
  1291. Button* LookAndFeel_V2::createSliderButton (Slider&, const bool isIncrement)
  1292. {
  1293. return new TextButton (isIncrement ? "+" : "-", String());
  1294. }
  1295. class LookAndFeel_V2::SliderLabelComp : public Label
  1296. {
  1297. public:
  1298. SliderLabelComp() : Label ({}, {}) {}
  1299. void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override {}
  1300. std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override
  1301. {
  1302. return createIgnoredAccessibilityHandler (*this);
  1303. }
  1304. };
  1305. Label* LookAndFeel_V2::createSliderTextBox (Slider& slider)
  1306. {
  1307. auto l = new SliderLabelComp();
  1308. l->setJustificationType (Justification::centred);
  1309. l->setKeyboardType (TextInputTarget::decimalKeyboard);
  1310. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  1311. l->setColour (Label::backgroundColourId,
  1312. (slider.getSliderStyle() == Slider::LinearBar || slider.getSliderStyle() == Slider::LinearBarVertical)
  1313. ? Colours::transparentBlack
  1314. : slider.findColour (Slider::textBoxBackgroundColourId));
  1315. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  1316. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  1317. l->setColour (TextEditor::backgroundColourId,
  1318. slider.findColour (Slider::textBoxBackgroundColourId)
  1319. .withAlpha ((slider.getSliderStyle() == Slider::LinearBar || slider.getSliderStyle() == Slider::LinearBarVertical)
  1320. ? 0.7f : 1.0f));
  1321. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  1322. l->setColour (TextEditor::highlightColourId, slider.findColour (Slider::textBoxHighlightColourId));
  1323. return l;
  1324. }
  1325. ImageEffectFilter* LookAndFeel_V2::getSliderEffect (Slider&)
  1326. {
  1327. return nullptr;
  1328. }
  1329. Font LookAndFeel_V2::getSliderPopupFont (Slider&)
  1330. {
  1331. return Font (15.0f, Font::bold);
  1332. }
  1333. int LookAndFeel_V2::getSliderPopupPlacement (Slider&)
  1334. {
  1335. return BubbleComponent::above
  1336. | BubbleComponent::below
  1337. | BubbleComponent::left
  1338. | BubbleComponent::right;
  1339. }
  1340. //==============================================================================
  1341. Slider::SliderLayout LookAndFeel_V2::getSliderLayout (Slider& slider)
  1342. {
  1343. // 1. compute the actually visible textBox size from the slider textBox size and some additional constraints
  1344. int minXSpace = 0;
  1345. int minYSpace = 0;
  1346. auto textBoxPos = slider.getTextBoxPosition();
  1347. if (textBoxPos == Slider::TextBoxLeft || textBoxPos == Slider::TextBoxRight)
  1348. minXSpace = 30;
  1349. else
  1350. minYSpace = 15;
  1351. auto localBounds = slider.getLocalBounds();
  1352. auto textBoxWidth = jmax (0, jmin (slider.getTextBoxWidth(), localBounds.getWidth() - minXSpace));
  1353. auto textBoxHeight = jmax (0, jmin (slider.getTextBoxHeight(), localBounds.getHeight() - minYSpace));
  1354. Slider::SliderLayout layout;
  1355. // 2. set the textBox bounds
  1356. if (textBoxPos != Slider::NoTextBox)
  1357. {
  1358. if (slider.isBar())
  1359. {
  1360. layout.textBoxBounds = localBounds;
  1361. }
  1362. else
  1363. {
  1364. layout.textBoxBounds.setWidth (textBoxWidth);
  1365. layout.textBoxBounds.setHeight (textBoxHeight);
  1366. if (textBoxPos == Slider::TextBoxLeft) layout.textBoxBounds.setX (0);
  1367. else if (textBoxPos == Slider::TextBoxRight) layout.textBoxBounds.setX (localBounds.getWidth() - textBoxWidth);
  1368. else /* above or below -> centre horizontally */ layout.textBoxBounds.setX ((localBounds.getWidth() - textBoxWidth) / 2);
  1369. if (textBoxPos == Slider::TextBoxAbove) layout.textBoxBounds.setY (0);
  1370. else if (textBoxPos == Slider::TextBoxBelow) layout.textBoxBounds.setY (localBounds.getHeight() - textBoxHeight);
  1371. else /* left or right -> centre vertically */ layout.textBoxBounds.setY ((localBounds.getHeight() - textBoxHeight) / 2);
  1372. }
  1373. }
  1374. // 3. set the slider bounds
  1375. layout.sliderBounds = localBounds;
  1376. if (slider.isBar())
  1377. {
  1378. layout.sliderBounds.reduce (1, 1); // bar border
  1379. }
  1380. else
  1381. {
  1382. if (textBoxPos == Slider::TextBoxLeft) layout.sliderBounds.removeFromLeft (textBoxWidth);
  1383. else if (textBoxPos == Slider::TextBoxRight) layout.sliderBounds.removeFromRight (textBoxWidth);
  1384. else if (textBoxPos == Slider::TextBoxAbove) layout.sliderBounds.removeFromTop (textBoxHeight);
  1385. else if (textBoxPos == Slider::TextBoxBelow) layout.sliderBounds.removeFromBottom (textBoxHeight);
  1386. const int thumbIndent = getSliderThumbRadius (slider);
  1387. if (slider.isHorizontal()) layout.sliderBounds.reduce (thumbIndent, 0);
  1388. else if (slider.isVertical()) layout.sliderBounds.reduce (0, thumbIndent);
  1389. }
  1390. return layout;
  1391. }
  1392. //==============================================================================
  1393. Rectangle<int> LookAndFeel_V2::getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea)
  1394. {
  1395. const TextLayout tl (LookAndFeelHelpers::layoutTooltipText (tipText, Colours::black));
  1396. auto w = (int) (tl.getWidth() + 14.0f);
  1397. auto h = (int) (tl.getHeight() + 6.0f);
  1398. return Rectangle<int> (screenPos.x > parentArea.getCentreX() ? screenPos.x - (w + 12) : screenPos.x + 24,
  1399. screenPos.y > parentArea.getCentreY() ? screenPos.y - (h + 6) : screenPos.y + 6,
  1400. w, h)
  1401. .constrainedWithin (parentArea);
  1402. }
  1403. void LookAndFeel_V2::drawTooltip (Graphics& g, const String& text, int width, int height)
  1404. {
  1405. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  1406. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  1407. g.setColour (findColour (TooltipWindow::outlineColourId));
  1408. g.drawRect (0, 0, width, height, 1);
  1409. #endif
  1410. LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId))
  1411. .draw (g, Rectangle<float> ((float) width, (float) height));
  1412. }
  1413. //==============================================================================
  1414. Button* LookAndFeel_V2::createFilenameComponentBrowseButton (const String& text)
  1415. {
  1416. return new TextButton (text, TRANS("click to browse for a different file"));
  1417. }
  1418. void LookAndFeel_V2::layoutFilenameComponent (FilenameComponent& filenameComp,
  1419. ComboBox* filenameBox, Button* browseButton)
  1420. {
  1421. if (browseButton == nullptr || filenameBox == nullptr)
  1422. return;
  1423. browseButton->setSize (80, filenameComp.getHeight());
  1424. if (auto* tb = dynamic_cast<TextButton*> (browseButton))
  1425. tb->changeWidthToFitText();
  1426. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  1427. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  1428. }
  1429. //==============================================================================
  1430. void LookAndFeel_V2::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int>& area,
  1431. bool isMouseOver, bool /*isMouseDown*/,
  1432. ConcertinaPanel&, Component& panel)
  1433. {
  1434. g.fillAll (Colours::grey.withAlpha (isMouseOver ? 0.9f : 0.7f));
  1435. g.setColour (Colours::black.withAlpha (0.5f));
  1436. g.drawRect (area);
  1437. g.setColour (Colours::white);
  1438. g.setFont (Font ((float) area.getHeight() * 0.7f).boldened());
  1439. g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
  1440. }
  1441. //==============================================================================
  1442. void LookAndFeel_V2::drawImageButton (Graphics& g, Image* image,
  1443. int imageX, int imageY, int imageW, int imageH,
  1444. const Colour& overlayColour,
  1445. float imageOpacity,
  1446. ImageButton& button)
  1447. {
  1448. if (! button.isEnabled())
  1449. imageOpacity *= 0.3f;
  1450. AffineTransform t = RectanglePlacement (RectanglePlacement::stretchToFit)
  1451. .getTransformToFit (image->getBounds().toFloat(),
  1452. Rectangle<int> (imageX, imageY, imageW, imageH).toFloat());
  1453. if (! overlayColour.isOpaque())
  1454. {
  1455. g.setOpacity (imageOpacity);
  1456. g.drawImageTransformed (*image, t, false);
  1457. }
  1458. if (! overlayColour.isTransparent())
  1459. {
  1460. g.setColour (overlayColour);
  1461. g.drawImageTransformed (*image, t, true);
  1462. }
  1463. }
  1464. //==============================================================================
  1465. void LookAndFeel_V2::drawCornerResizer (Graphics& g, int w, int h, bool /*isMouseOver*/, bool /*isMouseDragging*/)
  1466. {
  1467. auto lineThickness = jmin ((float) w, (float) h) * 0.075f;
  1468. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  1469. {
  1470. g.setColour (Colours::lightgrey);
  1471. g.drawLine ((float) w * i,
  1472. (float) h + 1.0f,
  1473. (float) w + 1.0f,
  1474. (float) h * i,
  1475. lineThickness);
  1476. g.setColour (Colours::darkgrey);
  1477. g.drawLine ((float) w * i + lineThickness,
  1478. (float) h + 1.0f,
  1479. (float) w + 1.0f,
  1480. (float) h * i + lineThickness,
  1481. lineThickness);
  1482. }
  1483. }
  1484. void LookAndFeel_V2::drawResizableFrame (Graphics& g, int w, int h, const BorderSize<int>& border)
  1485. {
  1486. if (! border.isEmpty())
  1487. {
  1488. const Rectangle<int> fullSize (0, 0, w, h);
  1489. auto centreArea = border.subtractedFrom (fullSize);
  1490. Graphics::ScopedSaveState ss (g);
  1491. g.excludeClipRegion (centreArea);
  1492. g.setColour (Colour (0x50000000));
  1493. g.drawRect (fullSize);
  1494. g.setColour (Colour (0x19000000));
  1495. g.drawRect (centreArea.expanded (1, 1));
  1496. }
  1497. }
  1498. //==============================================================================
  1499. void LookAndFeel_V2::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  1500. const BorderSize<int>& /*border*/, ResizableWindow& window)
  1501. {
  1502. g.fillAll (window.getBackgroundColour());
  1503. }
  1504. void LookAndFeel_V2::drawResizableWindowBorder (Graphics&, int /*w*/, int /*h*/,
  1505. const BorderSize<int>& /*border*/, ResizableWindow&)
  1506. {
  1507. }
  1508. void LookAndFeel_V2::drawDocumentWindowTitleBar (DocumentWindow& window, Graphics& g,
  1509. int w, int h, int titleSpaceX, int titleSpaceW,
  1510. const Image* icon, bool drawTitleTextOnLeft)
  1511. {
  1512. if (w * h == 0)
  1513. return;
  1514. const bool isActive = window.isActiveWindow();
  1515. g.setGradientFill (ColourGradient::vertical (window.getBackgroundColour(), 0,
  1516. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f), (float) h));
  1517. g.fillAll();
  1518. Font font ((float) h * 0.65f, Font::bold);
  1519. g.setFont (font);
  1520. int textW = font.getStringWidth (window.getName());
  1521. int iconW = 0;
  1522. int iconH = 0;
  1523. if (icon != nullptr)
  1524. {
  1525. iconH = (int) font.getHeight();
  1526. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  1527. }
  1528. textW = jmin (titleSpaceW, textW + iconW);
  1529. int textX = drawTitleTextOnLeft ? titleSpaceX
  1530. : jmax (titleSpaceX, (w - textW) / 2);
  1531. if (textX + textW > titleSpaceX + titleSpaceW)
  1532. textX = titleSpaceX + titleSpaceW - textW;
  1533. if (icon != nullptr)
  1534. {
  1535. g.setOpacity (isActive ? 1.0f : 0.6f);
  1536. g.drawImageWithin (*icon, textX, (h - iconH) / 2, iconW, iconH,
  1537. RectanglePlacement::centred, false);
  1538. textX += iconW;
  1539. textW -= iconW;
  1540. }
  1541. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  1542. g.setColour (window.findColour (DocumentWindow::textColourId));
  1543. else
  1544. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  1545. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  1546. }
  1547. //==============================================================================
  1548. class LookAndFeel_V2::GlassWindowButton : public Button
  1549. {
  1550. public:
  1551. GlassWindowButton (const String& name, Colour col,
  1552. const Path& normalShape_,
  1553. const Path& toggledShape_) noexcept
  1554. : Button (name),
  1555. colour (col),
  1556. normalShape (normalShape_),
  1557. toggledShape (toggledShape_)
  1558. {
  1559. }
  1560. //==============================================================================
  1561. void paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
  1562. {
  1563. float alpha = shouldDrawButtonAsHighlighted ? (shouldDrawButtonAsDown ? 1.0f : 0.8f) : 0.55f;
  1564. if (! isEnabled())
  1565. alpha *= 0.5f;
  1566. float x = 0, y = 0, diam;
  1567. if (getWidth() < getHeight())
  1568. {
  1569. diam = (float) getWidth();
  1570. y = (float) (getHeight() - getWidth()) * 0.5f;
  1571. }
  1572. else
  1573. {
  1574. diam = (float) getHeight();
  1575. y = (float) (getWidth() - getHeight()) * 0.5f;
  1576. }
  1577. x += diam * 0.05f;
  1578. y += diam * 0.05f;
  1579. diam *= 0.9f;
  1580. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  1581. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  1582. g.fillEllipse (x, y, diam, diam);
  1583. x += 2.0f;
  1584. y += 2.0f;
  1585. diam -= 4.0f;
  1586. LookAndFeel_V2::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  1587. Path& p = getToggleState() ? toggledShape : normalShape;
  1588. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  1589. diam * 0.4f, diam * 0.4f, true));
  1590. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  1591. g.fillPath (p, t);
  1592. }
  1593. private:
  1594. Colour colour;
  1595. Path normalShape, toggledShape;
  1596. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlassWindowButton)
  1597. };
  1598. Button* LookAndFeel_V2::createDocumentWindowButton (int buttonType)
  1599. {
  1600. Path shape;
  1601. const float crossThickness = 0.25f;
  1602. if (buttonType == DocumentWindow::closeButton)
  1603. {
  1604. shape.addLineSegment (Line<float> (0.0f, 0.0f, 1.0f, 1.0f), crossThickness * 1.4f);
  1605. shape.addLineSegment (Line<float> (1.0f, 0.0f, 0.0f, 1.0f), crossThickness * 1.4f);
  1606. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  1607. }
  1608. if (buttonType == DocumentWindow::minimiseButton)
  1609. {
  1610. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), crossThickness);
  1611. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  1612. }
  1613. if (buttonType == DocumentWindow::maximiseButton)
  1614. {
  1615. shape.addLineSegment (Line<float> (0.5f, 0.0f, 0.5f, 1.0f), crossThickness);
  1616. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), crossThickness);
  1617. Path fullscreenShape;
  1618. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  1619. fullscreenShape.lineTo (0.0f, 100.0f);
  1620. fullscreenShape.lineTo (0.0f, 0.0f);
  1621. fullscreenShape.lineTo (100.0f, 0.0f);
  1622. fullscreenShape.lineTo (100.0f, 45.0f);
  1623. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  1624. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  1625. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  1626. }
  1627. jassertfalse;
  1628. return nullptr;
  1629. }
  1630. void LookAndFeel_V2::positionDocumentWindowButtons (DocumentWindow&,
  1631. int titleBarX, int titleBarY,
  1632. int titleBarW, int titleBarH,
  1633. Button* minimiseButton,
  1634. Button* maximiseButton,
  1635. Button* closeButton,
  1636. bool positionTitleBarButtonsOnLeft)
  1637. {
  1638. const int buttonW = titleBarH - titleBarH / 8;
  1639. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  1640. : titleBarX + titleBarW - buttonW - buttonW / 4;
  1641. if (closeButton != nullptr)
  1642. {
  1643. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  1644. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  1645. }
  1646. if (positionTitleBarButtonsOnLeft)
  1647. std::swap (minimiseButton, maximiseButton);
  1648. if (maximiseButton != nullptr)
  1649. {
  1650. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  1651. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  1652. }
  1653. if (minimiseButton != nullptr)
  1654. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  1655. }
  1656. int LookAndFeel_V2::getDefaultMenuBarHeight()
  1657. {
  1658. return 24;
  1659. }
  1660. //==============================================================================
  1661. std::unique_ptr<DropShadower> LookAndFeel_V2::createDropShadowerForComponent (Component&)
  1662. {
  1663. return std::make_unique<DropShadower> (DropShadow (Colours::black.withAlpha (0.4f), 10, Point<int> (0, 2)));
  1664. }
  1665. std::unique_ptr<FocusOutline> LookAndFeel_V2::createFocusOutlineForComponent (Component&)
  1666. {
  1667. struct WindowProperties : public FocusOutline::OutlineWindowProperties
  1668. {
  1669. Rectangle<int> getOutlineBounds (Component& c) override
  1670. {
  1671. return c.getScreenBounds();
  1672. }
  1673. void drawOutline (Graphics& g, int width, int height) override
  1674. {
  1675. g.setColour (Colours::yellow.withAlpha (0.6f));
  1676. g.drawRoundedRectangle ({ (float) width, (float) height }, 3.0f, 3.0f);
  1677. }
  1678. };
  1679. return std::make_unique<FocusOutline> (std::make_unique<WindowProperties>());
  1680. }
  1681. //==============================================================================
  1682. void LookAndFeel_V2::drawStretchableLayoutResizerBar (Graphics& g, int w, int h,
  1683. bool /*isVerticalBar*/,
  1684. bool isMouseOver,
  1685. bool isMouseDragging)
  1686. {
  1687. auto alpha = 0.5f;
  1688. if (isMouseOver || isMouseDragging)
  1689. {
  1690. g.fillAll (Colour (0x190000ff));
  1691. alpha = 1.0f;
  1692. }
  1693. auto cx = (float) w * 0.5f;
  1694. auto cy = (float) h * 0.5f;
  1695. auto cr = (float) jmin (w, h) * 0.4f;
  1696. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  1697. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  1698. true));
  1699. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  1700. }
  1701. //==============================================================================
  1702. void LookAndFeel_V2::drawGroupComponentOutline (Graphics& g, int width, int height,
  1703. const String& text, const Justification& position,
  1704. GroupComponent& group)
  1705. {
  1706. const float textH = 15.0f;
  1707. const float indent = 3.0f;
  1708. const float textEdgeGap = 4.0f;
  1709. auto cs = 5.0f;
  1710. Font f (textH);
  1711. Path p;
  1712. auto x = indent;
  1713. auto y = f.getAscent() - 3.0f;
  1714. auto w = jmax (0.0f, (float) width - x * 2.0f);
  1715. auto h = jmax (0.0f, (float) height - y - indent);
  1716. cs = jmin (cs, w * 0.5f, h * 0.5f);
  1717. auto cs2 = 2.0f * cs;
  1718. auto textW = text.isEmpty() ? 0
  1719. : jlimit (0.0f,
  1720. jmax (0.0f, w - cs2 - textEdgeGap * 2),
  1721. (float) f.getStringWidth (text) + textEdgeGap * 2.0f);
  1722. auto textX = cs + textEdgeGap;
  1723. if (position.testFlags (Justification::horizontallyCentred))
  1724. textX = cs + (w - cs2 - textW) * 0.5f;
  1725. else if (position.testFlags (Justification::right))
  1726. textX = w - cs - textW - textEdgeGap;
  1727. p.startNewSubPath (x + textX + textW, y);
  1728. p.lineTo (x + w - cs, y);
  1729. p.addArc (x + w - cs2, y, cs2, cs2, 0, MathConstants<float>::halfPi);
  1730. p.lineTo (x + w, y + h - cs);
  1731. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, MathConstants<float>::halfPi, MathConstants<float>::pi);
  1732. p.lineTo (x + cs, y + h);
  1733. p.addArc (x, y + h - cs2, cs2, cs2, MathConstants<float>::pi, MathConstants<float>::pi * 1.5f);
  1734. p.lineTo (x, y + cs);
  1735. p.addArc (x, y, cs2, cs2, MathConstants<float>::pi * 1.5f, MathConstants<float>::twoPi);
  1736. p.lineTo (x + textX, y);
  1737. auto alpha = group.isEnabled() ? 1.0f : 0.5f;
  1738. g.setColour (group.findColour (GroupComponent::outlineColourId)
  1739. .withMultipliedAlpha (alpha));
  1740. g.strokePath (p, PathStrokeType (2.0f));
  1741. g.setColour (group.findColour (GroupComponent::textColourId)
  1742. .withMultipliedAlpha (alpha));
  1743. g.setFont (f);
  1744. g.drawText (text,
  1745. roundToInt (x + textX), 0,
  1746. roundToInt (textW),
  1747. roundToInt (textH),
  1748. Justification::centred, true);
  1749. }
  1750. //==============================================================================
  1751. int LookAndFeel_V2::getTabButtonOverlap (int tabDepth)
  1752. {
  1753. return 1 + tabDepth / 3;
  1754. }
  1755. int LookAndFeel_V2::getTabButtonSpaceAroundImage()
  1756. {
  1757. return 4;
  1758. }
  1759. int LookAndFeel_V2::getTabButtonBestWidth (TabBarButton& button, int tabDepth)
  1760. {
  1761. int width = Font ((float) tabDepth * 0.6f).getStringWidth (button.getButtonText().trim())
  1762. + getTabButtonOverlap (tabDepth) * 2;
  1763. if (auto* extraComponent = button.getExtraComponent())
  1764. width += button.getTabbedButtonBar().isVertical() ? extraComponent->getHeight()
  1765. : extraComponent->getWidth();
  1766. return jlimit (tabDepth * 2, tabDepth * 8, width);
  1767. }
  1768. Rectangle<int> LookAndFeel_V2::getTabButtonExtraComponentBounds (const TabBarButton& button, Rectangle<int>& textArea, Component& comp)
  1769. {
  1770. Rectangle<int> extraComp;
  1771. auto orientation = button.getTabbedButtonBar().getOrientation();
  1772. if (button.getExtraComponentPlacement() == TabBarButton::beforeText)
  1773. {
  1774. switch (orientation)
  1775. {
  1776. case TabbedButtonBar::TabsAtBottom:
  1777. case TabbedButtonBar::TabsAtTop: extraComp = textArea.removeFromLeft (comp.getWidth()); break;
  1778. case TabbedButtonBar::TabsAtLeft: extraComp = textArea.removeFromBottom (comp.getHeight()); break;
  1779. case TabbedButtonBar::TabsAtRight: extraComp = textArea.removeFromTop (comp.getHeight()); break;
  1780. default: jassertfalse; break;
  1781. }
  1782. }
  1783. else
  1784. {
  1785. switch (orientation)
  1786. {
  1787. case TabbedButtonBar::TabsAtBottom:
  1788. case TabbedButtonBar::TabsAtTop: extraComp = textArea.removeFromRight (comp.getWidth()); break;
  1789. case TabbedButtonBar::TabsAtLeft: extraComp = textArea.removeFromTop (comp.getHeight()); break;
  1790. case TabbedButtonBar::TabsAtRight: extraComp = textArea.removeFromBottom (comp.getHeight()); break;
  1791. default: jassertfalse; break;
  1792. }
  1793. }
  1794. return extraComp;
  1795. }
  1796. void LookAndFeel_V2::createTabButtonShape (TabBarButton& button, Path& p, bool /*isMouseOver*/, bool /*isMouseDown*/)
  1797. {
  1798. auto activeArea = button.getActiveArea();
  1799. auto w = (float) activeArea.getWidth();
  1800. auto h = (float) activeArea.getHeight();
  1801. auto length = w;
  1802. auto depth = h;
  1803. if (button.getTabbedButtonBar().isVertical())
  1804. std::swap (length, depth);
  1805. const float indent = (float) getTabButtonOverlap ((int) depth);
  1806. const float overhang = 4.0f;
  1807. switch (button.getTabbedButtonBar().getOrientation())
  1808. {
  1809. case TabbedButtonBar::TabsAtLeft:
  1810. p.startNewSubPath (w, 0.0f);
  1811. p.lineTo (0.0f, indent);
  1812. p.lineTo (0.0f, h - indent);
  1813. p.lineTo (w, h);
  1814. p.lineTo (w + overhang, h + overhang);
  1815. p.lineTo (w + overhang, -overhang);
  1816. break;
  1817. case TabbedButtonBar::TabsAtRight:
  1818. p.startNewSubPath (0.0f, 0.0f);
  1819. p.lineTo (w, indent);
  1820. p.lineTo (w, h - indent);
  1821. p.lineTo (0.0f, h);
  1822. p.lineTo (-overhang, h + overhang);
  1823. p.lineTo (-overhang, -overhang);
  1824. break;
  1825. case TabbedButtonBar::TabsAtBottom:
  1826. p.startNewSubPath (0.0f, 0.0f);
  1827. p.lineTo (indent, h);
  1828. p.lineTo (w - indent, h);
  1829. p.lineTo (w, 0.0f);
  1830. p.lineTo (w + overhang, -overhang);
  1831. p.lineTo (-overhang, -overhang);
  1832. break;
  1833. case TabbedButtonBar::TabsAtTop:
  1834. default:
  1835. p.startNewSubPath (0.0f, h);
  1836. p.lineTo (indent, 0.0f);
  1837. p.lineTo (w - indent, 0.0f);
  1838. p.lineTo (w, h);
  1839. p.lineTo (w + overhang, h + overhang);
  1840. p.lineTo (-overhang, h + overhang);
  1841. break;
  1842. }
  1843. p.closeSubPath();
  1844. p = p.createPathWithRoundedCorners (3.0f);
  1845. }
  1846. void LookAndFeel_V2::fillTabButtonShape (TabBarButton& button, Graphics& g, const Path& path,
  1847. bool /*isMouseOver*/, bool /*isMouseDown*/)
  1848. {
  1849. auto tabBackground = button.getTabBackgroundColour();
  1850. const bool isFrontTab = button.isFrontTab();
  1851. g.setColour (isFrontTab ? tabBackground
  1852. : tabBackground.withMultipliedAlpha (0.9f));
  1853. g.fillPath (path);
  1854. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  1855. : TabbedButtonBar::tabOutlineColourId, false)
  1856. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  1857. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  1858. }
  1859. Font LookAndFeel_V2::getTabButtonFont (TabBarButton&, float height)
  1860. {
  1861. return { height * 0.6f };
  1862. }
  1863. void LookAndFeel_V2::drawTabButtonText (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
  1864. {
  1865. auto area = button.getTextArea().toFloat();
  1866. auto length = area.getWidth();
  1867. auto depth = area.getHeight();
  1868. if (button.getTabbedButtonBar().isVertical())
  1869. std::swap (length, depth);
  1870. Font font (getTabButtonFont (button, depth));
  1871. font.setUnderline (button.hasKeyboardFocus (false));
  1872. AffineTransform t;
  1873. switch (button.getTabbedButtonBar().getOrientation())
  1874. {
  1875. case TabbedButtonBar::TabsAtLeft: t = t.rotated (MathConstants<float>::pi * -0.5f).translated (area.getX(), area.getBottom()); break;
  1876. case TabbedButtonBar::TabsAtRight: t = t.rotated (MathConstants<float>::pi * 0.5f).translated (area.getRight(), area.getY()); break;
  1877. case TabbedButtonBar::TabsAtTop:
  1878. case TabbedButtonBar::TabsAtBottom: t = t.translated (area.getX(), area.getY()); break;
  1879. default: jassertfalse; break;
  1880. }
  1881. Colour col;
  1882. if (button.isFrontTab() && (button.isColourSpecified (TabbedButtonBar::frontTextColourId)
  1883. || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  1884. col = findColour (TabbedButtonBar::frontTextColourId);
  1885. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId)
  1886. || isColourSpecified (TabbedButtonBar::tabTextColourId))
  1887. col = findColour (TabbedButtonBar::tabTextColourId);
  1888. else
  1889. col = button.getTabBackgroundColour().contrasting();
  1890. auto alpha = button.isEnabled() ? ((isMouseOver || isMouseDown) ? 1.0f : 0.8f) : 0.3f;
  1891. g.setColour (col.withMultipliedAlpha (alpha));
  1892. g.setFont (font);
  1893. g.addTransform (t);
  1894. g.drawFittedText (button.getButtonText().trim(),
  1895. 0, 0, (int) length, (int) depth,
  1896. Justification::centred,
  1897. jmax (1, ((int) depth) / 12));
  1898. }
  1899. void LookAndFeel_V2::drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
  1900. {
  1901. Path tabShape;
  1902. createTabButtonShape (button, tabShape, isMouseOver, isMouseDown);
  1903. auto activeArea = button.getActiveArea();
  1904. tabShape.applyTransform (AffineTransform::translation ((float) activeArea.getX(),
  1905. (float) activeArea.getY()));
  1906. DropShadow (Colours::black.withAlpha (0.5f), 2, Point<int> (0, 1)).drawForPath (g, tabShape);
  1907. fillTabButtonShape (button, g, tabShape, isMouseOver, isMouseDown);
  1908. drawTabButtonText (button, g, isMouseOver, isMouseDown);
  1909. }
  1910. void LookAndFeel_V2::drawTabbedButtonBarBackground (TabbedButtonBar&, Graphics&) {}
  1911. void LookAndFeel_V2::drawTabAreaBehindFrontButton (TabbedButtonBar& bar, Graphics& g, const int w, const int h)
  1912. {
  1913. auto shadowSize = 0.2f;
  1914. Rectangle<int> shadowRect, line;
  1915. ColourGradient gradient (Colours::black.withAlpha (bar.isEnabled() ? 0.25f : 0.15f), 0, 0,
  1916. Colours::transparentBlack, 0, 0, false);
  1917. switch (bar.getOrientation())
  1918. {
  1919. case TabbedButtonBar::TabsAtLeft:
  1920. gradient.point1.x = (float) w;
  1921. gradient.point2.x = (float) w * (1.0f - shadowSize);
  1922. shadowRect.setBounds ((int) gradient.point2.x, 0, w - (int) gradient.point2.x, h);
  1923. line.setBounds (w - 1, 0, 1, h);
  1924. break;
  1925. case TabbedButtonBar::TabsAtRight:
  1926. gradient.point2.x = (float) w * shadowSize;
  1927. shadowRect.setBounds (0, 0, (int) gradient.point2.x, h);
  1928. line.setBounds (0, 0, 1, h);
  1929. break;
  1930. case TabbedButtonBar::TabsAtTop:
  1931. gradient.point1.y = (float) h;
  1932. gradient.point2.y = (float) h * (1.0f - shadowSize);
  1933. shadowRect.setBounds (0, (int) gradient.point2.y, w, h - (int) gradient.point2.y);
  1934. line.setBounds (0, h - 1, w, 1);
  1935. break;
  1936. case TabbedButtonBar::TabsAtBottom:
  1937. gradient.point2.y = (float) h * shadowSize;
  1938. shadowRect.setBounds (0, 0, w, (int) gradient.point2.y);
  1939. line.setBounds (0, 0, w, 1);
  1940. break;
  1941. default: break;
  1942. }
  1943. g.setGradientFill (gradient);
  1944. g.fillRect (shadowRect.expanded (2, 2));
  1945. g.setColour (Colour (0x80000000));
  1946. g.fillRect (line);
  1947. }
  1948. Button* LookAndFeel_V2::createTabBarExtrasButton()
  1949. {
  1950. auto thickness = 7.0f;
  1951. auto indent = 22.0f;
  1952. Path p;
  1953. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  1954. DrawablePath ellipse;
  1955. ellipse.setPath (p);
  1956. ellipse.setFill (Colour (0x99ffffff));
  1957. p.clear();
  1958. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  1959. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  1960. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  1961. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  1962. p.setUsingNonZeroWinding (false);
  1963. DrawablePath dp;
  1964. dp.setPath (p);
  1965. dp.setFill (Colour (0x59000000));
  1966. DrawableComposite normalImage;
  1967. normalImage.addAndMakeVisible (ellipse.createCopy().release());
  1968. normalImage.addAndMakeVisible (dp.createCopy().release());
  1969. dp.setFill (Colour (0xcc000000));
  1970. DrawableComposite overImage;
  1971. overImage.addAndMakeVisible (ellipse.createCopy().release());
  1972. overImage.addAndMakeVisible (dp.createCopy().release());
  1973. auto db = new DrawableButton (TRANS ("Additional Items"), DrawableButton::ImageFitted);
  1974. db->setImages (&normalImage, &overImage, nullptr);
  1975. return db;
  1976. }
  1977. //==============================================================================
  1978. void LookAndFeel_V2::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  1979. {
  1980. g.fillAll (Colours::white);
  1981. auto area = header.getLocalBounds();
  1982. area.removeFromTop (area.getHeight() / 2);
  1983. auto backgroundColour = header.findColour (TableHeaderComponent::backgroundColourId);
  1984. g.setGradientFill (ColourGradient (backgroundColour,
  1985. 0.0f, (float) area.getY(),
  1986. backgroundColour.withMultipliedSaturation (.5f),
  1987. 0.0f, (float) area.getBottom(),
  1988. false));
  1989. g.fillRect (area);
  1990. g.setColour (header.findColour (TableHeaderComponent::outlineColourId));
  1991. g.fillRect (area.removeFromBottom (1));
  1992. for (int i = header.getNumColumns (true); --i >= 0;)
  1993. g.fillRect (header.getColumnPosition (i).removeFromRight (1));
  1994. }
  1995. void LookAndFeel_V2::drawTableHeaderColumn (Graphics& g, TableHeaderComponent& header,
  1996. const String& columnName, int /*columnId*/,
  1997. int width, int height, bool isMouseOver, bool isMouseDown,
  1998. int columnFlags)
  1999. {
  2000. auto highlightColour = header.findColour (TableHeaderComponent::highlightColourId);
  2001. if (isMouseDown)
  2002. g.fillAll (highlightColour);
  2003. else if (isMouseOver)
  2004. g.fillAll (highlightColour.withMultipliedAlpha (0.625f));
  2005. Rectangle<int> area (width, height);
  2006. area.reduce (4, 0);
  2007. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  2008. {
  2009. Path sortArrow;
  2010. sortArrow.addTriangle (0.0f, 0.0f,
  2011. 0.5f, (columnFlags & TableHeaderComponent::sortedForwards) != 0 ? -0.8f : 0.8f,
  2012. 1.0f, 0.0f);
  2013. g.setColour (Colour (0x99000000));
  2014. g.fillPath (sortArrow, sortArrow.getTransformToScaleToFit (area.removeFromRight (height / 2).reduced (2).toFloat(), true));
  2015. }
  2016. g.setColour (header.findColour (TableHeaderComponent::textColourId));
  2017. g.setFont (Font ((float) height * 0.5f, Font::bold));
  2018. g.drawFittedText (columnName, area, Justification::centredLeft, 1);
  2019. }
  2020. //==============================================================================
  2021. void LookAndFeel_V2::drawLasso (Graphics& g, Component& lassoComp)
  2022. {
  2023. const int outlineThickness = 1;
  2024. g.fillAll (lassoComp.findColour (0x1000440 /*lassoFillColourId*/));
  2025. g.setColour (lassoComp.findColour (0x1000441 /*lassoOutlineColourId*/));
  2026. g.drawRect (lassoComp.getLocalBounds(), outlineThickness);
  2027. }
  2028. //==============================================================================
  2029. void LookAndFeel_V2::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  2030. {
  2031. auto background = toolbar.findColour (Toolbar::backgroundColourId);
  2032. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  2033. background.darker (0.1f),
  2034. toolbar.isVertical() ? (float) w - 1.0f : 0.0f,
  2035. toolbar.isVertical() ? 0.0f : (float) h - 1.0f,
  2036. false));
  2037. g.fillAll();
  2038. }
  2039. Button* LookAndFeel_V2::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  2040. {
  2041. return createTabBarExtrasButton();
  2042. }
  2043. void LookAndFeel_V2::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  2044. bool isMouseOver, bool isMouseDown,
  2045. ToolbarItemComponent& component)
  2046. {
  2047. if (isMouseDown)
  2048. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  2049. else if (isMouseOver)
  2050. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  2051. }
  2052. void LookAndFeel_V2::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  2053. const String& text, ToolbarItemComponent& component)
  2054. {
  2055. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  2056. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  2057. auto fontHeight = jmin (14.0f, (float) height * 0.85f);
  2058. g.setFont (fontHeight);
  2059. g.drawFittedText (text,
  2060. x, y, width, height,
  2061. Justification::centred,
  2062. jmax (1, height / (int) fontHeight));
  2063. }
  2064. //==============================================================================
  2065. void LookAndFeel_V2::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  2066. bool isOpen, int width, int height)
  2067. {
  2068. auto buttonSize = (float) height * 0.75f;
  2069. auto buttonIndent = ((float) height - buttonSize) * 0.5f;
  2070. drawTreeviewPlusMinusBox (g, Rectangle<float> (buttonIndent, buttonIndent, buttonSize, buttonSize), Colours::white, isOpen, false);
  2071. auto textX = (int) (buttonIndent * 2.0f + buttonSize + 2.0f);
  2072. g.setColour (Colours::black);
  2073. g.setFont (Font ((float) height * 0.7f, Font::bold));
  2074. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  2075. }
  2076. void LookAndFeel_V2::drawPropertyComponentBackground (Graphics& g, int width, int height, PropertyComponent& component)
  2077. {
  2078. g.setColour (component.findColour (PropertyComponent::backgroundColourId));
  2079. g.fillRect (0, 0, width, height - 1);
  2080. }
  2081. void LookAndFeel_V2::drawPropertyComponentLabel (Graphics& g, int, int height, PropertyComponent& component)
  2082. {
  2083. g.setColour (component.findColour (PropertyComponent::labelTextColourId)
  2084. .withMultipliedAlpha (component.isEnabled() ? 1.0f : 0.6f));
  2085. g.setFont ((float) jmin (height, 24) * 0.65f);
  2086. auto r = getPropertyComponentContentPosition (component);
  2087. g.drawFittedText (component.getName(),
  2088. 3, r.getY(), r.getX() - 5, r.getHeight(),
  2089. Justification::centredLeft, 2);
  2090. }
  2091. Rectangle<int> LookAndFeel_V2::getPropertyComponentContentPosition (PropertyComponent& component)
  2092. {
  2093. const int textW = jmin (200, component.getWidth() / 3);
  2094. return Rectangle<int> (textW, 1, component.getWidth() - textW - 1, component.getHeight() - 3);
  2095. }
  2096. int LookAndFeel_V2::getPropertyPanelSectionHeaderHeight (const String& sectionTitle)
  2097. {
  2098. return sectionTitle.isEmpty() ? 0 : 22;
  2099. }
  2100. //==============================================================================
  2101. void LookAndFeel_V2::drawCallOutBoxBackground (CallOutBox& box, Graphics& g,
  2102. const Path& path, Image& cachedImage)
  2103. {
  2104. if (cachedImage.isNull())
  2105. {
  2106. cachedImage = Image (Image::ARGB, box.getWidth(), box.getHeight(), true);
  2107. Graphics g2 (cachedImage);
  2108. DropShadow (Colours::black.withAlpha (0.7f), 8, Point<int> (0, 2)).drawForPath (g2, path);
  2109. }
  2110. g.setColour (Colours::black);
  2111. g.drawImageAt (cachedImage, 0, 0);
  2112. g.setColour (Colour::greyLevel (0.23f).withAlpha (0.9f));
  2113. g.fillPath (path);
  2114. g.setColour (Colours::white.withAlpha (0.8f));
  2115. g.strokePath (path, PathStrokeType (2.0f));
  2116. }
  2117. int LookAndFeel_V2::getCallOutBoxBorderSize (const CallOutBox&)
  2118. {
  2119. return 20;
  2120. }
  2121. float LookAndFeel_V2::getCallOutBoxCornerSize (const CallOutBox&)
  2122. {
  2123. return 9.0f;
  2124. }
  2125. //==============================================================================
  2126. AttributedString LookAndFeel_V2::createFileChooserHeaderText (const String& title,
  2127. const String& instructions)
  2128. {
  2129. AttributedString s;
  2130. s.setJustification (Justification::centred);
  2131. auto colour = findColour (FileChooserDialogBox::titleTextColourId);
  2132. s.append (title + "\n\n", Font (17.0f, Font::bold), colour);
  2133. s.append (instructions, Font (14.0f), colour);
  2134. return s;
  2135. }
  2136. void LookAndFeel_V2::drawFileBrowserRow (Graphics& g, int width, int height,
  2137. const File&, const String& filename, Image* icon,
  2138. const String& fileSizeDescription,
  2139. const String& fileTimeDescription,
  2140. bool isDirectory, bool isItemSelected,
  2141. int /*itemIndex*/, DirectoryContentsDisplayComponent& dcc)
  2142. {
  2143. auto fileListComp = dynamic_cast<Component*> (&dcc);
  2144. if (isItemSelected)
  2145. g.fillAll (fileListComp != nullptr ? fileListComp->findColour (DirectoryContentsDisplayComponent::highlightColourId)
  2146. : findColour (DirectoryContentsDisplayComponent::highlightColourId));
  2147. const int x = 32;
  2148. g.setColour (Colours::black);
  2149. if (icon != nullptr && icon->isValid())
  2150. {
  2151. g.drawImageWithin (*icon, 2, 2, x - 4, height - 4,
  2152. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  2153. false);
  2154. }
  2155. else
  2156. {
  2157. if (auto* d = isDirectory ? getDefaultFolderImage()
  2158. : getDefaultDocumentFileImage())
  2159. d->drawWithin (g, Rectangle<float> (2.0f, 2.0f, x - 4.0f, (float) height - 4.0f),
  2160. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f);
  2161. }
  2162. if (isItemSelected)
  2163. g.setColour (fileListComp != nullptr ? fileListComp->findColour (DirectoryContentsDisplayComponent::highlightedTextColourId)
  2164. : findColour (DirectoryContentsDisplayComponent::highlightedTextColourId));
  2165. else
  2166. g.setColour (fileListComp != nullptr ? fileListComp->findColour (DirectoryContentsDisplayComponent::textColourId)
  2167. : findColour (DirectoryContentsDisplayComponent::textColourId));
  2168. g.setFont ((float) height * 0.7f);
  2169. if (width > 450 && ! isDirectory)
  2170. {
  2171. auto sizeX = roundToInt ((float) width * 0.7f);
  2172. auto dateX = roundToInt ((float) width * 0.8f);
  2173. g.drawFittedText (filename,
  2174. x, 0, sizeX - x, height,
  2175. Justification::centredLeft, 1);
  2176. g.setFont ((float) height * 0.5f);
  2177. g.setColour (Colours::darkgrey);
  2178. if (! isDirectory)
  2179. {
  2180. g.drawFittedText (fileSizeDescription,
  2181. sizeX, 0, dateX - sizeX - 8, height,
  2182. Justification::centredRight, 1);
  2183. g.drawFittedText (fileTimeDescription,
  2184. dateX, 0, width - 8 - dateX, height,
  2185. Justification::centredRight, 1);
  2186. }
  2187. }
  2188. else
  2189. {
  2190. g.drawFittedText (filename,
  2191. x, 0, width - x, height,
  2192. Justification::centredLeft, 1);
  2193. }
  2194. }
  2195. Button* LookAndFeel_V2::createFileBrowserGoUpButton()
  2196. {
  2197. auto goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  2198. Path arrowPath;
  2199. arrowPath.addArrow ({ 50.0f, 100.0f, 50.0f, 0.0f }, 40.0f, 100.0f, 50.0f);
  2200. DrawablePath arrowImage;
  2201. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  2202. arrowImage.setPath (arrowPath);
  2203. goUpButton->setImages (&arrowImage);
  2204. return goUpButton;
  2205. }
  2206. void LookAndFeel_V2::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  2207. DirectoryContentsDisplayComponent* fileListComponent,
  2208. FilePreviewComponent* previewComp,
  2209. ComboBox* currentPathBox,
  2210. TextEditor* filenameBox,
  2211. Button* goUpButton)
  2212. {
  2213. const int x = 8;
  2214. auto w = browserComp.getWidth() - x - x;
  2215. if (previewComp != nullptr)
  2216. {
  2217. auto previewWidth = w / 3;
  2218. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  2219. w -= previewWidth + 4;
  2220. }
  2221. int y = 4;
  2222. const int controlsHeight = 22;
  2223. const int upButtonWidth = 50;
  2224. auto bottomSectionHeight = controlsHeight + 8;
  2225. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  2226. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  2227. y += controlsHeight + 4;
  2228. if (auto listAsComp = dynamic_cast<Component*> (fileListComponent))
  2229. {
  2230. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  2231. y = listAsComp->getBottom() + 4;
  2232. }
  2233. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  2234. }
  2235. //==============================================================================
  2236. static std::unique_ptr<Drawable> createDrawableFromSVG (const char* data)
  2237. {
  2238. auto xml = parseXML (data);
  2239. jassert (xml != nullptr);
  2240. return Drawable::createFromSVG (*xml);
  2241. }
  2242. const Drawable* LookAndFeel_V2::getDefaultFolderImage()
  2243. {
  2244. if (folderImage == nullptr)
  2245. folderImage = createDrawableFromSVG (R"svgdata(
  2246. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="706" height="532">
  2247. <defs>
  2248. <linearGradient id="a">
  2249. <stop stop-color="#adf" offset="0"/>
  2250. <stop stop-color="#ecfaff" offset="1"/>
  2251. </linearGradient>
  2252. <linearGradient id="b" x1=".6" x2="0" y1=".9" xlink:href="#a"/>
  2253. <linearGradient id="c" x1=".6" x2=".1" y1=".9" y2=".3" xlink:href="#a"/>
  2254. </defs>
  2255. <g class="currentLayer">
  2256. <path d="M112.1 104c-8.2 2.2-13.2 11.6-11.3 21l68.3 342.7c1.9 9.4 10.1 15.2 18.4 13l384.3-104.1c8.2-2.2 13.2-11.6 11.3-21l-48-266a15.8 15.8 0 0 0-18.4-12.8l-224.2 38s-20.3-41.3-28.3-39.3z" display="block" fill="url(#b)" stroke="#446c98" stroke-width="7"/>
  2257. <path d="M608.6 136.8L235.2 208a22.7 22.7 0 0 0-16 19l-40.8 241c1.7 8.4 9.6 14.5 17.8 12.3l380-104c8-2.2 10.7-10.2 12.3-18.4l38-210.1c.4-15.4-10.4-11.8-18-11.1z" display="block" fill="url(#c)" opacity=".8" stroke="#446c98" stroke-width="7"/>
  2258. </g>
  2259. </svg>
  2260. )svgdata");
  2261. return folderImage.get();
  2262. }
  2263. const Drawable* LookAndFeel_V2::getDefaultDocumentFileImage()
  2264. {
  2265. if (documentImage == nullptr)
  2266. documentImage = createDrawableFromSVG (R"svgdata(
  2267. <svg version="1" viewBox="-10 -10 450 600" xmlns="http://www.w3.org/2000/svg">
  2268. <path d="M17 0h290l120 132v426c0 10-8 19-17 19H17c-9 0-17-9-17-19V19C0 8 8 0 17 0z" fill="#e5e5e5" stroke="#888888" stroke-width="7"/>
  2269. <path d="M427 132H324c-9 0-17-9-17-19V0l120 132z" fill="#ccc"/>
  2270. </svg>
  2271. )svgdata");
  2272. return documentImage.get();
  2273. }
  2274. //==============================================================================
  2275. static Path createPathFromData (float height, const unsigned char* data, size_t size)
  2276. {
  2277. Path p;
  2278. p.loadPathFromData (data, size);
  2279. p.scaleToFit (0, 0, height * 2.0f, height, true);
  2280. return p;
  2281. }
  2282. Path LookAndFeel_V2::getTickShape (float height)
  2283. {
  2284. static const unsigned char data[] =
  2285. {
  2286. 109,0,224,168,68,0,0,119,67,108,0,224,172,68,0,128,146,67,113,0,192,148,68,0,0,219,67,0,96,110,68,0,224,56,68,113,0,64,51,68,0,32,130,68,0,64,20,68,0,224,
  2287. 162,68,108,0,128,3,68,0,128,168,68,113,0,128,221,67,0,192,175,68,0,0,207,67,0,32,179,68,113,0,0,201,67,0,224,173,68,0,0,181,67,0,224,161,68,108,0,128,168,67,
  2288. 0,128,154,68,113,0,128,141,67,0,192,138,68,0,128,108,67,0,64,131,68,113,0,0,62,67,0,128,119,68,0,0,5,67,0,128,114,68,113,0,0,102,67,0,192,88,68,0,128,155,
  2289. 67,0,192,88,68,113,0,0,190,67,0,192,88,68,0,128,232,67,0,224,131,68,108,0,128,246,67,0,192,139,68,113,0,64,33,68,0,128,87,68,0,0,93,68,0,224,26,68,113,0,
  2290. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  2291. };
  2292. return createPathFromData (height, data, sizeof (data));
  2293. }
  2294. Path LookAndFeel_V2::getCrossShape (float height)
  2295. {
  2296. static const unsigned char data[] =
  2297. {
  2298. 109,0,0,17,68,0,96,145,68,108,0,192,13,68,0,192,147,68,113,0,0,213,67,0,64,174,68,0,0,168,67,0,64,174,68,113,0,0,104,67,0,64,174,68,0,0,5,67,0,64,
  2299. 153,68,113,0,0,18,67,0,64,153,68,0,0,24,67,0,64,153,68,113,0,0,135,67,0,64,153,68,0,128,207,67,0,224,130,68,108,0,0,220,67,0,0,126,68,108,0,0,204,67,
  2300. 0,128,117,68,113,0,0,138,67,0,64,82,68,0,0,138,67,0,192,57,68,113,0,0,138,67,0,192,37,68,0,128,210,67,0,64,10,68,113,0,128,220,67,0,64,45,68,0,0,8,
  2301. 68,0,128,78,68,108,0,192,14,68,0,0,87,68,108,0,64,20,68,0,0,80,68,113,0,192,57,68,0,0,32,68,0,128,88,68,0,0,32,68,113,0,64,112,68,0,0,32,68,0,
  2302. 128,124,68,0,64,68,68,113,0,0,121,68,0,192,67,68,0,128,119,68,0,192,67,68,113,0,192,108,68,0,192,67,68,0,32,89,68,0,96,82,68,113,0,128,69,68,0,0,97,68,
  2303. 0,0,56,68,0,64,115,68,108,0,64,49,68,0,128,124,68,108,0,192,55,68,0,96,129,68,113,0,0,92,68,0,224,146,68,0,192,129,68,0,224,146,68,113,0,64,110,68,0,64,
  2304. 168,68,0,64,87,68,0,64,168,68,113,0,128,66,68,0,64,168,68,0,64,27,68,0,32,150,68,99,101
  2305. };
  2306. return createPathFromData (height, data, sizeof (data));
  2307. }
  2308. //==============================================================================
  2309. void LookAndFeel_V2::drawLevelMeter (Graphics& g, int width, int height, float level)
  2310. {
  2311. g.setColour (Colours::white.withAlpha (0.7f));
  2312. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  2313. g.setColour (Colours::black.withAlpha (0.2f));
  2314. g.drawRoundedRectangle (1.0f, 1.0f, (float) width - 2.0f, (float) height - 2.0f, 3.0f, 1.0f);
  2315. const int totalBlocks = 7;
  2316. const int numBlocks = roundToInt (totalBlocks * level);
  2317. auto w = ((float) width - 6.0f) / (float) totalBlocks;
  2318. for (int i = 0; i < totalBlocks; ++i)
  2319. {
  2320. if (i >= numBlocks)
  2321. g.setColour (Colours::lightblue.withAlpha (0.6f));
  2322. else
  2323. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  2324. : Colours::red);
  2325. g.fillRoundedRectangle (3.0f + (float) i * w + w * 0.1f,
  2326. 3.0f,
  2327. (float) w * 0.8f,
  2328. (float) height - 6.0f,
  2329. (float) w * 0.4f);
  2330. }
  2331. }
  2332. //==============================================================================
  2333. void LookAndFeel_V2::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  2334. {
  2335. auto textColour = button.findColour (0x100ad01 /*KeyMappingEditorComponent::textColourId*/, true);
  2336. if (keyDescription.isNotEmpty())
  2337. {
  2338. if (button.isEnabled())
  2339. {
  2340. auto alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  2341. g.fillAll (textColour.withAlpha (alpha));
  2342. g.setOpacity (0.3f);
  2343. drawBevel (g, 0, 0, width, height, 2);
  2344. }
  2345. g.setColour (textColour);
  2346. g.setFont ((float) height * 0.6f);
  2347. g.drawFittedText (keyDescription,
  2348. 3, 0, width - 6, height,
  2349. Justification::centred, 1);
  2350. }
  2351. else
  2352. {
  2353. const float thickness = 7.0f;
  2354. const float indent = 22.0f;
  2355. Path p;
  2356. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  2357. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  2358. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  2359. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  2360. p.setUsingNonZeroWinding (false);
  2361. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  2362. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, (float) width - 4.0f, (float) height - 4.0f, true));
  2363. }
  2364. if (button.hasKeyboardFocus (false))
  2365. {
  2366. g.setColour (textColour.withAlpha (0.4f));
  2367. g.drawRect (0, 0, width, height);
  2368. }
  2369. }
  2370. //==============================================================================
  2371. Font LookAndFeel_V2::getSidePanelTitleFont (SidePanel&)
  2372. {
  2373. return Font (18.0f);
  2374. }
  2375. Justification LookAndFeel_V2::getSidePanelTitleJustification (SidePanel& panel)
  2376. {
  2377. return panel.isPanelOnLeft() ? Justification::centredRight
  2378. : Justification::centredLeft;
  2379. }
  2380. Path LookAndFeel_V2::getSidePanelDismissButtonShape (SidePanel& panel)
  2381. {
  2382. return getCrossShape ((float) panel.getTitleBarHeight());
  2383. }
  2384. //==============================================================================
  2385. void LookAndFeel_V2::drawBevel (Graphics& g, const int x, const int y, const int width, const int height,
  2386. const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
  2387. const bool useGradient, const bool sharpEdgeOnOutside)
  2388. {
  2389. if (g.clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  2390. {
  2391. auto& context = g.getInternalContext();
  2392. Graphics::ScopedSaveState ss (g);
  2393. for (int i = bevelThickness; --i >= 0;)
  2394. {
  2395. const float op = useGradient ? (float) (sharpEdgeOnOutside ? bevelThickness - i : i) / (float) bevelThickness
  2396. : 1.0f;
  2397. context.setFill (topLeftColour.withMultipliedAlpha (op));
  2398. context.fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  2399. context.setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
  2400. context.fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  2401. context.setFill (bottomRightColour.withMultipliedAlpha (op));
  2402. context.fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  2403. context.setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
  2404. context.fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  2405. }
  2406. }
  2407. }
  2408. //==============================================================================
  2409. void LookAndFeel_V2::drawShinyButtonShape (Graphics& g, float x, float y, float w, float h,
  2410. float maxCornerSize, const Colour& baseColour, float strokeWidth,
  2411. bool flatOnLeft, bool flatOnRight, bool flatOnTop, bool flatOnBottom) noexcept
  2412. {
  2413. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  2414. return;
  2415. auto cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  2416. Path outline;
  2417. outline.addRoundedRectangle (x, y, w, h, cs, cs,
  2418. ! (flatOnLeft || flatOnTop),
  2419. ! (flatOnRight || flatOnTop),
  2420. ! (flatOnLeft || flatOnBottom),
  2421. ! (flatOnRight || flatOnBottom));
  2422. ColourGradient cg (baseColour, 0.0f, y,
  2423. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  2424. false);
  2425. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  2426. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  2427. g.setGradientFill (cg);
  2428. g.fillPath (outline);
  2429. g.setColour (Colour (0x80000000));
  2430. g.strokePath (outline, PathStrokeType (strokeWidth));
  2431. }
  2432. //==============================================================================
  2433. void LookAndFeel_V2::drawGlassSphere (Graphics& g, const float x, const float y,
  2434. const float diameter, const Colour& colour,
  2435. const float outlineThickness) noexcept
  2436. {
  2437. if (diameter <= outlineThickness)
  2438. return;
  2439. Path p;
  2440. p.addEllipse (x, y, diameter, diameter);
  2441. {
  2442. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  2443. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  2444. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  2445. g.setGradientFill (cg);
  2446. g.fillPath (p);
  2447. }
  2448. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  2449. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  2450. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  2451. ColourGradient cg (Colours::transparentBlack,
  2452. x + diameter * 0.5f, y + diameter * 0.5f,
  2453. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  2454. x, y + diameter * 0.5f, true);
  2455. cg.addColour (0.7, Colours::transparentBlack);
  2456. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  2457. g.setGradientFill (cg);
  2458. g.fillPath (p);
  2459. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  2460. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  2461. }
  2462. //==============================================================================
  2463. void LookAndFeel_V2::drawGlassPointer (Graphics& g,
  2464. const float x, const float y, const float diameter,
  2465. const Colour& colour, const float outlineThickness,
  2466. const int direction) noexcept
  2467. {
  2468. if (diameter <= outlineThickness)
  2469. return;
  2470. Path p;
  2471. p.startNewSubPath (x + diameter * 0.5f, y);
  2472. p.lineTo (x + diameter, y + diameter * 0.6f);
  2473. p.lineTo (x + diameter, y + diameter);
  2474. p.lineTo (x, y + diameter);
  2475. p.lineTo (x, y + diameter * 0.6f);
  2476. p.closeSubPath();
  2477. p.applyTransform (AffineTransform::rotation ((float) direction * MathConstants<float>::halfPi,
  2478. x + diameter * 0.5f,
  2479. y + diameter * 0.5f));
  2480. {
  2481. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  2482. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  2483. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  2484. g.setGradientFill (cg);
  2485. g.fillPath (p);
  2486. }
  2487. ColourGradient cg (Colours::transparentBlack,
  2488. x + diameter * 0.5f, y + diameter * 0.5f,
  2489. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  2490. x - diameter * 0.2f, y + diameter * 0.5f, true);
  2491. cg.addColour (0.5, Colours::transparentBlack);
  2492. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  2493. g.setGradientFill (cg);
  2494. g.fillPath (p);
  2495. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  2496. g.strokePath (p, PathStrokeType (outlineThickness));
  2497. }
  2498. //==============================================================================
  2499. void LookAndFeel_V2::drawGlassLozenge (Graphics& g,
  2500. float x, float y, float width, float height,
  2501. const Colour& colour, float outlineThickness, float cornerSize,
  2502. bool flatOnLeft, bool flatOnRight, bool flatOnTop, bool flatOnBottom) noexcept
  2503. {
  2504. if (width <= outlineThickness || height <= outlineThickness)
  2505. return;
  2506. auto intX = (int) x;
  2507. auto intY = (int) y;
  2508. auto intW = (int) width;
  2509. auto intH = (int) height;
  2510. auto cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  2511. auto edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  2512. auto intEdge = (int) edgeBlurRadius;
  2513. Path outline;
  2514. outline.addRoundedRectangle (x, y, width, height, cs, cs,
  2515. ! (flatOnLeft || flatOnTop),
  2516. ! (flatOnRight || flatOnTop),
  2517. ! (flatOnLeft || flatOnBottom),
  2518. ! (flatOnRight || flatOnBottom));
  2519. {
  2520. ColourGradient cg (colour.darker (0.2f), 0, y,
  2521. colour.darker (0.2f), 0, y + height, false);
  2522. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  2523. cg.addColour (0.4, colour);
  2524. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  2525. g.setGradientFill (cg);
  2526. g.fillPath (outline);
  2527. }
  2528. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  2529. colour.darker (0.2f), x, y + height * 0.5f, true);
  2530. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  2531. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  2532. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  2533. {
  2534. Graphics::ScopedSaveState ss (g);
  2535. g.setGradientFill (cg);
  2536. g.reduceClipRegion (intX, intY, intEdge, intH);
  2537. g.fillPath (outline);
  2538. }
  2539. if (! (flatOnRight || flatOnTop || flatOnBottom))
  2540. {
  2541. cg.point1.setX (x + width - edgeBlurRadius);
  2542. cg.point2.setX (x + width);
  2543. Graphics::ScopedSaveState ss (g);
  2544. g.setGradientFill (cg);
  2545. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  2546. g.fillPath (outline);
  2547. }
  2548. {
  2549. auto leftIndent = (flatOnTop || flatOnLeft) ? 0.0f : cs * 0.4f;
  2550. auto rightIndent = (flatOnTop || flatOnRight) ? 0.0f : cs * 0.4f;
  2551. Path highlight;
  2552. highlight.addRoundedRectangle (x + leftIndent,
  2553. y + cs * 0.1f,
  2554. width - (leftIndent + rightIndent),
  2555. height * 0.4f,
  2556. cs * 0.4f,
  2557. cs * 0.4f,
  2558. ! (flatOnLeft || flatOnTop),
  2559. ! (flatOnRight || flatOnTop),
  2560. ! (flatOnLeft || flatOnBottom),
  2561. ! (flatOnRight || flatOnBottom));
  2562. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  2563. Colours::transparentWhite, 0, y + height * 0.4f, false));
  2564. g.fillPath (highlight);
  2565. }
  2566. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  2567. g.strokePath (outline, PathStrokeType (outlineThickness));
  2568. }
  2569. } // namespace juce