bsnes/hiro/cocoa/widget/text-edit.cpp

130 lines
3.1 KiB
C++
Raw Normal View History

#if defined(Hiro_TextEdit)
@implementation CocoaTextEdit : NSScrollView
-(id) initWith:(hiro::mTextEdit&)textEditReference {
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
textEdit = &textEditReference;
content = [[[NSTextView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)] autorelease];
[content setDelegate:self];
[content setRichText:NO];
[self setBorderType:NSBezelBorder];
[self setDocumentView:content];
[self configure];
}
return self;
}
-(NSTextView*) content {
return content;
}
-(void) configure {
[content setMinSize:NSMakeSize(0, 0)];
[content setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[[content textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[[content textContainer] setWidthTracksTextView:textEdit->wordWrap()];
[content setHorizontallyResizable:YES];
[content setVerticallyResizable:YES];
[content setAutoresizingMask:NSViewNotSizable];
[self setHasHorizontalScroller:!textEdit->wordWrap()];
[self setHasVerticalScroller:YES];
}
-(void) textDidChange:(NSNotification*)notification {
textEdit->state.text = [[content string] UTF8String];
textEdit->doChange();
}
@end
namespace hiro {
auto pTextEdit::construct() -> void {
@autoreleasepool {
cocoaView = cocoaTextEdit = [[CocoaTextEdit alloc] initWith:self()];
pWidget::construct();
setEditable(state().editable);
setWordWrap(state().wordWrap);
setText(state().text);
setTextCursor(state().textCursor);
}
Update to v094r08 release. byuu says: Lots of changes this time around. FreeBSD stability and compilation is still a work in progress. FreeBSD 10 + Clang 3.3 = 108fps FreeBSD 10 + GCC 4.7 = 130fps Errata 1: I've been fighting that god-damned endian.h header for the past nine WIPs now. The above WIP isn't building now because FreeBSD isn't including headers before using certain types, and you end up with a trillion error messages. So just delete all the endian.h includes from nall/intrinsics.hpp to build. Errata 2: I was trying to match g++ and g++47, so I used $(findstring g++,$(compiler)), which ends up also matching clang++. Oops. Easy fix, put Clang first and then else if g++ next. Not ideal, but oh well. All it's doing for now is declaring -fwrapv twice, so you don't have to fix it just yet. Probably just going to alias g++="g++47" and do exact matching instead. Errata 3: both OpenGL::term and VideoGLX::term are causing a core dump on BSD. No idea why. The resources are initialized and valid, but releasing them crashes the application. Changelog: - nall/Makefile is more flexible with overriding $(compiler), so you can build with GCC or Clang on BSD (defaults to GCC now) - PLATFORM_X was renamed to PLATFORM_XORG, and it's also declared with PLATFORM_LINUX or PLATFORM_BSD - PLATFORM_XORG probably isn't the best name ... still thinking about what best to call LINUX|BSD|SOLARIS or ^(WINDOWS|MACOSX) - fixed a few legitimate Clang warning messages in nall - Compiler::VisualCPP is ugly as hell, renamed to Compiler::CL - nall/platform includes nall/intrinsics first. Trying to move away from testing for _WIN32, etc directly in all files. Work in progress. - nall turns off Clang warnings that I won't "fix", because they aren't broken. It's much less noisy to compile with warnings on now. - phoenix gains the ability to set background and foreground colors on various text container widgets (GTK only for now.) - rewrote a lot of the MSU1 code to try and simplify it. Really hope I didn't break anything ... I don't have any MSU1 test ROMs handy - SNES coprocessor audio is now mixed as sclamp<16>(system_sample + coprocessor_sample) instead of sclamp<16>((sys + cop) / 2) - allows for greater chance of aliasing (still low, SNES audio is quiet), but doesn't cut base system volume in half anymore - fixed Super Scope and Justifier cursor colors - use input.xlib instead of input.x ... allows Xlib input driver to be visible on Linux and BSD once again - make install and make uninstall must be run as root again; no longer using install but cp instead for BSD compatibility - killed $(DESTDIR) ... use make prefix=$DESTDIR$prefix instead - you can now set text/background colors for the loki console via (eg): - settings.terminal.background-color 0x000000 - settings.terminal.foreground-color 0xffffff
2014-02-24 09:39:09 +00:00
}
auto pTextEdit::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}
auto pTextEdit::setBackgroundColor(Color color) -> void {
}
auto pTextEdit::setEditable(bool editable) -> void {
@autoreleasepool {
[[cocoaView content] setEditable:(editable && self().enabled(true))];
}
}
auto pTextEdit::setEnabled(bool enabled) -> void {
pWidget::setEnabled(enabled);
Update to v097 release. byuu says: This release features improvements to all emulation cores, but most substantially for the Game Boy core. All of blargg's test ROMs that pass in gambatte now either pass in higan, or are off by 1-2 clocks (the actual behaviors are fully emulated.) I consider the Game Boy core to now be fairly accurate, but there's still more improvements to be had. Also, what's sure to be a major feature for some: higan now has full support for loading and playing ordinary ROM files, whether they have copier headers, weird extensions, or are inside compressed archives. You can load these games from the command-line, from the main Library menu (via Load ROM Image), or via drag-and-drop on the main higan window. Of course, fans of game folders and the library need not worry: that's still there as well. Also new, you can drop the (uncompressed) Game Boy Advance BIOS onto the higan main window to install it into the correct location with the correct file name. Lastly, this release technically restores Mac OS X support. However, it's still not very stable, so I have decided against releasing binaries at this time. I'd rather not rush this and leave a bad first impression for OS X users. Changelog (since v096): - higan: project source code hierarchy restructured; icarus directly integrated - higan: added software emulation of color-bleed, LCD-refresh, scanlines, interlacing - icarus: you can now load and import ROM files/archives from the main higan menu - NES: fixed manifest parsing for board mirroring and VRC pinouts - SNES: fixed manifest for Star Ocean - SNES: fixed manifest for Rockman X2,X3 - GB: enabling LCD restarts frame - GB: emulated extra OAM STAT IRQ quirk required for GBVideoPlayer (Shonumi) - GB: VBK, BGPI, OBPI are readable - GB: OAM DMA happens inside PPU core instead of CPU core - GB: fixed APU length and sweep operations - GB: emulated wave RAM quirks when accessing while channel is enabled - GB: improved timings of several CPU opcodes (gekkio) - GB: improved timings of OAM DMA refresh (gekkio) - GB: CPU uses open collector logic; return 0xFF for unmapped memory (gekkio) - GBA: fixed sequencer enable flags; fixes audio in Zelda - Minish Cap (Jonas Quinn) - GBA: fixed disassembler masking error (Lioncash) - hiro: Cocoa support added; higan can now be compiled on Mac OS X 10.7+ - nall: improved program path detection on Windows - higan/Windows: moved configuration data from %appdata% to %localappdata% - higan/Linux,BSD: moved configuration data from ~/.config/higan to ~/.local/higan
2016-01-17 08:59:25 +00:00
setEditable(state().editable); //Cocoa lacks NSTextView::setEnabled; simulate via setEnabled()
}
auto pTextEdit::setFont(const Font& font) -> void {
@autoreleasepool {
[[cocoaView content] setFont:pFont::create(font)];
}
}
auto pTextEdit::setForegroundColor(Color color) -> void {
Update to v094r08 release. byuu says: Lots of changes this time around. FreeBSD stability and compilation is still a work in progress. FreeBSD 10 + Clang 3.3 = 108fps FreeBSD 10 + GCC 4.7 = 130fps Errata 1: I've been fighting that god-damned endian.h header for the past nine WIPs now. The above WIP isn't building now because FreeBSD isn't including headers before using certain types, and you end up with a trillion error messages. So just delete all the endian.h includes from nall/intrinsics.hpp to build. Errata 2: I was trying to match g++ and g++47, so I used $(findstring g++,$(compiler)), which ends up also matching clang++. Oops. Easy fix, put Clang first and then else if g++ next. Not ideal, but oh well. All it's doing for now is declaring -fwrapv twice, so you don't have to fix it just yet. Probably just going to alias g++="g++47" and do exact matching instead. Errata 3: both OpenGL::term and VideoGLX::term are causing a core dump on BSD. No idea why. The resources are initialized and valid, but releasing them crashes the application. Changelog: - nall/Makefile is more flexible with overriding $(compiler), so you can build with GCC or Clang on BSD (defaults to GCC now) - PLATFORM_X was renamed to PLATFORM_XORG, and it's also declared with PLATFORM_LINUX or PLATFORM_BSD - PLATFORM_XORG probably isn't the best name ... still thinking about what best to call LINUX|BSD|SOLARIS or ^(WINDOWS|MACOSX) - fixed a few legitimate Clang warning messages in nall - Compiler::VisualCPP is ugly as hell, renamed to Compiler::CL - nall/platform includes nall/intrinsics first. Trying to move away from testing for _WIN32, etc directly in all files. Work in progress. - nall turns off Clang warnings that I won't "fix", because they aren't broken. It's much less noisy to compile with warnings on now. - phoenix gains the ability to set background and foreground colors on various text container widgets (GTK only for now.) - rewrote a lot of the MSU1 code to try and simplify it. Really hope I didn't break anything ... I don't have any MSU1 test ROMs handy - SNES coprocessor audio is now mixed as sclamp<16>(system_sample + coprocessor_sample) instead of sclamp<16>((sys + cop) / 2) - allows for greater chance of aliasing (still low, SNES audio is quiet), but doesn't cut base system volume in half anymore - fixed Super Scope and Justifier cursor colors - use input.xlib instead of input.x ... allows Xlib input driver to be visible on Linux and BSD once again - make install and make uninstall must be run as root again; no longer using install but cp instead for BSD compatibility - killed $(DESTDIR) ... use make prefix=$DESTDIR$prefix instead - you can now set text/background colors for the loki console via (eg): - settings.terminal.background-color 0x000000 - settings.terminal.foreground-color 0xffffff
2014-02-24 09:39:09 +00:00
}
auto pTextEdit::setGeometry(Geometry geometry) -> void {
pWidget::setGeometry(geometry);
[cocoaView configure];
}
auto pTextEdit::setText(const string& text) -> void {
@autoreleasepool {
[[cocoaView content] setString:[NSString stringWithUTF8String:text]];
}
}
auto pTextEdit::setTextCursor(TextCursor cursor) -> void {
@autoreleasepool {
//todo: handle text selection (cursor.length())
string text = [[[cocoaView content] string] UTF8String];
auto offset = min(cursor.offset(), text.length());
[[cocoaView content] setSelectedRange:NSMakeRange(offset, 0)];
}
}
auto pTextEdit::setWordWrap(bool wordWrap) -> void {
@autoreleasepool {
[cocoaView configure];
}
}
auto pTextEdit::text() const -> string {
@autoreleasepool {
return [[[cocoaView content] string] UTF8String];
}
}
auto pTextEdit::textCursor() const -> TextCursor {
//TODO
return state().textCursor;
}
}
#endif