Skip to content

Commit aa04f04

Browse files
committed
UPD: New Text Elements
- 4 rows of text elements created for the dyadic operations. - Removed and cleaned-up commented-out code and copied comments.
1 parent d40eb2d commit aa04f04

File tree

2 files changed

+59
-29
lines changed

2 files changed

+59
-29
lines changed

calculator_simple/src/app_window.cpp

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ AppWindow::AppWindow():
7777
, &btn_num_f_obj
7878
}}
7979
, txt_str_top("")
80+
, txt_str_bot("")
81+
, txt_str_opr("")
82+
, txt_str_res("")
8083
{
8184
set_title("Simple Calculator");
8285

@@ -166,6 +169,10 @@ AppWindow::~AppWindow()
166169

167170
/**
168171
* @brief Handler method for the display area redraws.
172+
*
173+
* References:
174+
* - http://developer.gnome.org/pangomm/unstable/classPango_1_1Layout.html
175+
*
169176
*/
170177
bool AppWindow::handle_display_update(
171178
::Cairo::RefPtr<::Cairo::Context> const & draw_context_ptr
@@ -175,45 +182,66 @@ bool AppWindow::handle_display_update(
175182
int const area_x_full = display_area_allocation.get_width();
176183
// int const area_y_full = display_area_allocation.get_height();
177184

178-
// int const lft_x = (0);
179-
// int const top_y = (0);
180-
181-
// int const center_x = (area_x_full / 2);
182-
// int const center_y = (area_y_full / 2);
183-
184-
// // int const rght_x = (area_x_full);
185-
// int const bot_y = (area_y_full);
185+
Pango::FontDescription font;
186+
font.set_family("Monospace");
187+
font.set_weight(Pango::WEIGHT_NORMAL);
186188

187-
// draw_context_ptr->set_line_width(10.0);
188-
// draw_context_ptr->set_source_rgb(0.8, 0.0, 0.5);
189-
// draw_context_ptr->move_to(lft_x, top_y);
190-
// draw_context_ptr->line_to(center_x, center_y);
191-
// draw_context_ptr->line_to(lft_x, bot_y);
192-
// draw_context_ptr->stroke();
189+
auto top_txt_layout = create_pango_layout(txt_str_top.c_str());
190+
top_txt_layout->set_font_description(font);
193191

194-
Pango::FontDescription font;
192+
auto bot_txt_layout = create_pango_layout(txt_str_bot.c_str());
193+
bot_txt_layout->set_font_description(font);
195194

196-
font.set_family("Monospace");
197-
font.set_weight(Pango::WEIGHT_BOLD);
195+
auto opr_txt_layout = create_pango_layout(txt_str_opr.c_str());
196+
opr_txt_layout->set_font_description(font);
198197

199-
// http://developer.gnome.org/pangomm/unstable/classPango_1_1Layout.html
200-
auto layout = create_pango_layout(txt_str_top.c_str());
198+
auto res_txt_layout = create_pango_layout(txt_str_res.c_str());
199+
res_txt_layout->set_font_description(font);
201200

202-
layout->set_font_description(font);
201+
int top_txt_width;
202+
int top_txt_height;
203+
int bot_txt_width;
204+
int bot_txt_height;
205+
int opr_txt_width;
206+
int opr_txt_height;
207+
int res_txt_width;
208+
int res_txt_height;
203209

204-
int text_width;
205-
int text_height;
210+
top_txt_layout->get_pixel_size(top_txt_width, top_txt_height);
211+
float const pen_x_top_txt = (area_x_full - top_txt_width);
212+
float const pen_y_top_txt = (1.5 * top_txt_height);
213+
draw_context_ptr->move_to(
214+
pen_x_top_txt
215+
, pen_y_top_txt
216+
);
217+
top_txt_layout->show_in_cairo_context(draw_context_ptr);
206218

207-
//get the text dimensions (it updates the variables -- by reference)
208-
layout->get_pixel_size(text_width, text_height);
219+
opr_txt_layout->get_pixel_size(opr_txt_width, opr_txt_height);
220+
float const pen_x_opr_txt = (1.5 * opr_txt_width);
221+
float const pen_y_opr_txt = (pen_y_top_txt + (1.5 * opr_txt_height));
222+
draw_context_ptr->move_to(
223+
pen_x_opr_txt
224+
, pen_y_opr_txt
225+
);
226+
opr_txt_layout->show_in_cairo_context(draw_context_ptr);
209227

210-
// Position the text in the middle
228+
bot_txt_layout->get_pixel_size(bot_txt_width, bot_txt_height);
229+
float const pen_x_bot_txt = (area_x_full - bot_txt_width);
230+
float const pen_y_bot_txt = (pen_y_opr_txt + (1.5 * bot_txt_height));
211231
draw_context_ptr->move_to(
212-
(area_x_full - text_width)
213-
, (1.5 * text_height)
232+
pen_x_bot_txt
233+
, pen_y_bot_txt
214234
);
235+
bot_txt_layout->show_in_cairo_context(draw_context_ptr);
215236

216-
layout->show_in_cairo_context(draw_context_ptr);
237+
res_txt_layout->get_pixel_size(res_txt_width, res_txt_height);
238+
float const pen_x_res_txt = (area_x_full - res_txt_width);
239+
float const pen_y_res_txt = (pen_y_bot_txt + (2.5 * res_txt_height));
240+
draw_context_ptr->move_to(
241+
pen_x_res_txt
242+
, pen_y_res_txt
243+
);
244+
res_txt_layout->show_in_cairo_context(draw_context_ptr);
217245

218246
return PROPAGATE_SIG; // Should propagate to make sure save/restore are processed correctly.
219247
}

calculator_simple/src/app_window.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ class AppWindow :
113113
std::array<Gtk::Button *, 16> btn_arr;
114114

115115
std::string txt_str_top;
116-
// std::string txt_str_bot;
116+
std::string txt_str_bot;
117+
std::string txt_str_opr;
118+
std::string txt_str_res;
117119
};
118120

119121
#endif // HPP_APP_WINDOW_HPP

0 commit comments

Comments
 (0)