CtrlCore: Developing Cocoa

git-svn-id: svn://ultimatepp.org/upp/trunk@12076 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-07-16 13:07:47 +00:00
parent 8104c07ce4
commit 0f165c8214
22 changed files with 719 additions and 315 deletions

View file

@ -1,11 +1,11 @@
#define GUI_SKELETON
#define GUI_COCO
NAMESPACE_UPP
struct RectCG;
class SystemDraw : public Draw {
public:
virtual dword GetInfo() const;
virtual Size GetPageSize() const;
virtual void BeginOp();
virtual void EndOp();
@ -18,7 +18,7 @@ public:
virtual Rect GetPaintRect() const;
virtual void DrawRectOp(int x, int y, int cx, int cy, Color color);
virtual void SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color);
virtual void SysDrawImageOp(int x, int y, const Image& img, Color color);
virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);
virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
@ -34,60 +34,99 @@ public:
virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
Color ink, int n, const int *dx);
private:
Vector<Point> offset;
Vector<Rect> clip;
int top;
Color fill = Null;
virtual Size GetNativeDpi() const;
virtual void BeginNative();
virtual void EndNative();
void Push();
void Pop();
void *handle;
void ClipCG(const Rect& r);
void FlipY(int& y) { y = top - y; }
Rect GetClip() const { return clip.GetCount() ? clip.Top() : Rect(-999999, -999999, 999999, 999999); }
Point GetOffset() const { return offset.GetCount() ? offset.Top() : Point(0, 0); }
RectCG Convert(int x, int y, int cx, int cy);
RectCG Convert(const Rect& r);
virtual int GetCloffLevel() const;
void Set(Color c);
void Init(void *cgContext, int cy);
virtual ~SystemDraw();
SystemDraw() {}
friend class ImageDraw;
friend class BackDraw;
friend class ViewDraw;
friend class BackDraw__;
Point GetOffset() const { return Point(0, 0); }
bool CanSetSurface() { return false; }
static void Flush() {}
public:
bool CanSetSurface() { return false; }
static void Flush() {} // TODO?
SystemDraw(void *cgContext, int cy);
~SystemDraw();
};
class BackDraw : public SystemDraw {
inline void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff)
{ // TODO: Unless we can do this...
NEVER();
}
class ImageDraw : public SystemDraw {
ImageBuffer ib;
One<ImageDraw> alpha;
void Init(int cx, int cy);
public:
Draw& Alpha();
operator Image();
Image GetStraight();
ImageDraw(Size sz);
ImageDraw(int cx, int cy);
~ImageDraw();
};
struct BackDraw__ : public SystemDraw {
BackDraw__() : SystemDraw() {}
};
class BackDraw : public BackDraw__ { // Dummy only, as we are running in GlobalBackBuffer mode
Size size;
Draw *painting;
Point painting_offset;
ImageBuffer ib;
public:
virtual bool IsPaintingOp(const Rect& r) const;
public:
void Put(SystemDraw& w, int x, int y);
void Put(SystemDraw& w, int x, int y) {}
void Put(SystemDraw& w, Point p) { Put(w, p.x, p.y); }
void Create(SystemDraw& w, int cx, int cy);
void Create(SystemDraw& w, int cx, int cy) {}
void Create(SystemDraw& w, Size sz) { Create(w, sz.cx, sz.cy); }
void Destroy();
void Destroy() {}
void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; }
Point GetOffset() const { return Point(0, 0); }
BackDraw();
~BackDraw();
};
class ImageDraw : public SystemDraw {
SystemDraw alpha;
bool has_alpha;
Size size;
public:
Draw& Alpha();
operator Image() const;
Image GetStraight() const;
ImageDraw(Size sz);
ImageDraw(int cx, int cy);
~ImageDraw();
};
void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n,
Color color, uint64 pattern);
@ -106,11 +145,11 @@ void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rec
#define GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE <CtrlCore/CocoTop.h>
class PrinterJob {
NilDraw nil;
NilDraw nild;
Vector<int> pages;
public:
Draw& GetDraw() { return nil; }
Draw& GetDraw() { return nild; }
operator Draw&() { return GetDraw(); }
const Vector<int>& GetPages() const { return pages; }
int operator[](int i) const { return 0; }

View file

@ -1,6 +1,6 @@
#include <CtrlLib/CtrlLib.h>
#ifdef GUI_SKELETON
#ifdef GUI_COCO
NAMESPACE_UPP

View file

@ -1,7 +1,7 @@
#include <CtrlCore/CtrlCore.h>
#include <plugin/bmp/bmp.h>
#ifdef GUI_SKELETON
#ifdef GUI_COCO
NAMESPACE_UPP

View file

@ -1,6 +1,6 @@
#include <CtrlCore/CtrlCore.h>
#ifdef GUI_SKELETON
#ifdef GUI_COCO
#define LLOG(x) // DLOG(x)

View file

@ -1,4 +1,7 @@
//$ class Ctrl {
private:
void SetImageCursor(const Image& img);
public:
static void EndSession() {}
static bool IsEndSession() { return false; }

View file

@ -1,6 +1,6 @@
#include <CtrlCore/CtrlCore.h>
#ifdef GUI_SKELETON
#ifdef GUI_COCO
NAMESPACE_UPP

View file

@ -1,62 +0,0 @@
#include <CtrlCore/CtrlCore.h>
#ifdef GUI_SKELETON
NAMESPACE_UPP
#define LLOG(x) // LOG(x)
#define LTIMING(x) // RTIMING(x)
/*Rect SystemDraw::GetVirtualScreenArea()
{
GuiLock __;
}*/
dword SystemDraw::GetInfo() const
{
return NATIVE;
}
Size SystemDraw::GetPageSize() const
{
return Size(0, 0);
}
Size SystemDraw::GetNativeDpi() const
{
return Size(96, 96);
}
void SystemDraw::BeginNative()
{
}
void SystemDraw::EndNative()
{
}
int SystemDraw::GetCloffLevel() const
{
return 0;
}
SystemDraw::~SystemDraw() {
GuiLock __;
}
void BackDraw::Destroy()
{
GuiLock __;
}
void BackDraw::Create(SystemDraw& w, int cx, int cy) {
GuiLock __;
}
void BackDraw::Put(SystemDraw& w, int x, int y) {
GuiLock __;
}
END_UPP_NAMESPACE
#endif

168
uppsrc/CtrlCore/CocoDraw.mm Normal file
View file

@ -0,0 +1,168 @@
#include "CocoMM.h"
#ifdef GUI_COCO
namespace Upp {
void SystemDraw::Init(void *cgContext, int cy)
{
handle = cgContext;
top = cy;
Push();
CGContextSetTextPosition(cgHandle, 0, 0);
CGContextSetTextDrawingMode(cgHandle, kCGTextFill);
}
SystemDraw::SystemDraw(void *cgContext, int cy)
{
Init(cgContext, cy);
}
SystemDraw::~SystemDraw()
{
Pop();
}
void SystemDraw::Set(Color c)
{
if(c != fill) {
fill = c;
CGContextSetRGBFillColor(cgHandle, c.GetR() / 255.0, c.GetG() / 255.0, c.GetB() / 255.0, 1.0);
}
}
dword SystemDraw::GetInfo() const
{
return DRAWTEXTLINES;
}
void SystemDraw::Push()
{
CGContextSaveGState(cgHandle);
offset.Add(GetOffset());
clip.Add(GetClip());
}
void SystemDraw::Pop()
{
if(offset.GetCount())
offset.Drop();
if(clip.GetCount())
clip.Drop();
CGContextRestoreGState(cgHandle);
fill = Null;
}
void SystemDraw::BeginOp()
{
Push();
}
void SystemDraw::EndOp()
{
Pop();
}
void SystemDraw::OffsetOp(Point p)
{
Push();
offset.Top() += p;
}
#if 0
CGRect SystemDraw::AsCG(const Rect& r)
{
Point p = r.TopLeft();
Size sz = r.GetSize();
Convert(p.x, p.y);
CGRect cgr;
cgr.origin.x = p.x;
cgr.origin.y = p.y;
cgr.size.width = sz.cx;
cgr.size.height = sz.cy;
return cgr;
}
#endif
RectCG SystemDraw::Convert(int x, int y, int cx, int cy)
{
Point p = GetOffset(); // TODO: Optimize
x += p.x;
y += p.y;
return RectCG(x, top - y - cy, cx, cy);
}
RectCG SystemDraw::Convert(const Rect& r)
{
return Convert(r.left, r.top, r.GetWidth(), r.GetHeight());
}
void SystemDraw::ClipCG(const Rect& r)
{
Size sz = r.GetSize();
CGContextClipToRect(cgHandle, CGRectMake(r.left, top - r.top - sz.cy, sz.cx, sz.cy));
}
bool SystemDraw::ClipOp(const Rect& r)
{
Push();
clip.Top() &= r.Offseted(GetOffset());
ClipCG(clip.Top());
return true;
}
bool SystemDraw::ClipoffOp(const Rect& r)
{
Push();
clip.Top() &= r.Offseted(GetOffset());
offset.Top() += r.TopLeft();
ClipCG(clip.Top());
return true;
}
bool SystemDraw::ExcludeClipOp(const Rect& r)
{
// TODO, perhaps use CGContextClipToRects
return true;
}
bool SystemDraw::IntersectClipOp(const Rect& r)
{
ClipCG(r.Offseted(GetOffset()));
return true;
}
bool SystemDraw::IsPaintingOp(const Rect& r) const
{
// TODO
Rect cr = r.Offseted(GetOffset());
cr.Intersect(GetClip());
return !cr.IsEmpty();
}
Rect SystemDraw::GetPaintRect() const
{
return Rect(0, 0, INT_MAX, INT_MAX);
}
void SystemDraw::DrawRectOp(int x, int y, int cx, int cy, Color color)
{
DLOG("DrawRectOp");
CGRect cgr = Convert(x, y, cx, cy);
if(color == InvertColor()) {
Set(White());
CGContextSetBlendMode(cgHandle, kCGBlendModeExclusion);
CGContextFillRect(cgHandle, cgr);
CGContextSetBlendMode(cgHandle, kCGBlendModeNormal);
}
else {
Set(color);
CGContextFillRect(cgHandle, cgr);
}
}
};
#endif

View file

@ -1,104 +0,0 @@
#include <CtrlCore/CtrlCore.h>
#ifdef GUI_SKELETON
NAMESPACE_UPP
#define LLOG(x) // LOG(x)
#define LTIMING(x) // RTIMING(x)
void SystemDraw::BeginOp()
{
LTIMING("Begin");
GuiLock __;
}
void SystemDraw::OffsetOp(Point p)
{
GuiLock __;
}
bool SystemDraw::ClipOp(const Rect& r)
{
GuiLock __;
return true;
}
bool SystemDraw::ClipoffOp(const Rect& r)
{
GuiLock __;
return true;
}
void SystemDraw::EndOp()
{
GuiLock __;
}
bool SystemDraw::ExcludeClipOp(const Rect& r)
{
GuiLock __;
return true;
}
bool SystemDraw::IntersectClipOp(const Rect& r)
{
GuiLock __;
return true;
}
bool SystemDraw::IsPaintingOp(const Rect& r) const
{
GuiLock __;
return true;
}
Rect SystemDraw::GetPaintRect() const
{
GuiLock __;
return Rect(0, 0, 10000, 1000);
}
void SystemDraw::DrawRectOp(int x, int y, int cx, int cy, Color color)
{
GuiLock __;
}
void SystemDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color)
{
GuiLock __;
}
void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color)
{
GuiLock __;
}
void SystemDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count,
const int *counts, int count_count,
int width, Color color, Color doxor)
{
GuiLock __;
}
void SystemDraw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
const int *subpolygon_counts, int subpolygon_count_count,
const int *disjunct_polygon_counts, int disjunct_polygon_count_count,
Color color, int width, Color outline, uint64 pattern, Color doxor)
{
GuiLock __;
}
void SystemDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color)
{
GuiLock __;
}
void SystemDraw::DrawEllipseOp(const Rect& r, Color color, int width, Color pencolor)
{
GuiLock __;
}
END_UPP_NAMESPACE
#endif

