Skip to content

Commit

Permalink
Merge pull request #1857 from UnigramDev/develop
Browse files Browse the repository at this point in the history
v4.2
  • Loading branch information
FrayxRulez committed Jun 22, 2020
2 parents ed56188 + 5d69cdd commit 2f6d172
Show file tree
Hide file tree
Showing 120 changed files with 2,095 additions and 3,811 deletions.
176 changes: 62 additions & 114 deletions Unigram/Unigram.Native/PlaceholderImageHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,140 +164,88 @@ HRESULT PlaceholderImageHelper::InternalDrawSvg(String^ path, _In_ Color foregro
ReturnIfFailed(result, m_d2dContext->CreateSolidColorBrush(
D2D1::ColorF(foreground.R / 255.0f, foreground.G / 255.0f, foreground.B / 255.0f, foreground.A / 255.0f), &blackBrush));

for (auto shape = image->shapes; shape != NULL; shape = shape->next) {
if (!(shape->flags & NSVG_FLAGS_VISIBLE)) {
for (auto shape = image->shapes; shape != NULL; shape = shape->next)
{
if (!(shape->flags & NSVG_FLAGS_VISIBLE) || (shape->fill.type == NSVG_PAINT_NONE && shape->stroke.type == NSVG_PAINT_NONE))
{
continue;
}

if (shape->fill.type != NSVG_PAINT_NONE) {

ComPtr<ID2D1PathGeometry1> geometry;
ReturnIfFailed(result, m_d2dFactory->CreatePathGeometry(&geometry));

ComPtr<ID2D1GeometrySink> sink;
ReturnIfFailed(result, geometry->Open(&sink));
////CGContextSetFillColorWithColor(context, UIColorRGBA(shape->fill.color, shape->opacity).CGColor);
//CGContextSetFillColorWithColor(context, [foregroundColor colorWithAlphaComponent : shape->opacity].CGColor);

bool isFirst = true;
bool hasStartPoint = false;
D2D1_POINT_2F startPoint;
for (NSVGpath* path = shape->paths; path != NULL; path = path->next) {
if (isFirst) {
//CGContextBeginPath(context);
sink->BeginFigure(D2D1::Point2F(path->pts[0], path->pts[1]), D2D1_FIGURE_BEGIN_FILLED);
isFirst = false;
hasStartPoint = true;
startPoint.x = path->pts[0];
startPoint.y = path->pts[1];
}
//CGContextMoveToPoint(context, path->pts[0], path->pts[1]);
else {
sink->AddLine(D2D1::Point2F(path->pts[0], path->pts[1]));
}
for (int i = 0; i < path->npts - 1; i += 3) {
float* p = &path->pts[i * 2];
//CGContextAddCurveToPoint(context, p[2], p[3], p[4], p[5], p[6], p[7]);
sink->AddBezier(D2D1::BezierSegment(D2D1::Point2F(p[2], p[3]), D2D1::Point2F(p[4], p[5]), D2D1::Point2F(p[6], p[7])));
}
blackBrush->SetOpacity(shape->opacity);

if (path->closed) {
if (hasStartPoint) {
hasStartPoint = false;
//CGContextAddLineToPoint(context, startPoint.x, startPoint.y);
sink->AddLine(startPoint);
}
}
ComPtr<ID2D1PathGeometry1> geometry;
ReturnIfFailed(result, m_d2dFactory->CreatePathGeometry(&geometry));

if (path->next != NULL) {
int a = 1 + 2;
}
}
sink->EndFigure(D2D1_FIGURE_END_OPEN);
switch (shape->fillRule) {
case NSVG_FILLRULE_EVENODD:
//CGContextEOFillPath(context);
sink->SetFillMode(D2D1_FILL_MODE_ALTERNATE);
break;
default:
//CGContextFillPath(context);
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
break;
}
ComPtr<ID2D1GeometrySink> sink;
ReturnIfFailed(result, geometry->Open(&sink));

ReturnIfFailed(result, sink->Close());
m_d2dContext->FillGeometry(geometry.Get(), m_black.Get());
}
for (NSVGpath* path = shape->paths; path != NULL; path = path->next)
{
sink->BeginFigure({ path->pts[0], path->pts[1] }, D2D1_FIGURE_BEGIN_FILLED);

if (shape->stroke.type != NSVG_PAINT_NONE) {
ComPtr<ID2D1PathGeometry1> geometry;
ReturnIfFailed(result, m_d2dFactory->CreatePathGeometry(&geometry));
for (int i = 0; i < path->npts - 1; i += 3)
{
float* p = &path->pts[i * 2];
sink->AddBezier({ { p[2], p[3] }, { p[4], p[5] }, { p[6], p[7] }});
}

ComPtr<ID2D1GeometrySink> sink;
ReturnIfFailed(result, geometry->Open(&sink));
sink->EndFigure(path->closed ? D2D1_FIGURE_END_CLOSED : D2D1_FIGURE_END_OPEN);
}

////CGContextSetStrokeColorWithColor(context, UIColorRGBA(shape->fill.color, shape->opacity).CGColor);
//CGContextSetStrokeColorWithColor(context, [foregroundColor colorWithAlphaComponent : shape->opacity].CGColor);
//CGContextSetMiterLimit(context, shape->miterLimit);
if (shape->fill.type != NSVG_PAINT_NONE)
{
switch (shape->fillRule)
{
case NSVG_FILLRULE_EVENODD:
sink->SetFillMode(D2D1_FILL_MODE_ALTERNATE);
break;
default:
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
break;
}

ReturnIfFailed(result, sink->Close());
m_d2dContext->FillGeometry(geometry.Get(), blackBrush.Get());
}

if (shape->stroke.type != NSVG_PAINT_NONE)
{
D2D1_STROKE_STYLE_PROPERTIES1 strokeProperties{};
strokeProperties.miterLimit = shape->miterLimit;

//CGContextSetLineWidth(context, shape->strokeWidth);
switch (shape->strokeLineCap) {
case NSVG_CAP_BUTT:
//CGContextSetLineCap(context, kCGLineCapButt);
strokeProperties.startCap = strokeProperties.endCap = D2D1_CAP_STYLE_FLAT;
break;
case NSVG_CAP_ROUND:
//CGContextSetLineCap(context, kCGLineCapRound);
strokeProperties.startCap = strokeProperties.endCap = D2D1_CAP_STYLE_ROUND;
break;
case NSVG_CAP_SQUARE:
//CGContextSetLineCap(context, kCGLineCapSquare);
strokeProperties.startCap = strokeProperties.endCap = D2D1_CAP_STYLE_SQUARE;
break;
default:
break;
switch (shape->strokeLineCap)
{
case NSVG_CAP_BUTT:
strokeProperties.startCap = strokeProperties.endCap = D2D1_CAP_STYLE_FLAT;
break;
case NSVG_CAP_ROUND:
strokeProperties.startCap = strokeProperties.endCap = D2D1_CAP_STYLE_ROUND;
break;
case NSVG_CAP_SQUARE:
strokeProperties.startCap = strokeProperties.endCap = D2D1_CAP_STYLE_SQUARE;
break;
default:
break;
}
switch (shape->strokeLineJoin) {
case NSVG_JOIN_BEVEL:
//CGContextSetLineJoin(context, kCGLineJoinBevel);
strokeProperties.lineJoin = D2D1_LINE_JOIN_BEVEL;
break;
case NSVG_JOIN_MITER:
//CGContextSetLineCap(context, kCGLineJoinMiter);
strokeProperties.lineJoin = D2D1_LINE_JOIN_MITER;
break;
case NSVG_JOIN_ROUND:
//CGContextSetLineCap(context, kCGLineJoinRound);
strokeProperties.lineJoin = D2D1_LINE_JOIN_ROUND;
break;
default:
break;

switch (shape->strokeLineJoin)
{
case NSVG_JOIN_BEVEL:
strokeProperties.lineJoin = D2D1_LINE_JOIN_BEVEL;
break;
case NSVG_JOIN_MITER:
strokeProperties.lineJoin = D2D1_LINE_JOIN_MITER;
break;
case NSVG_JOIN_ROUND:
strokeProperties.lineJoin = D2D1_LINE_JOIN_ROUND;
break;
default:
break;
}

ComPtr<ID2D1StrokeStyle1> strokeStyle;
ReturnIfFailed(result, m_d2dFactory->CreateStrokeStyle(strokeProperties, NULL, 0, &strokeStyle));

for (NSVGpath* path = shape->paths; path != NULL; path = path->next) {
//CGContextBeginPath(context);
//CGContextMoveToPoint(context, path->pts[0], path->pts[1]);
sink->BeginFigure(D2D1::Point2F(path->pts[0], path->pts[1]), D2D1_FIGURE_BEGIN_HOLLOW);
for (int i = 0; i < path->npts - 1; i += 3) {
float* p = &path->pts[i * 2];
//CGContextAddCurveToPoint(context, p[2], p[3], p[4], p[5], p[6], p[7]);
sink->AddBezier(D2D1::BezierSegment(D2D1::Point2F(p[2], p[3]), D2D1::Point2F(p[4], p[5]), D2D1::Point2F(p[6], p[7])));
}

//if (path->closed) {
// CGContextClosePath(context);
//}
sink->EndFigure(path->closed ? D2D1_FIGURE_END_CLOSED : D2D1_FIGURE_END_OPEN);

//CGContextStrokePath(context);
}

ReturnIfFailed(result, sink->Close());
m_d2dContext->DrawGeometry(geometry.Get(), blackBrush.Get(), shape->strokeWidth);
Expand Down
2 changes: 1 addition & 1 deletion Unigram/Unigram.Native/VideoAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ int VideoAnimation::RenderSync(CanvasBitmap^ bitmap, bool preview)
unknown->QueryInterface(IID_PPV_ARGS(&bitmapAbi));

bitmapAbi->SetPixelBytes(pixelWidth * pixelHeight * 4, (BYTE*)pixels);
delete[] pixels;
free(pixels);

info->prevFrame = timestamp;
info->prevDuration = (1000 * info->frame->pkt_duration * av_q2d(info->video_stream->time_base));
Expand Down
5 changes: 1 addition & 4 deletions Unigram/Unigram/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
using Telegram.Td;
using Telegram.Td.Api;
using Unigram.Common;
using Unigram.Controls;
using Unigram.Navigation;
using Unigram.Navigation.Services;
using Unigram.Services;
using Unigram.Services.Navigation;
using Unigram.Services.Updates;
using Unigram.Views;
using Unigram.Views.Host;
Expand Down Expand Up @@ -389,15 +388,13 @@ public override UIElement CreateRootElement(IActivatedEventArgs e)
{
var navigationFrame = new Frame { FlowDirection = ApiInfo.FlowDirection };
var navigationService = NavigationServiceFactory(BackButton.Ignore, ExistingContent.Include, navigationFrame, sessionId, $"Main{sessionId}", false) as NavigationService;
navigationService.SerializationService = TLSerializationService.Current;

return navigationFrame;
}
else
{
var navigationFrame = new Frame();
var navigationService = NavigationServiceFactory(BackButton.Ignore, ExistingContent.Include, navigationFrame, sessionId, $"{sessionId}", true) as NavigationService;
navigationService.SerializationService = TLSerializationService.Current;

return new RootPage(navigationService) { FlowDirection = ApiInfo.FlowDirection };
}
Expand Down
18 changes: 6 additions & 12 deletions Unigram/Unigram/Collections/MvxObservableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public bool EventsAreSuppressed
get { return this._suppressEvents > 0; }
}

public void Dispose()
{
_suppressEvents = int.MaxValue;
}

/// <summary>
/// Raises the <see cref="E:System.Collections.ObjectModel.ObservableCollection`1.CollectionChanged"/> event with the provided event data.
/// </summary>
Expand All @@ -74,7 +79,7 @@ protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
if (!EventsAreSuppressed)
{
InvokeOnMainThread(() => base.OnCollectionChanged(e));
base.OnCollectionChanged(e);
}
}

Expand Down Expand Up @@ -290,17 +295,6 @@ public void Reset()
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}

protected void InvokeOnMainThread(Action action)
{
action();
//Execute.BeginOnUIThread(action);
}

protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
InvokeOnMainThread(() => base.OnPropertyChanged(e));
}

public virtual bool Set<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (object.Equals(storage, value))
Expand Down
2 changes: 1 addition & 1 deletion Unigram/Unigram/Common/AnimatedRepeaterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private void Play(IEnumerable<(Button Contaner, T Sticker)> items, bool auto)
var presenter = new AnimationView();
presenter.AutoPlay = true;
presenter.IsLoopingEnabled = true;
presenter.Source = new Uri("file:///" + data.File.Local.Path);
presenter.Source = UriEx.GetLocal(data.File.Local.Path);

data.Presenter = presenter;
data.Container.Children.Insert(1, presenter);
Expand Down
2 changes: 2 additions & 0 deletions Unigram/Unigram/Common/Emoticon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ public static class Emoticon
{ ":-*", "\U0001F61A" },
{ "B-)", "\U0001F60E" },
{ ":-D", "\U0001F603" },
{ ":D", "\U0001F600" },
{ ";-)", "\U0001F609" },
{ ";)", "\U0001F609" },
{ ";-P", "\U0001F61C" },
{ ":-p", "\U0001F60B" },
{ "3(", "\U0001F614" },
Expand Down
15 changes: 14 additions & 1 deletion Unigram/Unigram/Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
using Unigram.Controls.Messages;
using Unigram.Native;
using Unigram.Navigation;
using Unigram.Navigation.Services;
using Unigram.Services;
using Unigram.Services.Navigation;
using Windows.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;
Expand Down Expand Up @@ -921,4 +921,17 @@ public static WindowContext GetWindowWrapper(this INavigationService service)
public static IDispatcherWrapper GetDispatcherWrapper(this INavigationService service)
=> service.GetWindowWrapper()?.Dispatcher;
}

public static class UriEx
{
public static Uri GetLocal(string path)
{
return new Uri("file:///" + Uri.EscapeUriString(path.Replace('\\', '/')));

var directory = Path.GetDirectoryName(path);
var file = Path.GetFileName(path);

return new Uri("file:///" + directory + "\\" + Uri.EscapeUriString(file));
}
}
}
2 changes: 1 addition & 1 deletion Unigram/Unigram/Common/MessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using Unigram.Controls;
using Unigram.Converters;
using Unigram.Navigation;
using Unigram.Navigation.Services;
using Unigram.Services;
using Unigram.Services.Navigation;
using Unigram.ViewModels;
using Unigram.Views;
using Unigram.Views.Host;
Expand Down

0 comments on commit 2f6d172

Please sign in to comment.