Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
UI: Label: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
corwinn committed Feb 7, 2023
1 parent 7fc6d7d commit 9698a57
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 3 deletions.
47 changes: 47 additions & 0 deletions ui/h3r_label.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**** BEGIN LICENSE BLOCK ****
BSD 3-Clause License
Copyright (c) 2021-2023, the wind.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**** END LICENCE BLOCK ****/

#include "h3r_label.h"

H3R_NAMESPACE

Label::Label(
const String & text, const String & font, const Point & pos, Control * base)
: Control {base}, _tkey {RenderEngine::UI ().GenTextKey ()}, _text {text}
{
SetPos (pos.X, pos.Y);
RenderEngine::UI ().UploadText (_tkey, font, text, pos.X, pos.Y);
}

NAMESPACE_H3R
58 changes: 58 additions & 0 deletions ui/h3r_label.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**** BEGIN LICENSE BLOCK ****
BSD 3-Clause License
Copyright (c) 2021-2023, the wind.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**** END LICENCE BLOCK ****/

#ifndef _H3R_LABEL_H_
#define _H3R_LABEL_H_

#include "h3r.h"
#include "h3r_string.h"
#include "h3r_point.h"
#include "h3r_control.h"
#include "h3r_renderengine.h"

H3R_NAMESPACE

class Label: public Control
{
private: RenderEngine::TextKey _tkey;
private: String _text;

public: Label(
const String &, const String &, const Point &, Control * = nullptr);
public: ~Label() override {}
};

NAMESPACE_H3R

#endif
10 changes: 7 additions & 3 deletions ui/h3r_mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "h3r_list.h"
#include "h3r_string.h"
#include "h3r_renderengine.h"
#include "h3r_label.h"

#include <new>

Expand Down Expand Up @@ -96,6 +97,12 @@ MainWindow::MainWindow(OSWindow * actual_window)
btn->Pos ().X + ((ww - btn->Size ().X) / 2), btn->Pos ().Y);
// 3. Upload
for (Control * btn : Controls ()) btn->UploadFrames ();

Label * test_label;
Point test_label_pos {10, 2};
H3R_CREATE_OBJECT(test_label, Label) {
"Hi ,\n I'm a proof of concept edition", "tiny.fnt", test_label_pos};
Add (test_label);
}

MainWindow::~MainWindow() {}
Expand All @@ -108,9 +115,6 @@ void MainWindow::OnKeyUp(const EventArgs & e)

void MainWindow::OnShow()
{
auto textkey = RenderEngine::UI ().GenTextKey ();
RenderEngine::UI ().UploadText (textkey, "tiny.fnt",
"Hi ,\n I'm a proof of concept edition", 10, 10);
}

void MainWindow::OnRender()
Expand Down

0 comments on commit 9698a57

Please sign in to comment.