Skip to content

Commit

Permalink
Release Version 4.10.1
Browse files Browse the repository at this point in the history
Merge in VSTSDK/vstgui from develop to master

* commit '2cf61f5e1fefe4dcd3d19119ddf7b182719a2a5b':
  Fix compile-time check for pango
  add missing includes
  Update stb_textedit to v1.13
  Do not let newValue exceed 1.0 when adding up valueOffset multiple times.
  implement pango leading metrics
  implement cairo hitTest
  add patchlevel to vstgui version makros to support simple bug fix releases without API changes
  add visualize redraw areas to mac standalone apps in debug mode
  fix wrong clip rect calculation on linux
  add macro to conditionally compile for newer vstgui versions
  fix indexOf algo
  Fix segment button not being updated on parameter change from host.
  Fix the build with gcc 11 (#203)
  Return an empty string, when string list is empty (#204)
  Testing (#202)
  Add unit test for segment button with many segments (catch rounding errors).
  Round segmentIndex properly.
  macOS: create retina compatible menu icons and drag images out of CBitmaps
  macOS: fix menu icon with scale factor != 1
  increase version number
  • Loading branch information
scheffle committed Aug 9, 2021
2 parents a6a780d + 2cf61f5 commit 6c48e17
Show file tree
Hide file tree
Showing 35 changed files with 702 additions and 315 deletions.
2 changes: 1 addition & 1 deletion vstgui/lib/algorithm.h
Expand Up @@ -16,7 +16,7 @@ template <typename Iter, typename Type, typename ResultType = int32_t>
Optional<ResultType> indexOf (Iter first, Iter last, const Type& value)
{
auto it = std::find (first, last, value);
if (first == last)
if (it == last)
return {};
return {static_cast<ResultType> (std::distance (first, it))};
}
Expand Down
8 changes: 7 additions & 1 deletion vstgui/lib/controls/csegmentbutton.cpp
Expand Up @@ -349,6 +349,9 @@ CMouseEventResult CSegmentButton::onMouseDown (CPoint& where, const CButtonState
break; // out of for loop
}
newValue += valueOffset;

// Last segment can lead to newValue > 1.0
newValue = std::min(newValue, 1.f);
}
}
return kMouseDownEventHandledButDontNeedMovedOrUpEvents;
Expand Down Expand Up @@ -517,7 +520,10 @@ uint32_t CSegmentButton::getSegmentIndex (float value) const
{
if (value < 0.f || value > 1.f)
return kPushBack;
return static_cast<uint32_t> (static_cast<float> (segments.size () - 1) * value);

const auto segmentIndex = static_cast<float> (segments.size () - 1) * value;
const auto segmentIndexRounded = static_cast<uint32_t> (segmentIndex + 0.5f);
return segmentIndexRounded;
}

//-----------------------------------------------------------------------------
Expand Down
112 changes: 56 additions & 56 deletions vstgui/lib/platform/common/stb_textedit.h
@@ -1,4 +1,4 @@
// stb_textedit.h - v1.12 - public domain - Sean Barrett
// stb_textedit.h - v1.13 - public domain - Sean Barrett
// Development of this library was sponsored by RAD Game Tools
//
// This C header file implements the guts of a multi-line text-editing
Expand All @@ -13,7 +13,7 @@
// texts, as its performance does not scale and it has limited undo).
//
// Non-trivial behaviors are modelled after Windows text controls.
//
//
//
// LICENSE
//
Expand All @@ -29,6 +29,7 @@
//
// VERSION HISTORY
//
// 1.13 (2019-02-07) fix bug in undo size management
// 1.12 (2018-01-29) user can change STB_TEXTEDIT_KEYTYPE, fix redo to avoid crash
// 1.11 (2017-03-03) fix HOME on last line, dragging off single-line textfield
// 1.10 (2016-10-25) supress warnings about casting away const with -Wcast-qual
Expand Down Expand Up @@ -86,8 +87,8 @@
// moderate sizes. The undo system does no memory allocations, so
// it grows STB_TexteditState by the worst-case storage which is (in bytes):
//
// [4 + sizeof(STB_TEXTEDIT_POSITIONTYPE)] * STB_TEXTEDIT_UNDOSTATE_COUNT
// + sizeof(STB_TEXTEDIT_CHARTYPE) * STB_TEXTEDIT_UNDOCHAR_COUNT
// [4 + 3 * sizeof(STB_TEXTEDIT_POSITIONTYPE)] * STB_TEXTEDIT_UNDOSTATE_COUNT
// + sizeof(STB_TEXTEDIT_CHARTYPE) * STB_TEXTEDIT_UNDOCHAR_COUNT
//
//
// Implementation mode:
Expand All @@ -110,7 +111,7 @@
// Symbols that must be the same in header-file and implementation mode:
//
// STB_TEXTEDIT_CHARTYPE the character type
// STB_TEXTEDIT_POSITIONTYPE small type that a valid cursor position
// STB_TEXTEDIT_POSITIONTYPE small type that is a valid cursor position
// STB_TEXTEDIT_UNDOSTATECOUNT the number of undo states to allow
// STB_TEXTEDIT_UNDOCHARCOUNT the number of characters to store in the undo buffer
//
Expand Down Expand Up @@ -170,7 +171,7 @@
// Keyboard input must be encoded as a single integer value; e.g. a character code
// and some bitflags that represent shift states. to simplify the interface, SHIFT must
// be a bitflag, so we can test the shifted state of cursor movements to allow selection,
// i.e. (STB_TEXTED_K_RIGHT|STB_TEXTEDIT_K_SHIFT) should be shifted right-arrow.
// i.e. (STB_TEXTEDIT_K_RIGHT|STB_TEXTEDIT_K_SHIFT) should be shifted right-arrow.
//
// You can encode other things, such as CONTROL or ALT, in additional bits, and
// then test for their presence in e.g. STB_TEXTEDIT_K_WORDLEFT. For example,
Expand Down Expand Up @@ -212,20 +213,20 @@
// call this with the mouse x,y on a mouse down; it will update the cursor
// and reset the selection start/end to the cursor point. the x,y must
// be relative to the text widget, with (0,0) being the top left.
//
//
// drag:
// call this with the mouse x,y on a mouse drag/up; it will update the
// cursor and the selection end point
//
//
// cut:
// call this to delete the current selection; returns true if there was
// one. you should FIRST copy the current selection to the system paste buffer.
// (To copy, just copy the current selection out of the string yourself.)
//
//
// paste:
// call this to paste text at the current cursor point or over the current
// selection if there is one.
//
//
// key:
// call this for keyboard inputs sent to the textfield. you can use it
// for "key down" events or for "translated" key events. if you need to
Expand All @@ -236,7 +237,7 @@
// clear. STB_TEXTEDIT_KEYTYPE defaults to int, but you can #define it to
// anything other type you wante before including.
//
//
//
// When rendering, you can read the cursor position and selection state from
// the STB_TexteditState.
//
Expand Down Expand Up @@ -295,9 +296,9 @@ typedef struct
{
// private data
STB_TEXTEDIT_POSITIONTYPE where;
short insert_length;
short delete_length;
short char_storage;
STB_TEXTEDIT_POSITIONTYPE insert_length;
STB_TEXTEDIT_POSITIONTYPE delete_length;
int char_storage;
} StbUndoRecord;

typedef struct
Expand All @@ -306,7 +307,7 @@ typedef struct
StbUndoRecord undo_rec [STB_TEXTEDIT_UNDOSTATECOUNT];
STB_TEXTEDIT_CHARTYPE undo_char[STB_TEXTEDIT_UNDOCHARCOUNT];
short undo_point, redo_point;
short undo_char_point, redo_char_point;
int undo_char_point, redo_char_point;
} StbUndoState;

