Author Topic: [Help] Image format based on emulator  (Read 6257 times)

Kitsune42k

  • Newbie
  • *
  • Posts: 2
    • View Profile
[Help] Image format based on emulator
« on: October 31, 2015, 12:20:52 PM »
Hey ho  ;)

First of, I'm sorry for my English. I'm from Germany.

I trying to make a very modern looking Layout, but i stuck a little.

This is the actual progress of my layout:


I want to fix the size of the Boxart(flyer) and the screenshots, so all images of that type have the same size after scraping.

But i need to scale them, without changing there aspect ration.

I'm new with Squirrel but this is what i came up with:
Code: [Select]
// here Variables with width and hight of the different consoles

local emu = "[Emulator]";

local ttext = fe.add_text( "test", 640, 990, 640, 90 );    // for testing
local screenshot = fe.add_artwork( "screens", 640, 0, sceenshot_width, sceenshot_height );

if ( emu == "gb" ) {
    local sceenshot_width = gb_width * 8;
    local sceenshot_height = gb_height * 8;
    ttext.text.msg = "gb";    // for testing
}

The sting is working, when i use this it prints gb:
Code: [Select]
local ttext = fe.add_text( emu, 640, 990, 640, 90 );    // for testing
What am I doing wrong, or is there a better solution?
« Last Edit: October 31, 2015, 02:17:55 PM by Kitsune42k »

omegaman

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
    • View Profile
Re: [Help] Image format based on emulator
« Reply #1 on: October 31, 2015, 05:32:00 PM »
Kitsune42k-

Hi! Try creating a surface to bind the snap to. This way you can specify what size you want the art to be displayed at. And, this also helps if you want to pinch or skew an image as well. I think the dev Raygun created the fade module for this reason which is why I use it for all my layouts now. Here is an example of the code to give you an idea. You can also look at the reflect, cools, robospin layouts for a reference. Oh, and don't forget to load the fade module. Anyway, this will fix your problem.

fe.load_module( "fade" );

// fill an entire surface with our snap at a resolution of 480x360
//
local surface = fe.add_surface( 480, 360 );
local snap = FadeArt( "snap", 0, 0, 480, 360, surface );
snap.preserve_aspect_ratio = true;

// position and pinch the surface
//
surface.set_pos( 330, 80, 300, 250 );
surface.pinch_y = -80;



Kitsune42k

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: [Help] Image format based on emulator
« Reply #2 on: October 31, 2015, 07:32:01 PM »
Thanks  ;)

i have two more questions:

1. how do i save the width/height of a picture in a variable to center the image on x/y Solved
Code: [Select]
function screens_width()
{
   local sw = screens.texture_width;
   return sw;
}
fe.add_text( "[!screens_width]", 0, 0 );

1b. now i stuck on how to convert a magic token into a integer Solved
Code: [Select]
fe.layout.width=1920;
fe.layout.height=1080;

local lw = fe.layout.width;
local lh = fe.layout.height;

local img = fe.add_artwork( "img.png" );
img.preserve_aspect_ratio = true;

function img_width() return img.texture_width;
function img_height() return img.texture_height;

fe.add_transition_callback( "center_image" );
function center_image( ttype, var, ttime ) {
switch ( ttype ) {
case Transition.ToNewList:
case Transition.ToNewSelection:
img.x = (lw/2)-(img_width()/2);
img.y = (lh/2)-(img_height()/2);
break;
}
return false;
}

2. how do i compare a string? [if ( string == "text")?] Solved

ps, progress update:
« Last Edit: November 01, 2015, 12:14:56 PM by Kitsune42k »