Fix layer preview :

* Avoids running its own event loop and intercepting keyboard shortcuts
 * Show all the layers (lined up with the buttons)
 * Do not draw outside of screen when picture has strange dimensions.


git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1924 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2012-03-08 18:56:39 +00:00
parent b435ff2582
commit dcffab6c79

View File

@ -592,6 +592,9 @@ void Main_handler(void)
byte action; byte action;
dword key_pressed; dword key_pressed;
static int preview_is_visible;
// This is used for the layer preview
do do
{ {
// Resize requested // Resize requested
@ -1371,8 +1374,17 @@ void Main_handler(void)
Block(18*Menu_factor_X,Menu_status_Y,192*Menu_factor_X,Menu_factor_Y<<3,MC_Light); Block(18*Menu_factor_X,Menu_status_Y,192*Menu_factor_X,Menu_factor_Y<<3,MC_Light);
Update_rect(18*Menu_factor_X,Menu_status_Y,192*Menu_factor_X,Menu_factor_Y<<3); Update_rect(18*Menu_factor_X,Menu_status_Y,192*Menu_factor_X,Menu_factor_Y<<3);
Display_cursor(); Display_cursor();
}
} // If we get here, we mayjust have left the layerbar (towards the
// main menu or statusbar). If so, close the popup.
if (preview_is_visible) {
int x = Mouse_K;
Close_popup();
Mouse_K = x; // Close_popup waits for end of click and resets Mouse_K...
preview_is_visible = 0;
}
}
}
else else
{ {
if ( (prev_button_number!=BUTTON_CHOOSE_COL) if ( (prev_button_number!=BUTTON_CHOOSE_COL)
@ -1392,46 +1404,48 @@ void Main_handler(void)
{ {
int x,y; int x,y;
int previewW, previewH; int previewW, previewH;
short layer, prev_layer; short layer;
short layercount = Main_backups->Pages->Nb_layers;
previewW = Buttons_Pool[BUTTON_LAYER_SELECT].Width / Main_backups->Pages->Nb_layers; if (!preview_is_visible)
previewH = previewW * Main_image_height / Main_image_width; {
// TODO this will give stupid out of screen results for very narrow images... previewW = Buttons_Pool[BUTTON_LAYER_SELECT].Width / Main_backups->Pages->Nb_layers;
previewH = previewW * Main_image_height / Main_image_width;
if (previewH > Menu_Y) previewH = Menu_Y;
Open_popup((Buttons_Pool[BUTTON_LAYER_SELECT].X_offset + 2)*Menu_factor_X, Open_popup((Buttons_Pool[BUTTON_LAYER_SELECT].X_offset + 2)*Menu_factor_X,
Menu_Y - previewH, previewW, previewH); Menu_Y - previewH * Menu_factor_Y, previewW * layercount, previewH);
preview_is_visible = 1;
prev_layer = -1; // Make the system think the menu is visible (Open_popup hides it)
// so Button_under_mouse still works
Menu_is_visible=Menu_is_visible_before_window;
Menu_Y=Menu_Y_before_window;
}
// Make the system think the menu is visible (Open_popup hides it) // NOT an else of the previous if - variable may have changed
// so Button_under_mouse still works if (preview_is_visible)
Menu_is_visible=Menu_is_visible_before_window; {
Menu_Y=Menu_Y_before_window; layer = Layer_under_mouse();
while(Button_under_mouse() == BUTTON_LAYER_SELECT && Mouse_K == 0) for(layer = 0; layer < layercount; ++layer)
{ {
layer = Layer_under_mouse(); for (x = 0; x < Window_width; x++)
if (layer != prev_layer) for (y = 0; y < Window_height; y++)
{ {
for (x = 0; x < Window_width; x++) int imgx = x * Main_image_width / Window_width;
for (y = 0; y < Window_height; y++) int imgy = y * Main_image_height / Window_height;
{ Pixel_in_window(x + previewW*layer, y, *(Main_backups->Pages->Image[layer].Pixels
int imgx = x * Main_image_width / Window_width; + imgx + imgy * Main_image_width));
int imgy = y * Main_image_height / Window_height; }
Pixel_in_window(x, y, *(Main_backups->Pages->Image[layer].Pixels
+ imgx + imgy * Main_image_width));
}
Update_window_area(0,0,Window_width, Window_height);
prev_layer = layer;
}
Get_input(20);
};
x = Mouse_K;
Update_window_area(0,0,Window_width, Window_height);
}
}
} else if (preview_is_visible) {
int x = Mouse_K;
Close_popup(); Close_popup();
Mouse_K = x; // Close_popup waits for end of click and resets Mouse_K... Mouse_K = x; // Close_popup waits for end of click and resets Mouse_K...
preview_is_visible = 0;
} }
Print_in_menu(Buttons_Pool[button_index].Tooltip,0); Print_in_menu(Buttons_Pool[button_index].Tooltip,0);
@ -1460,6 +1474,15 @@ void Main_handler(void)
Update_rect(18*Menu_factor_X,Menu_status_Y,192*Menu_factor_X,8*Menu_factor_Y); Update_rect(18*Menu_factor_X,Menu_status_Y,192*Menu_factor_X,8*Menu_factor_Y);
Display_cursor(); Display_cursor();
} }
}
// If we get here, we mayjust have left the layerbar (towards the
// main menu or statusbar). If so, close the popup.
if (preview_is_visible) {
int x = Mouse_K;
Close_popup();
Mouse_K = x; // Close_popup waits for end of click and resets Mouse_K...
preview_is_visible = 0;
} }
} }
} }