typedef struct
Expand Down Expand Up @@ -558,7 +559,6 @@ static void stb_textedit_find_charpos(StbFindState *find, STB_TEXTEDIT_STRING *s

// now scan to find xpos
find->x = r.x0;
i = 0;
for (i=0; first+i < n; ++i)
find->x += STB_TEXTEDIT_GETWIDTH(str, first, i);
}
Expand Down Expand Up @@ -688,7 +688,7 @@ static void stb_textedit_prep_selection_at_cursor(STB_TexteditState *state)
static int stb_textedit_cut(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
{
if (STB_TEXT_HAS_SELECTION(state)) {
stb_textedit_delete_selection(str,state); // implicity clamps
stb_textedit_delete_selection(str,state); // implicitly clamps
state->has_preferred_x = 0;
return 1;
}
Expand Down Expand Up @@ -740,7 +740,7 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
state->has_preferred_x = 0;
}
} else {
stb_textedit_delete_selection(str,state); // implicity clamps
stb_textedit_delete_selection(str,state); // implicitly clamps
if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) {
stb_text_makeundo_insert(state, state->cursor, 1);
++state->cursor;
Expand All @@ -756,7 +756,7 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
state->insert_mode = !state->insert_mode;
break;
#endif

case STB_TEXTEDIT_K_UNDO:
stb_text_undo(str, state);
state->has_preferred_x = 0;
Expand All @@ -771,7 +771,7 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
// if currently there's a selection, move cursor to start of selection
if (STB_TEXT_HAS_SELECTION(state))
stb_textedit_move_to_first(state);
else
else
if (state->cursor > 0)
--state->cursor;
state->has_preferred_x = 0;
Expand Down Expand Up @@ -820,7 +820,7 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,

#ifdef STB_TEXTEDIT_MOVEWORDRIGHT
case STB_TEXTEDIT_K_WORDRIGHT:
if (STB_TEXT_HAS_SELECTION(state))
if (STB_TEXT_HAS_SELECTION(state))
stb_textedit_move_to_last(str, state);
else {
state->cursor = STB_TEXTEDIT_MOVEWORDRIGHT(str, state->cursor);
Expand Down Expand Up @@ -898,7 +898,7 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
}
break;
}

