1 // RC2WXR.cpp: implementation of the wxRC2WXR class.
3 //////////////////////////////////////////////////////////////////////
4 // For compilers that support precompilation, includes "wx/wx.h".
9 #include "wx/resource.h"
10 //////////////////////////////////////////////////////////////////////
11 // Construction/Destruction
12 //////////////////////////////////////////////////////////////////////
25 void wxRC2WXR::Open(wxString wxrfile
, wxString rcfile
)
27 wxFileProgressDlg fileprog
;
31 m_filesize
=m_rc
.Length();
32 if( (m_wxr
= fopen( wxrfile
, "wt" )) == NULL
)
50 fileprog
.UpdateProgress(&m_rc
);
57 fileprog
.UpdateProgress(&m_rc
);
62 fileprog
.UpdateProgress(&m_rc
);
73 Microsoft style as of v5.0
74 IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
75 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
76 CAPTION "About Funimator"
77 FONT 8, "MS Sans Serif"
80 IDD_DIBATTR DIALOG 7, 16, 172, 119
81 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
82 CAPTION "DIB Attributes"
83 FONT 8, "MS Sans Serif"
85 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
86 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
91 void wxRC2WXR::ParseDialog(wxString dlgname
)
96 /* Make sure that this really is a dialog
97 microsoft reuses the keyword DIALOG for other things
100 //Microsoft notation?
101 if (tok
=="DISCARDABLE")
106 //This isn't a Dialog resource eject eject
109 //Generate Dialog text
110 fprintf(m_wxr
,"static char *dialog%i = \"dialog(name = '%s',\\\n",dlgid
,dlgname
);
111 //be lazy about style for now. add it later
112 fprintf(m_wxr
,"style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n");
114 fprintf(m_wxr
,"id = %i,\\\n",dlgid
);
116 //Record x,y,width,height
117 int x
,y
,width
,height
;
118 ReadRect(x
,y
,width
,height
);
119 fprintf(m_wxr
,"x = %i, y = %i, width = %i, height = %i,\\\n",x
,y
,width
,height
);
122 //CAPTION "About Funimator"
127 while ((tok
!="BEGIN")&(tok
!="{"))
131 title
=GetQuoteField();
132 fprintf(m_wxr
,"title = '%s',\\\n",title
);
136 fprintf(m_wxr
,"use_dialog_units = 1,\\\n");
137 fprintf(m_wxr
,"use_system_defaults = 0,\\\n");
139 fprintf(m_wxr
,"font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n");
141 fprintf(m_wxr
,").\";\n\n");
149 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
151 LTEXT "Bands",IDC_STATIC,11,86,21,8
152 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
155 void wxRC2WXR::ParseControls()
160 while ((tok
!="END")&(tok
!="}"))
166 if (tok
=="PUSHBUTTON")
168 if (tok
=="DEFPUSHBUTTON")
181 //LTEXT "Radius",IDC_STATIC,9,67,23,8
182 void wxRC2WXR::ParseStaticText()
185 wxString phrase
,varname
;
186 phrase
=GetQuoteField();
189 int x
,y
,width
,height
;
190 ReadRect(x
,y
,width
,height
);
191 fprintf(m_wxr
," control = [%i,wxStaticText,'%s','0','%s',",m_controlid
,phrase
,varname
);
192 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
193 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
195 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
196 void wxRC2WXR::ParseTextCtrl()
202 int x
,y
,width
,height
;
203 ReadRect(x
,y
,width
,height
);
204 fprintf(m_wxr
," control = [%i,wxTextCtrl,'','0','%s',",m_controlid
,varname
);
205 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
206 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
209 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
210 void wxRC2WXR::ParsePushButton()
213 wxString phrase
,varname
;
214 phrase
=GetQuoteField();
222 if (varname
=="IDCANCEL")
225 if (varname
=="IDAPPLY")
228 int x
,y
,width
,height
;
229 ReadRect(x
,y
,width
,height
);
230 fprintf(m_wxr
," control = [%i,wxButton,'%s','0','%s',",c
,phrase
,varname
);
231 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
232 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
237 bool wxRC2WXR::Seperator(int ch
)
239 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='|'))
250 void wxRC2WXR::ParseGroupBox()
252 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
254 wxString phrase
,varname
;
255 phrase
=GetQuoteField();
258 int x
,y
,width
,height
;
259 ReadRect(x
,y
,width
,height
);
260 fprintf(m_wxr
," control = [%i,wxStaticBox,'%s','0','%s',",m_controlid
,phrase
,varname
);
261 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
262 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
267 void wxRC2WXR::ReadRect(int & x
, int & y
, int & width
, int & height
)
271 width
=atoi(GetToken());
272 height
=atoi(GetToken());
276 wxString
wxRC2WXR::GetToken()
294 while (Seperator(ch
))
308 while (!Seperator(ch
))
322 wxString
wxRC2WXR::GetQuoteField()
342 void wxRC2WXR::ReadChar(int &ch
)
347 if((result
>=m_filesize
))
350 result
=m_rc
.Read(&ch
,1);
359 void wxRC2WXR::ParseComboBox()
361 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
362 WS_VSCROLL | WS_TABSTOP */
367 int x
,y
,width
,height
;
368 ReadRect(x
,y
,width
,height
);
370 fprintf(m_wxr
," control = [%i,wxChoice,'','0','%s',",m_controlid
,varname
);
371 fprintf(m_wxr
,"%i,%i,%i,%i,[],\\\n",x
,y
,width
,height
);
372 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
377 void wxRC2WXR::ParseMenu(wxString name
)
382 fprintf(m_wxr
,"static char *MenuBar%i = \"menu(name = '%s',\\\n",menuid
,name
);
383 fprintf(m_wxr
,"menu = \\\n");
384 fprintf(m_wxr
,"[\\\n");
386 while ((tok
!="BEGIN")&(tok
!="{"))
389 while ((tok
!="END")&(tok
!="}"))
395 fprintf(m_wxr
," ],\\\n");
399 fprintf(m_wxr
,"]).\";\n\n");
402 void wxRC2WXR::ParsePopupMenu()
404 static int menuitem
=99;
410 //Remove /t because it causes problems
411 spot
=tok
.First("\\t");
413 fprintf(m_wxr
," ['%s',%i,'',\\\n",tok
,menuitem
);
414 while ((tok
!="BEGIN")&(tok
!="{"))
417 while ((tok
!="END")&(tok
!="}"))
422 if (PeekToken()=="SEPARATOR")
423 fprintf(m_wxr
," [],\\\n");
427 //Remove /t because it causes problems
428 spot
=tok
.First("\\t");
431 fprintf(m_wxr
," ['%s',%i,''],\\\n",tok
,menuitem
);
440 wxString
wxRC2WXR::PeekToken()
450 //Windows pain in the butt CONTROL
451 void wxRC2WXR::ParseControlMS()
453 wxString label
,varname
,kindctrl
,tok
;
454 label
=GetQuoteField();
456 kindctrl
=GetQuoteField();
457 kindctrl
.MakeUpper();
460 if (kindctrl
=="MSCTLS_TRACKBAR32")
461 ParseSlider(label
,varname
);
462 if (kindctrl
=="MSCTLS_PROGRESS32")
463 ParseProgressBar(label
,varname
);
464 if (kindctrl
=="BUTTON")
465 ParseCtrlButton(label
,varname
);
467 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
468 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
471 void wxRC2WXR::ParseSlider(wxString label
, wxString varname
)
474 while (ReadOrs(tok
));
475 fprintf(m_wxr
," control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',",m_controlid
,varname
);
476 int x
,y
,width
,height
;
477 ReadRect(x
,y
,width
,height
);
478 fprintf(m_wxr
,"%i,%i,%i,%i,",x
,y
,width
,height
);
479 fprintf(m_wxr
," 1, 1, 10,\\\n");
480 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
483 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
484 WS_BORDER,15,52,154,13
486 void wxRC2WXR::ParseProgressBar(wxString label
, wxString varname
)
489 while (ReadOrs(tok
));
490 fprintf(m_wxr
," control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',",m_controlid
,varname
);
491 int x
,y
,width
,height
;
492 ReadRect(x
,y
,width
,height
);
493 fprintf(m_wxr
,"%i,%i,%i,%i,",x
,y
,width
,height
);
494 fprintf(m_wxr
," 0, 10,\\\n");
495 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
498 bool wxRC2WXR::ReadOrs(wxString
& w
)
508 //Is it a check button or a radio button
509 void wxRC2WXR::ParseCtrlButton(wxString label
, wxString varname
)
515 int x
,y
,width
,height
;
517 if (tok
=="BS_AUTOCHECKBOX")
519 fprintf(m_wxr
," control = [%i,wxCheckBox,'%s','0','%s',",m_controlid
,label
,varname
);
520 while (ReadOrs(tok
));
521 ReadRect(x
,y
,width
,height
);
522 fprintf(m_wxr
,"%i,%i,%i,%i,0,\\\n",x
,y
,width
,height
);
523 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
526 if (tok
=="BS_AUTORADIOBUTTON")
528 fprintf(m_wxr
," control = [%i,wxRadioButton,'%s','0','%s',",m_controlid
,label
,varname
);
530 ReadRect(x
,y
,width
,height
);
531 fprintf(m_wxr
,"%i,%i,%i,%i,0,\\\n",x
,y
,width
,height
);
532 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
539 BEGIN_EVENT_TABLE(wxFileProgressDlg
,wxDialog
)
542 wxFileProgressDlg::wxFileProgressDlg()
546 pos
= ConvertDialogToPixels(wxPoint(10,10));
547 size
= ConvertDialogToPixels(wxSize(170,31));
548 Create(GetParent(),100,"Parsing RC File",pos
,size
,603985920);
552 pos
= ConvertDialogToPixels(wxPoint(16,16));
553 size
= ConvertDialogToPixels(wxSize(136,6));
554 m_pProgress
= new wxGauge(this,101,100,pos
,size
);
555 //wxStaticText Control
556 pos
= ConvertDialogToPixels(wxPoint(72,4));
557 size
= ConvertDialogToPixels(wxSize(18,6));
558 m_pCompleteLabel
= new wxStaticText(this,102,"0",pos
,size
,0);
560 wxFileProgressDlg::~wxFileProgressDlg()
565 void wxFileProgressDlg::UpdateProgress(wxFile
* f
)
568 p
=(int)((float)f
->Tell()/(float)f
->Length()*100.0);
569 m_pProgress
->SetValue(p
);
572 m_pCompleteLabel
->SetLabel(t
);
578 //////////////////////////////////////////////////////////////////////
579 // GenerateBitmapSrc Class
580 //////////////////////////////////////////////////////////////////////
582 //////////////////////////////////////////////////////////////////////
583 // Construction/Destruction
584 //////////////////////////////////////////////////////////////////////
586 GenerateBitmapSrc::GenerateBitmapSrc()
591 GenerateBitmapSrc::~GenerateBitmapSrc()
596 bool GenerateBitmapSrc::Create(wxString imfile
, wxString srcfile
,wxString varname
)
604 img
.LoadFile(imfile
,wxBITMAP_TYPE_ANY
);
608 if( (src
= fopen( srcfile
, "at" )) == NULL
)
610 fprintf(src
,"#if !defined(IMG_%s)\n",varname
);
611 fprintf(src
,"#define IMG_%s\n",varname
);
613 fprintf(src
,"//Data from bitmap file %s \n",imfile
);
614 fprintf(src
,"//Image Height=%i,Width=%i RGB format\n",h
,w
);
615 fprintf(src
,"static unsigned char %s[][3]={\n",varname
);
618 for (int y
=0;y
<h
;y
++)
620 for (int x
=0;x
<w
;x
++)
622 //fprintf(src,"{%i,%i,%i},",img.GetRed(x,y),img.GetGreen(x,y),img.GetBlue(x,y));
628 fprintf(src
,"};\n\n");
630 fprintf(src
,"wxBitmap Load%s()\n{\n",varname
);
631 fprintf(src
,"wxImage myimg(%i,%i);\n",w
,h
);
633 fprintf(src
,"memcpy(myimg.GetData(),&%s[0][0],%i);\n",varname
,size
);
634 fprintf(src
,"return myimg.ConvertToBitmap();\n");
636 fprintf(src
,"#endif\n");