2 * psychlops_widgets_osx.cpp
3 * Psychlops Standard Library (OSX)
5 * Last Modified 2009/12/14 by Kenchi HOSOKAWA
6 * (C) 2009 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
10 #include <AppKit/AppKit.h>
11 #include "../../../core/ApplicationInterfaces/psychlops_code_exception.h"
12 #include "../../../extension/standard/widgets/psychlops_widget.h"
13 #include "../psychlops_app_tweak_osx.h"
21 void alert(std::string message)
23 boolean_t mouse_visible = CGCursorIsVisible();
24 if(!mouse_visible) CGDisplayShowCursor( kCGDirectMainDisplay );
25 NSString *str = [[ NSString alloc ] autorelease];
26 [str initWithCString: message.c_str() ];
27 NSAlert *alert = [[ NSAlert alertWithMessageText: @"Alert"
31 informativeTextWithFormat: @"Notification" ] autorelease];
32 if(!mouse_visible) CGDisplayHideCursor( kCGDirectMainDisplay );
35 void alert(std::wstring message)
37 boolean_t mouse_visible = CGCursorIsVisible();
38 if(!mouse_visible) CGDisplayShowCursor( kCGDirectMainDisplay );
39 NSString *str = [[NSString alloc] autorelease];
40 [ str initWithBytes: message.c_str()
41 length: message.length()
42 encoding: NSUnicodeStringEncoding ];
43 NSAlert *alert = [[ NSAlert alertWithMessageText: @"Alert"
47 informativeTextWithFormat: @"Notification" ] autorelease];
49 if(!mouse_visible) CGDisplayHideCursor( kCGDirectMainDisplay );
52 std::string getOpenFileName()
54 boolean_t mouse_visible = CGCursorIsVisible();
55 if(!mouse_visible) CGDisplayShowCursor( kCGDirectMainDisplay );
56 NSOpenPanel *openBox = [ NSOpenPanel openPanel ];
57 //[ openBox setTitle: @"Select File" ];
58 [ openBox setAllowsMultipleSelection: NO ];
60 if(!mouse_visible) CGDisplayHideCursor( kCGDirectMainDisplay );
61 const char *url = [ [ [ openBox URL ] path ] UTF8String ];
64 if(url!=0) result = url;
67 catch (std::exception e) {
73 } /* <- namespace Dialog */
79 CloseButton::CloseButton()
82 theme_type = Widgets::Theme::ALERT;
83 Button::onClick = &exitApp;
84 label.font.weight = Font::bold;
85 label.fill = Color::white;
87 void CloseButton::exitApp()
89 if(AppState::shouldBeClose) exit(0);
90 AppState::shouldBeClose = true;
93 MinimizeButton::MinimizeButton(Canvas &target)
98 Button::onClickP = &minimizeApp;
99 label.font.weight = Font::bold;
100 label.fill = Color::white;
102 void MinimizeButton::minimizeApp(void *hwnd)
104 MinimizeButton *button = (MinimizeButton*)(hwnd);
105 button->pushed_ = false;
106 // HWND window = Psychlops::DebugTweakTool::getRawWindowHandle(*(button->window));
107 // ShowWindow( window, SW_MINIMIZE );
111 TitleBar::TitleBar(Canvas &target)
112 : mleft(Mouse::left), minimize(target)
115 area.set(target.getWidth()-85, 20);
116 area.fill = Color::white;
117 close.area.set(50, 20).setDatum(Point(target.getWidth()-55, 0));
118 minimize.area.set(30, 20).setDatum(Point(target.getWidth()-85, 0));
121 TitleBar& TitleBar::draw(Drawable &target)
124 Canvas *cnvs = dynamic_cast<Canvas*>(&target);
126 TRACKMOUSEEVENT eventTrack;
129 HWND window = Psychlops::DebugTweakTool::getRawWindowHandle(*cnvs);
132 if(area.include(Mouse::position)) {
133 GetWindowRect(window, &rect);
134 begin_w.set(rect.left, rect.top);
135 begin_w_size.set(rect.right - rect.left, rect.bottom - rect.top);
136 begin_m = Mouse::uniPosition;
137 GetCursorPos(&mousept);
138 eventTrack.cbSize = sizeof(TRACKMOUSEEVENT);
139 eventTrack.dwFlags = TME_LEAVE;
140 eventTrack.hwndTrack = window;
141 eventTrack.dwHoverTime = 100;
142 TrackMouseEvent(&eventTrack);
143 DragDetect( window, mousept );
144 //ClipCursor( rect );
147 } else if(mleft.pressed() && dragged_) {
148 GetWindowRect(window, &rect);
149 Point p = (Point)Mouse::uniPosition - begin_m, np = p + begin_w;
150 MoveWindow(window, np.x, np.y, begin_w_size.x, begin_w_size.y, false);
151 eventTrack.cbSize = sizeof(TRACKMOUSEEVENT);
152 eventTrack.dwFlags = TME_LEAVE;
153 eventTrack.hwndTrack = window;
154 eventTrack.dwHoverTime = 100;
155 TrackMouseEvent(&eventTrack);
156 //GetCursorPos(&mousept);
157 //DragDetect( window, mousept );
158 //ClipCursor( rect );
159 } else if(mleft.released()) {
160 //ClipCursor( NULL );
163 cnvs->drawImage(*(Theme::current.button_back), area);
164 cnvs->drawImage(*(Theme::current.horiz_grad), area);
174 //std::string SequentialScreenshot::bin_path = "C:\\Library\\Frameworks\\Psychlops.framework\\bin\\fmpeg.exe ";
175 const SequentialScreenshot& SequentialScreenshot::save(std::string filename) {
177 std::stringstream command;
179 for(int i=0; i<movie.size(); i++) {
181 sprintf(buf, "snap%04d.png\0", i+1);
182 movie[i]->save(directory+"/ScreenShots/"+buf);
184 command << bin_path << " -r 60 -y -i cap\\cap%04d.png -vcodec msmpeg4 " << filename;
185 const char *lpArg = command.str().c_str();
186 PROCESS_INFORMATION pi;
188 ZeroMemory(&si,sizeof(si));
190 CreateProcess(NULL,(LPTSTR)lpArg,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si, &pi);
191 CloseHandle(pi.hThread);
192 WaitForSingleObject(pi.hProcess,INFINITE);
193 CloseHandle(pi.hProcess);
201 } /* <- namespace Widgets */
203 std::string Movie::bin_path = "ffmpeg ";
204 const Movie& Movie::save(std::string filename)
206 //Process Manager Reference(Carbon) LaunchApplication
207 //NSWorkspace(Cocoa) launchApplication
208 std::string app_ = File::decodePath("%APP%");
209 std::stringstream command;
211 for(int i=0; i<frame.size(); i++) {
213 sprintf(buf, "cap/snap%04d.png\0", i+1);
217 command << bin_path << " -i \"cap/snap%04d.png\" -loop_output 0 -pix_fmt rgb24 \"" << filename << "\"";
218 NSString *str = [[NSString alloc] initWithUTF8String:command.str().c_str()];
219 [[NSWorkspace sharedWorkspace] launchApplication:str];
224 } /* <- namespace Psycholops */