View file

@ -0,0 +1,29 @@
#include "CocoMM.h"
#ifdef GUI_COCO
namespace Upp {
void SystemDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color)
{
}
void SystemDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor)
{
}
void SystemDraw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, const int *subpolygon_counts, int scc, const int *disjunct_polygon_counts, int dpcc, Color color, int width, Color outline, uint64 pattern, Color doxor)
{
}
void SystemDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color)
{
}
void SystemDraw::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor)
{
}
};
#endif

View file

@ -1,16 +0,0 @@
#include <CtrlCore/CtrlCore.h>
#ifdef GUI_SKELETON
NAMESPACE_UPP
#define LLOG(x)
void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink,
int n, const int *dx) {
Std(font);
}
END_UPP_NAMESPACE
#endif

View file

@ -0,0 +1,171 @@
#include "CocoMM.h"
#ifdef GUI_COCO
#define LLOG(x)
#define LTIMING(x)
namespace Upp {
CTFontRef CT_Font(Font fnt)
{ // TODO: Caching (?)
CFRef<CFStringRef> s = CFStringCreateWithCString(NULL, ~fnt.GetFaceName(), kCFStringEncodingUTF8);
CFRef<CTFontRef> ctfont0 = CTFontCreateWithName(s, fnt.GetHeight(), NULL);
if(fnt.IsItalic() || fnt.IsBold()) {
CTFontSymbolicTraits symbolicTraits = 0;
if(fnt.IsBold())
symbolicTraits |= kCTFontBoldTrait;
if(fnt.IsItalic())
symbolicTraits |= kCTFontItalicTrait;
CGAffineTransform transform = CGAffineTransformIdentity;
return CTFontCreateCopyWithSymbolicTraits(ctfont0, 32, &transform, symbolicTraits, symbolicTraits);
}
return ctfont0.Detach();
}
CommonFontInfo GetFontInfoSys(Font font)
{
CommonFontInfo fi;
String path;
CFRef<CTFontRef> ctfont = CT_Font(font);
if(ctfont) {
#if 0
DDUMP(font);
DDUMP(CTFontGetAscent(ctfont));
DDUMP(CTFontGetDescent(ctfont));
DDUMP(CTFontGetLeading(ctfont));
DDUMP(CTFontGetXHeight(ctfont));
DDUMP(CTFontGetUnderlinePosition(ctfont));
#endif
fi.ascent = ceil(CTFontGetAscent(ctfont));
fi.descent = ceil(CTFontGetDescent(ctfont));
fi.height = fi.ascent + fi.descent;
fi.lineheight = fi.height; // TODO!
fi.external = 0;
fi.internal = 0;
fi.overhang = 0;
fi.maxwidth = 99999; // TODO?
fi.avewidth = fi.maxwidth;
fi.default_char = '?';
fi.fixedpitch = false; _DBG_ // TODO!
fi.ttf = true;
_DBG_ // TODO: PATH for data
// if(path.GetCount() < 250)
// strcpy(fi.path, ~path);
// else
*fi.path = 0;
}
return fi;
}
GlyphInfo GetGlyphInfoSys(Font font, int chr)
{
LTIMING("GetGlyphInfoSys");
GlyphInfo gi;
gi.lspc = gi.rspc = 0;
gi.width = 0x8000;
CFRef<CTFontRef> ctfont = CT_Font(font);
if(ctfont) {
LTIMING("GetGlyphInfoSys 2");
CGGlyph glyph_index;
UniChar h = chr;
CTFontGetGlyphsForCharacters(ctfont, &h, &glyph_index, 1);
if(glyph_index) {
CGSize advance;
CTFontGetAdvancesForGlyphs(ctfont, kCTFontOrientationHorizontal, &glyph_index, &advance, 1);
gi.width = ceil(advance.width);
gi.lspc = gi.rspc = 0; _DBG_ // TODO! (using bounding box?)
gi.glyphi = glyph_index;
}
}
return gi;
}
Vector<FaceInfo> GetAllFacesSys()
{
Index<String> facename;
facename.Add("Arial"); // TODO: This should be default GUI font
facename.Add("Times New Roman");
facename.Add("Arial");
facename.Add("Courier New");
AutoreleasePool __;
CFRef<CTFontCollectionRef> collection = CTFontCollectionCreateFromAvailableFonts(0);
if(collection) {
CFRef<CFArrayRef> fonts = CTFontCollectionCreateMatchingFontDescriptors(collection);
if(fonts) {
int count = CFArrayGetCount(fonts);
for(int i = 0; i < count; ++i) {
CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fonts, i);
CFRef<CFStringRef> family_name = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute);
facename.FindAdd(ToString(family_name));
}
}
}
Vector<FaceInfo> r;
for(String s : facename) {
FaceInfo& fi = r.Add();
fi.name = s;
fi.info = 0;
}
return r;
}
String GetFontDataSys(Font font)
{// TODO! CFUrl?
_DBG_
return Null;
}
void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int ch, Font fnt)
{
// TODO!
_DBG_
}
void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink,
int n, const int *dx)
{
DLOG("angle " << angle << ", text " << text << ", ink " << ink);
Set(ink); // needs to be here because rotation saves context...
if(angle) {
// TODO: Fix this!
CGContextSaveGState(cgHandle);
CGContextRotateCTM(cgHandle, 3 * M_PI * angle / 1800);
CGContextTranslateCTM(cgHandle, x, -y);
DrawTextOp(0, 0, 0, text, font, ink, n, dx);
CGContextRestoreGState(cgHandle);
return;
}
CFRef<CTFontRef> ctfont = CT_Font(font);
CFRef<CGFontRef> cgFont = CTFontCopyGraphicsFont(ctfont, NULL);
CGContextSetFont(cgHandle, cgFont);
Point off = GetOffset();
x += off.x;
y = top - y - font.GetAscent() - off.y;
Buffer<CGGlyph> g(n);
Buffer<CGPoint> p(n);
for(int i = 0; i < n; i++) {
int chr = text[i];
GlyphInfo f = GetGlyphInfo(font, chr);
p[i].y = y;
p[i].x = x;
g[i] = f.glyphi;
x += dx ? *dx++ : f.width;
}
CGContextSetFontSize(cgHandle, font.GetHeight());
CGContextShowGlyphsAtPositions(cgHandle, g, p, n);
}
};
#endif

