Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

Stimgui.m 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. function varargout = Stimgui(varargin)
  2. % STIMGUI M-file for Stimgui.fig
  3. % STIMGUI, by itself, creates a new STIMGUI or raises the existing
  4. % singleton*.
  5. %
  6. % H = STIMGUI returns the handle to a new STIMGUI or the handle to
  7. % the existing singleton*.
  8. %
  9. % STIMGUI('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in STIMGUI.M with the given input arguments.
  11. %
  12. % STIMGUI('Property','Value',...) creates a new STIMGUI or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before Stimgui_OpeningFunction gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to Stimgui_OpeningFcn via varargin.
  17. %
  18. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
  19. % instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES
  22. % Edit the above text to modify the response to help Stimgui
  23. % Last Modified by GUIDE v2.5 28-Mar-2013 13:51:35
  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name', mfilename, ...
  27. 'gui_Singleton', gui_Singleton, ...
  28. 'gui_OpeningFcn', @Stimgui_OpeningFcn, ...
  29. 'gui_OutputFcn', @Stimgui_OutputFcn, ...
  30. 'gui_LayoutFcn', [] , ...
  31. 'gui_Callback', []);
  32. if nargin && ischar(varargin{1})
  33. gui_State.gui_Callback = str2func(varargin{1});
  34. end
  35. if nargout
  36. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38. gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT
  41. % --- Executes just before Stimgui is made visible.
  42. function Stimgui_OpeningFcn(hObject, eventdata, handles, varargin)
  43. % This function has no output args, see OutputFcn.
  44. % hObject handle to figure
  45. % eventdata reserved - to be defined in a future version of MATLAB
  46. % handles structure with handles and user data (see GUIDATA)
  47. % varargin command line arguments to Stimgui (see VARARGIN)
  48. % Choose default command line output for Stimgui
  49. %set(hObject, 'Position', [ -100 42 63 10])
  50. handles.output = hObject;
  51. warning('off','MATLAB:dispatcher:InexactMatch')
  52. if -2 == cgflip
  53. cgloadlib
  54. Mon = get(0,'MonitorPosition');
  55. if size(Mon,1) > 1
  56. cgopen(3,0,0,2)
  57. else %if there is only one monitor!!!
  58. cgopen(3,0,0,0)
  59. end
  60. end
  61. handles.Backgroundcolor = [0 0 0];
  62. %Update handles structure
  63. guidata(hObject, handles);
  64. % UIWAIT makes Stimgui wait for user response (see UIRESUME)
  65. % uiwait(handles.figure1);
  66. % --- Outputs from this function are returned to the command line.
  67. function varargout = Stimgui_OutputFcn(hObject, eventdata, handles)
  68. % varargout cell array for returning output args (see VARARGOUT);
  69. % hObject handle to figure
  70. % eventdata reserved - to be defined in a future version of MATLAB
  71. % handles structure with handles and user data (see GUIDATA)
  72. % Get default command line output from handles structure
  73. varargout{1} = handles.output;
  74. % --------------------------------------------------------------------
  75. function I_New_G_Callback(hObject, eventdata, handles)
  76. % hObject handle to I_New_G (see GCBO)
  77. % eventdata reserved - to be defined in a future version of MATLAB
  78. % handles structure with handles and user data (see GUIDATA)
  79. % [Selection,ok] = listdlg('ListString', {'Bezier', 'Dot', 'Movingbar', 'Figure_ground'}, ...
  80. % 'SelectionMode', 'single', 'Name', 'Create object');
  81. %
  82. % HF = figure('Position', [100 700 200 120], 'MenuBar', 'none', 'NumberTitle', 'off', 'name', 'Create object');
  83. % h1 = uicontrol(HF, 'style', 'listbox', 'string', {'Bezier', 'Dot', 'Movingbar', 'Figure_ground'}, ...
  84. % 'Position', [10 10 100 100]);
  85. %
  86. % h2 = uicontrol(HF, 'style', 'pushbutton', 'string', 'Ok', 'Position', [120 10 50 20], 'callback', {@CB_done, h1});
  87. % --------------------------------------------------------------------
  88. function I_Save_Callback(hObject, eventdata, handles)
  89. % hObject handle to I_Save (see GCBO)
  90. % eventdata reserved - to be defined in a future version of MATLAB
  91. % handles structure with handles and user data (see GUIDATA)
  92. global StimObj
  93. if isfield(StimObj, 'Pf')
  94. save( StimObj.Pf, 'StimObj')
  95. else
  96. [file,path] = uiputfile('StimObj.mat','Save StimObj as');
  97. if file ~= 0
  98. save([path file], 'StimObj')
  99. end
  100. end
  101. % --------------------------------------------------------------------
  102. function I_saveas_Callback(hObject, eventdata, handles)
  103. % hObject handle to I_saveas (see GCBO)
  104. % eventdata reserved - to be defined in a future version of MATLAB
  105. % handles structure with handles and user data (see GUIDATA)
  106. global StimObj
  107. [file,path] = uiputfile('*.mat','Save StimObj as');
  108. if file == 0
  109. return
  110. end
  111. save([path file], 'StimObj')
  112. % --------------------------------------------------------------------
  113. function I_Read_Callback(hObject, eventdata, handles)
  114. % hObject handle to I_Read (see GCBO)
  115. % eventdata reserved - to be defined in a future version of MATLAB
  116. % handles structure with handles and user data (see GUIDATA)
  117. global StimObj
  118. [FileName,PathName] = uigetfile('*.mat','Select a StimObj Mat-file');
  119. Pf = fullfile(PathName,FileName);
  120. if FileName == 0
  121. return
  122. end
  123. load( Pf)
  124. if isfield(StimObj, 'Obj')
  125. OBJ = StimObj.Obj;
  126. len = length(OBJ);
  127. Str_Obj = cell(len, 1);
  128. for i = 1:len
  129. Str_Obj(i) = {[num2str(OBJ(i).Id) '-' OBJ(i).Type]};
  130. end
  131. set(handles.StimObjLB, 'String', Str_Obj);
  132. end
  133. set(handles.PM_Event, 'Value', 1);
  134. if isfield(StimObj, 'Stm')
  135. Stm = StimObj.Stm;
  136. len = length(Stm);
  137. Str_Stms = cell(len, 1);
  138. for i = 1:len
  139. Str_Stms(i) = {[num2str(Stm(i).Id) '-' Stm(i).Name]};
  140. end
  141. set(handles.PM_Event, 'String', Str_Stms);
  142. end
  143. StimObj.Pf = Pf;
  144. guidata(hObject, handles);
  145. % --- Executes on selection change in StimObjLB.
  146. function StimObjLB_Callback(hObject, eventdata, handles)
  147. % hObject handle to StimObjLB (see GCBO)
  148. % eventdata reserved - to be defined in a future version of MATLAB
  149. % handles structure with handles and user data (see GUIDATA)
  150. % Hints: contents = get(hObject,'String') returns StimObjLB contents as cell array
  151. % contents{get(hObject,'Value')} returns selected item from StimObjLB
  152. % --- Executes during object creation, after setting all properties.
  153. function StimObjLB_CreateFcn(hObject, eventdata, handles)
  154. % hObject handle to StimObjLB (see GCBO)
  155. % eventdata reserved - to be defined in a future version of MATLAB
  156. % handles empty - handles not created until after all CreateFcns called
  157. % Hint: listbox controls usually have a white background on Windows.
  158. % See ISPC and COMPUTER.
  159. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  160. set(hObject,'BackgroundColor','white');
  161. end
  162. global StimObj
  163. if isfield(StimObj, 'Obj')
  164. OBJ = StimObj.Obj;
  165. len = length(OBJ);
  166. Str_Obj = cell(len, 1);
  167. for i = 1:len
  168. Str_Obj(i) = {[num2str(OBJ(i).Id) '-' OBJ(i).Type]};
  169. end
  170. set(hObject, 'String', Str_Obj);
  171. else
  172. set(hObject, 'String', {'none'});
  173. end
  174. % --- Executes on button press in Btn_Clr.
  175. function Btn_Clr_Callback(hObject, eventdata, handles)
  176. % hObject handle to Btn_Clr (see GCBO)
  177. % eventdata reserved - to be defined in a future version of MATLAB
  178. % handles structure with handles and user data (see GUIDATA)
  179. cgflip(0,0,0)
  180. cgflip(0,0,0)
  181. % --------------------------------------------------------------------
  182. function M_File_Callback(hObject, eventdata, handles)
  183. % hObject handle to M_File (see GCBO)
  184. % eventdata reserved - to be defined in a future version of MATLAB
  185. % handles structure with handles and user data (see GUIDATA)
  186. %//////////////GRAPHIC OBJECT CREATION/////////////////////////////
  187. % --------------------------------------------------------------------
  188. function T_Dot_Callback(hObject, eventdata, handles)
  189. % hObject handle to T_Dot (see GCBO)
  190. % eventdata reserved - to be defined in a future version of MATLAB
  191. % handles structure with handles and user data (see GUIDATA)
  192. newObj.Type = 'Dot';
  193. newObj.Data = cgdot;
  194. update_objects(newObj, handles);
  195. % --------------------------------------------------------------------
  196. function T_Box_Callback(hObject, eventdata, handles)
  197. % hObject handle to T_Box (see GCBO)
  198. % eventdata reserved - to be defined in a future version of MATLAB
  199. % handles structure with handles and user data (see GUIDATA)
  200. newObj.Type = 'Box';
  201. newObj.Data = cgbox;
  202. update_objects(newObj, handles);
  203. % --------------------------------------------------------------------
  204. function T_Bezier_Callback(hObject, eventdata, handles)
  205. % hObject handle to T_Bezier (see GCBO)
  206. % eventdata reserved - to be defined in a future version of MATLAB
  207. % handles structure with handles and user data (see GUIDATA)
  208. newObj.Type = 'Bezier';
  209. newObj.Data = cgbezier;
  210. update_objects(newObj, handles);
  211. % --------------------------------------------------------------------
  212. function T_Tex_Callback(hObject, eventdata, handles)
  213. % hObject handle to T_Tex (see GCBO)
  214. % eventdata reserved - to be defined in a future version of MATLAB
  215. % handles structure with handles and user data (see GUIDATA)
  216. newObj.Type = 'Texture';
  217. newObj.Data = cgTexture;
  218. update_objects(newObj, handles);
  219. % --------------------------------------------------------------------
  220. function T_Poly_Callback(hObject, eventdata, handles)
  221. % hObject handle to T_Poly (see GCBO)
  222. % eventdata reserved - to be defined in a future version of MATLAB
  223. % handles structure with handles and user data (see GUIDATA)
  224. newObj.Type = 'Polyline';
  225. newObj.Data = cgPolyline;
  226. update_objects(newObj, handles);
  227. % --------------------------------------------------------------------
  228. function T_Bitload_Callback(hObject, eventdata, handles)
  229. % hObject handle to T_Bitload (see GCBO)
  230. % eventdata reserved - to be defined in a future version of MATLAB
  231. % handles structure with handles and user data (see GUIDATA)
  232. [FileName, PathName] = uigetfile('*.bmp', 'Read bitmaps', 'MultiSelect', 'on');
  233. if ischar(FileName)
  234. newObj.Type = 'Bitmap';
  235. Bitmap.Filename = [PathName FileName];
  236. cgloadbmp(1, Bitmap.Filename )
  237. spr = cggetdata('SPR', 1);
  238. Bitmap.cx = 0;
  239. Bitmap.cy = 0;
  240. Bitmap.w = spr.Width;
  241. Bitmap.h = spr.Height;
  242. Bitmap.Tcol = [];
  243. Bitmap.isLoaded = false;
  244. Bitmap.Id = [];
  245. newObj.Data = Bitmap;
  246. update_objects(newObj, handles);
  247. elseif iscell(FileName)
  248. for i = 1:length(FileName)
  249. newObj.Type = 'Bitmap';
  250. Bitmap.Filename = [PathName FileName{i}];
  251. cgloadbmp(1, Bitmap.Filename )
  252. spr = cggetdata('SPR', 1);
  253. Bitmap.cx = 0;
  254. Bitmap.cy = 0;
  255. Bitmap.w = spr.Width;
  256. Bitmap.h = spr.Height;
  257. Bitmap.Tcol = [];
  258. Bitmap.isLoaded = false;
  259. Bitmap.Id = [];
  260. newObj.Data = Bitmap;
  261. update_objects(newObj, handles);
  262. end
  263. end
  264. % --------------------------------------------------------------------
  265. %callback f0r randomsquares pattern
  266. function T_RP_Callback(hObject, ~, handles)
  267. % hObject handle to T_RP (see GCBO)
  268. % eventdata reserved - to be defined in a future version of MATLAB
  269. % handles structure with handles and user data (see GUIDATA)
  270. newObj.Type = 'Randompattern';
  271. newObj.Data = cgRandompattern;
  272. update_objects(newObj, handles);
  273. % -----------------------------------------------------------------------
  274. function update_objects(Obj, handles)
  275. global StimObj
  276. if isfield(StimObj, 'Obj')
  277. len = length(StimObj.Obj);
  278. else
  279. len = 0;
  280. end
  281. if len == 0
  282. Obj.Id = 1;
  283. StimObj.Obj = Obj;
  284. Str_Obj = {[num2str(Obj.Id) '-' Obj.Type]};
  285. else
  286. Str_Obj = get(handles.StimObjLB, 'String');
  287. Obj.Id = max([ StimObj.Obj(:).Id ]) + 1;
  288. StimObj.Obj(len+1) = Obj;
  289. Str_Obj(len+1) = {[num2str(Obj.Id) '-' Obj.Type]};
  290. end
  291. % guidata(hObject, handles);
  292. set(handles.StimObjLB, 'String', Str_Obj);
  293. % --------------------------------------------------------------------
  294. function Graphic_Object_Callback(hObject, eventdata, handles)
  295. % hObject handle to Graphic_Object (see GCBO)
  296. % eventdata reserved - to be defined in a future version of MATLAB
  297. % handles structure with handles and user data (see GUIDATA)
  298. % --------------------------------------------------------------------
  299. function T_Display_Callback(hObject, eventdata, handles)
  300. % hObject handle to T_Display (see GCBO)
  301. % eventdata reserved - to be defined in a future version of MATLAB
  302. % handles structure with handles and user data (see GUIDATA)
  303. global StimObj
  304. OBJ = StimObj.Obj;
  305. item = get(handles.StimObjLB,'Value');
  306. switch OBJ(item).Type
  307. case 'Bezier'
  308. cgbezier(OBJ(item).Data, 'D'); %(D)isplay
  309. case 'Dot'
  310. cgdot(OBJ(item).Data, 'D');
  311. case 'Box'
  312. cgbox(OBJ(item).Data, 'D');
  313. case 'Polyline'
  314. cgPolyline(OBJ(item).Data, 'D');
  315. case 'Bitmap'
  316. StimObj.Obj(item).Data = cgbitmap(OBJ(item).Data, 'D', OBJ(item).Id);
  317. %update bitmap because isloaded is true and Id is added
  318. %since this is a sprite
  319. case 'Texture'
  320. Tex = OBJ(item).Data;
  321. Id = OBJ(item).Id;
  322. StimObj.Obj(item).Data = cgTexture(Tex, 'D', Id);
  323. %also becomes a sprite
  324. case 'Randompattern'
  325. RP = OBJ(item).Data;
  326. %Id = OBJ(item).Id;
  327. cgRandompattern(RP);
  328. % StimObj.Obj(item).Data = RP;
  329. %this objects changes on each presentation
  330. end
  331. % --------------------------------------------------------------------
  332. function T_Edit_Callback(hObject, eventdata, handles)
  333. % hObject handle to T_Edit (see GCBO)
  334. % eventdata reserved - to be defined in a future version of MATLAB
  335. % handles structure with handles and user data (see GUIDATA)
  336. global StimObj
  337. OBJ = StimObj.Obj;
  338. set(handles.stimeditor, 'Visible', 'off');
  339. item = get(handles.StimObjLB,'Value');
  340. if strcmp(OBJ(item).Type, 'Bezier')
  341. Bez = OBJ(item).Data;
  342. StimObj.Obj(item).Data = cgbezier(Bez, 'E');
  343. elseif strcmp(OBJ(item).Type, 'Dot')
  344. Dot = OBJ(item).Data;
  345. StimObj.Obj(item).Data = cgdot(Dot, 'E');
  346. elseif strcmp(OBJ(item).Type, 'Box')
  347. Box = OBJ(item).Data;
  348. StimObj.Obj(item).Data = cgbox(Box, 'E');
  349. elseif strcmp(OBJ(item).Type, 'Polyline')
  350. Poly = OBJ(item).Data;
  351. StimObj.Obj(item).Data = cgPolyline(Poly, 'E');
  352. elseif strcmp(OBJ(item).Type, 'Texture')
  353. Tex = OBJ(item).Data;
  354. StimObj.Obj(item).Data = cgTexture(Tex, 'E');
  355. elseif strcmp(OBJ(item).Type, 'Bitmap')
  356. Bmp = OBJ(item).Data;
  357. Id = OBJ(item).Id;
  358. StimObj.Obj(item).Data = cgbitmap(Bmp, 'E', Id);
  359. end
  360. set(handles.stimeditor, 'Visible', 'on');
  361. % --------------------------------------------------------------------
  362. function T_Del_Callback(hObject, eventdata, handles)
  363. % hObject handle to T_Del_Stim (see GCBO)
  364. % eventdata reserved - to be defined in a future version of MATLAB
  365. % handles structure with handles and user data (see GUIDATA)
  366. global StimObj
  367. numObj = length(StimObj.Obj);
  368. item = get(handles.StimObjLB,'Value');
  369. Str_Obj = get(handles.StimObjLB, 'String');
  370. ID = StimObj.Obj(item).Id;
  371. Inuse = 0;
  372. if isfield(StimObj, 'Stm')
  373. Stms = StimObj.Stm;
  374. lenStm = length(Stms);
  375. for i = 1:lenStm
  376. IdA = [ Stms(i).Event{:} Stms(i).Fix Stms(i).Targ Stms(i).Talt{:} ];
  377. Inx = find(IdA == ID, 1);
  378. if ~isempty(Inx) %this Id is used in one of the stimuli
  379. errordlg(['Cannot delete this object, used by stimulus Id ' num2str(Stms(i).Id) ])
  380. Inuse = 1;
  381. break
  382. end
  383. end
  384. end
  385. if Inuse == 0
  386. StimObj.Obj(item) = [];
  387. if (numObj - 1) == 0
  388. Str_Obj = ' ';
  389. else
  390. Str_Obj(item) = [];
  391. end
  392. set(handles.StimObjLB, 'String', Str_Obj, 'Value', 1);
  393. end
  394. % --------------------------------------------------------------------
  395. function T_Copy_Callback(hObject, eventdata, handles)
  396. % hObject handle to T_Copy_stim (see GCBO)
  397. % eventdata reserved - to be defined in a future version of MATLAB
  398. % handles structure with handles and user data (see GUIDATA)
  399. global StimObj
  400. OBJ = StimObj.Obj;
  401. len = length(OBJ);
  402. item = get(handles.StimObjLB,'Value');
  403. Str_Obj = get(handles.StimObjLB, 'String');
  404. StimObj.Obj(len + 1) = OBJ(item);
  405. IDs = [OBJ(:).Id ];
  406. StimObj.Obj(len + 1).Id = max(IDs) + 1;
  407. newObj = StimObj.Obj(len + 1);
  408. Str_Obj(len+1) = {[num2str(newObj.Id) '-' newObj.Type]};
  409. set(handles.StimObjLB, 'String', Str_Obj);
  410. %///////////////////STIMULUS CREATE AND EDIT//////////////////////////////
  411. % --- Executes on selection change in PM_EVENT.
  412. function PM_Event_Callback(hObject, eventdata, handles)
  413. % hObject handle to PM_EVENT (see GCBO)
  414. % eventdata reserved - to be defined in a future version of MATLAB
  415. % handles structure with handles and user data (see GUIDATA)
  416. % Hints: contents = get(hObject,'String') returns PM_EVENT contents as cell array
  417. % contents{get(hObject,'Value')} returns selected item from PM_EVENT
  418. %UPDATE STIMULUS PARAMATER PANEL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  419. global StimObj
  420. Objs = StimObj.Obj; %graphic object array
  421. lenObj = length(Objs);
  422. % Str_Obj = cell(1,2);
  423. Ctrl_Obj = cell(1,2); %objects used to position control windows, (need a center position: cx, cy)
  424. IDS = [];
  425. Ind = 1;
  426. for i = 1:lenObj
  427. if isfield(Objs(i).Data, 'cx') %does this object have a center point
  428. Ctrl_Obj(Ind) = {[num2str(Objs(i).Id) '-' Objs(i).Type]};
  429. IDS(Ind) = Objs(i).Id;
  430. Ind = Ind + 1;
  431. end
  432. % Str_Obj(i) = {[num2str(Objs(i).Id) '-' Objs(i).Type]};
  433. end
  434. Ctrl_Obj(Ind) = {'NONE'};
  435. Stmnum = get(hObject,'Value'); %the selected stimulus
  436. %Str_Stm = get(hObject,'String');
  437. Stim = StimObj.Stm(Stmnum);
  438. EVENT = Stim.Event;
  439. %E_Fixon, E_Stimon, E_Targon, E_Targoff, PU_Fix, PU_Correct, LB_Error
  440. %E = edit t_box
  441. %PU = popup t_box
  442. %LB = listbox
  443. set(handles.E_Fixon, 'String', num2str( EVENT{1}) )
  444. set(handles.E_Stimon, 'String', num2str( EVENT{2}) )
  445. set(handles.E_Targon, 'String', num2str( EVENT{3}) )
  446. set(handles.E_Targoff, 'String', num2str( EVENT{4}) )
  447. if ~isempty(Stim.Fix)
  448. Idx = find(IDS == Stim.Fix, 1);
  449. set(handles.PU_Fix, 'String', Ctrl_Obj, 'value', Idx)
  450. else
  451. set(handles.PU_Fix, 'String', Ctrl_Obj, 'value', Ind)
  452. end
  453. if ~isempty(Stim.Targ)
  454. Idx = find(IDS == Stim.Targ, 1);
  455. set(handles.PU_Correct, 'String', Ctrl_Obj, 'value', Idx )
  456. else
  457. set(handles.PU_Correct, 'String', Ctrl_Obj, 'value', Ind)
  458. end
  459. Ids = Stim.Talt{:};
  460. Mx = length(Ctrl_Obj) -1;
  461. if ~isempty(Ids)
  462. Idx = [];
  463. for j = 1:length(Ids)
  464. Idx = [Idx find(IDS == Ids(j),1) ]; %#ok<AGROW>
  465. end
  466. set(handles.LB_Error, 'String', Ctrl_Obj, 'value', Idx, 'Max', Mx)
  467. else
  468. set(handles.LB_Error, 'String', Ctrl_Obj, 'value', Ind, 'Max', Mx)
  469. end
  470. handles.IDS = IDS; %save the Ctrl IDS in the handles stucture for updating
  471. guidata(hObject, handles);
  472. % --- Executes during object creation, after setting all properties.
  473. function PM_Event_CreateFcn(hObject, eventdata, handles)
  474. % hObject handle to PM_EVENT (see GCBO)
  475. % eventdata reserved - to be defined in a future version of MATLAB
  476. % handles empty - handles not created until after all CreateFcns called
  477. % Hint: popupmenu controls usually have a white background on Windows.
  478. % See ISPC and COMPUTER.
  479. %FILL STIMULUS POPUP LIST
  480. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  481. set(hObject,'BackgroundColor','white');
  482. end
  483. global StimObj
  484. if isfield(StimObj, 'Stm')
  485. Stms = StimObj.Stm;
  486. len = length(Stms);
  487. if len > 0
  488. Str_Stms = cell(len, 1);
  489. for i = 1:len
  490. Str_Stms(i) = {[num2str(Stms(i).Id) '-' Stms(i).Name]};
  491. end
  492. set(hObject, 'String', Str_Stms);
  493. else
  494. set(hObject, 'String', {'none'});
  495. end
  496. else
  497. set(hObject, 'String', {'none'});
  498. end
  499. function Pre_T_Callback(hObject, eventdata, handles)
  500. % hObject handle to Pre_T (see GCBO)
  501. % eventdata reserved - to be defined in a future version of MATLAB
  502. % handles structure with handles and user data (see GUIDATA)
  503. % Hints: get(hObject,'String') returns contents of Pre_T as text
  504. % str2double(get(hObject,'String')) returns contents of Pre_T as a double
  505. % --- Executes during object creation, after setting all properties.
  506. function Pre_T_CreateFcn(hObject, eventdata, handles)
  507. % hObject handle to Pre_T (see GCBO)
  508. % eventdata reserved - to be defined in a future version of MATLAB
  509. % handles empty - handles not created until after all CreateFcns called
  510. % Hint: edit controls usually have a white background on Windows.
  511. % See ISPC and COMPUTER.
  512. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  513. set(hObject,'BackgroundColor','white');
  514. end
  515. % --- Executes on selection change in E_Fixon.
  516. function E_Fixon_Callback(hObject, eventdata, handles)
  517. % hObject handle to E_Fixon (see GCBO)
  518. % eventdata reserved - to be defined in a future version of MATLAB
  519. % handles structure with handles and user data (see GUIDATA)
  520. % Hints: contents = get(hObject,'String') returns E_Fixon contents as cell array
  521. % contents{get(hObject,'Value')} returns selected item from E_Fixon
  522. global StimObj
  523. Objs = StimObj.Obj;
  524. Stmnum = get(handles.PM_Event,'Value');
  525. IdE = str2num(get(hObject,'String'));
  526. IDs = [ Objs(:).Id ];
  527. if any(setdiff(IdE, IDs))
  528. errordlg('Only numbers corresponding to stimulus objects (IDs)')
  529. else
  530. StimObj.Stm(Stmnum).Event(1) = { IdE };
  531. end
  532. % --- Executes during object creation, after setting all properties.
  533. function E_Fixon_CreateFcn(hObject, eventdata, handles)
  534. % hObject handle to E_Fixon (see GCBO)
  535. % eventdata reserved - to be defined in a future version of MATLAB
  536. % handles empty - handles not created until after all CreateFcns called
  537. % Hint: popupmenu controls usually have a white background on Windows.
  538. % See ISPC and COMPUTER.
  539. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  540. set(hObject,'BackgroundColor','white');
  541. end
  542. function E_Stimon_Callback(hObject, eventdata, handles)
  543. % hObject handle to E_Stimon (see GCBO)
  544. % eventdata reserved - to be defined in a future version of MATLAB
  545. % handles structure with handles and user data (see GUIDATA)
  546. % Hints: get(hObject,'String') returns contents of E_Stimon as text
  547. % str2double(get(hObject,'String')) returns contents of E_Stimon as a double
  548. global StimObj
  549. Objs = StimObj.Obj;
  550. Stmnum = get(handles.PM_Event,'Value');
  551. IdE = str2num(get(hObject,'String'));
  552. IDs = [ Objs(:).Id ];
  553. if any(setdiff(IdE, IDs))
  554. errordlg('Only numbers corresponding to stimulus objects (IDs)', 'Invalid input!!!')
  555. else
  556. StimObj.Stm(Stmnum).Event(2) = { IdE };
  557. end
  558. % --- Executes during object creation, after setting all properties.
  559. function E_Stimon_CreateFcn(hObject, eventdata, handles)
  560. % hObject handle to E_Stimon (see GCBO)
  561. % eventdata reserved - to be defined in a future version of MATLAB
  562. % handles empty - handles not created until after all CreateFcns called
  563. % Hint: edit controls usually have a white background on Windows.
  564. % See ISPC and COMPUTER.
  565. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  566. set(hObject,'BackgroundColor','white');
  567. end
  568. function E_Targon_Callback(hObject, eventdata, handles)
  569. % hObject handle to E_Targon (see GCBO)
  570. % eventdata reserved - to be defined in a future version of MATLAB
  571. % handles structure with handles and user data (see GUIDATA)
  572. % Hints: get(hObject,'String') returns contents of E_Targon as text
  573. % str2double(get(hObject,'String')) returns contents of E_Targon as a double
  574. global StimObj
  575. Objs = StimObj.Obj;
  576. Stmnum = get(handles.PM_Event,'Value');
  577. IdE = str2num(get(hObject,'String'));
  578. IDs = [ Objs(:).Id ];
  579. if any(setdiff(IdE, IDs))
  580. errordlg('Only numbers corresponding to stimulus objects (IDs)')
  581. else
  582. StimObj.Stm(Stmnum).Event(3) = { IdE };
  583. end
  584. % --- Executes during object creation, after setting all properties.
  585. function E_Targon_CreateFcn(hObject, eventdata, handles)
  586. % hObject handle to E_Targon (see GCBO)
  587. % eventdata reserved - to be defined in a future version of MATLAB
  588. % handles empty - handles not created until after all CreateFcns called
  589. % Hint: edit controls usually have a white background on Windows.
  590. % See ISPC and COMPUTER.
  591. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  592. set(hObject,'BackgroundColor','white');
  593. end
  594. function E_Targoff_Callback(hObject, eventdata, handles)
  595. % hObject handle to e_Targoff (see GCBO)
  596. % eventdata reserved - to be defined in a future version of MATLAB
  597. % handles structure with handles and user data (see GUIDATA)
  598. % Hints: get(hObject,'String') returns contents of e_Targoff as text
  599. % str2double(get(hObject,'String')) returns contents of e_Targoff as a double
  600. global StimObj
  601. Objs = StimObj.Obj;
  602. Stmnum = get(handles.PM_Event,'Value');
  603. IdE = str2num(get(hObject,'String'));
  604. IDs = [ Objs(:).Id ];
  605. if any(setdiff(IdE, IDs))
  606. errordlg('Only numbers corresponding to stimulus objects (IDs)')
  607. else
  608. StimObj.Stm(Stmnum).Event(4) = { IdE };
  609. end
  610. % --- Executes during object creation, after setting all properties.
  611. function E_Targoff_CreateFcn(hObject, eventdata, handles)
  612. % hObject handle to e_Targoff (see GCBO)
  613. % eventdata reserved - to be defined in a future version of MATLAB
  614. % handles empty - handles not created until after all CreateFcns called
  615. % Hint: edit controls usually have a white background on Windows.
  616. % See ISPC and COMPUTER.
  617. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  618. set(hObject,'BackgroundColor','white');
  619. end
  620. % --- Executes on selection change in PU_Fix.
  621. function PU_Fix_Callback(hObject, eventdata, handles)
  622. % hObject handle to PU_Fix (see GCBO)
  623. % eventdata reserved - to be defined in a future version of MATLAB
  624. % handles structure with handles and user data (see GUIDATA)
  625. % Hints: contents = get(hObject,'String') returns PU_Fix contents as cell array
  626. % contents{get(hObject,'Value')} returns selected item from PU_Fix
  627. global StimObj
  628. Stmnum = get(handles.PM_Event,'Value');
  629. num = get(hObject,'Value');
  630. if ~(num > length(handles.IDS))
  631. StimObj.Stm(Stmnum).Fix = handles.IDS(num);
  632. else
  633. errordlg('You must select a fixation target')
  634. end
  635. % --- Executes during object creation, after setting all properties.
  636. function PU_Fix_CreateFcn(hObject, eventdata, handles)
  637. % hObject handle to PU_Fix (see GCBO)
  638. % eventdata reserved - to be defined in a future version of MATLAB
  639. % handles empty - handles not created until after all CreateFcns called
  640. % Hint: popupmenu controls usually have a white background on Windows.
  641. % See ISPC and COMPUTER.
  642. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  643. set(hObject,'BackgroundColor','white');
  644. end
  645. % --- Executes on selection change in PU_Correct.
  646. function PU_Correct_Callback(hObject, eventdata, handles)
  647. % hObject handle to PU_Correct (see GCBO)
  648. % eventdata reserved - to be defined in a future version of MATLAB
  649. % handles structure with handles and user data (see GUIDATA)
  650. % Hints: contents = get(hObject,'String') returns PU_Correct contents as cell array
  651. % contents{get(hObject,'Value')} returns selected item from PU_Correct
  652. global StimObj
  653. Stmnum = get(handles.PM_Event,'Value');
  654. num = get(hObject,'Value');
  655. if ~(num > length(handles.IDS))
  656. StimObj.Stm(Stmnum).Targ = handles.IDS(num);
  657. else
  658. errordlg('You must select a correct target')
  659. end
  660. % --- Executes during object creation, after setting all properties.
  661. function PU_Correct_CreateFcn(hObject, eventdata, handles)
  662. % hObject handle to PU_Correct (see GCBO)
  663. % eventdata reserved - to be defined in a future version of MATLAB
  664. % handles empty - handles not created until after all CreateFcns called
  665. % Hint: popupmenu controls usually have a white background on Windows.
  666. % See ISPC and COMPUTER.
  667. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  668. set(hObject,'BackgroundColor','white');
  669. end
  670. % --- Executes on selection change in LB_Error.
  671. function LB_Error_Callback(hObject, eventdata, handles)
  672. % hObject handle to LB_Error (see GCBO)
  673. % eventdata reserved - to be defined in a future version of MATLAB
  674. % handles structure with handles and user data (see GUIDATA)
  675. % Hints: contents = get(hObject,'String') returns LB_Error contents as cell array
  676. % contents{get(hObject,'Value')} returns selected item from LB_Error
  677. global StimObj
  678. Stmnum = get(handles.PM_Event,'Value');
  679. num = get(hObject,'Value');
  680. if any(num > length(handles.IDS))
  681. StimObj.Stm(Stmnum).Talt = {[]};
  682. else
  683. StimObj.Stm(Stmnum).Talt = { handles.IDS(num) };
  684. end
  685. % --- Executes during object creation, after setting all properties.
  686. function LB_Error_CreateFcn(hObject, eventdata, handles)
  687. % hObject handle to LB_Error (see GCBO)
  688. % eventdata reserved - to be defined in a future version of MATLAB
  689. % handles empty - handles not created until after all CreateFcns called
  690. % Hint: popupmenu controls usually have a white background on Windows.
  691. % See ISPC and COMPUTER.
  692. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  693. set(hObject,'BackgroundColor','white');
  694. end
  695. % --------------------------------------------------------------------
  696. function Stimulus_Object_Callback(hObject, eventdata, handles)
  697. % hObject handle to Stimulus_Object (see GCBO)
  698. % eventdata reserved - to be defined in a future version of MATLAB
  699. % handles structure with handles and user data (see GUIDATA)
  700. % --------------------------------------------------------------------
  701. function T_Display_stim_Callback(hObject, eventdata, handles)
  702. % hObject handle to T_Display_stim (see GCBO)
  703. % eventdata reserved - to be defined in a future version of MATLAB
  704. % handles structure with handles and user data (see GUIDATA)
  705. global StimObj
  706. Objs = StimObj.Obj; %graphic object array
  707. % lenObj = length(Objs);
  708. Stmnum = get(handles.PM_Event,'Value');
  709. % Str_Stm = get(handles.PM_Event,'String');
  710. Stim = StimObj.Stm(Stmnum);
  711. Str_EVENT = {'Fix', 'Stim', 'Targ', 'Targoff' };
  712. BGcolor = handles.Backgroundcolor;
  713. cgflip(BGcolor(1), BGcolor(2), BGcolor(3));
  714. ObjIds = [ Objs(:).Id ];
  715. if ~isempty(Stim.Fix)
  716. FIn = find(ObjIds == Stim.Fix);
  717. Fix = [Objs(FIn).Data.cx Objs(FIn).Data.cy Objs(FIn).Data.w Objs(FIn).Data.h];
  718. end
  719. if ~isempty(Stim.Targ)
  720. TIn = find(ObjIds == Stim.Targ);
  721. Targ = [Objs(TIn).Data.cx Objs(TIn).Data.cy Objs(TIn).Data.w Objs(TIn).Data.h];
  722. end
  723. TA = Stim.Talt{:};
  724. Talt = [];
  725. for i = 1:length(TA)
  726. TIn = find(ObjIds == TA(i));
  727. Talt = [Talt; Objs(TIn).Data.cx Objs(TIn).Data.cy Objs(TIn).Data.w Objs(TIn).Data.h];
  728. end
  729. %you should identify bitmaps and textures, and load them in advance
  730. Ids = unique([ Stim.Event{:}]); %get all object ids in stimulus
  731. for i = 1:length(Ids)
  732. Oix = find(ObjIds == Ids(i));
  733. if strcmp(Objs(Oix).Type, 'Texture')
  734. Objs(Oix).Data = cgTexture(Objs(Oix).Data, 'L', Ids(i)); %load the texture
  735. elseif strcmp(Objs(Oix).Type, 'Bitmap')
  736. Objs(Oix).Data = cgbitmap(Objs(Oix).Data, 'L', Ids(i)); %load the bitmap
  737. elseif strcmp(Objs(Oix).Type, 'Bezier')
  738. Objs(Oix).Data = cgbezier(Objs(Oix).Data, 'S', Ids(i)); %load the bezier
  739. elseif strcmp(Objs(Oix).Type, 'Randompattern')
  740. Objs(Oix).Data = cgRandompattern(Objs(Oix).Data, 'sprite', Ids(i)); %load the Randompattern
  741. end
  742. end
  743. for i = 1:4
  744. STM = Stim.Event{i};
  745. if ~isempty(STM)
  746. cgplotstim(STM, Objs); %cell array -> (Id) array
  747. cgpenwid(1)
  748. cgpencol(1, 1, 1)
  749. cgfont('Arial',20)
  750. cgtext( Str_EVENT{i}, 200, 0)
  751. if ~isempty(Stim.Fix)
  752. cgellipse(Fix(1), Fix(2), Fix(3), Fix(4), [1 1 1])
  753. cgtext( 'Fix', Fix(1) + 100, Fix(2))
  754. end
  755. if ~isempty(Stim.Targ)
  756. cgellipse(Targ(1), Targ(2), Targ(3), Targ(4), [1 1 1])
  757. cgtext( 'C_T', Targ(1), Targ(2) + 50)
  758. end
  759. for k = 1:length(TA)
  760. cgellipse(Talt(k,1), Talt(k,2), Talt(k,3), Talt(k,4), [1 1 1])
  761. cgtext( 'I_T', Talt(k,1), Talt(k,2) + 50)
  762. end
  763. cgflip(BGcolor(1), BGcolor(2), BGcolor(3));
  764. pause( 2)
  765. end
  766. end
  767. % --------------------------------------------------------------------
  768. function T_Del_Stim_Callback(hObject, eventdata, handles)
  769. % hObject handle to T_Del_Stim (see GCBO)
  770. % eventdata reserved - to be defined in a future version of MATLAB
  771. % handles structure with handles and user data (see GUIDATA)
  772. %CONTEXT MENU CALLBACK TO DELETE A STIMULUS
  773. global StimObj
  774. Stmnum = get(handles.PM_Event,'Value');
  775. Str_Stm = get(handles.PM_Event,'String');
  776. StimObj.Stm(Stmnum) = [];
  777. Str_Stm(Stmnum) = [];
  778. set(handles.PM_Event, 'String', Str_Stm, 'Value', 1);
  779. % --------------------------------------------------------------------
  780. function T_Copy_stim_Callback(hObject, eventdata, handles)
  781. % hObject handle to T_Copy_stim (see GCBO)
  782. % eventdata reserved - to be defined in a future version of MATLAB
  783. % handles structure with handles and user data (see GUIDATA)
  784. %CONTEXT MENU CALLBACK TO COPY A STIMULUS
  785. global StimObj
  786. Stmnum = get(handles.PM_Event,'Value');
  787. Str_Stm = get(handles.PM_Event,'String');
  788. Stim = StimObj.Stm(Stmnum);
  789. IDs = [ StimObj.Stm(:).Id ];
  790. len = length(IDs);
  791. Stim.Id = max(IDs) + 1;
  792. StimObj.Stm(len+1) = Stim;
  793. Str_Stm(len+1) = {[num2str(Stim.Id) '-' Stim.Name]};
  794. set(handles.PM_Event, 'String', Str_Stm, 'Value', 1);
  795. % --------------------------------------------------------------------
  796. function Create_stimulus( hObject, eventdata, hedit, handles )
  797. global StimObj
  798. if isfield(StimObj, 'Stm')
  799. if ~isempty(StimObj.Stm)
  800. IDs = [ StimObj.Stm(:).Id ];
  801. len = length(IDs);
  802. else
  803. IDs = 0;
  804. len = 0;
  805. end
  806. else
  807. IDs = 0;
  808. len = 0;
  809. end
  810. Str_stim = get( hedit, 'String');
  811. newStim.Name = Str_stim;
  812. newStim.Id = max(IDs) + 1;
  813. newStim.Fix = [];
  814. newStim.Targ = [];
  815. newStim.Talt = {[]};
  816. newStim.Event = cell(5,1);
  817. StimObj.Stm(len+1) = newStim;
  818. Str_Stm = get(handles.PM_Event, 'String');
  819. Str_Stm(len+1) = {[num2str(newStim.Id) '-' newStim.Name]};
  820. set(handles.PM_Event, 'String', Str_Stm, 'Value', 1);
  821. delete(gcf)
  822. % --------------------------------------------------------------------
  823. function T_New_Callback(hObject, eventdata, handles)
  824. % hObject handle to T_New (see GCBO)
  825. % eventdata reserved - to be defined in a future version of MATLAB
  826. % handles structure with handles and user data (see GUIDATA)
  827. %CONTEXT MENU CALLBACK TO CREATE A NEW STIMULUS
  828. POS = get(handles.figure1, 'Position');
  829. HF = figure('Position', [(POS(1)+40) 700 200 60], 'MenuBar', 'none', 'NumberTitle', 'off', 'name', 'Stim name');
  830. hedit = uicontrol(HF, 'style', 'edit', 'Position', [10 35 180 20]);
  831. uicontrol(HF, 'style', 'pushbutton', 'string', 'Ok', 'Position', [80 5 50 20], ...
  832. 'Callback', { @Create_stimulus, hedit, handles } );
  833. uicontrol(HF, 'style', 'pushbutton', 'string', 'Cancel', 'Position', [130 5 50 20],...
  834. 'Callback', { @delete, gcf } );
  835. % --------------------------------------------------------------------
  836. function T_BGColor_Callback(hObject, eventdata, handles)
  837. % hObject handle to T_BGColor (see GCBO)
  838. % eventdata reserved - to be defined in a future version of MATLAB
  839. % handles structure with handles and user data (see GUIDATA)
  840. BGcolor = handles.Backgroundcolor;
  841. answ = inputdlg({'R', 'G', 'B'}, 'Enter RGB 0-1' , 1, {num2str(BGcolor(1)), num2str(BGcolor(2)), num2str(BGcolor(3)) } );
  842. if ~isempty(answ)
  843. handles.Backgroundcolor = [str2double(answ{1}) str2double(answ{2}) str2double(answ{3})];
  844. guidata(hObject, handles);
  845. end