case STB_TEXTEDIT_K_UP:
case STB_TEXTEDIT_K_UP | STB_TEXTEDIT_K_SHIFT: {
StbFindState find;
Expand Down Expand Up @@ -975,7 +975,7 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
}
state->has_preferred_x = 0;
break;

#ifdef STB_TEXTEDIT_K_TEXTSTART2
case STB_TEXTEDIT_K_TEXTSTART2:
#endif
Expand All @@ -992,7 +992,7 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
state->select_start = state->select_end = 0;
state->has_preferred_x = 0;
break;

#ifdef STB_TEXTEDIT_K_TEXTSTART2
case STB_TEXTEDIT_K_TEXTSTART2 | STB_TEXTEDIT_K_SHIFT:
#endif
Expand Down Expand Up @@ -1096,11 +1096,11 @@ static void stb_textedit_discard_undo(StbUndoState *state)
if (state->undo_rec[0].char_storage >= 0) {
int n = state->undo_rec[0].insert_length, i;
// delete n characters from all other records
state->undo_char_point = state->undo_char_point - (short) n; // vsnet05
state->undo_char_point -= n;
STB_TEXTEDIT_memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE)));
for (i=0; i < state->undo_point; ++i)
if (state->undo_rec[i].char_storage >= 0)
state->undo_rec[i].char_storage = state->undo_rec[i].char_storage - (short) n; // vsnet05 // @OPTIMIZE: get rid of char_storage and infer it
state->undo_rec[i].char_storage -= n; // @OPTIMIZE: get rid of char_storage and infer it
}
--state->undo_point;
STB_TEXTEDIT_memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0])));
Expand All @@ -1120,12 +1120,12 @@ static void stb_textedit_discard_redo(StbUndoState *state)
if (state->undo_rec[k].char_storage >= 0) {
int n = state->undo_rec[k].insert_length, i;
// move the remaining redo character data to the end of the buffer
state->redo_char_point = state->redo_char_point + (short) n; // vsnet05
state->redo_char_point += n;
STB_TEXTEDIT_memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((STB_TEXTEDIT_UNDOCHARCOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE)));
// adjust the position of all the other records to account for above memmove
for (i=state->redo_point; i < k; ++i)
if (state->undo_rec[i].char_storage >= 0)
state->undo_rec[i].char_storage += (short) n; // vsnet05
state->undo_rec[i].char_storage += n;
}
// now move all the redo records towards the end of the buffer; the first one is at 'redo_point'
STB_TEXTEDIT_memmove(state->undo_rec + state->redo_point+1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0])));
Expand Down Expand Up @@ -1165,15 +1165,15 @@ static STB_TEXTEDIT_CHARTYPE *stb_text_createundo(StbUndoState *state, int pos,
return NULL;

r->where = pos;
r->insert_length = (short) insert_len;
r->delete_length = (short) delete_len;
r->insert_length = (STB_TEXTEDIT_POSITIONTYPE) insert_len;
r->delete_length = (STB_TEXTEDIT_POSITIONTYPE) delete_len;

if (insert_len == 0) {
r->char_storage = -1;
return NULL;
} else {
r->char_storage = state->undo_char_point;
state->undo_char_point = state->undo_char_point + (short) insert_len;
state->undo_char_point += insert_len;
return &state->undo_char[r->char_storage];
}
}
Expand Down Expand Up @@ -1222,7 +1222,7 @@ static void stb_text_undo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
r = &s->undo_rec[s->redo_point-1];

