-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdittime.cpp
1562 lines (1355 loc) · 39.4 KB
/
Edittime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ============================================================================
//
// This file contains routines that are handled only during the Edittime,
// under the Frame and Event editors.
//
// Including creating, display, and setting up your object.
//
// ============================================================================
#include "common.h"
// --------------------
// Properties
// --------------------
PROPS_IDS_START()
//Image bank
PROPID_GRP0,
PROPID_IMAGES,
PROPID_REMOVEDEF,
PROPID_MULTIIMG,
PROPID_LOADIMG,
PROPID_DISPTARGET,
PROPID_SELECTLAST,
//Settings
PROPID_GRP1,
PROPID_USEABS,
PROPID_KEEPPOINTS,
PROPID_THREADEDIO,
PROPID_RESAMPLING,
//Font tab
PROPID_TEXT_MULTILINE,
PROPID_TEXT_NOCLIP,
PROPID_TEXT_WORDELLIPSIS,
PROPID_TEXT_WORDBREAK,
PROPS_IDS_END()
PROPS_DATA_START()
PropData_Group(PROPID_GRP0,(int)_T("Image bank"),(int)_T("")),
PropData_ImageList(PROPID_IMAGES,(int)_T("Images"),(int)_T("")),
PropData_Button(PROPID_REMOVEDEF,(int)_T(""),(int)_T(""),(int)_T("Remove")),
//PropData_CheckBox(PROPID_MULTIIMG,(int)_T("Allow multiple images"),(int)_T("Actions to manage multiple images will be provided. Recommended over using multiple Surface objects .")),
PropData_CheckBox(PROPID_LOADIMG,(int)_T("Load first image on start"),(int)_T("Loads and displays image 0 if available on start.")),
PropData_CheckBox(PROPID_SELECTLAST,(int)_T("Select new images"),(int)_T("When an image is added, it is automatically selected for editing.")),
PropData_CheckBox(PROPID_DISPTARGET,(int)_T("Display selected image"),(int)_T("\"Set display image\" will not be available and the selected editing image is drawn instead.")),
PropData_Group(PROPID_GRP1,(int)_T("Settings"),(int)_T("")),
PropData_CheckBox(PROPID_USEABS,(int)_T("Use absolute coordinates"),(int)_T("Coordinates are not relative to the surface position.")),
PropData_CheckBox(PROPID_KEEPPOINTS,(int)_T("Keep polygon points after drawing"),(int)_T("The polygon points will be kept after drawing one.")),
PropData_CheckBox(PROPID_THREADEDIO,(int)_T("Background file input/output"),(int)_T("If checked, the application does not freeze while a file is being loaded or saved.")),
PropData_CheckBox(PROPID_RESAMPLING,(int)_T("Linear resampling for transformations"),(int)_T("Some actions like \"Resize\" and \"Rotate\" can achieve better quality with this option.")),
PROPS_DATA_END()
TCHAR* FontQuality[] =
{
0,
_T("Aliased"),
_T("Anti-aliased"),
_T("ClearType"),
0
};
PropData FontProps[] = {
PropData_CheckBox(PROPID_TEXT_MULTILINE,(int)_T("Multi-line"),(int)_T("If checked, line breaks will be rendered, but vertical alignment is not supported.")),
PropData_CheckBox(PROPID_TEXT_NOCLIP,(int)_T("No text clipping"),(int)_T("If checked, the text won't be clipped if it exceeds the given rectangle.")),
PropData_CheckBox(PROPID_TEXT_WORDELLIPSIS,(int)_T("Add ellipsis"),(int)_T("Truncates any word that does not fit in the rectangle and adds an ellipsis.")),
PropData_CheckBox(PROPID_TEXT_WORDBREAK,(int)_T("Break words"),(int)_T("Break words that don't fit in the rectangle.")),
PropData_End()
};
// --------------------
// Debugger
// --------------------
DEBUGGER_IDS_START()
// DB_CURRENTSTRING,
DEBUGGER_IDS_END()
DEBUGGER_ITEMS_START()
// DB_CURRENTSTRING,
// DB_CURRENTSTRING|DB_EDITABLE,
// DB_CURRENTVALUE|DB_EDITABLE,
// DB_CURRENTCHECK,
// DB_CURRENTCOMBO,
DEBUGGER_ITEMS_END()
// --------------------
// GetProperties
// --------------------
// Inserts properties into the properties of the object.
//
BOOL WINAPI DLLExport GetProperties(LPMV mV, LPEDATA edPtr, BOOL bMasterItem)
{
#ifndef RUN_ONLY
mvInsertProps(mV, edPtr, Properties, PROPID_TAB_GENERAL, TRUE);
mvInsertProps(mV, edPtr, FontProps, PROPID_TAB_TEXTOPT, TRUE);
#endif // !RUN_ONLY
// OK
return TRUE;
}
// --------------------
// ReleaseProperties
// --------------------
// Called when the properties are removed from the property window.
//
void WINAPI DLLExport ReleaseProperties(LPMV mV, LPEDATA edPtr, BOOL bMasterItem)
{
#ifndef RUN_ONLY
// Write your code here
#endif // !RUN_ONLY
}
// --------------------
// GetPropCreateParam
// --------------------
// Called when a property is initialized and its creation parameter is NULL (in the PropData).
// Allows you, for example, to change the content of a combobox property according to specific settings in the EDITDATA structure.
//
LPARAM WINAPI DLLExport GetPropCreateParam(LPMV mV, LPEDATA edPtr, UINT nPropID)
{
#ifndef RUN_ONLY
// Example
// -------
// if ( nPropID == PROPID_COMBO )
// {
// switch (edPtr->sType)
// {
// case TYPE1:
// return (LPARAM)ComboList1;
// case TYPE2:
// return (LPARAM)ComboList2;
// }
// }
#endif // !RUN_ONLY
return NULL;
}
// ----------------------
// ReleasePropCreateParam
// ----------------------
// Called after a property has been initialized.
// Allows you, for example, to free memory allocated in GetPropCreateParam.
//
void WINAPI DLLExport ReleasePropCreateParam(LPMV mV, LPEDATA edPtr, UINT nPropID, LPARAM lParam)
{
#ifndef RUN_ONLY
#endif // !RUN_ONLY
}
// --------------------
// GetPropValue
// --------------------
// Returns the value of properties that have a value.
// Note: see GetPropCheck for checkbox properties
//
LPVOID WINAPI DLLExport GetPropValue(LPMV mV, LPEDATA edPtr, UINT nPropID)
{
#ifndef RUN_ONLY
// Example
// -------
switch (nPropID) {
case PROPID_IMAGES:
{
CPropDataValue* pv = new CPropDataValue((edPtr->imageCount + 1) * sizeof(WORD), NULL);
if (pv)
{
if (pv->m_pData)
{
LPWORD pw = (LPWORD)pv->m_pData;
*pw++ = edPtr->imageCount;
for (WORD w=0;w<edPtr->imageCount;w++)
*pw++ = edPtr->images[w];
return pv;
}
pv->Delete();
}
break;
}
}
#endif // !RUN_ONLY
return NULL;
}
// --------------------
// GetPropCheck
// --------------------
// Returns the checked state of properties that have a check box.
//
BOOL WINAPI DLLExport GetPropCheck(LPMV mV, LPEDATA edPtr, UINT nPropID)
{
#ifndef RUN_ONLY
// Example
// -------
switch (nPropID) {
case PROPID_LOADIMG:
return edPtr->loadFirst;
case PROPID_MULTIIMG:
return edPtr->multiImg;
case PROPID_USEABS:
return edPtr->useAbs;
case PROPID_KEEPPOINTS:
return edPtr->keepPoints;
case PROPID_THREADEDIO:
return edPtr->threadedIO;
case PROPID_DISPTARGET:
return edPtr->dispTarget;
case PROPID_SELECTLAST:
return edPtr->selectLast;
case PROPID_RESAMPLING:
return mvGetPropCheck(mV,edPtr,PROPID_FITEM_ANTIA);
//Text
case PROPID_TEXT_MULTILINE:
return !(edPtr->textFlags&DT_SINGLELINE);
case PROPID_TEXT_NOCLIP:
return (edPtr->textFlags&DT_NOCLIP)==DT_NOCLIP;
case PROPID_TEXT_WORDBREAK:
return (edPtr->textFlags&DT_WORDBREAK)==DT_WORDBREAK;
case PROPID_TEXT_WORDELLIPSIS:
return (edPtr->textFlags&DT_WORD_ELLIPSIS)==DT_WORD_ELLIPSIS;
}
#endif // !RUN_ONLY
return 0; // Unchecked
}
// --------------------
// SetPropValue
// --------------------
// This routine is called by MMF after a property has been modified.
//
void WINAPI DLLExport SetPropValue(LPMV mV, LPEDATA edPtr, UINT nPropID, LPVOID lParam)
{
#ifndef RUN_ONLY
// Gets the pointer to the CPropValue structure
CPropValue* pValue = (CPropValue*)lParam;
// Example
// -------
switch (nPropID)
{
case PROPID_IMAGES:
if(((CPropDataValue*)pValue)->m_pData)
{
LPWORD pw = (LPWORD)((CPropDataValue*)pValue)->m_pData;
//edPtr->imageCount = *pw++;
for (WORD w=0;w<edPtr->imageCount;w++)
edPtr->images[w] = *pw++;
}
mvInvalidateObject(mV,edPtr);
break;
}
#endif // !RUN_ONLY
}
// --------------------
// SetPropCheck
// --------------------
// This routine is called by MMF when the user modifies a checkbox in the properties.
//
void WINAPI DLLExport SetPropCheck(LPMV mV, LPEDATA edPtr, UINT nPropID, BOOL nCheck)
{
#ifndef RUN_ONLY
// Example
// -------
switch (nPropID)
{
case PROPID_LOADIMG:
edPtr->loadFirst = nCheck;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_LOADIMG, true);
break;
case PROPID_MULTIIMG:
edPtr->multiImg = nCheck;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_MULTIIMG, true);
mvRefreshProp(mV, edPtr, PROPID_LOADIMG, true);
mvRefreshProp(mV, edPtr, PROPID_SELECTLAST, true);
mvRefreshProp(mV, edPtr, PROPID_DISPTARGET, true);
break;
case PROPID_USEABS:
edPtr->useAbs = nCheck;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_USEABS, true);
break;
case PROPID_KEEPPOINTS:
edPtr->keepPoints = nCheck;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_KEEPPOINTS, true);
break;
case PROPID_THREADEDIO:
edPtr->threadedIO = nCheck;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_THREADEDIO, true);
break;
case PROPID_DISPTARGET:
edPtr->dispTarget = nCheck;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_DISPTARGET, true);
break;
case PROPID_SELECTLAST:
edPtr->selectLast = nCheck;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_SELECTLAST, true);
break;
case PROPID_RESAMPLING:
mvSetPropCheck(mV,edPtr,PROPID_FITEM_ANTIA,nCheck);
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_RESAMPLING, true);
mvRefreshProp(mV, edPtr, PROPID_FITEM_ANTIA, true);
break;
//Font
case PROPID_TEXT_MULTILINE:
if(nCheck)
edPtr->textFlags &= ~DT_SINGLELINE;
else
edPtr->textFlags |= DT_SINGLELINE;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_TEXT_MULTILINE, true);
break;
case PROPID_TEXT_NOCLIP:
if(nCheck)
edPtr->textFlags |= DT_NOCLIP;
else
edPtr->textFlags &= ~DT_NOCLIP;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_TEXT_NOCLIP, true);
break;
case PROPID_TEXT_WORDBREAK:
if(nCheck)
edPtr->textFlags |= DT_WORDBREAK;
else
edPtr->textFlags &= ~DT_WORDBREAK;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_TEXT_WORDBREAK, true);
break;
case PROPID_TEXT_WORDELLIPSIS:
if(nCheck)
edPtr->textFlags |= DT_WORD_ELLIPSIS;
else
edPtr->textFlags &= ~DT_WORD_ELLIPSIS;
mvInvalidateObject(mV, edPtr);
mvRefreshProp(mV, edPtr, PROPID_TEXT_WORDELLIPSIS, true);
break;
}
#endif // !RUN_ONLY
}
// --------------------
// EditProp
// --------------------
// This routine is called when the user clicks the button of a Button or EditButton property.
//
BOOL WINAPI DLLExport EditProp(LPMV mV, LPEDATA edPtr, UINT nPropID)
{
#ifndef RUN_ONLY
// Example
// -------
if (nPropID==PROPID_REMOVEDEF)
{
int kill = MessageBox(0,_T("Do you really want to delete all images?"),_T("Warning"),MB_YESNO|MB_ICONWARNING);
if(kill==IDYES)
{
mvInvalidateObject(mV,edPtr);
for(int i=0;i<MAX_IMAGES;i++)
edPtr->images[i] = 0;
edPtr->imageCount = 0;
//edPtr->width = 320;
//edPtr->height = 240;
mvRefreshProp(mV, edPtr, PROPID_LOADIMG, true);
mvRefreshProp(mV, edPtr, PROPID_IMAGES, true);
return true;
}
return false;
}
else if(nPropID==PROPID_IMAGES)
{
mvInvalidateObject(mV,edPtr);
EditAnimationParams eip;
eip.m_dwSize = sizeof(EditAnimationParams);
eip.m_pWindowTitle = 0;
eip.m_nImages = edPtr->imageCount;
eip.m_nMaxImages = MAX_IMAGES;
eip.m_nStartIndex = 0;
eip.m_pImages = &edPtr->images[0];
eip.m_pImageTitles = 0;
eip.m_dwOptions = PICTEDOPT_CANBETRANSPARENT|PICTEDOPT_HOTSPOT;
eip.m_dwFixedWidth = edPtr->width?edPtr->width:DEF_WIDTH;
eip.m_dwFixedHeight = edPtr->height?edPtr->height:DEF_HEIGHT;
BOOL output = mV->mvEditAnimation(edPtr,&eip,mV->mvHEditWin);
//Update object count
edPtr->imageCount = eip.m_nImages;
//Update object dimensions
if(output&&edPtr->images[0])
{
cSurface is;
LockImageSurface(mV->mvIdAppli,edPtr->images[0],is);
edPtr->width = edPtr->width_def = is.GetWidth();
edPtr->height = edPtr->height_def = is.GetHeight();
UnlockImageSurface(is);
}
mvRefreshProp(mV, edPtr, PROPID_LOADIMG, true);
mvRefreshProp(mV, edPtr, PROPID_IMAGES, true);
return output;
}
#endif // !RUN_ONLY
return FALSE;
}
// --------------------
// IsPropEnabled
// --------------------
// This routine returns the enabled state of a property.
//
BOOL WINAPI IsPropEnabled(LPMV mV, LPEDATA edPtr, UINT nPropID)
{
#ifndef RUN_ONLY
// Example
// -------
switch (nPropID) {
case PROPID_LOADIMG:
return edPtr->multiImg||!edPtr->imageCount;
break;
case PROPID_SELECTLAST:
return edPtr->multiImg;
break;
case PROPID_DISPTARGET:
return edPtr->multiImg;
break;
}
#endif // !RUN_ONLY
return TRUE;
}
// ============================================================================
//
// TEXT PROPERTIES
//
// ============================================================================
// --------------------
// GetTextCaps
// --------------------
// Return the text capabilities of the object under the frame editor.
//
DWORD WINAPI DLLExport GetTextCaps(mv _far *mV, LPEDATA edPtr)
{
return (TEXT_ALIGN_LEFT|TEXT_ALIGN_HCENTER|TEXT_ALIGN_RIGHT|TEXT_ALIGN_TOP|TEXT_ALIGN_VCENTER|TEXT_ALIGN_BOTTOM|TEXT_FONT);
}
// --------------------
// GetTextFont
// --------------------
// Return the font used the object.
// Note: the pStyle and cbSize parameters are obsolete and passed for compatibility reasons only.
//
BOOL WINAPI DLLExport GetTextFont(mv _far *mV, LPEDATA edPtr, LPLOGFONT plf, LPTSTR pStyle, UINT cbSize)
{
#if !RUN_ONLY
// Example: copy LOGFONT structure from EDITDATA
memcpy(plf, &edPtr->textFont, sizeof(LOGFONT));
#endif // !RUN_ONLY
return TRUE;
}
// --------------------
// SetTextFont
// --------------------
// Change the font used the object.
// Note: the pStyle parameter is obsolete and passed for compatibility reasons only.
//
BOOL WINAPI DLLExport SetTextFont(mv _far *mV, LPEDATA edPtr, LPLOGFONT plf, LPCSTR pStyle)
{
#if !RUN_ONLY
// Example: copy LOGFONT structure to EDITDATA
memcpy(&edPtr->textFont, plf, sizeof(LOGFONT));
#endif // !RUN_ONLY
return TRUE;
}
// --------------------
// GetTextClr
// --------------------
// Get the text color of the object.
//
COLORREF WINAPI DLLExport GetTextClr(mv _far *mV, LPEDATA edPtr)
{
// Example
return edPtr->textColor;
}
// --------------------
// SetTextClr
// --------------------
// Set the text color of the object.
//
void WINAPI DLLExport SetTextClr(mv _far *mV, LPEDATA edPtr, COLORREF color)
{
// Example
edPtr->textColor = color;
}
// --------------------
// GetTextAlignment
// --------------------
// Get the text alignment of the object.
//
DWORD WINAPI DLLExport GetTextAlignment(mv _far *mV, LPEDATA edPtr)
{
DWORD dw = 0;
#if !RUN_ONLY
// Example
// -------
if ( (edPtr->textFlags & DT_LEFT) != 0 )
dw |= TEXT_ALIGN_LEFT;
if ( (edPtr->textFlags & DT_CENTER) != 0 )
dw |= TEXT_ALIGN_HCENTER;
if ( (edPtr->textFlags & DT_RIGHT) != 0 )
dw |= TEXT_ALIGN_RIGHT;
if ( (edPtr->textFlags & DT_TOP) != 0 )
dw |= TEXT_ALIGN_TOP;
if ( (edPtr->textFlags & DT_VCENTER) != 0 )
dw |= TEXT_ALIGN_VCENTER;
if ( (edPtr->textFlags & DT_BOTTOM) != 0 )
dw |= TEXT_ALIGN_BOTTOM;
#endif // !RUN_ONLY
return dw;
}
// --------------------
// SetTextAlignment
// --------------------
// Set the text alignment of the object.
//
void WINAPI DLLExport SetTextAlignment(mv _far *mV, LPEDATA edPtr, DWORD dwAlignFlags)
{
#if !RUN_ONLY
// Example
// -------
DWORD dw = edPtr->textFlags;
if ( (dwAlignFlags & TEXT_ALIGN_LEFT) != 0 )
dw = (dw & ~(DT_LEFT|DT_RIGHT|DT_CENTER)) | DT_LEFT;
if ( (dwAlignFlags & TEXT_ALIGN_HCENTER) != 0 )
dw = (dw & ~(DT_LEFT|DT_RIGHT|DT_CENTER)) | DT_CENTER;
if ( (dwAlignFlags & TEXT_ALIGN_RIGHT) != 0 )
dw = (dw & ~(DT_LEFT|DT_RIGHT|DT_CENTER)) | DT_RIGHT;
if ( (dwAlignFlags & TEXT_ALIGN_TOP) != 0 )
dw = (dw & ~(DT_TOP|DT_VCENTER|DT_RIGHT)) | DT_TOP;
if ( (dwAlignFlags & TEXT_ALIGN_VCENTER) != 0 )
dw = (dw & ~(DT_TOP|DT_VCENTER|DT_RIGHT)) | DT_VCENTER;
if ( (dwAlignFlags & TEXT_ALIGN_BOTTOM) != 0 )
dw = (dw & ~(DT_TOP|DT_VCENTER|DT_RIGHT)) | DT_BOTTOM;
edPtr->textFlags = dw;
#endif // !RUN_ONLY
}
// -----------------
// BmpToImg
// -----------------
// Converts an image from the resource to an image displayable under MMF2
// Not used in this template, but it is a good example on how to create
// an image.
//
/*
WORD BmpToImg(int bmID, npAppli idApp, short HotX = 0, short HotY = 0, short ActionX = 0, short ActionY = 0)
{
Img ifo;
WORD img;
HRSRC hs;
HGLOBAL hgBuf;
LPBYTE adBuf;
LPBITMAPINFOHEADER adBmi;
img = 0;
if ((hs = FindResource(hInstLib, MAKEINTRESOURCE(bmID), RT_BITMAP)) != NULL)
{
if ((hgBuf = LoadResource(hInstLib, hs)) != NULL)
{
if ((adBuf = (LPBYTE)LockResource(hgBuf)) != NULL)
{
adBmi = (LPBITMAPINFOHEADER)adBuf;
ifo.imgXSpot = HotX;
ifo.imgYSpot = HotY;
ifo.imgXAction = ActionX;
ifo.imgYAction = ActionY;
if (adBmi->biBitCount > 4)
RemapDib((LPBITMAPINFO)adBmi, idApp, NULL);
img = (WORD)DibToImage(idApp, &ifo, adBmi);
UnlockResource(hgBuf);
}
FreeResource(hgBuf);
}
}
return img;
}
*/
// ============================================================================
//
// ROUTINES USED UNDER FRAME EDITOR
//
// ============================================================================
// --------------------
// MakeIcon
// --------------------
// Called once object is created or modified, just after setup.
//
// Note: this function is optional. If it's not defined in your extension,
// MMF2 will load the EXO_ICON bitmap if it's defined in your resource file.
//
// If you need to draw the icon manually, remove the comments around this function and in the .def file.
//
int WINAPI DLLExport MakeIconEx ( mv _far *mV, cSurface* pIconSf, LPTSTR lpName, fpObjInfo oiPtr, LPEDATA edPtr )
{
int error = -1;
#ifndef RUN_ONLY
//Load icon
if((edPtr->multiImg&&!edPtr->loadFirst)||!edPtr->images[0])
{
if(pIconSf->LoadImage(hInstLib, EXO_ICON))
{
error = 0;
pIconSf->SetTransparentColor(0xff00ff);
}
}
//Draw image
else
{
cSurface is;
LockImageSurface(mV->mvIdAppli,edPtr->images[0],is);
is.Minimize();
//Draw grid
for(int x=0;x<7;x++)
for(int y=0;y<7;y++)
pIconSf->Rectangle(x*4+2,y*4+2,x*4+6,y*4+6,(x+y)%2?LIGHT_GRAY:WHITE,0,0,1);
int sw = is.GetWidth(), sh = is.GetHeight();
int dw,dh;
//Square
if(sw==sh)
{
dw = min(28,sw);
dh = dw;
}
//Wide
else if(sw>sh)
{
dw = min(28,sw);
dh = sh*1.0/sw*dw;
}
//Tall
else
{
dh = min(28,sh);
dw = sw*1.0/sh*dh;
}
//Draw image
if(is.Stretch(*pIconSf,16-dw/2,16-dh/2,dw,dh,BMODE_TRANSP,BOP_COPY,0,STRF_RESAMPLE_TRANSP))
error = 0;
//Get transparent color
COLORREF trans = is.GetTransparentColor();
pIconSf->SetTransparentColor(trans);
UnlockImageSurface(is);
//Outline
pIconSf->Rectangle(0,0,32,32,1,0x333333);
CFillFlat white(WHITE);
pIconSf->Rectangle(1,1,31,31,1,&white,0,BMODE_OPAQUE,BOP_BLEND,32);
//Smooth border
pIconSf->SetPixel(0,0,trans);
pIconSf->SetPixel(31,31,trans);
pIconSf->SetPixel(31,0,trans);
pIconSf->SetPixel(0,31,trans);
}
#endif // !RUN_ONLY
return error;
}
// --------------------
// CreateObject
// --------------------
// Called when you choose "Create new object". It should display the setup box
// and initialize everything in the datazone.
void WINAPI DLLExport CreateFromFile (LPMV mV, LPTSTR fileName, LPEDATA edPtr);
int WINAPI DLLExport CreateObject(mv _far *mV, fpLevObj loPtr, LPEDATA edPtr)
{
#ifndef RUN_ONLY
// Do some rSDK stuff
#include "rCreateObject.h"
CreateFromFile(mV,0,edPtr);
return 0; // No error
#endif // !RUN_ONLY
// Error
return -1;
}
// --------------------
// EditObject
// --------------------
// One of the option from the menu has been selected, and not a default menu option
// automatically handled by MMF2: this routine is then called.
//
BOOL WINAPI EditObject (mv _far *mV, fpObjInfo oiPtr, fpLevObj loPtr, LPEDATA edPtr)
{
#ifndef RUN_ONLY
return EditProp(mV,edPtr,PROPID_IMAGES);
#endif // !RUN_ONLY
// Error
return FALSE;
}
// --------------------
// SetEditSize
// --------------------
// Called by MMF2 when the object has been resized
//
// Note: remove the comments if your object can be resized (and remove the comments in the .def file)
BOOL WINAPI SetEditSize(LPMV mv, LPEDATA edPtr, int cx, int cy)
{
#ifndef RUN_ONLY
//Single, empty image
if(edPtr->loadFirst&&!edPtr->images[0]) //&&!edPtr->multiImg
{
edPtr->width = edPtr->width_def = cx;
edPtr->height = edPtr->height_def = cy;
}
//Multiple images or single image
else if(edPtr->images[0]&&(edPtr->loadFirst||!edPtr->multiImg))
{
mvInvalidateObject(mv, edPtr);
cSurface is, tmp;
LockImageSurface(mv->mvIdAppli,edPtr->images[0],is);
tmp.Clone(is,cx,cy);
is.Delete();
is.Clone(tmp);
Img old;
GetImageInfos(mv->mvIdAppli,edPtr->images[0],&old);
edPtr->images[0] = CreateImageFromSurface(mv,&is,cx,cy,old.imgXSpot*1.0f*cx/old.imgWidth,old.imgYSpot*1.0f*cy/old.imgHeight,0,0);
UnlockImageSurface(is);
edPtr->width = edPtr->width_def = cx;
edPtr->height = edPtr->height_def = cy;
}
#endif // !RUN_ONLY
return TRUE; // OK
}
// --------------------
// PutObject
// --------------------
// Called when each individual object is dropped in the frame.
//
void WINAPI DLLExport PutObject(mv _far *mV, fpLevObj loPtr, LPEDATA edPtr, ushort cpt)
{
#ifndef RUN_ONLY
#endif // !RUN_ONLY
}
// --------------------
// RemoveObject
// --------------------
// Called when each individual object is removed from the frame.
//
void WINAPI DLLExport RemoveObject(mv _far *mV, fpLevObj loPtr, LPEDATA edPtr, ushort cpt)
{
#ifndef RUN_ONLY
// Is the last object removed?
if (0 == cpt)
{
// Do whatever necessary to remove our data
}
#endif // !RUN_ONLY
}
// --------------------
// DuplicateObject
// --------------------
// Called when an object is created from another one (note: should be called CloneObject instead...)
//
void WINAPI DLLExport DuplicateObject(mv __far *mV, fpObjInfo oiPtr, LPEDATA edPtr)
{
#ifndef RUN_ONLY
#endif // !RUN_ONLY
}
// --------------------
// GetObjectRect
// --------------------
// Returns the size of the rectangle of the object in the frame editor.
//
void WINAPI DLLExport GetObjectRect(mv _far *mV, RECT FAR *rc, fpLevObj loPtr, LPEDATA edPtr)
{
#ifndef RUN_ONLY
int width = 32;
int height = 32;
int hotX = 0;
int hotY = 0;
//Display first image or don't use multiple images
if(edPtr->loadFirst||!edPtr->multiImg)
{
//First image is valid
if(edPtr->images[0])
{
width = edPtr->width_def;
height = edPtr->height_def;
//Get hotspot
Img imgInfo;
GetImageInfos(mV->mvIdAppli,edPtr->images[0],&imgInfo);
hotX = imgInfo.imgXSpot;
hotY = imgInfo.imgYSpot;
}
//No images in the bank
else if(!edPtr->images[0]&&edPtr->loadFirst) //!edPtr->multiImg)
{
width = edPtr->width;
height = edPtr->height;
}
}
//Apply hotspot
rc->left -= hotX;
rc->top -= hotY;
//Apply size
if(width==0) width = DEF_WIDTH;
if(height==0) height = DEF_HEIGHT;
rc->right = rc->left + width;
rc->bottom = rc->top + height;
#endif // !RUN_ONLY
return;
}
// --------------------
// EditorDisplay
// --------------------
// Displays the object under the frame editor
//
// Note: this function is optional. If it's not defined in your extension,
// MMF2 will load and display the EXO_IMAGE bitmap if it's defined in your resource file.
//
// If you need to draw the icon manually, remove the comments around this function and in the .def file.
//
void WINAPI DLLExport EditorDisplay(mv _far *mV, fpObjInfo oiPtr, fpLevObj loPtr, LPEDATA edPtr, RECT FAR *rc)
{
#ifndef RUN_ONLY
// This is a simple case of drawing an image onto MMF's frame editor window
// First, we must get a pointer to the surface used by the frame editor
LPSURFACE ps = WinGetSurface((int)mV->mvIdEditWin);
if(!ps) return;
cSurface is;
//Draw extension icon
if((edPtr->multiImg||!edPtr->images[0])&&(!edPtr->loadFirst||!edPtr->images[0])) {
is.Create(4,4,ps);
is.LoadImage(hInstLib,EXO_IMAGE,LI_REMAP);
is.SetTransparentColor(0xff00ff);
//Also draw surface borders
if(edPtr->loadFirst&&!edPtr->images[0])
{
//Create tile
cSurface* proto;
GetSurfacePrototype(&proto, 24, ST_MEMORY, SD_DIB);
cSurface tile;
tile.Create(16,16, proto);
tile.Fill(LIGHT_GRAY);
tile.Rectangle(0,0,8,8,DARK_GRAY,0,0,TRUE);
tile.Rectangle(16,16,8,8,DARK_GRAY,0,0,TRUE);
CFillMosaic mosaic(&tile);
CFillFlat light(LIGHT_GRAY);
CFillFlat dark(DARK_GRAY);
CFillFlat outline(BLACK);
//Draw shapes
ps->Rectangle(rc->left, rc->top, rc->right, rc->bottom, &mosaic, 1, &outline, 0, BMODE_TRANSP, BOP_BLEND, 32);
//Icon
if(rc->right - rc->left >=32 && rc->bottom - rc->top >= 32)
is.Blit(*ps, (rc->right + rc->left)/2 - 16, (rc->bottom + rc->top)/2 - 16, BMODE_TRANSP);
}
//Icon only
else
{
is.Blit(*ps,rc->left,rc->top,BMODE_TRANSP);
}
}
//Draw default image
else
{
BlitMode blitMode = oiPtr->oiHdr.oiInkEffect & EFFECTFLAG_TRANSPARENT ? BMODE_TRANSP : BMODE_OPAQUE;
LockImageSurface(mV->mvIdAppli,edPtr->images[0],is);
is.Blit(*ps,rc->left,rc->top,blitMode,(BlitOp)(oiPtr->oiHdr.oiInkEffect & EFFECT_MASK),oiPtr->oiHdr.oiInkEffectParam);
UnlockImageSurface(is);
}
#endif // !RUN_ONLY
}
// --------------------
// IsTransparent
// --------------------
// This routine tells MMF2 if the mouse pointer is over a transparent zone of the object.
//
extern "C" BOOL WINAPI DLLExport IsTransparent(mv _far *mV, fpLevObj loPtr, LPEDATA edPtr, int dx, int dy)
{
#ifndef RUN_ONLY
if (edPtr->images[0]&&edPtr->loadFirst) {
BOOL out = FALSE;
cSurface is;
LockImageSurface(mV->mvIdAppli,edPtr->images[0],is);
//Alpha channel
if(is.HasAlpha())
out = is.GetAlphaSurface()->GetPixelFast(dx,dy)==0;
//Transparent color
else out = is.GetTransparentColor()==is.GetPixelFast(dx,dy);
UnlockImageSurface(is);
return out;
}
#endif // !RUN_ONLY
return FALSE;
}
// --------------------
// PrepareToWriteObject
// --------------------
// Just before writing the datazone when saving the application, MMF2 calls this routine.
//
void WINAPI DLLExport PrepareToWriteObject(mv _far *mV, LPEDATA edPtr, fpObjInfo adoi)