View file

@ -1,71 +0,0 @@
#include <CtrlCore/CtrlCore.h>
#ifdef GUI_SKELETON
//#include <shellapi.h>
NAMESPACE_UPP
#define LTIMING(x) // RTIMING(x)
void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels)
{
GuiLock __;
}
void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size psz, Point poff)
{
GuiLock __;
}
ImageDraw::operator Image() const
{
return Image();
}
Image ImageDraw::GetStraight() const
{
return Image();
}
Draw& ImageDraw::Alpha()
{
if(!has_alpha) {
alpha.DrawRect(size, GrayColor(0));
has_alpha = true;
}
return alpha;
}
ImageDraw::ImageDraw(Size sz)
{
}
ImageDraw::ImageDraw(int cx, int cy)
{
}
ImageDraw::~ImageDraw()
{
}
Image Image::Arrow() { return Null; }
Image Image::Hand() { return Null; }
Image Image::Wait() { return Null; }
Image Image::IBeam() { return Null; }
Image Image::No() { return Null; }
Image Image::SizeAll() { return Null; }
Image Image::SizeHorz() { return Null; }
Image Image::SizeVert() { return Null; }
Image Image::SizeTopLeft() { return Null; }
Image Image::SizeTop() { return Null; }
Image Image::SizeTopRight() { return Null; }
Image Image::SizeLeft() { return Null; }
Image Image::SizeRight() { return Null; }
Image Image::SizeBottomLeft() { return Null; }
Image Image::SizeBottom() { return Null; }
Image Image::SizeBottomRight() { return Null; }
END_UPP_NAMESPACE
#endif