r->char_storage = s->redo_char_point - u.delete_length;
s->redo_char_point = s->redo_char_point - (short) u.delete_length;
s->redo_char_point = s->redo_char_point - u.delete_length;

// now save the characters
for (i=0; i < u.delete_length; ++i)
Expand Down Expand Up @@ -1367,38 +1367,38 @@ This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Sean Barrett
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/
11 changes: 7 additions & 4 deletions vstgui/lib/platform/linux/cairocontext.cpp
Expand Up @@ -56,10 +56,7 @@ inline bool needPixelAlignment (CDrawMode mode)
DrawBlock::DrawBlock (Context& context) : context (context)
{
auto ct = context.getCurrentTransform ();
CRect clip;
context.getClipRect (clip);
ct.transform (clip);
clip.bound (context.getSurfaceRect ());
CRect clip = context.getCurrentStateClipRect ();
if (clip.isEmpty ())
{
clipIsEmpty = true;
Expand Down Expand Up @@ -124,6 +121,12 @@ void Context::init ()
super::init ();
}

//-----------------------------------------------------------------------------
CRect Context::getCurrentStateClipRect () const
{
return getCurrentState ().clipRect;
}

//-----------------------------------------------------------------------------
void Context::beginDraw ()
{
Expand Down
1 change: 1 addition & 0 deletions vstgui/lib/platform/linux/cairocontext.h
Expand Up @@ -58,6 +58,7 @@ class Context : public COffscreenContext
void beginDraw () override;
void endDraw () override;

CRect getCurrentStateClipRect () const;
private:
void init () override;
void setSourceColor (CColor color);
Expand Down
7 changes: 6 additions & 1 deletion vstgui/lib/platform/linux/cairofont.cpp
Expand Up @@ -156,6 +156,12 @@ Font::Font (UTF8StringPtr name, const CCoord& size, const int32_t& style)
{
impl->ascent = pango_units_to_double (pango_font_metrics_get_ascent (metrics));
impl->descent = pango_units_to_double (pango_font_metrics_get_descent (metrics));
#if (PANGO_VERSION_MAJOR > 1) || ((PANGO_VERSION_MAJOR == 1) && PANGO_VERSION_MINOR >= 44)
auto height = pango_units_to_double (pango_font_metrics_get_height (metrics));
impl->leading = height - (impl->ascent + impl->descent);
#else
impl->leading = 0.;
#endif
pango_font_metrics_unref (metrics);
}

Expand Down Expand Up @@ -210,7 +216,6 @@ double Font::getDescent () const
//------------------------------------------------------------------------
double Font::getLeading () const
{
#warning TODO: Implementation
return impl->leading;
}

Expand Down

0 comments on commit 6c48e17

Please sign in to comment.