在 OS X 上的 Cocoa 中实现自定义 NSView
我正在创建一个 Cocoa 应用程序,其中一个视图将包含当前加载文档的“十六进制转储”。到目前为止,我一直在使用沼泽标准(并且非常没有吸引力)NSTextField
,但我现在正在寻找更强大的东西。
我是 0xED.app
的忠实粉丝,并且会喜欢复制其主要的“十六进制转储”视图。我该怎么做呢?
我不一定追求养眼的效果,而是能够选择一系列字节而无需选择偏移量或文本列。我什至不知道从哪里开始有效地实施这一点。这肯定不是在空白画布上绘制的吗?
I am creating a Cocoa application wherein one view will contain the "hex dump" of the currently loaded document. Up until this point, I have been using a bog-standard (and very unappealing) NSTextField
, but I am now looking for something more powerful.
I am a great fan of 0xED.app
and would love to replicate its main "hex dump" view. How would I go about doing this?
I'm not necessarily after the eye-candy, but the ability to select a range of bytes without also selecting the offset or text columns. I am a loss as to where I would even begin to implement this effectively. Surely this is not drawn upon a blank canvas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要开始并了解事情的基本工作原理:
对于大量数据,这种方法会很慢,但可以让您很好地实现 NSView 子类。之后,您将希望通过实现比重复调用一次绘制一个字符串更好的方法来提高绘制性能。您还需要实现 mouseDown: 和 keyDown: 等方法的重写,以处理用户的输入,以允许选择字节范围等操作。
这应该可以帮助您开始,一旦您开始这样做,我建议您提出后续问题。
To get started and see how things basically work:
This approach will be slow for a large amount of data, but will give you a good handle on implementing a NSView subclass. After that, you'll want to improve the drawing performance by implementing something better than repeated calls to draw strings one at a time. You'll also want to implement overrides of methods like mouseDown: and keyDown: to handle input from the user to allow things like selecting a range of bytes.
That should get you started, once you have that going, I'd suggest asking follow up questions.
我的猜测是,它可能是使用 NSTableView 或其子类。
以这种方式完成正确的文本选择可能有点棘手,但这可能是可能的。
My guess is that it's probably accomplished using a NSTableView or subclass of it.
It might be a little tricky to get the correct text selection accomplished this way, but it's probably possible.
如果你想看看 Cocoa 界面是如何构建的,你可以使用 NibToXibConverter。
双击 XIB 在 XCode 中打开它,您可以看到它们是如何构造的
If you want to take a look at how a Cocoa interface is built you can use NibToXibConverter.
Double click a XIB to open it in XCode and you can see how they are constructed