mirror of
https://github.com/schrodinger/pymol-open-source.git
synced 2026-06-04 20:04:21 +08:00
bg_gradient=2 grid mode
This commit is contained in:
committed by
Jarrett Johnson
parent
c314c5a218
commit
f70c533d01
@@ -60,3 +60,10 @@ enum class GridMode
|
||||
ByObjectByState = 3, // One slot per state per object
|
||||
ByCamera = 4, // One slot per camera
|
||||
};
|
||||
|
||||
enum class BgGradient
|
||||
{
|
||||
None = 0,
|
||||
Vertical = 1,
|
||||
Grid = 2,
|
||||
};
|
||||
|
||||
@@ -1310,6 +1310,35 @@ void OrthoBackgroundTextureNeedsUpdate(PyMOLGlobals * G){
|
||||
I->bg_texture_needs_update = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a background image for grid mode.
|
||||
*
|
||||
* Repurpose the `bg_rgb_top` and `bg_rgb_bottom` colors to color grid cells
|
||||
* with alternating colors.
|
||||
*/
|
||||
static std::unique_ptr<pymol::Image> makeBgGridImage(PyMOLGlobals* G)
|
||||
{
|
||||
auto const& grid = G->Scene->grid;
|
||||
auto tmpImg = pymol::make_unique<pymol::Image>( //
|
||||
grid.n_col > 1 ? grid.n_col : 1, //
|
||||
grid.n_row > 1 ? grid.n_row : 1);
|
||||
|
||||
unsigned char top[4]{0, 0, 0, 0xFF}, bottom[4]{0, 0, 0, 0xFF};
|
||||
pymol::scale3(ColorGet(G, SettingGet_color(G, cSetting_bg_rgb_top)), 0xFF, top);
|
||||
pymol::scale3(ColorGet(G, SettingGet_color(G, cSetting_bg_rgb_bottom)), 0xFF, bottom);
|
||||
|
||||
unsigned char* q = tmpImg->bits();
|
||||
|
||||
for (unsigned j = 0; j != tmpImg->getHeight(); ++j) {
|
||||
for (unsigned i = 0; i != tmpImg->getWidth(); ++i, q += 4) {
|
||||
auto color = (i + j) % 2 ? top : bottom;
|
||||
copy4(color, q);
|
||||
}
|
||||
}
|
||||
|
||||
return tmpImg;
|
||||
}
|
||||
|
||||
static std::unique_ptr<pymol::Image> makeBgGradientImage(PyMOLGlobals* G)
|
||||
{
|
||||
constexpr unsigned height = BACKGROUND_TEXTURE_SIZE;
|
||||
@@ -1385,14 +1414,19 @@ static void updateBgTexture(
|
||||
|
||||
void bg_grad(PyMOLGlobals * G) {
|
||||
COrtho *I = G->Ortho;
|
||||
int bg_gradient = SettingGet_b(G, NULL, NULL, cSetting_bg_gradient);
|
||||
auto bg_gradient = SettingGet<BgGradient>(G, cSetting_bg_gradient);
|
||||
const char * bg_image_filename = SettingGetGlobal_s(G, cSetting_bg_image_filename);
|
||||
|
||||
if (bg_image_filename && !bg_image_filename[0]) {
|
||||
bg_image_filename = nullptr;
|
||||
}
|
||||
|
||||
if (!(bg_gradient || bg_image_filename || I->bgData) ||
|
||||
if (bg_gradient == BgGradient::Grid &&
|
||||
SettingGet<GridMode>(G, cSetting_grid_mode) == GridMode::NoGrid) {
|
||||
bg_gradient = BgGradient::None;
|
||||
}
|
||||
|
||||
if (!(bg_gradient != BgGradient::None || bg_image_filename || I->bgData) ||
|
||||
!G->ShaderMgr->ShadersPresent()) {
|
||||
const float *bg_rgb = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rgb));
|
||||
SceneGLClearColor(bg_rgb[0], bg_rgb[1], bg_rgb[2], 1.0);
|
||||
@@ -1423,7 +1457,9 @@ void bg_grad(PyMOLGlobals * G) {
|
||||
SettingSetGlobal_s(G, cSetting_bg_image_filename, "");
|
||||
G->ShaderMgr->Reload_All_Shaders();
|
||||
}
|
||||
} else if (bg_gradient) {
|
||||
} else if (bg_gradient == BgGradient::Grid) {
|
||||
bgImage = makeBgGridImage(G);
|
||||
} else if (bg_gradient == BgGradient::Vertical) {
|
||||
bgImage = makeBgGradientImage(G);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,8 @@ void SceneRender(PyMOLGlobals* G, const SceneRenderInfo& renderInfo)
|
||||
|
||||
G->ShaderMgr->Check_Reload();
|
||||
|
||||
auto const last_grid_shape = std::array<int, 2>{I->grid.n_col, I->grid.n_row};
|
||||
|
||||
auto grid_mode = SettingGet<GridMode>(G, cSetting_grid_mode);
|
||||
int grid_size = 0;
|
||||
if (grid_mode != GridMode::NoGrid) {
|
||||
@@ -199,6 +201,14 @@ void SceneRender(PyMOLGlobals* G, const SceneRenderInfo& renderInfo)
|
||||
} else {
|
||||
I->grid.active = false;
|
||||
}
|
||||
|
||||
auto const grid_shape = std::array<int, 2>{I->grid.n_col, I->grid.n_row};
|
||||
|
||||
if (last_grid_shape != grid_shape &&
|
||||
SettingGet<BgGradient>(G, cSetting_bg_gradient) == BgGradient::Grid) {
|
||||
OrthoBackgroundTextureNeedsUpdate(G);
|
||||
}
|
||||
|
||||
if (last_grid_active != I->grid.active || grid_size != I->last_grid_size) {
|
||||
G->ShaderMgr->ResetUniformSet();
|
||||
}
|
||||
|
||||
@@ -2755,6 +2755,7 @@ void SettingGenerateSideEffects(PyMOLGlobals * G, int index, const char *sele, i
|
||||
case cSetting_bg_gradient:
|
||||
ColorUpdateFrontFromSettings(G);
|
||||
ExecutiveInvalidateRep(G, inv_sele, cRepAll, cRepInvColor);
|
||||
OrthoBackgroundTextureNeedsUpdate(G);
|
||||
G->ShaderMgr->Set_Reload_Bits(RELOAD_VARIABLES);
|
||||
SceneChanged(G);
|
||||
break;
|
||||
|
||||
@@ -759,7 +759,7 @@ enum {
|
||||
REC_s( 659, default_2fofc_map_rep , global , "volume" ),
|
||||
REC_s( 660, atom_type_format , global , "mol2" ),
|
||||
REC_b( 661, autoclose_dialogs , global , 1 ),
|
||||
REC_b( 662, bg_gradient , global , 0 ),
|
||||
REC_i( 662, bg_gradient , global , 0 ),
|
||||
REC_c( 663, bg_rgb_top , global , "0x00004D" ),
|
||||
REC_c( 664, bg_rgb_bottom , global , "0x333380" ),
|
||||
REC_b( 665, ray_volume , global , 0 ),
|
||||
|
||||
Reference in New Issue
Block a user