Develop and Download Open Source Software

Browse CVS Repository

Contents of /enbanfukusyaya/EnbanKensa/macosx/ui.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Wed Dec 7 15:35:35 2005 UTC (18 years, 4 months ago) by bananajinn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
*** empty log message ***

1 /* 円盤複写屋 - EnbanKensa
2 * Copyright (c) 2005 Kagetani Hideto
3 * ui.m - ユーザインターフェース処理
4 * $Date: 2005/05/29 17:12:23 $
5 * $Revision: 1.1 $
6 */
7 #define COCOA
8 #include "ui.h"
9 #include "SettingDialogControl.h"
10
11 #define min_value(a,b) ((a)<(b) ? (a):(b))
12
13 static BOOL g_bAbort=FALSE;
14 static UIWIDGETINFO *g_WidgetInfo=NULL;
15
16 static void UIFlushMessage()
17 {
18 NSEvent *ev;
19 while(1){
20 ev = [NSApp nextEventMatchingMask: NSAnyEventMask
21 untilDate: [NSDate date]
22 inMode: NSEventTrackingRunLoopMode /*NSDefaultRunLoopMode*/
23 dequeue: YES];
24 if(ev==nil)
25 break;
26 [NSApp sendEvent: ev];
27 }
28 }
29
30 BOOL UICheckAbort()
31 {
32 UIFlushMessage();
33 return g_bAbort;
34 }
35
36 void UISetAbort()
37 {
38 g_bAbort = TRUE;
39 }
40
41 void UIClearAbort()
42 {
43 g_bAbort = FALSE;
44 }
45
46 int UIDispMessage(const char *message, int type)
47 {
48 int ret;
49 NSString *msgStr;
50
51 msgStr = [NSString stringWithCString : message];
52 switch(type){
53 case UIDMT_ERROR:
54 ret = NSRunAlertPanel(@"ERROR", msgStr,
55 [NSString stringWithCString: "了解"],
56 nil, nil);
57 ret = UIDMRET_OK;
58 break;
59 case UIDMT_QUESTION:
60 ret = NSRunAlertPanel(@"QUESTION", msgStr,
61 [NSString stringWithCString: "はい"],
62 [NSString stringWithCString: "いいえ"], nil);
63 ret = (ret==0) ? UIDMRET_CANCEL : UIDMRET_OK;
64 break;
65 default:
66 ret = NSRunInformationalAlertPanel(@"Information", msgStr,
67 [NSString stringWithCString: "了解"],
68 nil, nil);
69 ret = UIDMRET_OK;
70 }
71 return ret;
72 }
73
74 void UISetWidgetInfo(UIWIDGETINFO *widget_info)
75 {
76 g_WidgetInfo = widget_info;
77 }
78
79
80 void UIDispInfo(const char *message)
81 {
82 if(message==NULL)
83 message="";
84 if(g_WidgetInfo!=NULL)
85 [g_WidgetInfo->label setStringValue : [NSString stringWithCString : message]];
86 }
87
88 void UIDrawLine(int x0, int y0, int x1, int y1, const UICOLOR *color)
89 {
90 NSPoint point0, point1;
91
92 if(g_WidgetInfo == NULL)
93 return;
94
95 [g_WidgetInfo->drawArea lockFocus];
96
97 [[NSColor colorWithDeviceRed:(color->red)/65536.0
98 green:(color->green)/65536.0
99 blue:(color->blue)/65536.0
100 alpha:1.0] set];
101
102 NSSize size = [g_WidgetInfo->drawArea size];
103 point0.x = x0;
104 point0.y = size.height - y0;
105 point1.x = x1;
106 point1.y = size.height - y1;
107 [NSBezierPath strokeLineFromPoint:point0 toPoint:point1];
108
109 [g_WidgetInfo->drawArea unlockFocus];
110
111 [g_WidgetInfo->view setNeedsDisplayInRect:
112 NSMakeRect(min_value(point0.x, point1.x),
113 min_value(point0.y, point1.y),
114 abs(point1.x-point0.x)+1,
115 abs(point1.y-point0.y)+1)];
116 }
117
118 void UIDrawBox(int x0, int y0, int x1, int y1, const UICOLOR *color, BOOL fill)
119 {
120 NSRect rect;
121
122 if(g_WidgetInfo == NULL)
123 return;
124
125 [g_WidgetInfo->drawArea lockFocus];
126
127 [[NSColor colorWithDeviceRed:(color->red)/65536.0
128 green:(color->green)/65536.0
129 blue:(color->blue)/65536.0
130 alpha:1.0] set];
131
132 NSSize size = [g_WidgetInfo->drawArea size];
133 rect = NSMakeRect(min_value(x0, x1),
134 min_value(size.height-y0, size.height-y1),
135 abs(x1-x0), abs(y1-y0));
136
137 if(fill)
138 NSRectFill(rect);
139 else
140 NSFrameRect(rect);
141
142 [g_WidgetInfo->drawArea unlockFocus];
143
144 [g_WidgetInfo->view setNeedsDisplayInRect: rect];
145 }
146
147 void UIDrawText(int x0, int y0, const UICOLOR *color, const char *text)
148 {
149 if(g_WidgetInfo == NULL)
150 return;
151
152 NSAttributedString *string;
153 NSMutableDictionary *attributes;
154 NSColor *col;
155 NSSize size;
156
157 [g_WidgetInfo->drawArea lockFocus];
158
159 col = [NSColor colorWithDeviceRed:(color->red)/65536.0
160 green:(color->green)/65536.0
161 blue:(color->blue)/65536.0
162 alpha:1.0];
163
164 NSSize areaSize = [g_WidgetInfo->drawArea size];
165
166 attributes = [NSMutableDictionary dictionary];
167 [attributes setObject:col forKey:NSForegroundColorAttributeName];
168
169 [g_WidgetInfo->font set];
170
171 string = [[NSAttributedString alloc]
172 initWithString: [NSString stringWithCString: text]
173 attributes: attributes];
174 size = [string size];
175 [string drawAtPoint: NSMakePoint(x0, areaSize.height-y0-size.height)];
176
177 [g_WidgetInfo->drawArea unlockFocus];
178
179 [g_WidgetInfo->view setNeedsDisplayInRect:
180 NSMakeRect(x0, areaSize.height-y0-size.height, size.width, size.height)];
181
182 [string release];
183 }
184
185 void UIGetDrawableSize(int *width, int *height)
186 {
187 if(g_WidgetInfo==NULL){
188 *width = 0;
189 *height = 0;
190 return;
191 }
192
193 NSSize size = [g_WidgetInfo->drawArea size];
194 *width = size.width;
195 *height = size.height;
196 }
197
198 int UISetting(OPTIONS *option)
199 {
200 if(g_WidgetInfo==NULL){
201 return RET_NG;
202 }
203
204 return [g_WidgetInfo->settingPanel openSettingDialog: option];
205 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26