心寄笔端 附庸风雅

甘草的技术博客

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  16 随笔 :: 78 文章 :: 12 评论 :: 0 引用

公告

2012年2月15日 #

... ...最近写了一个RichTextView。

支持<text>, <s>, <a> <img> 等标签。

我没法给出全部代码,只会讲述一下面向对象的结构。真是的,在GDI时代,已实现过一次了,还真累。

1. 要有一个描述Style的class,[本篇文章class以C作为前缀,于是该类就是CStyle]

对于iOS来说,Font的size,和是否bold,都在UIFont中了,不需要额外定义相关成员。否则冗余。

还要有个UIColor成员,和确定是否需要Word-Wrap的成员。

2. 有个好的Element派生结构

CElement作为基类,派生出CTextElement和CImageElement,还可以有其他的,比如说CTableElement[不过我是没有实现了]。

 

3. 关于CTextElement更多的细节

我把Text-element作为section的Holder,<s>, 和<a>, s表示string,a表示link。

4. Line-Height简化高度计算

5. 加入textOnly熟悉,以加速和简化纯文本的绘制。

6.  

 

 

posted @ 2012-02-15 23:47 甘草 阅读(47) 评论(0) 编辑

2012年1月19日 #

我感觉,这个可以Win32里面的while( PeekMessage( ... ) )是一会儿事情。比较简单。

CFRunLoopRun();就完成了这个事情。

那么如何解除这个Block呢?

可以用这个:

CFRunLoopStop( someLoop );

someLoop可以通过CFRunLoopGetCurrent()函数来获得。

这样就可以轻易地等待各种线程了,比如说动画线程。

 

@interface UIViewDelegate : NSObject
{
	CFRunLoopRef     _currentLoop;
}
@end

@implementation UIViewDelegate
-(id) init:(CFRunLoopRef)runLoop 
{
	if (self = [super init]) 
              _currentLoop = runLoop;
	return self;
}

-(void) animationFinished: (id) sender
{
	CFRunLoopStop(_currentLoop);
}
@end

