• R/O
  • SSH
  • HTTPS

molby: Commit


Commit MetaInfo

Revision605 (tree)
Time2016-09-08 13:34:38
Authortoshinagata1964

Log Message

export_graphic now allows specification of the width and height of the captured image.

Change Summary

Incremental Difference

--- trunk/MolLib/MainView.c (revision 604)
+++ trunk/MolLib/MainView.c (revision 605)
@@ -1737,9 +1737,17 @@
17371737 scale = mview->offline_scale;
17381738
17391739 MainViewCallback_frame(mview, frame);
1740- width = (frame[2] - frame[0]) * scale;
1741- height = (frame[3] - frame[1]) * scale;
1740+ width = frame[2] - frame[0];
1741+ height = frame[3] - frame[1];
17421742
1743+ if (mview->offline_width > 0)
1744+ width = mview->offline_width;
1745+ if (mview->offline_height > 0)
1746+ height = mview->offline_height;
1747+
1748+ width *= scale;
1749+ height *= scale;
1750+
17431751 glViewport(0, 0, width, height);
17441752
17451753 /* Clear the buffer */
--- trunk/MolLib/MainView.h (revision 604)
+++ trunk/MolLib/MainView.h (revision 605)
@@ -134,6 +134,7 @@
134134 float dimension;
135135
136136 float offline_scale; /* If non-zero, this is the expansion factor for offline-rendering */
137+ int offline_width, offline_height; /* If non-zero, then these are size for offline-rendering */
137138
138139 #if !defined(__CMDMAC__)
139140 /* The following members are used in GUI version only */
@@ -268,7 +269,7 @@
268269 STUB int MainViewCallback_mouseCheck(MainView *mview);
269270 STUB void MainViewCallback_clearLabels(MainView *mview);
270271 STUB void MainViewCallback_drawLabel(MainView *mview, const float *pos, const char *label);
271-STUB int MainViewCallback_exportGraphic(MainView *mview, const char *fname, float scale, int bg_color);
272+STUB int MainViewCallback_exportGraphic(MainView *mview, const char *fname, float scale, int bg_color, int width, int height);
272273
273274 STUB void MainViewCallback_drawInfoText(MainView *mview, const char *label);
274275 STUB void MainViewCallback_selectMatrixCellForMode(MainView *mview, int mode);
--- trunk/MolLib/Ruby_bind/ruby_bind.c (revision 604)
+++ trunk/MolLib/Ruby_bind/ruby_bind.c (revision 605)
@@ -9419,24 +9419,24 @@
94199419
94209420 /*
94219421 * call-seq:
9422- * export_graphic(fname, scale = 1.0, bg_color = -1)
9422+ * export_graphic(fname, scale = 1.0, bg_color = -1, width = 0, height = 0)
94239423 *
94249424 * Export the current graphic to a PNG or TIF file (determined by the extension).
94259425 * bg_color: -1, same as screen; 0, transparent; 1, black; 2, white.
9426- *
9426+ * If either width or height is not specified, then the screen width/height is used instead.
94279427 */
94289428 static VALUE
94299429 s_Molecule_ExportGraphic(int argc, VALUE *argv, VALUE self)
94309430 {
94319431 Molecule *mol;
9432- VALUE fval, sval, bval;
9432+ VALUE fval, sval, bval, wval, hval;
94339433 char *fname;
94349434 float scale;
9435- int bg_color;
9435+ int bg_color, width, height;
94369436 Data_Get_Struct(self, Molecule, mol);
94379437 if (mol->mview == NULL)
94389438 rb_raise(rb_eMolbyError, "The molecule has no associated graphic view");
9439- rb_scan_args(argc, argv, "12", &fval, &sval, &bval);
9439+ rb_scan_args(argc, argv, "14", &fval, &sval, &bval, &wval, &hval);
94409440 fname = FileStringValuePtr(fval);
94419441 if (sval == Qnil)
94429442 scale = 1.0;
@@ -9444,7 +9444,13 @@
94449444 if (bval == Qnil)
94459445 bg_color = -1;
94469446 else bg_color = NUM2INT(rb_Integer(bval));
9447- if (MainViewCallback_exportGraphic(mol->mview, fname, scale, bg_color) == 0)
9447+ if (wval == Qnil)
9448+ width = 0;
9449+ else width = NUM2INT(rb_Integer(wval));
9450+ if (hval == Qnil)
9451+ height = 0;
9452+ else height = NUM2INT(rb_Integer(hval));
9453+ if (MainViewCallback_exportGraphic(mol->mview, fname, scale, bg_color, width, height) == 0)
94489454 return fval;
94499455 else return Qnil;
94509456 }
--- trunk/MolLib/cmdtool_stubs.c (revision 604)
+++ trunk/MolLib/cmdtool_stubs.c (revision 605)
@@ -312,7 +312,7 @@
312312 }
313313
314314 int
315-MainViewCallback_exportGraphic(MainView *mview, const char *fname, float scale, int bg_color)
315+MainViewCallback_exportGraphic(MainView *mview, const char *fname, float scale, int bg_color, int width, int height)
316316 {
317317 return 0;
318318 }
--- trunk/wxSources/MoleculeView.cpp (revision 604)
+++ trunk/wxSources/MoleculeView.cpp (revision 605)
@@ -425,14 +425,22 @@
425425 }
426426
427427 wxImage *
428-MoleculeView::CaptureGLCanvas(float scale, int bg_color)
428+MoleculeView::CaptureGLCanvas(float scale, int bg_color, int width, int height)
429429 {
430430 if (canvas && mview->mol != NULL) {
431- int x, y, width, height;
432- float bgcol[4];
431+ int x, y, cwidth, cheight;
432+ float bgcol[4], rx, ry;
433433
434434 canvas->SetCurrent();
435- canvas->GetClientSize(&width, &height);
435+ canvas->GetClientSize(&cwidth, &cheight);
436+ if (width <= 0)
437+ width = cwidth;
438+ if (height <= 0)
439+ height = cheight;
440+ rx = (float)width / cwidth;
441+ ry = (float)height / cheight;
442+ if (rx > ry)
443+ rx = ry;
436444 width *= scale;
437445 height *= scale;
438446
@@ -455,7 +463,10 @@
455463
456464 MainView_initializeOpenGL();
457465
458- mview->offline_scale = scale;
466+ mview->offline_scale = 1.0; /* Scale is handled in offline_width and offline_height */
467+ mview->offline_width = width;
468+ mview->offline_height = height;
469+
459470 for (x = 0; x < 4; x++) {
460471 bgcol[x] = mview->background_color[x];
461472 }
@@ -482,6 +493,8 @@
482493 mview->background_color[x] = bgcol[x];
483494 }
484495 mview->offline_scale = 0.0;
496+ mview->offline_width = 0;
497+ mview->offline_height = 0;
485498
486499 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
487500 unsigned char *glBitmapData = (unsigned char *)malloc(4 * width * height);
@@ -515,9 +528,9 @@
515528 }
516529
517530 int
518-MoleculeView::DoExportGraphic(wxString& fname, float scale, int bg_color)
531+MoleculeView::DoExportGraphic(wxString& fname, float scale, int bg_color, int width, int height)
519532 {
520- wxImage *img = CaptureGLCanvas(scale, bg_color);
533+ wxImage *img = CaptureGLCanvas(scale, bg_color, width, height);
521534 if (img == NULL)
522535 return -1;
523536 wxString ext = fname.AfterLast('.');
@@ -1370,11 +1383,11 @@
13701383 }
13711384
13721385 int
1373-MainViewCallback_exportGraphic(MainView *mview, const char *fname, float scale, int bg_color)
1386+MainViewCallback_exportGraphic(MainView *mview, const char *fname, float scale, int bg_color, int width, int height)
13741387 {
13751388 if (mview != NULL && mview->ref != NULL && ((MoleculeView *)(mview->ref))->MolDocument() != NULL) {
13761389 wxString fnamestr(fname, wxConvFile);
1377- return ((MoleculeView *)(mview->ref))->DoExportGraphic(fnamestr, scale, bg_color);
1390+ return ((MoleculeView *)(mview->ref))->DoExportGraphic(fnamestr, scale, bg_color, width, height);
13781391 }
13791392 return -100;
13801393 }
--- trunk/wxSources/MoleculeView.h (revision 604)
+++ trunk/wxSources/MoleculeView.h (revision 605)
@@ -61,8 +61,8 @@
6161 void OnDraw(wxDC *dc);
6262 void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
6363 bool OnClose(bool deleteWindow = true);
64- wxImage *CaptureGLCanvas(float scale = 1.0, int bg_color = -1);
65- int DoExportGraphic(wxString& fname, float scale, int bg_color);
64+ wxImage *CaptureGLCanvas(float scale = 1.0, int bg_color = -1, int width = 0, int height = 0);
65+ int DoExportGraphic(wxString& fname, float scale, int bg_color, int width, int height);
6666
6767 virtual void Activate (bool activate);
6868 virtual wxPrintout *OnCreatePrintout();
--- trunk/wxSources/MyDocument.cpp (revision 604)
+++ trunk/wxSources/MyDocument.cpp (revision 605)
@@ -402,7 +402,7 @@
402402 if (dialog->ShowModal() == wxID_OK) {
403403 wxString fnpath = dialog->GetPath();
404404 MoleculeView *myview = (MoleculeView *)GetFirstView();
405- myview->DoExportGraphic(fnpath, scale, bg_color);
405+ myview->DoExportGraphic(fnpath, scale, bg_color, 0, 0);
406406 }
407407 dialog->Destroy();
408408 }
Show on old repository browser