Skip to content

Commit

Permalink
Updated the image class to include a new embed data method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Willoughby committed Feb 4, 2014
1 parent 6f93337 commit d7995f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
26 changes: 14 additions & 12 deletions docs/tkd/image/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ <h3>Parameters</h3><table class="parameter-list"><tr><td>string <em>file</em></t
</table>
</div>
</div>
<h2><a name="Image.embedDataFromFile"></a>void <span class="symbol">embedDataFromFile</span>(string filename)();
</h2>
<div class="declaration-description"><div class="sections"><p>This method embeds the image as a base64 encoded string into the application.
The path to the image must be passed to the compiler using the -J switch.
</p>
<h3>Parameters</h3><table class="parameter-list"><tr><td>filename</td>
<td>The filename to read the data from.</td></tr>
</table>
</div>
</div>
<h2><a name="Image.getFile"></a>string <span class="symbol">getFile</span>();
</h2>
<div class="declaration-description"><div class="sections"><p>Get the image file.
Expand Down Expand Up @@ -152,13 +162,9 @@ <h3>Return Value</h3><p>The current cropped image height. Returns 0 if no croppi
</div>
</div>
</div>
<h2><a name="PngImage"></a>class <span class="symbol">PngImage</span>(string filename): Image;
<h2><a name="Png"></a>class <span class="symbol">Png</span>(string filename): Image;
</h2>
<div class="declaration-description"><div class="sections"><p>The png image class.
</p>
<p>This class embeds the image as a base64 encoded string into the application.
The path to the image must be passed to the compiler using the -J switch.

<div class="declaration-description"><div class="sections"><p>Helper class to quickly create an embedded <span class="symbol">Png</span> format image.
</p>
<h3>Parameters</h3><table class="parameter-list"><tr><td>filename</td>
<td>The filename of the image to embed.</td></tr>
Expand All @@ -171,13 +177,9 @@ <h3>Parameters</h3><table class="parameter-list"><tr><td>filename</td>
</div>
</div>
</div>
<h2><a name="GifImage"></a>class <span class="symbol">GifImage</span>(string filename): Image;
<h2><a name="Gif"></a>class <span class="symbol">Gif</span>(string filename): Image;
</h2>
<div class="declaration-description"><div class="sections"><p>The gif image class.
</p>
<p>This class embeds the image as a base64 encoded string into the application.
The path to the image must be passed to the compiler using the -J switch.

<div class="declaration-description"><div class="sections"><p>Helper class to quickly create an embedded <span class="symbol">Gif</span> format image.
</p>
<h3>Parameters</h3><table class="parameter-list"><tr><td>filename</td>
<td>The filename of the image to embed.</td></tr>
Expand Down
2 changes: 1 addition & 1 deletion source/example.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Application : TkdApplication
this.button.exit = new Button(this.frame.root, "Exit");

this.button.hello.bind("<Button-1>", &this.button_hello_click);
this.button.hello.addImage(new PngImage!("thumbnail.png"), ImagePosition.top);
this.button.hello.addImage(new Png!("thumbnail.png"), ImagePosition.top);
this.button.hello.underlineChar(0);

this.button.exit.bind("<Button-1>", &this.button_quit_click);
Expand Down
30 changes: 18 additions & 12 deletions source/tkd/image/image.d
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ class Image : Element
this._tk.eval("%s configure -file %s", this.id, file);
}

/**
* This method embeds the image as a base64 encoded string into the application.
* The path to the image must be passed to the compiler using the -J switch.
*
* Params:
* filename = The filename to read the data from.
*/
public void embedDataFromFile(string filename)()
{
this.setData(base64Encode!(filename));
}

/**
* Get the image file.
*
Expand Down Expand Up @@ -210,15 +222,12 @@ class Image : Element
}

/**
* The png image class.
*
* This class embeds the image as a base64 encoded string into the application.
* The path to the image must be passed to the compiler using the -J switch.
* Helper class to quickly create an embedded Png format image.
*
* Params:
* filename = The filename of the image to embed.
*/
class PngImage(string filename) : Image
class Png(string filename) : Image
{
/**
* Construct the image.
Expand All @@ -228,20 +237,17 @@ class PngImage(string filename) : Image
super();

this.setFormat(ImageFormat.png);
this.setData(base64Encode!(filename));
this.embedDataFromFile!(filename);
}
}

/**
* The gif image class.
*
* This class embeds the image as a base64 encoded string into the application.
* The path to the image must be passed to the compiler using the -J switch.
* Helper class to quickly create an embedded Gif format image.
*
* Params:
* filename = The filename of the image to embed.
*/
class GifImage(string filename) : Image
class Gif(string filename) : Image
{
/**
* Construct the image.
Expand All @@ -251,7 +257,7 @@ class GifImage(string filename) : Image
super();

this.setFormat(ImageFormat.gif);
this.setData(base64Encode!(filename));
this.embedDataFromFile!(filename);
}
}

Expand Down

0 comments on commit d7995f8

Please sign in to comment.