@implementation UIView (Block)
+ (void) commitAnimationsAndBlock
{
	CFRunLoopRef currentLoop = CFRunLoopGetCurrent();
	UIViewDelegate *delegate = [[UIViewDelegate alloc] init:currentLoop];
	[UIView setAnimationDelegate:delegate];
	[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
	[UIView commitAnimations];
	CFRunLoopRun();
	[delegate release];
}
@end

  

posted @ 2012-01-19 17:09 甘草 阅读(65) 评论(0) 编辑

2012年1月18日 #

1.

 

2.

posted @ 2012-01-18 11:17 甘草 阅读(184) 评论(0) 编辑

2012年1月12日 #

1,怎么使用Block

1.1 Block是iOS SDK中的一个语法点,我觉得可以和C语言的函数指针和C++11里面的Lambda进行类比。

搞iOS,不想太抠语法,作为一个搞C++ templates的人啊,哥烦了。

 

Block,我猜测是一个栈的指针对象,出了作用域就无效了,我试过 retain 一个 block对象,但是无果。

后来发现 Block_copy函数。。。

#define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__)))
#define Block_release(...) _Block_release((const void *)(__VA_ARGS__))

用这个复制一份,就可以真正的持有了。你把它想象为一个C++的函数对象好了。特别是某个函数对象是个栈对象的时候~

1.2 其他的内容

2,真机上面出问题

2.1 我的iPad是iOS5.0的版本,居然在Block上面有问题。

2.2 先不解决了,用delegate和@selector吧

posted @ 2012-01-12 11:28 甘草 阅读(50) 评论(0) 编辑

2012年1月9日 #

1. CATransform3D结构成员的意义。

struct CATransform3D
{
CGFloat m11(x缩放), m12(y切变), m13(旋转), m14();
CGFloat m21(x切变), m22(y缩放), m23(), m24();
CGFloat m31(旋转), m32(), m33(), m34(透视效果,要操作的这个对象要有旋转的角度,否则没有效果。正直/负值都有意义);
CGFloat m41(x平移), m42(y平移), m43(z平移), m44();
}; 

ps:整体比例变换时,也就是m11==m22时,若m33>1,图形整体缩小,若0<m33<1,图形整体放大,若s<0,发生关于原点的对称等比变换。

()空的地方以后补充。

2. CATransform3DMakeTranslation

CATransform3DMakeTranslation(0, 0, 0) 创建了一个4*4的单位矩阵。

3. CATransform3DMakeRotation And CATransform3DRotate

CATransform3DMakeRotation()

    _transformedLayer = [CALayer layer];
    _transformedLayer.frame = self.bounds;
    _transformedLayer.anchorPoint = CGPointMake(0.5f, 0.5f);
    CATransform3D sublayerTransform = CATransform3DIdentity;
    // Set perspective
    sublayerTransform.m34 = kPerspective;
    [_transformedLayer setSublayerTransform:sublayerTransform];
    
    [self.layer addSublayer:_transformedLayer];
    //init Sublayers
    CATransform3D t = CATransform3DMakeTranslation(0, 0, 0);
    // take snapshot of the current view
    [_transformedLayer addSublayer:[self snapshot:t 
                                         withView:_contentView 
                                         isMasked:YES]];
    // 暂时先支持一个方向翻转
    RotateDirection direction = RotateFromBottom;
    if (YES || direction == RotateFromBottom)
    {
        CGFloat height = self.bounds.size.height;
        //CGFloat cubeSize = 100.0f;
        t = CATransform3DRotate(t, D2R(90.0), 1, 0, 0);【1】
        t = CATransform3DTranslate(t, 0, height, 0);
        CALayer *subLayer = [self snapshot:t withView:view isMasked:YES];
        [_transformedLayer addSublayer:subLayer];
    }
    else 
    {
    }
    
    _newContentView = view;
    
    [self animationCubeRotate:direction withDuration:duration];

  

4. 翻转的动画

- (void)animationCubeRotate:(RotateDirection)direction 
               withDuration:(float)duration
{
    [CATransaction flush];
    CGFloat height = self.bounds.size.height;
    CABasicAnimation *rotation;
    // CABasicAnimation *translationX;	// 如果沿X轴翻转,则用不到这个变量.
    CABasicAnimation *translationY;	// 如果沿Y轴翻转,则用不到这个变量.
    CABasicAnimation *translationZ;
    CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
    animationGroup.delegate = self;
    animationGroup.duration = duration;
    
    if ( direction == RotateFromBottom )
    {
        // 创建(某方向)关键帧动画.
        translationY = [CABasicAnimation animationWithKeyPath:
                        @"sublayerTransform.translation.y"];
        translationY.toValue = [NSNumber numberWithFloat:-(height / 2)];【2】
        rotation = [CABasicAnimation animationWithKeyPath:
                    @"sublayerTransform.rotation.x"];
        rotation.toValue = [NSNumber numberWithFloat:D2R(-90.0f)];
    } 
    else if ( direction == RotateFromTop )
    {
    }
    
    // 处理Z轴
    translationZ = [CABasicAnimation animationWithKeyPath:
                    @"sublayerTransform.translation.z"];
    translationZ.toValue = [NSNumber numberWithFloat:height / 2];【3】
    animationGroup.animations = 
    	[NSArray arrayWithObjects: rotation, translationY, translationZ, nil];
    animationGroup.fillMode = kCAFillModeForwards;
    animationGroup.removedOnCompletion = NO;
    [_transformedLayer addAnimation:animationGroup forKey:kAnimationKey];
}

made, 我发现这个东西确实很难讲清楚,主要是因为我理论薄弱,

【1】针对X轴旋转,就是1,0,0,针对Y轴旋转,就是0,1,0...下面那行也要进行正确的转换。

【2】此处应该是和 anchorPoint有关系的。

【3】这个值会影响类似于深度的东西,比如说Cube会离我们更近,或者是更远。(但是,似乎不算是透视关系)

posted @ 2012-01-09 22:30 甘草 阅读(595) 评论(0) 编辑

2011年12月31日 #

摘要: 编译成功,运行没有窗口。http://stackoverflow.com/questions/8680550/create-a-nswindow-under-c本质原因是Bundle相关的:http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html阅读全文
posted @ 2011-12-31 21:53 甘草 阅读(28) 评论(0) 编辑

摘要: 1. SEL和IMP最早我把SEL理解为函数指针,现在看来,不是这样的。1.1 SEL类型SEL类型的变量,可以通过@selector(方法名)来取得,当然了,Objective C的方法名,我们也知道了,多么恶心(比Java废话还多)。而它真正得到的,只要方法名一样,它的值就是一样的,不管这个方法定义于哪个类,是不是实例方法【再说了,@selector的时候,除了方法名也没有什么类啊,对象啊什么事情】。所以我现在把它理解为“方法名的某种映射结果”。(从C++程序员的眼光看,我觉得没啥可以对应的,既不是函数指针,也不是函数指针类型,像是函数指针类型的名字吧。)1.2 IMP类型这个才是函数指针阅读全文
posted @ 2011-12-31 16:58 甘草 阅读(75) 评论(0) 编辑

2011年12月29日 #

摘要: 1.transitionFromView它会做这样的事情[fromViewremoveFromSuperview];所以我会持有UIView对象,保证它不会release到retain count 0. 然后把remove的View,重新insert进来,以应对被remove的情况。2.alwaysBounceVertical的弹力效果_scrollView.alwaysBounceVertical=YES;让某个UIView能产生某种垂直的“弹力效果”,可以把这个UIView加到一个UIScrollView上,然后设置alwaysBounceVertical=YES;3.UIViewAnim阅读全文
posted @ 2011-12-29 22:38 甘草 阅读(33) 评论(0) 编辑

摘要: 关于内存管理1. 如何正确返回一个NSArray对象...– (NSArray *)sprockets { NSArray *array = [NSArray arrayWithObjects:mainSprocket, auxiliarySprocket, nil]; return array;}函数中使用调用autorelease的方法在array不被需要时将其释放,因此不得到这个对象的所有权,但是又可以使用它。Final. 原则总结1. 想持有对象的,要主动retain和release。自己来掌握时机。(不想持有对象...阅读全文
posted @ 2011-12-29 18:19 甘草 阅读(39) 评论(0) 编辑

2011年11月5日 #

摘要: 1.SaveDC和RestoreDC.说起来很费解,不如写个代码show下它们的能力~// DCLib... ...void Draw(HDC hdc){ // Draw a line (10, 10) - (190, 190) MoveToEx(hdc, 10, 10, (LPPOINT)NULL); LineTo(hdc, 190, 190); // comments? [2] SaveDC(hdc); // comments? [1] IntersectClipRect(hdc, 20, 20, 100, 100); // Draw a r...阅读全文
posted @ 2011-11-05 11:40 甘草 阅读(29) 评论(0) 编辑

2011年10月31日 #

摘要: 玩Python搞HTTP用什么库?1.http.client是实现了RFC2616, HTTP协议的底层库.2.urllib.request建立在http.client之上一个抽象层. 它为访问HTTP和FTP服务器提供了一个标准的api,可以自动跟随HTTP重定向,并且处理了一些常见形式的HTTP认证.3.第三方的开源库,它比http.client更完整的实现了HTTP协议,同时比urllib.request提供了更好的抽象.阅读全文
posted @ 2011-10-31 17:45 甘草 阅读(14) 评论(0)  编辑

摘要: [专门研究PlgBlt]:BOOLPlgBlt(HDChdcDest,//handletodestinationDCCONSTPOINT*lpPoint,//destinationvertices // 目标DC的三点,顺序是从左上角->右上角->左下角,映射到Source的RECT DC.HDChdcSrc,//handletosourceDCintnXSrc,//x-coordofsourceupper-leftcornerintnYSrc,//y-coordofsourceupper-leftcornerintnWidth,//widthofsourcerectangle..阅读全文
posted @ 2011-10-31 11:29 甘草 阅读(21) 评论(0) 编辑

2011年10月12日 #

摘要: 1.CCustomDraw和LVS_OWNERDRAWFIXED我发现我去掉了LVS_OWNERDRAWFIXED风格,继承了CCustomDraw的CListView自绘就OK了。2.CCustomDraw<T>CCustomDraw<T>利用静多态,给派生类一个可以定制自绘Options的策略。//customdrawreturnflags//valuesunder0x00010000arereservedforglobalcustomdrawvalues.//abovethatareforspecificcontrols#defineCDRF_DODEFAULT0阅读全文
posted @ 2011-10-12 20:59 甘草 阅读(162) 评论(0) 编辑

2011年9月24日 #

摘要: [接上篇]封装目标: 最终目标是封装WinSock的WSAAsyncSelectIO模型。封装原则: 耦合性[减少各种依赖,包括classes之间,编译模块之间。],小粒度增加可复用性。依赖ATL/WTL。CKxAsyncSocket是我要实现的class,它只需要维护SOCKET成员,另外因为是异步选择,所以可以再维护一个HWND。关于HWND,是否有必要暴露给用户,关键在于Socket要仅仅运行于UI主线程,还是用户可以自己创建另一个有消息循环的Thread,在其上处理Socket的消息。我选择后者,因为,尽管异步的Socket,在Recv大数据的时候,还是可能导致UI“卡”的。那么,我们阅读全文
posted @ 2011-09-24 16:21 甘草 阅读(95) 评论(0) 编辑

2011年9月20日 #

摘要: [WTL]调用JS有两种办法,一种是依赖于IWebBrowser接口的,就是可以操纵Web的。我们先说另外一种,把JScript(VBS)当纯脚本调用的。部分参考了这个BLOG:http://www.cppblog.com/free2000fly/archive/2009/05/23/85549.html保存下面的内容为 a.wsc:<?xmlversion="1.0"encoding="UTF-8"?><?componenterror="true"debug="true"?><com阅读全文
posted @ 2011-09-20 23:16 甘草 阅读(83) 评论(0) 编辑

2011年8月29日 #

摘要: 1.REFLECT_NOTIFICATIONS macro笔者(就不自称寡人了),试验了两天两夜,终于有些要领了。我的主窗口,不加REFLECT_NOTIFICATIONS 或者REFLECT_NOTIFICATIONS_EX,自绘的CListBox Items就显示不出来。---- ---- ----在WTL使用中,需要注意的是CListBox风格 |= LBS_OWNERDRAWFIXED和LBS_HASSTRINGS,需要在消息宏添加REFLECT_NOTIFICATION()以支持自绘消息。这个宏调用的是函数CWindowImplRoot::ReflectNotifications。这阅读全文
posted @ 2011-08-29 14:15 甘草 阅读(126) 评论(0) 编辑

2011年8月25日 #

摘要: 1. 实现自绘窗口的Resize自绘的主窗口,往往没有WS_BORDER【特别是Win7下的Border,厚厚的~】,但是没有Border,就等于没有了WS_SIZEBOX。那么我们怎么样才能实现同等的功能呢?接管以下三个消息:MESSAGE_HANDLER(WM_NCHITTEST,OnNcHitTest)MESSAGE_HANDLER(WM_SETCURSOR,OnSetCursor)MESSAGE_HANDLER(WM_NCLBUTTONDOWN,OnNcLButtonDown)第一个好说,到处都是MFC的例子,判断以下Border的位置,返回HTBOTTOMRIGHT这些值即可。Cur阅读全文
posted @ 2011-08-25 13:52 甘草 阅读(65) 评论(0) 编辑

2011年5月4日 #

摘要: 1. IDEPyScripter今天用PyScripter(最新版)发现Module和Packages怎么就是不对呢?后来才发现代码没有问题,是IDE的事情:设置PyScripter的Python引擎为远程即可,内部的好像对其他modules的变化不是很感冒。阅读全文
posted @ 2011-05-04 23:39 甘草 阅读(27) 评论(0)  编辑

2011年3月6日 #

摘要: 1. 安装pywin32-216.1.win32-py3.2.exe http://sourceforge.net/projects/pywin32/files/pywin32/Build216/有为Python各个版本的Build。2. import import win32apiimport win32guiimport win32con3. 例子 defmain():win32gui.MessageBox(None,"Python","PythonWin32Call",win32con.MB_OK)modPath =win32api.GetModu阅读全文
posted @ 2011-03-06 16:55 甘草 阅读(348) 评论(0)  编辑

2011年2月19日 #

摘要: 我不经常写Python代码,所以记不住很多Python API,要是Win32 API嘛,在IBM写了3年HTML,JavaScript后,再写Windows程序,还是记得住很多API的参数。1. Python2 Python3的差别http://diveintopython3.org/porting-code-to-python-3-with-2to3.html2. 字符串字面量"Python"r"c:\windows"u"您好"ur"c:\新建文件夹"3. 字符串操作字符串长度Code highlighting阅读全文
posted @ 2011-02-19 00:10 甘草 阅读(66) 评论(0)  编辑

仅列出标题  下一页
Baidu
Google
心寄笔端
TEST
以后我会加上Power By的,先别介意