<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Вписать один прямоугольник в другой]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14507&amp;type=atom" />
	<updated>2019-01-23T19:23:36Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=14507</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131553#p131553" />
			<content type="html"><![CDATA[<p>В таком уже завтра, сам не разберёшься. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-23T19:23:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131553#p131553</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131551#p131551" />
			<content type="html"><![CDATA[<p>Или так:<br /></p><div class="codebox"><pre><code>StretchYellow(ParentW, ParentH, ratio) {
   ParentRatio := ParentH/ParentW
   bool := ParentRatio &gt; ratio
   a := bool ? &quot;W&quot; : &quot;H&quot;, b := bool ? &quot;H&quot; : &quot;W&quot;, r := bool ? ratio : 1/ratio
   %a% := Parent%a%, %b% := %a% * r, X := (ParentW - W)/2, Y := (ParentH - H)/2
   Gui, Yellow: Show, NA x%X% y%Y% w%W% h%H%
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-01-23T19:05:54Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131551#p131551</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131550#p131550" />
			<content type="html"><![CDATA[<p>Норм, я на &quot;больше он единицы, или меньше&quot; зациклился. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-23T18:52:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131550#p131550</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131549#p131549" />
			<content type="html"><![CDATA[<p>Как-то так:<br /></p><div class="codebox"><pre><code>AreaWidth := 800
AreaHeight := 800

yellowRatio := 1/2  ; H/W жёлтого прямоугольника

Gui, Area: New, -DPIScale
Gui, Color, E3E3E0
Gui, Show, w%AreaWidth% h%AreaHeight%

Gui, Red: New, +ParentArea -DPIScale -Caption
Gui, Color, Red

Gui, Yellow: New, +ParentRed -DPIScale -Caption
Gui, Color, Yellow

Loop {
   RedWidth := Random(200, AreaWidth - 200)
   RedHeight := Random(200, AreaHeight - 200)
   Gui, Red: Show, NA x100 y100 w%RedWidth% h%RedHeight%
   StretchYellow(RedWidth, RedHeight, yellowRatio)
   MsgBox, 4096,,
}
   
Random(min, max) {
   Random, rand, min, max
   Return rand
}

StretchYellow(ParentW, ParentH, ratio) {
   ParentRatio := ParentH/ParentW
   if (ParentRatio &gt; ratio)
      W := ParentW, H := W*ratio, X := 0, Y := (ParentH - H)/2
   else
      H := ParentH, W := H/ratio, X := (ParentW - W)/2, Y := 0
   Gui, Yellow: Show, NA x%X% y%Y% w%W% h%H%
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-01-23T18:47:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131549#p131549</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131547#p131547" />
			<content type="html"><![CDATA[<p>Думал про это, но что то не соображу.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-23T17:34:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131547#p131547</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131546#p131546" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>вычисляется два соотношения - ширина к высоте, и высота к ширине.</p></blockquote></div><p>Тоже ни к чему, достаточно одного варианта, и смотреть, больше он единицы, или меньше. Кроме того, H/W = 1/(W/H).</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-01-23T17:28:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131546#p131546</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131545#p131545" />
			<content type="html"><![CDATA[<p>Ну как сказать, ширина и высота могут впоследствии меняться, а в том что у меня получилось, вычисляется два соотношения - ширина к высоте, и высота к ширине.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-23T17:13:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131545#p131545</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131544#p131544" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Задаются изначальные размеры желтого прямоугольника, для последующего получения соотношения его сторон.</p></blockquote></div><p>Проще сразу задавать соотношение сторон, так как изначальные размеры не имеют значения.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-01-23T16:20:30Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131544#p131544</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131539#p131539" />
			<content type="html"><![CDATA[<p>Хотя вроде не всё так страшно, но с WinApi наверное было бы предпочтительнее.<br /></p><div class="codebox"><pre><code>
StretchToFit(ParentWidth, ParentHeight, ChildWidthOriginal, ChildHeightOriginal, ByRef ChildX, ByRef ChildY, ByRef ChildWidth, ByRef ChildHeight) {
	ParentRatioW := ParentWidth / ParentHeight
	ChildRatioW := ChildWidthOriginal / ChildHeightOriginal
	
	ParentRatioH := ParentHeight / ParentWidth
	ChildRatioH := ChildHeightOriginal / ChildWidthOriginal
	
	ChildWidth := ParentRatioW &lt; ChildRatioW ? ParentWidth : ParentWidth * (ChildRatioW / ParentRatioW)
	ChildHeight := ParentRatioH &lt; ChildRatioH ? ParentHeight : ParentHeight * (ChildRatioH / ParentRatioH)
	
	ChildX := (ParentWidth - ChildWidth) / 2
	ChildY := (ParentHeight - ChildHeight) / 2
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-23T13:21:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131539#p131539</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Вписать один прямоугольник в другой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131537#p131537" />
			<content type="html"><![CDATA[<p>Нужно в центр красного прямоугольника &quot;вписать&quot; желтый прямоугольник, с сохранением соотношения его сторон, заняв в красном&nbsp; максимальную площадь, например как видео в окне плеера при его растягивании. Пока не начал писать, но думается не лучший алгоритм у меня получится.</p><p>Предлагайте свои варианты, или может такое есть в WinApi.</p><div class="codebox"><pre><code>
#SingleInstance Force
#NoEnv 
ListLines Off
SetBatchLines -1 

AreaWidth := 800
AreaHeight := 800

ChildWidthOriginal := 1000
ChildHeightOriginal := 500

Gui, +HWNDhGui -DPIScale -Caption 
Gui, Show, Na y100 w%AreaWidth% h%AreaHeight%

Gui, New
Gui, +HWNDhParent -DPIScale -Caption +Parent%hGui%
Gui, Color, Red
Gui, Show, Na

Gui, New
Gui, +HWNDhChild -DPIScale -Caption +Parent%hGui%
Gui, Color, Yellow
Gui, Show, Na 

Loop
{
	ParentWidth := Random(200, AreaWidth - 200)
	ParentHeight := Random(200, AreaHeight - 200)  
	
	StretchToFit(ParentWidth, ParentHeight, ChildWidthOriginal, ChildHeightOriginal, ChildX, ChildY, ChildWidth, ChildHeight)
	; красный прямоугольник 
	Gui, %hParent%:Show, % &quot;NA x&quot; 100 &quot; y&quot; 100 &quot; w&quot; ParentWidth &quot; h&quot; ParentHeight
	; желтый прямоугольник 
	Gui, %hChild%:Show, % &quot;NA x&quot; 100 + ChildX &quot; y&quot; 100 + ChildY &quot; w&quot; ChildWidth &quot; h&quot; ChildHeight 
	
	MsgBox, 4096, , 
}
Return

StretchToFit(ParentWidth, ParentHeight, ChildWidthOriginal, ChildHeightOriginal, ByRef ChildX, ByRef ChildY, ByRef ChildWidth, ByRef ChildHeight) {
	ParentRatioW := ParentWidth / ParentHeight
	ChildRatioW := ChildWidthOriginal / ChildHeightOriginal
	
	ParentRatioH := ParentHeight / ParentWidth
	ChildRatioH := ChildHeightOriginal / ChildWidthOriginal
	
	ChildWidth := ParentRatioW &lt; ChildRatioW ? ParentWidth : ParentWidth * (ChildRatioW / ParentRatioW)
	ChildHeight := ParentRatioH &lt; ChildRatioH ? ParentHeight : ParentHeight * (ChildRatioH / ParentRatioH)
	
	ChildX := (ParentWidth - ChildWidth) / 2
	ChildY := (ParentHeight - ChildHeight) / 2
}

Random(min, max) {
	Random, rand, min, max
	Return rand
}

GuiEscape:
GuiClose:	
Escape:: ExitApp
</code></pre></div><div class="codebox"><pre><code>ChildWidthOriginal := 1000
ChildHeightOriginal := 500</code></pre></div><p>Задаются изначальные размеры желтого прямоугольника, для последующего получения соотношения его сторон.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-23T12:53:57Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131537#p131537</id>
		</entry>
</feed>