View file

@ -0,0 +1,166 @@
#include "CocoMM.h"
#ifdef GUI_COCO
#define LLOG(x)
namespace Upp {
CGImageRef createCGImage(const Image &img)
{
CGDataProvider *dataProvider = CGDataProviderCreateWithData(NULL, ~img, img.GetLength() * sizeof(RGBA), NULL);
static CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // TODO: This is probably wrong...
Upp::Size isz = img.GetSize();
CGImageRef cg_img = CGImageCreate(isz.cx, isz.cy, 8, 32, isz.cx * sizeof(RGBA),
colorSpace, kCGImageAlphaPremultipliedFirst,
dataProvider, 0, false, kCGRenderingIntentDefault);
CGDataProviderRelease(dataProvider);
return cg_img;
}
struct ImageSysData {
Image img;
CGImageRef cgimg = NULL;
void Init(const Image& img);
~ImageSysData();
};
void ImageSysData::Init(const Image& m)
{
img = m;
cgimg = createCGImage(img);
SysImageRealized(img);
}
ImageSysData::~ImageSysData()
{
DLOG("destruct");
SysImageReleased(img);
CGImageRelease(cgimg);
}
struct ImageSysDataMaker : LRUCache<ImageSysData, int64>::Maker {
Image img;
virtual int64 Key() const { return img.GetSerialId(); }
virtual int Make(ImageSysData& object) const { object.Init(img); return img.GetLength(); }
};
static LRUCache<ImageSysData, int64> cg_image_cache;
void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, Color color)
{
GuiLock __;
if(img.GetLength() == 0)
return;
ImageSysDataMaker m;
LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount());
m.img = IsNull(color) ? img : CachedSetColorKeepAlpha(img, color); // TODO: Can setcolor be optimized out? By masks e.g.?
ImageSysData& sd = cg_image_cache.Get(m);
Size isz = img.GetSize();
CGContextDrawImage(cgHandle, Convert(x, y, isz.cx, isz.cy), sd.cgimg);
cg_image_cache.Shrink(4 * 1024 * 768, 1000); // Cache must be after Paint because of PaintOnly!
}
// TODO:
Image Image::Arrow() { return Image(); }
Image Image::Wait() { return Image(); }
Image Image::IBeam() { return Image(); }
Image Image::No() { return Image(); }
Image Image::SizeAll() { return Image(); }
Image Image::SizeHorz() { return Image(); }
Image Image::SizeVert() { return Image(); }
Image Image::SizeTopLeft() { return Image(); }
Image Image::SizeTop() { return Image(); }
Image Image::SizeTopRight() { return Image(); }
Image Image::SizeLeft() { return Image(); }
Image Image::SizeRight() { return Image(); }
Image Image::SizeBottomLeft() { return Image(); }
Image Image::SizeBottom() { return Image(); }
Image Image::SizeBottomRight() { return Image(); }
Image Image::Cross() { return Image(); }
Image Image::Hand() { return Image(); }
void Ctrl::SetImageCursor(const Image& img)
{
ImageSysDataMaker m;
LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount());
m.img = img;
ImageSysData& sd = cg_image_cache.Get(m);
Point p = img.GetHotSpot();
Size isz = img.GetSize();
NSSize size;
size.width = isz.cx;
size.height = isz.cy;
NSPoint hot;
hot.x = p.x;
hot.y = p.y;
NSImage *nsimg = [[NSImage alloc] initWithCGImage:sd.cgimg size:size];
NSCursor *cursor = [[NSCursor alloc] initWithImage:nsimg hotSpot:hot];
[cursor set];
[cursor release];
[nsimg release];
}
void ImageDraw::Init(int cx, int cy)
{
ib.Create(cx, cy);
static CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // TODO: This is probably wrong...
SystemDraw::Init(CGBitmapContextCreateWithData(~ib, cx, cy, 8, cx * sizeof(RGBA),
colorSpace, kCGImageAlphaPremultipliedFirst,
NULL, NULL), cy);
}
ImageDraw::ImageDraw(Size sz)
{
Init(sz.cx, sz.cy);
}
ImageDraw::ImageDraw(int cx, int cy)
{
Init(cx, cy);
}
Draw& ImageDraw::Alpha()
{
if(!alpha)
alpha.Create(ib.GetSize());
return *alpha;
}
ImageDraw::~ImageDraw()
{
CGContextRelease(cgHandle);
}
Image ImageDraw::GetStraight()
{
if(alpha) {
RGBA *e = ib.End();
RGBA *t = ib;
RGBA *s = alpha->ib;
while(t < e) {
t->a = s->r;
s++;
t++;
}
}
return Image(ib);
}
ImageDraw::operator Image()
{
if(alpha)
return Premultiply(GetStraight());
return Image(ib);
}
};
#endif

54
uppsrc/CtrlCore/CocoMM.h Normal file
View file

@ -0,0 +1,54 @@
#ifndef _CtrlCore_CocoMM_h_
#define _CtrlCore_CocoMM_h_
#define Point NS_Point
#define Rect NS_Rect
#define Size NS_Size
#include <AppKit/AppKit.h>
#undef Point
#undef Rect
#undef Size
#include "CtrlCore.h"
namespace Upp {
template <class T>
struct CFRef {
T ptr;
T operator~() { return ptr; }
operator T() { return ptr; }
T operator->() { return ptr; }
T Detach() { T h = ptr; ptr = NULL; return h; }
CFRef(T p) { ptr = p; }
~CFRef() { if(ptr) CFRelease(ptr); }
};
struct AutoreleasePool {
NSAutoreleasePool *pool;
AutoreleasePool() {
pool = [[NSAutoreleasePool alloc] init];
}
~AutoreleasePool() {
[pool release];
}
};
WString ToWString(CFStringRef s);
String ToString(CFStringRef s);
#define cgHandle (CGContextRef)handle
struct RectCG {
int x, y, cx, cy;
operator CGRect() const { return CGRectMake(x, y, cx, cy); }
RectCG(int x, int y, int cx, int cy) : x(x), y(y), cx(cx), cy(cy) {}
RectCG();
};
}
#endif

View file

@ -1,6 +1,6 @@
#include <CtrlCore/CtrlCore.h>
#ifdef GUI_SKELETON
#ifdef GUI_COCO
//#include <winnls.h>

View file

@ -1,6 +1,6 @@
#include <CtrlCore/CtrlCore.h>
#ifdef GUI_SKELETON
#ifdef GUI_COCO
NAMESPACE_UPP

View file

@ -1,11 +1,27 @@
#include <CtrlCore/CtrlCore.h>
#include "CocoMM.h"
#ifdef GUI_SKELETON
#ifdef GUI_COCO
NAMESPACE_UPP
namespace Upp {
WString ToWString(CFStringRef s)
{
if(!s) return Null;
CFIndex l = CFStringGetLength(s);
if(!l) return Null;
WStringBuffer b(l);
CFStringGetCharacters(s, CFRangeMake(0, l), (UniChar *)~b);
return b;
}
String ToString(CFStringRef s)
{
return ToWString(s).ToString();
}
void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n, Color color, uint64 pattern)
{
// TODO
}
/*
@ -35,6 +51,6 @@ void DrawDragRect(Ctrl& q, const Rect& rect1, const Rect& rect2, const Rect& cli
DrawDragRect(w, rect1, rect2, clip, n, color, sGetAniPat(pattern, animation));
}
END_UPP_NAMESPACE
};
#endif

View file

@ -1,6 +1,6 @@
#include <CtrlCore/CtrlCore.h>
#ifdef GUI_SKELETON
#ifdef GUI_COCO
NAMESPACE_UPP

View file

@ -25,9 +25,8 @@
#elif VIRTUALGUI
#define GUIPLATFORM_KEYCODES_INCLUDE <VirtualGui/Keys.h>
#define GUIPLATFORM_INCLUDE <VirtualGui/VirtualGui.h>
#elif COCO
#define GUIPLATFORM_KEYCODES_INCLUDE <Coco/Keys.h>
#define GUIPLATFORM_INCLUDE <Coco/Coco.h>
#elif flagCOCOA
#define GUIPLATFORM_INCLUDE "Coco.h"
#elif PLATFORM_WIN32
#define GUIPLATFORM_INCLUDE "Win32Gui.h"
#else

View file

@ -124,21 +124,23 @@ file
Cocoa readonly separator,
Coco.h,
CocoAfter.h,
CocoChSysInit.cpp,
CocoClip.cpp,
CocoCtrl.cpp,
CocoCtrl.h,
CocoDnD.cpp,
CocoDraw.cpp,
CocoDrawOp.cpp,
CocoDrawText.cpp,
CocoImage.cpp,
CocoKeys.h,
CocoProc.cpp,
CocoTop.cpp,
CocoTop.h,
CocoUtil.cpp,
CocoMM.h,
CocoUtil.mm,
CocoDraw.mm,
CocoDrawOp.mm,
CocoDrawText.mm,
CocoImage.mm,
CocoCtrl.h,
CocoCtrl.cpp,
CocoWnd.cpp,
CocoClip.cpp,
CocoDnD.cpp,
CocoProc.cpp,
CocoTop.h,
CocoTop.cpp,
CocoChSysInit.cpp,
cocotodo.txt,
"RTF support" readonly separator,
ParseRTF.cpp,
EncodeRTF.cpp,

View file

@ -0,0 +1,10 @@
- PrinterJob
- DrawDragRect
- CT_Font caching
- CommonFontInfo GetFontInfoSys(Font font) metrics
- ROTATED TEXT
- GetGlyphInfoSys metrics
- Default gui font (also in GetAllFacesSys)
- EndSession ?
- Image::Arrow etc...